gpt4 book ai didi

iphone - 当我在 openGL 中将纹理加载为 RGBA4444 时,设备会消耗多少内存?

转载 作者:行者123 更新时间:2023-12-03 19:12:56 25 4
gpt4 key购买 nike

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

使用这种方法,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)关于这个主题有这样的说法:

The GL stores the resulting texture with internal component resolutions of its own choosing. The allocation of internal component resolution may vary based on any TexImage2D parameter (except target), but the allocation must not be a function of any other state and cannot be changed once established.

但是,根据 iphone dev center ,原生支持RGBA4444。所以我预计你的代码片段会消耗 2MB 的空间。您有理由怀疑它使用的是 2MB 吗?

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

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com