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

Framebuffer problem

Started by Lord Faron Mar 23, 2006 at 4:39 PM 9 replies 2.4k views
Original Post
Lord Faron
Lord Faron
I have a problem with framebuffers. I'm trying to render the scene into a framebuffer for further postprocessing. I create a framebuffer with renderbuffer as depth and a rectangle texture as color buffer. The renderbuffer is of DEPTH_COMPONENT24 type. The texture has GL_RGB16F_ARB internal format (for HDR). On every frame I call glBindFramebufferEXT(), then glFramebufferTexture2DEXT() to bind the color tex to GL_COLOR_ATTACHMENT0_EXT and glFramebufferRenderbufferEXT() to bind the renderbuffer to depth. Then I check the framebuffer status and I always get GL_FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER_EXT. According to the specification this happens because GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE_EXT is GL_NONE for GL_COLOR_ATTACHMENT0_EXT. Well, it's not. And that's the problem. I don't know what to do with this. Everything is theoreticaly OK, but according to OGl it's not. Can anybody help?
if (time() == $) { $ = 0; }
Daishim
Daishim
Unless you're detaching the color buffer (texture) and the depth buffer (render buffer) from the framebuffer every frame, you don't need to call glFramebufferTexture2DEXT() and glFramebufferRenderbufferEXT() every frame. Just make sure that your current draw buffer is GL_COLOR_ATTACHMENT0_EXT by using the glDrawBuffer() function.

Did you bind everything in the proper order? ie...
- Bind framebuffer before attachment of color buffer
- Bind renderbuffer before setup of attributes
- Framebuffer still bound before renderbuffer attachment

I know only that which I know, but I do not know what I know.
Lord Faron
Lord Faron
Quote:
Original post by Daishi
Did you bind everything in the proper order?


Yes, everything is in order:

1. bind the framebuffer
2. bind the texture (I use it later so I need to bind it every frame)
3. bind the renderbuffer (I think that's not needed every frame)
4. render frame
5. bind framebuffer 0
6. bind and use color texture for postprocessing

I still get the same error. I tried changing the texture format, but that's not it. I also tried setting drawbuffer and readbuffer to COLOR_ATTACHMENT0 every frame and it doesn't work either. I think the problem is not in the renderbuffer, so I have no idea what's wrong.
if (time() == $) { $ = 0; }
Daishim
Daishim
Can you post a snippet of the code involving your framebuffer?

I know only that which I know, but I do not know what I know.
Lord Faron
Lord Faron
Setting up framebuffer:

glGenTextures(1,&SceneTex);glBindTexture(GL_TEXTURE_RECTANGLE_ARB,SceneTex);glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGB16F_ARB,Width,Height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);glGenFramebuffersEXT(1,&ViewBuffer);glGenRenderbuffersEXT(1,&ViewDepth);glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,ViewDepth);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24,Viewport->GetWidth(),Viewport->GetHeight());


Before every frame:

void GOpenGLRenderer::PreRender(void){	glLoadIdentity();	if (UseHDR || CustomPostShader)	{		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,ViewBuffer);		glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_RECTANGLE_ARB,SceneTex,0);		glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,ViewDepth);		//int s = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);		//gLog->Log("%X\n",s);	}}


After the frame has been rendered:

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,0);glActiveTexture(GL_TEXTURE0);glBindTexture(GL_TEXTURE_RECTANGLE_ARB,SceneTex);
if (time() == $) { $ = 0; }
Kazade
Kazade
I think your problem is having this called every frame..
glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_RECTANGLE_ARB,SceneTex,0);glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,ViewDepth);


All this does is attach the texture and depth buffer to the FBO, it doesnt bind them for writing.

All you need to call before rendering is...

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,ViewBuffer);

and

glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);

after rendering.

Move the first to calls to after the rest of your initialisation code.

Luke.
Member of the NeHe team.
Lord Faron
Lord Faron
Quote:
Original post by Kazade
Move the first to calls to after the rest of your initialisation code..


I moved renderbuffer attachment to initialisation section, but I have to attach the color texture every frame because I use it after rendering.
Moving renderbuffer attachment didn't help. I get the same thing every time. I thought it was because of the color texture internal format (fp16), but when I changed it to plain rgb8 it didn't help.
I could use glCopyTexSubImage() to fill the texture data, but if I want to use HDR I have to get as much precision as possible.
if (time() == $) { $ = 0; }
Daishim
Daishim
If you're attaching the same texture (color buffer) every frame, you can leave it attached and still bind it as a texture for rendering also.

I would change your code to look like this.

Your initialization:
// Generate color buffer texture textureglGenTextures(1,&SceneTex);glBindTexture(GL_TEXTURE_RECTANGLE_ARB,SceneTex);glTexImage2D(GL_TEXTURE_RECTANGLE_ARB,0,GL_RGB16F_ARB,Width,Height,0,GL_RGB,GL_UNSIGNED_BYTE,NULL);// Generate the framebuffer objectglGenFramebuffersEXT(1,&ViewBuffer);// Generate and initialize renderbuffer objectglGenRenderbuffersEXT(1,&ViewDepth);glBindRenderbufferEXT(GL_RENDERBUFFER_EXT,ViewDepth);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT,GL_DEPTH_COMPONENT24,Viewport->GetWidth(),Viewport->GetHeight());// Attach color buffer (texture) and depth buffer (renderbuffer)glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT,GL_DEPTH_ATTACHMENT_EXT,GL_RENDERBUFFER_EXT,ViewDepth);glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT,GL_COLOR_ATTACHMENT0_EXT,GL_TEXTURE_RECTANGLE_ARB,SceneTex,0);


Code to call every frame:
void GOpenGLRenderer::PreRender(void){	glLoadIdentity();	if (UseHDR || CustomPostShader)	{                // You only need to bind the framebuffer to activate it and its contents for use in drawing		glBindFramebufferEXT(GL_FRAMEBUFFER_EXT,ViewBuffer);		//int s = glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT);		//gLog->Log("%X\n",s);	}}


Your post frame code is fine as is.

I know only that which I know, but I do not know what I know.
Daishim
Daishim
If that doesn't work, I'm willing to bet that the problem is with the format of your texture (color buffer). I have not done any work with GL_TEXTURE_RECTANGLE and the GL_RGB16F texture format so I can't say for sure.

I know only that which I know, but I do not know what I know.
Lord Faron
Lord Faron
Changing format to GL_RGB8 and type to GL_TEXTURE_2D didn't help. But I found something strange. I usually have 2 OGL windows visible. First one creates the framebuffer without any errors. The second one returns this one error every time. I can't figure out what's going on.
if (time() == $) { $ = 0; }
Daishim
Daishim
Hmmm... that is interesting indeed.

I know only that which I know, but I do not know what I know.

Topic Locked

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

Sign in to reply to this topic.