Search code examples
copengl-es-2.0framebuffer

Open GL ES 2 - glFramebufferTexture2D with Incomplete Missing Attachment error


I'm new to OpenGL/GLES, I got Incomplete Missing Attachment error when generate framebuffer from EGLImageKHR with below code:

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);

I got GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT when using:

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

and GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT when changing texture to GL_TEXTURE_2D:

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

The image and texture is correct as I can display correctly. I don't know what I'm missing here.


Solution

  • I just found the answer, as it is explained in Raspi forum: Can't render to render buffer

    We have to use GL_TEXTURE_2D in this function:

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

    and have to create an empty texture GL_TEXTURE_2D to bind our framebuffer to that texture before rendering. GL_TEXTURE_EXTERNAL_OES and GL_TEXTURE_2D are different textures, cannot mix them together.