Framebuffer Incomplete Error On glTexImage2D OpenGL4.5

I’m trying to create a basic framebuffer with two color attachments and a depth + stencil attachment, all are plain textures.

This is the OpenGL code that is eventually executed behind my C++ abstraction:

GLuint framebuffer;
glGenFramebuffers(1, &framebuffer);
glBindFramebuffer(GL_FRAMEBUFFER, framebuffer);

GLuint color_attachment;
glGenTextures(1, &color_attachment);
glBindTexture(GL_TEXTURE_2D, color_attachment);

glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_BORDER);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_BORDER);

glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1024, 576, 0, GL_RGB,
             GL_UNSIGNED_BYTE, nullptr);  // Here is the error

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

// More OpenGL code here, but unimportant since the error is already thrown

// glCheckFramebufferStatus succeeds...
if (!(glCheckFramebufferStatus(GL_FRAMEBUFFER) == GL_FRAMEBUFFER_COMPLETE)) {
    SPDLOG_CRITICAL("Framebuffer {} is incomplete", framebuffer);
    std::exit(1);
}

Now, the strange problem is this:
When the code oddly reaches the glTexImage2D function, OpenGL will print this message to the console (I have set the error callback, because I’m using OpenGL >= 4.3) with severity GL_DEBUG_SEVERITY_MEDIUM:

FBO incomplete: no attachments and default width or height is 0 [-1]

But the code continues with no problems and glCheckFramebufferStatus returns GL_FRAMEBUFFER_COMPLETE, which means that the framebuffer is complete.

I don’t understand what is the problem. I saw this error message on the internet only once, but with no context and no help. Can somebody help me, please?

I’m on Linux, OpenGL version 4.5 (Core Profile) Mesa 20.0.8 and driver Intel Open Source Technology Center.

Thank you!

Well, there isn’t really a problem. This is arguably a “flaw” in the driver (it’s not really a bug as the specification doesn’t really dictate what is supposed to be logged, other than for errors), generating a debug message regarding an incomplete framebuffer at a point where it doesn’t matter whether the framebuffer is incomplete.

The message itself isn’t wrong; what’s wrong is the fact that it’s being generated. All framebuffers are incomplete when first created as they have no attachments and their default width and height are zero. But that shouldn’t matter unless you actually try to use it (render to it or read pixels from it) or explicitly check its status.

It’s possible that the driver validates the bound FBO whenever any texture is modified (bear in mind that the texture is created by the glBindTexture call, initially with zero width and height, then modified by the glTexImage2D call). It would be reasonable to emit this message if a change to a texture which was actually attached to the bound FBO resulted in the FBO being incomplete, but it seems to do it whenever there’s any change to a texture while an incomplete FBO is bound.

I suspect that initialising the texture first then binding the FBO immediately before the glFramebufferTexture2D call will avoid the message. Creating the texture with glTextureStorage2D (note: Texture, not Tex) may also do so, as that should avoid the create-on-bind behaviour which results in the texture briefly having zero width and height.

1 Like

Right now I replaced the glTexImage2D call with

glTexStorage2D(GL_TEXTURE_2D, 1, internal_format, width, height);

and there is no error.

I forgot to mention that I’m using FLTK to create the OpenGL context. Maybe there are some interferences with FLTK’s code, but after I read your reply, I think that you’re right.