OpenGL 3.1 explicit_multisample VS OpenGL 3.2 multisample textures

23.09.2009 12:04 in OpenGL

I wanted to compare NV_explicit_multisample and new multisample textures that are now part of OpenGL 3.2 core.

Results:

  • both methods give exactly same results (pixel accurate)
  • FPS is also exactly the same
  • multisample textures are little easier to use

To use multisample textures, you need to change just few lines in your FBO code:

Non-MS:

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D, tex);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA32F, 1024, 768, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex, 0);

BTW - here's the tip: 7th and 8th parameters in glTexImage2D (GL_RGBA, GL_UNSIGNED_BYTE in this case) doesn't matter if you pass NULL pointer to data. They are used only to convert data to texture format (so you can upload integer data to float texture). However they must be valid enums, otherwise function will fail.

And now MS version:

glGenTextures(1, &tex);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);
glTexImage2DMultisample(GL_TEXTURE_2D_MULTISAMPLE, 4, GL_RGBA32F, 1024, 768, false);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D_MULTISAMPLE, tex, 0);

Pretty easy, huh? And to bind this texture to sampler, you only need to change GL_TEXTURE_2D to GL_TEXTURE_2D_MULTISAMPLE:

glActiveTexture(GL_TEXTURE0);
glBindTexture(GL_TEXTURE_2D_MULTISAMPLE, tex);

So now the fragment shader part. Take code from my previous post and make following changes:

  • #extension GL_NV_explicit_multisample : enable is obviously unnecessary
  • change all samplerRenderbuffer to sampler2DMS
  • change texelFetchRenderbuffer to texelFetch
  • change textureSizeRenderbuffer to textureSize

That's it. I think it's quite easy to use.

BTW. I've made various versions of my GI demo. I've made also a OpenGL 3.1 version that should run on all DX10 cards (NV & ATI). I'd be glad if you test it (and tell me it actually works).

Comments:

  1. John Aughey

    John Aughey:

    Beautiful. Thank you for sharing this.

    24.09.2009 23:48:41

  2. oscarbg

    oscarbg:

    Hi,
    this three exes still crash at init on ATI 4850.
    Now tested also with catalyst 9.10 rc7
    Waiting for yo to share the code so I can try fix it!!

    25.09.2009 16:31:37

  3. Damien

    Damien:

    Hi,
    First I wanted to thank you for this post, in fact i like the whole blog.

    Please can you tell me when we'll be able to read the code from this demo ?

    Damien,
    France

    10.02.2010 15:37:48

  4. mindbound

    mindbound:

    Seconded the wish for the source code. :)

    08.03.2010 10:14:17

Leave comment: