Hello
I would like to enable MSAA with my FBO but I do not manage to make it work. I tried to follow the official Opengl sample code, but no luck either. Here is my FBO initialisation :
// Initialising part
// Creation of the multisampled FBO
glGenFramebuffers(1, @MultisampledFBOId);
glBindFramebuffer(GL_FRAMEBUFFER, MultisampledFBOId);
// Color render buffer
glGenRenderbuffers(1, @ColorBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, ColorBufferId);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA, MultisampledFBOWidth, MultisampledFBOHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, ColorBufferId);
// Color buffer texture attachment
glGenTextures(1, @ColorBufferTextureId);
glBindTexture(GL_TEXTURE_2D, ColorBufferTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, MultisampledFBOWidth, MultisampledFBOHeight, 0, GL_RGBA, GL_UNSIGNED_BYTE, nil);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, ColorBufferTextureId, 0);
// Depth render buffer
glGenRenderbuffers(1, @DepthBufferId);
glBindRenderbuffer(GL_RENDERBUFFER, DepthBufferId);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT32, MultisampledFBOWidth, MultisampledFBOHeight);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, DepthBufferId);
// Depth buffer texture attachment
glGenTextures(1, @DepthBufferTextureId);
glBindTexture(GL_TEXTURE_2D, DepthBufferTextureId);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT32, MultisampledFBOWidth, MultisampledFBOHeight, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nil);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, DepthBufferTextureId, 0);
glBindFramebuffer(GL_FRAMEBUFFER, 0);
...
...// Creation of the non-multisampled FBO
...
// Drawing Part
glEnable(GL_MULTISAMPLE);
glBindFramebuffer(GL_FRAMEBUFFER, MultisampledFBOId);
glPushAttrib(GL_VIEWPORT_BIT);
glViewport(0, 0, MultisampledFBOWidth, MultisampledFBOHeight);
...
...// Render the scene
...
glPopAttrib;
glBindFramebuffer(GL_FRAMEBUFFER, 0);
glDisable(GL_MULTISAMPLE);
// Copy the Multisampled FBO into the other
glBindFramebuffer(GL_READ_FRAMEBUFFER, MultisampledFBOId);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, NonMultisampledFBOId);
glBlitFramebuffer(0, 0, MultisampledFBOWidth, MultisampledFBOHeight, 0, 0, NonMultisampledFBOWidth, NonMultisampledFBOHeight, GL_COLOR_BUFFER_BIT, GL_NEAREST);
glBindFramebuffer(GL_READ_FRAMEBUFFER, 0);
glBindFramebuffer(GL_DRAW_FRAMEBUFFER, 0);
...
...// Display the non multisampledFBO Color texture
...
The non-multisampled FBO is created the same way as the other, just with “glRenderbufferStorage” instead of “glRenderbufferStorageMultisample”.
I also found that if I change the two “GL_TEXTURE_2D” in “glFramebufferTexture2D” with “GL_TEXTURE_2D_MULTISAMPLE”, it appears to work, but according to the OpenGL sample code, it should also work without.
Thank you for your help, and sorry for my poor English