EAGL - Double allocation of texture memory?
I am using a 1024x1024 texture page in Opengl, and everything loads and displays fine. However when looking in Leaks tool, I see that the memory for the texutre page is double what it should be. (1024x1024x4 = 4.4mb, but 8.8 are allocated). I'm using code based on the Apple default OpenGL ES project. I think I'm freeing everything possible. Leaks says that either GLClear or GLRendererFloat are malloc'ing 4.2 mb.. Any ideas? Here is my texture loading code:
spriteImage = [UIImage imageNamed:[list objectAtIndex:i]].CGImage;
// Get the width and height of the image
width = CGImageGetWidth(spriteImage);
height = CGImageGetHeight(spriteImage);
// Texture dimensions must be a power of 2. If you write an application that allows users to supply an image,
// you'll want to add code that checks the dimensions and takes appropriate action if they are not a power of 2.
if(spriteImage) {
// Allocated memory needed for the bitmap context
spriteData = (GLubyte *) malloc(width * height * 4);
// Uses the bitmatp creation function provided by the Core Graphics framework.
spriteContext = CGBitmapContextCreate(spriteData, width, height, 8, width * 4, CGImageGetColorSpace(spriteImage), kCGImageAlphaPremultipliedLast);
// After you create the context, you can draw the sprite image to the context.
CGContextDrawImage(spriteContext, CGRectMake(0.0, 0.0, (CGFloat)width, (CGFloat)height), spriteImage);
// You don't need the context at this point, so you need to release it to avoid memory leaks.
CGContextRelease(spriteContext);
// Use OpenGL ES to generate a name for the texture.
glGenTextures(1, &spriteTextures);
// Bind the texture name.
glBindTexture(GLTEXTURE2D, spriteTextures);
// Speidfy a 2D texture image, provideing the a pointer to the image data in memory
glTexImage2D(GLTEXTURE2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GLUNSIGNEDBYTE, spriteData);
// Release the image data
free(spriteData);
glTexParameteri(GLTEXTURE2D, GLTEXTURE_MINFILTER, GL_LINEAR);
glTexParameteri(GLTEXTURE2D, GLTEXTURE_MAGFILTER, GL_LINEAR);
}
CGContextRelease(spriteContext);
CGImageRelease(spriteImage);
Thank you very much
Skynet MBP, Mac OS X (10.5.4)