Skip to main content
gamedev.net
🔒 Locked

FrameBuffer and MultiSampling

Started by JackOfAllTrades 2 replies 6.1k views
Original Post
JackOfAllTrades
JackOfAllTrades
I'm trying to create a framebuffer with multisampling but if I attach a texture I get the error GL_FRAMEBUFFER_INCOMPLETE_MULTISAMPLE from glCheckFramebufferStatus.

multisample framebuffer initialization code:

// Framebuffer
glGenFramebuffers(1, &rendertarget->frameBuffer);
glBindFramebuffer(GL_FRAMEBUFFER, rendertarget->frameBuffer);

// Multi sample colorbuffer
glGenRenderbuffers(1, &rendertarget->colorBuffer);
glBindRenderbuffer(GL_RENDERBUFFER, rendertarget->colorBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_RGBA8, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_RENDERBUFFER, rendertarget->colorBuffer);

// Multi sample depth buffer
glGenRenderbuffers(1, &rendertarget->depthBuffer);
glBindRenderbuffer(GL_RENDERBUFFER_EXT, rendertarget->depthBuffer);
glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);
glFramebufferRenderbuffer(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_RENDERBUFFER, rendertarget->depthBuffer);

// Create and bind texture
glGenTextures(1, &rendertarget->BaseTexture);
glBindTexture(GL_TEXTURE_2D, rendertarget->BaseTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
// This is where the problem happens:
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, rendertarget->BaseTexture, 0);



The code above works fine until the part where I bind a texture to the frame buffer. This is how I set my pixel format on my window:



int pixelFormat;
UINT numFormats;
float fAttributes[] = {0,0};

int iAttributes[] = { WGL_DRAW_TO_WINDOW_ARB,GL_TRUE,
WGL_SUPPORT_OPENGL_ARB,GL_TRUE,
WGL_ACCELERATION_ARB, WGL_FULL_ACCELERATION_ARB,
WGL_COLOR_BITS_ARB, 24,
WGL_ALPHA_BITS_ARB,8,
WGL_DEPTH_BITS_ARB,16,
WGL_STENCIL_BITS_ARB,0,
WGL_DOUBLE_BUFFER_ARB, GL_TRUE,
WGL_SAMPLE_BUFFERS_ARB, GL_TRUE,
WGL_SAMPLES_ARB, 4,
0, 0};
wglChoosePixelFormatARB( rendertarget->hDC, iAttributes, fAttributes,1, &pixelFormat, &numFormats);
SetPixelFormat( rendertarget->hDC, pixelFormat, NULL );
JackOfAllTrades
JackOfAllTrades
Possibly found the problem. I was creating my context like this:



int attribs[] =
{
WGL_CONTEXT_MAJOR_VERSION_ARB, 3,
WGL_CONTEXT_MINOR_VERSION_ARB, 1,
0
};
instance->hRC = wglCreateContextAttribsARB( instance->hDC, 0, attribs );



I think multi sampling with a texture is not supported until opengl version 3.2 but my other problem is that if I try to create a 3.2 context I am unable to render anything... Does CG 3.0 support OpenGL 3.2?
RobTheBloke
RobTheBloke
Get rid of this line:
[source]glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);[/source]
Multi-sampling depth buffers isn't supported afaik. Also, don't mix EXT and ARB framebuffer tokens( i.e. GL_RENDERBUFFER_EXT is bad!) - they aren't the same.

Are you creating a depth texture too?

[source]
// Create and bind texture
glGenTextures(1, &rendertarget->DepthTexture);
glBindTexture(GL_TEXTURE_2D, rendertarget->DepthTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, 0, GL_DEPTH_COMPONENT , GL_FLOAT, NULL);
glBindRenderBuffer(GL_RENDER_BUFFER, renderTarget->depthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rendertarget->DepthTexture, 0);
[/source]

If it's still causing problems, check for errors after each GL call to figure out what failed.

[source]
#define CHECK_ERR \
if(glGetError() != GL_NO_ERROR) { const char* str = (const char*)gluErrorString(glGetError()); assert(0); }
[/source]
JackOfAllTrades
JackOfAllTrades

Get rid of this line:
[source]glRenderbufferStorageMultisample(GL_RENDERBUFFER, 4, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top);[/source]
Multi-sampling depth buffers isn't supported afaik. Also, don't mix EXT and ARB framebuffer tokens( i.e. GL_RENDERBUFFER_EXT is bad!) - they aren't the same.

Are you creating a depth texture too?

[source]
// Create and bind texture
glGenTextures(1, &rendertarget->DepthTexture);
glBindTexture(GL_TEXTURE_2D, rendertarget->DepthTexture);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, WindowRect.right - WindowRect.left, WindowRect.bottom - WindowRect.top, 0, GL_DEPTH_COMPONENT , GL_FLOAT, NULL);
glBindRenderBuffer(GL_RENDER_BUFFER, renderTarget->depthBuffer);
glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, rendertarget->DepthTexture, 0);
[/source]

If it's still causing problems, check for errors after each GL call to figure out what failed.

[source]
#define CHECK_ERR \
if(glGetError() != GL_NO_ERROR) { const char* str = (const char*)gluErrorString(glGetError()); assert(0); }
[/source]


Actually m[color="#1c2837"]ulti-sampling depth buffers are apparently supported since I am using one at the moment. lol
[color="#1c2837"]

[color="#1c2837"]What I ended up doing was using two frame buffers one for multi sampling and the other for textures. After I draw my scene to the multisample frame buffer I blit it to the texture frame buffer. All is well now!

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.