glCheckFrameBufferStatus()总是返回36054

时间:2016-03-28 13:47:19

标签: opengl-es

我已经实现了使用openGL ES 3.0 for android将YUV颜色空间转换为RGB的示例代码。我是顶点&片段着色器,我定义了会聚公式。

我已经创建了如下纹理,

glActiveTexture(GL_TEXTURE0);
glGenTextures(1, &ytex);
glBindTexture(GL_TEXTURE_2D,ytex);
GLint textureBinding;
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}
// Setup the texture parameters
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
//Define the texture image
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 640, 480, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, yBuffer);

glFramebufferTexture2D(GL_FRAMEBUFFER,GL_COLOR_ATTACHMENT0,GL_TEXTURE_2D,ytex,0);

glActiveTexture(GL_TEXTURE1);
glGenTextures(1, &utex);
glBindTexture(GL_TEXTURE_2D,utex);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 320, 240, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, uBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, utex, 0);
glActiveTexture(GL_TEXTURE2);
glGenTextures(1, &vtex);
glBindTexture(GL_TEXTURE_2D,vtex);
glGetIntegerv(GL_TEXTURE_BINDING_2D, &textureBinding);
if(textureBinding == 0)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, textureBinding, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);

glTexImage2D(GL_TEXTURE_2D, 0, GL_LUMINANCE, 320, 240, 0, GL_LUMINANCE, GL_UNSIGNED_BYTE, NULL);

当我使用glGetError()验证时,我没有收到任何错误。

纹理的输出我不想在视口上显示,而是我想将它存储在一个缓冲区中以便稍后使用输出。所以我创建了framebuffer和渲染缓冲区,如下所示,

//Framebuffer
glGenFramebuffers(1, &fboId);
glBindFramebuffer(GL_FRAMEBUFFER, fboId);


glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, vtex, 0);
//Check the framebuffer status
GLint status = glCheckFramebufferStatus(GL_FRAMEBUFFER);
if(status != GL_FRAMEBUFFER_COMPLETE)
{
        char* infoLog = (char*) malloc(100);
        glGetProgramInfoLog(programObject, status, NULL, infoLog);
        errormsg = infoLog;
        free (infoLog);}

当我验证状态时,它总是返回36054(GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT),但是当我在调用glCheckFrameBufferStatus()之前取消绑定缓冲区时返回GL_FRAMEBUFFER_COMPLETE

     glbindFrameBuffer(GL_FRAMEBUFFER, 0);

所以后来我想使用glReadpixels()读取帧缓冲区的输出,但这也失败了。请有人帮忙解决这个问题吗?

2 个答案:

答案 0 :(得分:2)

36054表示GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT检查您的视图框架是否正确?

答案 1 :(得分:0)

没有实现OpenGL / OpenGL ES支持alpha或亮度纹理作为颜色可渲染。您可以使用GL_R8,GL_RG8复制行为。当您想使用FBO绘制单通道或双通道图像格式时,这两种格式非常有用(因为GL_LUMINANCE,GL_ALPHA和GL_LUMINANCE_ALPHA不是可颜色渲染的格式)。

尝试用GL_R8替换内部格式,并使用GL_RED格式化。