PDA

View Full Version : Multisample and multiple framebuffers



Taicoon
05-28-2010, 03:52 PM
I have an application in which I create a large offscreen framebuffer for rendering and then copy the result into the window displaybuffer using glBlitFramebufferEXT. This works well and lets me render the graphics at the required resolution even when the (preview) window is resized.

Multisampling is giving me trouble though.
If I select a x4 multisampling pixelformat (like 44) by SetPixelFormat and the create my context wglCreateContext, then it does not give an error. I just get a valid context and can render fine after setting glEnable(GL_MULTISAMPLE_ARB)... but it is not multisampled which glGetIntegerv(GL_SAMPLES,&numSamples) also tells me. It returns 0.

I then tried not rendering to my framebuffer (bound to the default fb=0) and dropping the blit. Now everything worked fine with antialiasing.

It makes me think that somehow I get a context with multisampling, but this is turned off when I use an incompatible framebuffer. The question is then why my framebuffer is not good. I only need color in it, not stencil or depth, so I only make a color texture and bind it. Is this not enough? What else should it contain...? or is my problem something else entirely?


-----------------------------------

//create frame buffer and make it current by binding
GLuint frameBufferID;
glGenFramebuffersEXT(1,&frameBufferID);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, frameBufferID);

//create texture for color
GLuint colorTextureID;
glGenTextures(1,&colorTextureID);
glBindTexture(GL_TEXTURE_2D,colorTextureID);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
glTexImage2D (GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);

//bind color texture
glBindTexture(GL_TEXTURE_2D,colorTextureID);//TODO: is this required?
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, colorTextureID, 0);

//bind this new framebuffer
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, frameBufferID);

Alfonse Reinheart
05-28-2010, 05:55 PM
If I select a x4 multisampling pixelformat (like 44) by SetPixelFormat and the create my context wglCreateContext, then it does not give an error. I just get a valid context and can render fine after setting glEnable(GL_MULTISAMPLE_ARB)... but it is not multisampled which glGetIntegerv(GL_SAMPLES,&numSamples) also tells me. It returns 0.

When are you asking for the number of samples? If it is while you have an FBO bound, then it will return the number of samples in the FBO. So, unless you created multisample buffers for your FBO, you will get 0.

You shouldn't be using the pixel format for multisampling if you're doing your multisampled rendering to an FBO. You should use a non-multisample default framebuffer and use multisampled renderbuffers.

Taicoon
05-29-2010, 05:13 AM
I changed the frame buffer creation and explicitly defined the multisample leven in it. Now I have multisampling.

I now have another problem relating to the blit, but I have put that in a new thread since it does not seem to have anything to do with multisampling per se.