使用此方法加载的纹理将消耗多少内存?

使用这种方法,1024x1024 的纹理会消耗 4MB 吗? (无论将其加载为 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);

}

最佳答案

GL ES 1.1.12 specification (pdf) 在这个问题上有这样的说法:



但是,根据 iphone dev center , native 支持 RGBA4444。所以我希望它使用您的代码片段消耗 2MB。你有理由怀疑它使用的是 2MB 吗?

关于iphone - 当我在 openGL 中加载纹理为 RGBA4444 时,设备消耗了多少内存?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/2255885/

10-10 04:27