ZillaLib icon indicating copy to clipboard operation
ZillaLib copied to clipboard

Questions/suggestions about ZL_Surface

Open tobybear opened this issue 3 years ago • 0 comments

  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;
}
  1. 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.

  2. 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?

tobybear avatar Feb 12 '22 21:02 tobybear