About glReadPixels and sample count > 0

Hi everyone,

reading the docs about glReadPixels I found something that is not entirely clear to me:

GL_INVALID_OPERATION is generated if GL_READ_FRAMEBUFFER_BINDING is non-zero, the read framebuffer is complete, and the value of GL_SAMPLE_BUFFERS for the read framebuffer is greater than zero.

Is it allowed to read from the default framebuffer if it is multisampled (“GL_READ_FRAMEBUFFER_BINDING is non-zero”)?

Ok. So this speaks specifically to the “readback from FBO” case (when MSAA is enabled) and has nothing to do with “readback from the default/system framebuffer” (window, pbuffer, etc.)

That’s a separate question unrelated to the above. I don’t see a clear answer in the spec. The behavior of the default framebuffer is left to the window system. The spec does indicate that the default framebuffer can be read back (at least under some circumstances). But I don’t see a statement on behavior when reading back from the default framebuffer if its MSAA. If there isn’t one, this behavior is window-system specific.

In practice, I think I’ve seen some drivers do an implicit downsample before the readback in this case. But AFAICT, that’s not required by the GL spec. Possibly driver-specific and/or window-specific behavior.

For the “in other words” part you put in the parenthesis, I think you meant: “the effective value of SAMPLE_BUFFERS for the read framebuffer is one.”

For the “in other words” part you put in the parenthesis, I think you meant: “the effective value of SAMPLE_BUFFERS for the read framebuffer is one .”

I interpreted the sentence

GL_INVALID_OPERATION is generated if GL_READ_FRAMEBUFFER_BINDING is non-zero…

as “if the current framebuffer for read operations is not the default framebuffer”, so the conditions to generate GL_INVALID_OPERATION are not met. (is this the correct interpretation?)

It was not really an “in other words” part, just wanted to highlight the …is non-zero part, however, I probably misinterpreted it.

That’s right, and exactly.

Ok, sorry. I was just confused by your wording. You were asking about behavior with the default framebuffer and quoting a section that basically said “not the default framebuffer”.

1 Like