BGRA on iPhone glTexImage2D and glReadPixels

半腔热情 提交于 2019-12-04 19:02:51

The third parameter to glTexImage2D() is the number of color components in the texture, not the pixel ordering of the texture. You want to use GL_RGBA here, or it just won't work.

I don't believe GL_BGRA is supported by glReadPixels() on iOS devices as a color format. While providing pixel data to the textures in BGRA format is recommended by Apple when processing video image frames, I think you're fine in reading that back in RGBA format and then encoding that to disk, as you've described elsewhere.

If you want to see a sample project that takes camera video frames in BGRA, sends them to a texture, processes them using shaders, and then reads the resulting pixels back, you can check out the one I built here.

My own looking around for OpenGL ES2 indicates that this works for the BGRA little endian native format under iOS. Here "pixels" points to a buffer of 32 bit BGRA that would come from a CGBitmapContextCreate() or grabbing the image data from out of a CGImageRef.

  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_BGRA_EXT, GL_UNSIGNED_BYTE, pixels);

See the apple ext for this here. Good discussion of this issue here

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!