schellingb / ZillaLib

Sleek multiplatform C++ 2D and 3D game creation!
https://zillalib.github.io/
zlib License
109 stars 8 forks source link

Questions/suggestions about ZL_Surface #16

Open tobybear opened 2 years ago

tobybear commented 2 years ago
  1. ZL_Surface does not seem to free the allocated memory for the texture if it gets reassigned. I know this is probably a not very common use case, but consider this:
    
    srfBuffer = ZL_Surface(pixelsA, w, h, 3);
    srfBuffer = ZL_Surface(pixelsB, w, h, 3);
    srfBuffer = ZL_Surface(pixelsC, w, h, 3);
The texture resources for the first two calls are not freed and eat up memory (the pixelsA/B/C buffer remain constant).
Even when doing a default constructor assign inbetween the calls, it doesn't change:
`srfBuffer = ZL_Surface();`
I haven't looked further into this, but as a quick fix, added my own clearing function, although I had to make the imp structures public:

void ZL_Surface::Clear() { if (impl->tex) { delete impl->tex; } delete impl; impl = NULL; }



2. In ZL_Texture_Impl::CreateFromBitmap(), is it necessary to do a memcpy of the whole provided buffer? I know the pixel buffer parameter pixels is const, but the memcpy introduces a bit of overhead.

3. Is there an easy way to update an existing ZL_Surface (created from a pixel buffer) with a new/modified buffer without re-creating everything? Maybe if dimensions are identical, just calling the glTexImage2D/glTexSubImage2D again.
I guess LoadBitmapIntoTexture() would already do this, but I can't access the implementation easily, right?