Ale*_*xey 10 iphone opengl-es core-graphics
我正在使用生成图像quartz2d,我想将其用作opengl纹理.棘手的部分是我想尽可能少地使用每个像素的位数,所以我创建cgContext如下:
int bitsPerComponent = 5;
int bytesPerPixel = 2;
int width = 1024;
int height = 1024;
void* imageData = malloc(width * height * bytesPerPixel);
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
CGImageContext context = CGBitmapContextCreate(imageData, width, height, bitsPerComponent, width * bytesPerPixel, colorSpace, kCGImageAlphaNoneSkipFirst);
//draw things into context, release memory, etc.
Run Code Online (Sandbox Code Playgroud)
如文档中表示这里,这是唯一支持的RGB像素格式,CGBitmapContextCreate它采用每像素16位.所以现在我想将这个看起来像"1位跳过 - 5位红色 - 5位绿色 - 5位蓝色"的imageData上传到opengl纹理中.所以我应该这样做:
glGenTextures(1, &texture);
glBindTexture(GL_TEXTURE_2D, texture);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_SHORT_5_5_5_1, imageData);
Run Code Online (Sandbox Code Playgroud)
这是行不通的,因为在这个调用中我将像素格式指定为5 red - 5 green - 5 blue - 1 alpha.这是错误的,但似乎没有匹配核心图形输出的格式.
还有一些其他的选择GL_UNSIGNED_SHORT_1_5_5_5_REV,但那些不会工作的iphone.
我需要一些方法来使用它imageData作为纹理,但我真的不想使用memset等手动交换字节,因为这看起来非常低效.
您确实需要交换位以将其转换为更密集的格式,例如 RGBA551 或 RGB565,因为正如您所注意到的,CGBitmapContext 不支持这些格式进行绘制(为了简单和高效)。
\n\nmemset并不能解决问题,但是Accelerate.framework.
请参阅vImageConvert_ARGB8888toRGB565(\xe2\x80\xa6)和vImageConvert_ARGB8888toARGB1555(\xe2\x80\xa6),适用于 iOS 5 及更高版本。
| 归档时间: |
|
| 查看次数: |
1522 次 |
| 最近记录: |