使用GLSL转换色彩空间的问题
hi,我要用opengles做一个yuv2rgb的功能,参考了一些网上的代码。
这个功能的大约思路是:
有pY,pU,pV三个数据源,生成 m_TextureY,m_TextureU,m_TextureV三个纹理。
把这三个纹理绑定到framebuffer的attament上。这个三个纹理在着色器中对应uniform sampler2D yTexture, uTexture, vTexture;
最后,在着色器中使用这三个纹理。
最后的显示结果不对,更换了一下测试数据,应只有yTexture这个纹理起作用了。各位大大指教一下,说说问题出在什么地方?怎么修改?
在代码里设定纹理的代码如下:
void Opengles2Render::Initialize(int width, int height)
{
//生成和绑定framebuffer
glGenFramebuffers(1, &m_framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, m_framebuffer);
//生成和绑定一个renderbuffer
glGenRenderbuffers(1, &m_renderbuffer);
glBindRenderbuffer(GL_RENDERBUFFER, m_renderbuffer);
// Set up the texture state.
glEnable(GL_TEXTURE_2D);
glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &m_TextureY);
glBindTexture(GL_TEXTURE_2D, m_TextureY);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, picWidth, picHight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pY);
glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &m_TextureU);
glBindTexture(GL_TEXTURE_2D, m_TextureU);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, picWidth, picHight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pU);
glActiveTexture(GL_TEXTURE2);
glGenTextures(1, &m_TextureV);
glBindTexture(GL_TEXTURE_2D, m_TextureV);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, picWidth, picHight, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, pV);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_RENDERBUFFER, m_TextureY);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_DEPTH_ATTACHMENT,GL_RENDERBUFFER, m_TextureU);
glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER, m_TextureV);
//glFramebufferRenderbuffer(GL_FRAMEBUFFER,GL_STENCIL_ATTACHMENT,GL_RENDERBUFFER, m_renderbuffer);
......
片段着色器如下:
uniform sampler2D yTexture;
uniform sampler2D uTexture;
uniform sampler2D vTexture;
varying highp vec2 _texcoord;
void main()
{
//gl_FragColor = texture2D(sampler0, _texcoord);
mediump vec3 yuv;
lowp vec3 rgb;
yuv.x = texture2D(yTexture, _texcoord).r;
yuv.y = texture2D(uTexture, _texcoord).r - 0.5;
yuv.z = texture2D(vTexture, _texcoord).r - 0.5;
rgb = mat3(1, 1, 1,
0, -.21482, 2.12798,
1.28033, -.38059, 0) * yuv;
gl_FragColor = vec4(rgb, 1);
}
[解决办法]
无一人回复,还是我来回复吧