如何在iPhone/iPad上的OpenGL ES中压缩纹理?

如何在iPhone/iPad上的OpenGL ES中压缩纹理?,iphone,ipad,opengl-es,Iphone,Ipad,Opengl Es,我正在制作一个需要OpenGL做翻转动画的iPad应用程序。我有一个正面图像纹理和一个背面图像纹理。这两种纹理都是屏幕截图 // Capture an image of the screen UIGraphicsBeginImageContext(view.bounds.size); [view.layer renderInContext:UIGraphicsGetCurrentContext()]; image = UIGraphicsGetImageFromCurrentImageConte

我正在制作一个需要OpenGL做翻转动画的iPad应用程序。我有一个正面图像纹理和一个背面图像纹理。这两种纹理都是屏幕截图

// Capture an image of the screen
UIGraphicsBeginImageContext(view.bounds.size);
[view.layer renderInContext:UIGraphicsGetCurrentContext()];
image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();

// Allocate some memory for the texture
GLubyte *textureData = (GLubyte*)calloc(maxTextureSize*4, maxTextureSize);

// Create a drawing context to draw image into texture memory
CGContextRef textureContext = CGBitmapContextCreate(textureData, maxTextureSize, maxTextureSize, 8, maxTextureSize*4, CGImageGetColorSpace(image.CGImage), kCGImageAlphaPremultipliedLast);
CGContextDrawImage(textureContext, CGRectMake(0, maxTextureSize-size.height, size.width, size.height), image.CGImage);
CGContextRelease(textureContext);
// ...done creating the texture data

[EAGLContext setCurrentContext:context];

glGenTextures(1, &textureToView);
glBindTexture(GL_TEXTURE_2D, textureToView);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, maxTextureSize, maxTextureSize, 0, GL_RGBA, GL_UNSIGNED_BYTE, textureData);

// free texture data which is by now copied into the GL context
free(textureData);

每个纹理占用大约8MB的内存,这对于iPhone/iPad应用程序来说是不可接受的。有人能告诉我如何压缩纹理以减少内存使用吗?

更高版本的OpenGL支持压缩纹理。您可以在上传纹理数据时让OpenGL对其进行压缩,也可以自己进行压缩并将预压缩的数据提供给OpenGL

OpenGL中压缩纹理支持的ARB规范

下面是对一种特殊压缩格式的描述

并且特定于OpenGL ES此压缩格式:

我不相信较旧的OpenGL引用适用于OpenGL ES,因此在这种情况下这些可能没有用处。iPhone专门使用PowerVR纹理压缩,因此我不确定爱立信纹理压缩的最后一个参考是否适用于此处。我建议研究设备上的PowerVR纹理压缩,但这个问题的答案似乎表明这是不可能的:。然而,可能有不同的方法来实现这一点。@BradLarson我认为我错了。我认为更好的方法是缩小屏幕截图(512*512)并缩放以适应纹理(1024*1024)。这样,现在每个纹理都是1MB。但我不知道如何做到这一点。有什么帮助吗?