Corrected memory leak
This commit is contained in:
parent
0dfc7fffff
commit
04caf1c262
1 changed files with 6 additions and 3 deletions
|
@ -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);
|
||||||
|
@ -1924,7 +1927,7 @@ void rlglGenerateMipmaps(Texture2D texture)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture.id);
|
else TraceLog(WARNING, "[TEX ID %i] Mipmaps can not be generated", texture.id);
|
||||||
|
|
||||||
glBindTexture(GL_TEXTURE_2D, 0);
|
glBindTexture(GL_TEXTURE_2D, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue