openglopengl-esmultisampling

How to find out if glEnable(GL_MULTISAMPLE) is working for my texture?


I am trying to display an image in full window using two simple GLSL shaders:

Vertex Shader:

#version 330

layout (location = 0) in vec3 aPos;
layout (location = 1) in vec2 aTexCoord;

out vec3 ourColor;
out vec2 TexCoord;

void main()
{
    TexCoord = aTexCoord;
    gl_Position = vec4(aPos, 1.0);
}

and fragment shader:

#version 330

uniform sampler2D tex0; // loading the texture here

in vec3 TexCoord; // texture coordinates
out vec4 fColor; // fragment shader output

void main(){
   fColor = texture2D(tex0,TexCoord);
}

In the OpenGL code, during OpenGL properties setting, I perform

glEnable(GL_MULTISAMPLE);

I read online that the OpenGL will ONLY perform Multisampling if the drivers support this.

Is there anyway in OpenGL we can confirm that the above call is working ? Or is there anyway we can find out if my machine graphics card supports this call ?


Solution

  • In the general case, seeing if your implementation supports multisampling is easy.

    You can get multisampling in two ways: a multisampled default framebuffer, or a multisampled FBO. The latter can only happen by you explicitly creating multisampled images for your FBO. I think you can tell when you're calling glRenderbufferStorageMultisample or glTexStorage2DMultisample, but that doesn't matter, because you can ask any framebuffer (FBO or default) if it has multiple samples.

    To do that, you can bind the framebuffer to the GL_DRAW_FRAMEBUFFER and call glGetIntegerv with GL_SAMPLE_BUFFERS. If that value is 1, then the buffer is mulitsampled. You can get the number of samples by querying GL_SAMPLES.

    Note that GL 4.5 and above allow you to use glGet(Named)FramebufferParameteriv to query these parameters, so that you don't have to bind the FBO.


    All that being said, you have one big problem. Nothing you've done in your rendering will be multisampled. Multisampling cannot anti-alias a textured quad. It only performs anti-aliasing at the edges of triangles. Unless you turn on per-sample shading (which you shouldn't unless you don't like performance), data fetched from texels will not be affected.

    So even if multisampling is going on, your specific rendering operation will not see the effects of it.