Skip to content

Commit

Permalink
V2.02 Plugged a leak
Browse files Browse the repository at this point in the history
Added a destructor for decal, optimised pixel construction
  • Loading branch information
OneLoneCoder authored Apr 13, 2020
1 parent 3621885 commit 13bb251
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions olcPixelGameEngine.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
olcPixelGameEngine.h
+-------------------------------------------------------------+
| OneLoneCoder Pixel Game Engine v2.01 |
| OneLoneCoder Pixel Game Engine v2.02 |
| "What do you need? Pixels... Lots of Pixels..." - javidx9 |
+-------------------------------------------------------------+
Expand Down Expand Up @@ -131,6 +131,7 @@
David Barr, aka javidx9, ©OneLoneCoder 2018, 2019, 2020
2.01: Made renderer and platform static for multifile projects
2.02: Added Decal destructor, optimised Pixel constructor
*/

//////////////////////////////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -453,6 +454,7 @@ namespace olc
{
public:
Decal(olc::Sprite* spr);
virtual ~Decal();
void Update();

public: // But dont touch
Expand Down Expand Up @@ -499,6 +501,7 @@ namespace olc
virtual void DrawDecalQuad(const olc::DecalInstance& decal) = 0;
virtual uint32_t CreateTexture(const uint32_t width, const uint32_t height) = 0;
virtual void UpdateTexture(uint32_t id, olc::Sprite* spr) = 0;
virtual uint32_t DeleteTexture(const uint32_t id) = 0;
virtual void ApplyTexture(uint32_t id) = 0;
virtual void UpdateViewport(const olc::vi2d& pos, const olc::vi2d& size) = 0;
virtual void ClearBuffer(olc::Pixel p, bool bDepth) = 0;
Expand Down Expand Up @@ -789,7 +792,8 @@ namespace olc
{ r = 0; g = 0; b = 0; a = nDefaultAlpha; }

Pixel::Pixel(uint8_t red, uint8_t green, uint8_t blue, uint8_t alpha)
{ r = red; g = green; b = blue; a = alpha; }
{ n = red | (green << 8) | (blue << 16) | (alpha << 24); } // Thanks jarekpelczar


Pixel::Pixel(uint32_t p)
{ n = p; }
Expand Down Expand Up @@ -968,6 +972,15 @@ namespace olc
renderer->UpdateTexture(id, sprite);
}

Decal::~Decal()
{
if (id != -1)
{
renderer->DeleteTexture(id);
id = -1;
}
}



// O------------------------------------------------------------------------------O
Expand Down Expand Up @@ -2386,6 +2399,12 @@ namespace olc
return id;
}

uint32_t DeleteTexture(const uint32_t id) override
{
glDeleteTextures(1, &id);
return id;
}

void UpdateTexture(uint32_t id, olc::Sprite* spr) override
{
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, spr->width, spr->height, 0, GL_RGBA, GL_UNSIGNED_BYTE, spr->GetData());
Expand Down

0 comments on commit 13bb251

Please sign in to comment.