mirror of
https://github.com/raysan5/raylib.git
synced 2025-09-27 13:38:30 +00:00
Corrected memory leak
This commit is contained in:
@@ -1892,9 +1892,9 @@ void rlglGenerateMipmaps(Texture2D texture)
|
|||||||
void *data = rlglReadTexturePixels(texture);
|
void *data = rlglReadTexturePixels(texture);
|
||||||
|
|
||||||
// NOTE: data size is reallocated to fit mipmaps data
|
// NOTE: data size is reallocated to fit mipmaps data
|
||||||
|
// NOTE: CPU mipmap generation only supports RGBA 32bit data
|
||||||
int mipmapCount = GenerateMipmaps(data, texture.width, texture.height);
|
int mipmapCount = GenerateMipmaps(data, texture.width, texture.height);
|
||||||
|
|
||||||
// TODO: Adjust mipmap size depending on texture format!
|
|
||||||
int size = texture.width*texture.height*4; // RGBA 32bit only
|
int size = texture.width*texture.height*4; // RGBA 32bit only
|
||||||
int offset = size;
|
int offset = size;
|
||||||
|
|
||||||
@@ -1915,6 +1915,9 @@ void rlglGenerateMipmaps(Texture2D texture)
|
|||||||
|
|
||||||
TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture.id);
|
TraceLog(WARNING, "[TEX ID %i] Mipmaps generated manually on CPU side", texture.id);
|
||||||
|
|
||||||
|
// NOTE: Once mipmaps have been generated and data has been uploaded to GPU VRAM, we can discard RAM data
|
||||||
|
free(data):
|
||||||
|
|
||||||
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
#elif defined(GRAPHICS_API_OPENGL_33) || defined(GRAPHICS_API_OPENGL_ES2)
|
||||||
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
glGenerateMipmap(GL_TEXTURE_2D); // Generate mipmaps automatically
|
||||||
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texture.id);
|
TraceLog(INFO, "[TEX ID %i] Mipmaps generated automatically", texture.id);
|
||||||
@@ -3106,7 +3109,7 @@ static int GenerateMipmaps(unsigned char *data, int baseWidth, int baseHeight)
|
|||||||
int mipmapCount = 1; // Required mipmap levels count (including base level)
|
int mipmapCount = 1; // Required mipmap levels count (including base level)
|
||||||
int width = baseWidth;
|
int width = baseWidth;
|
||||||
int height = baseHeight;
|
int height = baseHeight;
|
||||||
int size = baseWidth*baseHeight*4; // Size in bytes (will include mipmaps...)
|
int size = baseWidth*baseHeight*4; // Size in bytes (will include mipmaps...), RGBA only
|
||||||
|
|
||||||
// Count mipmap levels required
|
// Count mipmap levels required
|
||||||
while ((width != 1) && (height != 1))
|
while ((width != 1) && (height != 1))
|
||||||
|
Reference in New Issue
Block a user