Skip to main content
GameDev.net gamedev.net
🔒 Locked

FBO blit framebuffer

Started by Ne_cro May 9, 2010 at 2:38 PM 3 replies 9.6k views
Original Post
Ne_cro
Ne_cro
I'm having a problem with Renderbuffers. I have been messing around with this piece of code for a while and I couldn't get it to work the way I want. Here is how i initialize my color buffer, depth buffer and bind them to a FBO:

//Depth renderbuffer
glGenRenderbuffersEXT(1, &depthbuf);
gbuf.DepthBufferID = depthbuf;
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, depthbuf);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 4, GL_DEPTH_COMPONENT, >ResolutionX,ResolutionY);
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

//Color renderbuffer
glGenRenderbuffersEXT(1, &colorbuf);
gbuf.ColorBufferID = colorbuf;
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, colorbuf);
glRenderbufferStorageMultisampleEXT(GL_RENDERBUFFER_EXT, 4, GL_RGBA8, ResolutionX, ResolutionY); 
glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);

//FBO
glGenFramebuffersEXT(1, &framebuf);
gbuf.FramebufferID = framebuf;
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, framebuf);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_RENDERBUFFER_EXT, colorbuf);
glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depthbuf);



Here is how I render to the FBO and then blit the FBO to the normal frame buffer:

//Render to FBO
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);
glViewport(0, 0, ResolutionX, ResolutionY);
glBindTexture(GL_TEXTURE_2D, 0);
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Gbuffers[0].FramebufferID);

for(int i=0; i<this->Renderables.size(); i++)
{
	this->Renderables.Render();
}

glPopAttrib();

//Blit FBO to normal frame buffer
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, Gbuffers[0].FramebufferID);
glBindFramebufferEXT(GL_DRAW_FRAMEBUFFER_EXT, 0);
glBlitFramebufferEXT(0, 0, ResolutionX, ResolutionY, 0, 0, ResolutionX, ResolutionY, GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, GL_NEAREST);
glBindFramebufferEXT(GL_READ_FRAMEBUFFER_EXT, 0);



Now it is my understanding that this is enough and I should get something onscreen. However, thats not the case. I tried binding a texture instead of the color buffer and render it to a fullscreen quad with no success. I could however get something on the screen when i did not attach the depth component to the framebuffer (i.e. the framebuffer had a color texture only) but this is not what I'm looking for as there is no depth testing and no multisampling. What am I doing wrong? I'm sure it is something simple that I don't see.
Ne_cro
Ne_cro
I tried to use an opengl debugger to check the frambuffer and the size of the renderbuffer appears to be 0x0. This is really confusing me. It seems like nothing is being drawn to the renderbuffers at all. could it be that my graphics card support fbos but not renderbuffers?
Ne_cro
Ne_cro
Ok it seems that the problem is not in blitting the fbo. It looks like a much simpler problem. Maybe im missing something here, but whenever i attach any depthbuffer to any of the fbos that im reading from or drawing to, the colorbuffer/texture is completely black.
karwosts
karwosts
Is it possible that its black just because nothing is getting rendered to the fbo? Maybe your depth buffer is rejecting everything. Try disabling depth test and see if its still black?

I'm pretty rusty with my FBO's so I could be wrong, but wouldn't you want to call glClear after you bind your FB? I would guess that it only clears the active FB.

//Render to FBOglClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);glPushAttrib(GL_VIEWPORT_BIT | GL_ENABLE_BIT);glViewport(0, 0, ResolutionX, ResolutionY);glBindTexture(GL_TEXTURE_2D, 0);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, Gbuffers[0].FramebufferID);
[size=2]My Projects:
[size=2]Portfolio Map for Android - Free Visual Portfolio Tracker
[size=2]Electron Flux for Android - Free Puzzle/Logic Game
Ne_cro
Ne_cro
Thanks karwosts :D it works now. All I had to do was clear the buffer after binding it. I overlooked the fact that glClear effects the currently bound buffer.
I always try finding complicated solutions to a simple problem :( that's why I was looking in the wrong place.
Thanks again :)

Topic Locked

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

Sign in to reply to this topic.