2

在 iOS 设备上(我试过 ipad1 和 ipad2)glreadpixel 适用于 RGBA 像素格式,但对于 BGRA 像素格式则不起作用。在下面的代码中,我使用 GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 来获取原生像素格式,即 GL_BGRA_EXT,但 glgeterror 返回 GL_INVALID_ENUM。这与 opengl 文档http://www.khronos.org/opengles/sdk/1.1/docs/man/glReadPixels.xml中的声明相矛盾,如果格式不是 GL_RGBA 或 GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES 的值,则会生成 GL_INVALID_ENUM。

有人对此有任何看法吗?

GLint native_format;
GLint native_type;

glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES, &native_format);
glGetIntegerv(GL_IMPLEMENTATION_COLOR_READ_TYPE_OES, &native_type);

NSLog(@"native_format: 0x%04X", native_format);
NSLog(@"native_type: 0x%04X", native_type);

//screen size
CGSize s = [[CCDirector sharedDirector] winSize];
int tx = s.width;
int ty = s.height;

int bitsPerPixel=32;                

int bytesPerRow = (bitsPerPixel/8) * tx;
NSInteger myDataLength = bytesPerRow * ty;

GLubyte *buffer = malloc(sizeof(GLubyte)*myDataLength);

[target begin];
glReadPixels(0,0,tx,ty,native_format,native_type, buffer);
NSLog(@"gl get error %d", glGetError());
[target end];
4

0 回答 0