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).
- OpenGL 3.1 + NV_explicit_multisample - this should be most compatible, even with ATI cards and old NV drivers
- OpenGL 3.2 + core multisample textures
- OpenGL 3.2 + NV_explicit_multisample

