Search code examples
openglintegerfbomultisampling

How does OpenGL resolve a multisampled FBO-attached color buffer whose pixel format is integer-based?


Suppose I format a renderbuffer like so:

glRenderbufferStorageMultisample(GL_RENDERBUFFER, sampleCount, GL_R32UI, imageWidth, imageHeight);

where sampleCount >= 2.

And suppose I attach it to an FBO, draw some stuff into it, blit it to a non-multisampled FBO to resolve the multisampling, and finally call glReadPixels to get back some unsigned integers (one per pixel) from the resulting image.

What integers will I get?

Might some of them be a blend of multiple samples, or is only one sample per pixel chosen in this case (presumably because an integer-based format is not considered to be blendable in this context), with the other samples being discarded? Or does something else happen?


Solution

  • On page 511 of the OpenGL 4.5 spec, under section 18.3.1 "Blitting Pixel Rectangles", it says (emphasis added):

    If the read framebuffer is multisampled (its effective value of SAMPLE_BUFFERS is one) and the draw framebuffer is not (its value of SAMPLE_BUFFERS is zero), the samples corresponding to each pixel location in the source are converted to a single sample before being written to the destination. filter is ignored. If the source formats are integer types or stencil values, a single sample’s value is selected for each pixel.

    So it choses one sample per pixel, without specifying which of the samples.