On iOS device (I tried ipad1 and ipad2) glreadpixel works for the RGBA pixel format, but for BGRA pixel format it does not work. In开发者_C百科 the code below I use GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES to get the native pixel format, which is GL_BGRA_EXT, but glgeterror returns GL_INVALID_ENUM. This contradicts the statement in the opengl doc http://www.khronos.org/opengles/sdk/1.1/docs/man/glReadPixels.xml which says GL_INVALID_ENUM is generated if format is not GL_RGBA or the value of GL_IMPLEMENTATION_COLOR_READ_FORMAT_OES.
Does anyone have any take on this?
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];
精彩评论