打开GL ES 2 - glFramebufferTexture2D,其中包含不完整的丢失附件错误

时间:2018-01-13 10:46:04

标签: c opengl-es-2.0 framebuffer

我是OpenGL / GLES的新手,当我从EGLImageKHR生成带有以下代码的帧缓冲区时,我得到了不完整的丢失附件错误:

GLuint texture;
GLuint framebuffer;

EGLImageKHR image = eglCreateImageKHR(display,
                                      EGL_NO_CONTEXT,
                                      EGL_NATIVE_PIXMAP_KHR,
                                      (EGLClientBuffer)&pixmap,
                                      NULL);
assert(image != EGL_NO_IMAGE_KHR);

glGenTextures(1, &texture);
glGenTextures(1, &framebuffer);

glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_EXTERNAL_OES, GL_TEXTURE_MAG_FILTER, GL_NEAREST);

glBindTexture(GL_TEXTURE_EXTERNAL_OES, textureId);
glEGLImageTargetTexture2DOES(GL_TEXTURE_EXTERNAL_OES, image);

glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, 
                       GL_COLOR_ATTACHMENT0, 
                       GL_TEXTURE_EXTERNAL_OES, 
                       texture, 
                       0);
glCheckFramebufferStatus(GL_FRAMEBUFFER);
glBindFramebuffer(GL_FRAMEBUFFER, 0);

eglDestroyImageKHR(display,image);
glBindTexture(GL_TEXTURE_EXTERNAL_OES, 0);

使用时我得到了GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT:

glFramebufferTexture2D(GL_FRAMEBUFFER, 
                       GL_COLOR_ATTACHMENT0, 
                       GL_TEXTURE_EXTERNAL_OES, 
                       texture, 
                       0);
将纹理更改为GL_TEXTURE_2D时

和GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT:

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

图像和纹理正确,因为我可以正确显示。我不知道我在这里失踪了什么。

1 个答案:

答案 0 :(得分:0)

我刚刚找到了答案,正如Raspi论坛中所解释的那样: Can't render to render buffer

我们必须在此功能中使用GL_TEXTURE_2D:

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

并且必须创建一个空纹理GL_TEXTURE_2D以在渲染之前将我们的帧缓冲区绑定到该纹理。 GL_TEXTURE_EXTERNAL_OES和GL_TEXTURE_2D是不同的纹理,不能将它们混合在一起。