When I load a texture like RGBA4444 into openGL, how much memory is consumed in the device?

How much memory will the texture loaded with this method consume?

Using this method, texture 1024x1024 consumes 4 MB? (regardless of loading it as RGBA4444)?

-(void)loadTexture:(NSString*)nombre { CGImageRef textureImage =[UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:nombre ofType:nil]].CGImage; if (textureImage == nil) { NSLog(@"Failed to load texture image"); return; } // Dimensiones de nuestra imagen imageSizeX= CGImageGetWidth(textureImage); imageSizeY= CGImageGetHeight(textureImage); textureWidth = NextPowerOfTwo(imageSizeX); textureHeight = NextPowerOfTwo(imageSizeY); GLubyte *textureData = (GLubyte *)calloc(1,textureWidth * textureHeight * 4); CGContextRef textureContext = CGBitmapContextCreate(textureData, textureWidth,textureHeight,8, textureWidth * 4,CGImageGetColorSpace(textureImage),kCGImageAlphaPremultipliedLast ); CGContextDrawImage(textureContext, CGRectMake(0.0, 0.0, (float)textureWidth, (float)textureHeight), textureImage); /**************** Convert data to RGBA4444******************/ //Convert "RRRRRRRRRGGGGGGGGBBBBBBBBAAAAAAAA" to "RRRRGGGGBBBBAAAA" void *tempData = malloc(textureWidth * textureHeight * 2); unsigned int* inPixel32 = (unsigned int*)textureData; unsigned short* outPixel16 = (unsigned short*)tempData; for(int i = 0; i < textureWidth * textureHeight ; ++i, ++inPixel32) *outPixel16++ = ((((*inPixel32 >> 0) & 0xFF) >> 4) << 12) | // R ((((*inPixel32 >> 8) & 0xFF) >> 4) << 8) | // G ((((*inPixel32 >> 16) & 0xFF) >> 4) << 4) | // B ((((*inPixel32 >> 24) & 0xFF) >> 4) << 0); // A free(textureData); textureData = tempData; // Ya no necesitamos el bitmap, lo liberamos CGContextRelease(textureContext); glGenTextures(1, &textures[0]); glBindTexture(GL_TEXTURE_2D, textures[0]); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, textureWidth, textureHeight, 0, GL_RGBA, GL_UNSIGNED_SHORT_4_4_4_4, textureData); free(textureData); //glEnable(GL_BLEND); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); 

}

+4
source share
3 answers

specification GL ES 1.1.12 (pdf) has this to say on this subject:

GL stores the resulting texture with internal components of its own choice. The distribution of the internal resolution of the components can be on any TexImage2D parameter (except the target), but the distribution should not be a function of any other state and cannot be changed after its installation.

However, according to the iphone dev center , RGBA4444 is supported. Therefore, I expect it to consume 2 MB with your code snippet. Do you have any reason to doubt it using 2 MB?

+3
source

There is no way in OpenGL to find out how much video memory texture uses.

There is also no single answer to the question of where to start. Such details depend on the graphics card, driver version, platform.

+1
source

From the OpenGL ES Programming Guide for iOS :

If your application cannot use compressed textures, consider using a lower pixel format. textures in RGB565, RGBA5551 or RGBA4444 format uses half the texture memory in RGBA8888 format. using RGBA8888 only when your application needs this level of quality.

Beyond this paragraph, they also really recommend using compressed PVRTC textures, as they save even more memory.

+1
source

Source: https://habr.com/ru/post/1301166/


All Articles