问题描述
查看文档,我应该能够使用BGRA作为纹理的内部格式。我提供纹理与BGRA数据(使用GL_RGBA8_OES为glRenderbufferStorage,因为它似乎BGRA不允许)。但是,以下操作无效:
Looking at the docs, I should be able to use BGRA for the internal format of a texture. I am supplying the texture with BGRA data (using GL_RGBA8_OES for glRenderbufferStorage as it seems BGRA there is not allowed). However, the following does not work:
glTexImage2D(GL_TEXTURE_2D, 0, **GL_BGRA**, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
...
glReadPixels(0, 0, w,h, GL_BGRA, GL_UNSIGNED_BYTE,buffer, 0);
这给了我一个黑框:
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
...
glReadPixels(0, 0, w,h, **GL_BGRA**, GL_UNSIGNED_BYTE,buffer, 0);
这样做有效,但是蓝色/红色是反转的(我提供BGRA数据到纹理) :
And this does work, but the blues/reds are inverted (I supply BGRA data to the texture):
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA,w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, buffer);
...
glReadPixels(0, 0, w,h, **GL_RGBA**, GL_UNSIGNED_BYTE,buffer, 0);
...为什么我不能使用BGRA?我注意到glRenderbufferStorage似乎不接受任何BGRA格式...我真的很困惑。
...why can't I just use BGRA throughout? I do notice that glRenderbufferStorage does not seem to accept any BGRA formats...I'm really confused. BGRA is the only suitable format my data is in, as it comes from the iphone's camera.
推荐答案
<$>的第三个参数是
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.
我不相信<$在iOS设备上以 glReadPixels()
支持c $ c> GL_BGRA 虽然Apple在处理视频图像帧时推荐使用BGRA格式的纹理提供像素数据,但我认为你可以读取RGBA格式的数据,然后将其编码到磁盘,就像你在其他地方所描述的那样。
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.
如果你想看到一个示例项目,它在BGRA中使用摄像机视频帧,将它们发送到纹理,使用着色器处理它们,然后读取生成的像素,请点击。
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.
这篇关于BGRA在iPhone上的glTexImage2D和glReadPixels的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!