FBO Bafflement

Started by
1 comment, last by TiredofSleep 16 years, 8 months ago
Ok i came across a problem when using a FBO and Displaying the texture it created on a quad. I noticed that it looked like Depth testing was off, altho i created a depth buffer and color buffer for the FBO object, so i was baffled why i was getting no depth testing. Doing: glGenFramebuffersEXT(1, &this->FBOHandle); glGenRenderbuffersEXT(1, &this->FBODepth); Gave me no Depth testing yet switching the calls around worked. Like'a so. glGenRenderbuffersEXT(1, &this->FBODepth); glGenFramebuffersEXT(1, &this->FBOHandle); So why does creating the Render buffer first before creating the Frame buffer Fix my problem? Only thing odd i seen was that FBOHandle and FBODepth were both getting set to a value of "1"... Graphics Card: ATI Radeon 1950XT heres my source for FBO creation: Am i doing something stupid?


        // Save the Height and width.
	this->FBOHeight = height;
	this->FBOWidth = width;

	// Create the FBO Objects.
	glGenRenderbuffersEXT(1, &this->FBODepth);
	glGenFramebuffersEXT(1, &this->FBOHandle);
	
	glGenTextures(1, &this->FBOTex);

	// Bind everything.
	glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, this->FBOHandle);
	glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, this->FBODepth);

	// Give the Depth buffer the correct storage
	glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, width, height);

	// Create the Texture.
	glBindTexture(GL_TEXTURE_2D, this->FBOTex);
	glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8,  width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
	glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);

	// Attach everything.
	glFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, this->FBODepth);
	glFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, this->FBOTex, 0);

// Unbind the FBO for now	
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);


Advertisement
Quote:Original post by TiredofSleep
So why does creating the Render buffer first before creating the Frame buffer Fix my problem?

You provided the answer yourself:
Quote:
Graphics Card: ATI Radeon 1950XT

ATI's implementation of the FBO extension is horribly broken on every single driver/card combination I've ever seen (and I've seen a lot). It's extremely sensitive to the ordering of FBO calls. If you do not respect a certain order, it will either not work, give weird results or crash (pick one). The trick to get it to work on (probably) all ATI cards is to religiously follow the exact order of instructions in the ATI FBO demo sample code.

This order is as follows:
// Step 1: Create your colour texture // (this could be done anywhere, it doesn't seem to be order dependent)// Step 2: Create new FBO and bind itglGenFramebuffersEXT(1, &p_handle);glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, p_handle);// Step 3: Create depth renderbuffer, but do not attach it yetglGenRenderbuffersEXT(1, &p_depth);glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, p_depth);glRenderbufferStorageEXT(GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24_ARB, p_size.x, p_size.y);glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, 0);// This was the setup, you're now ready to render your frames.// For each frame do this:// Bind the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, p_handle);// VERY IMPORTANT: the two following attach calls *MUST* be done in exactly this// order: first colour, then depth. Otherwise, some ATI drivers will crash.// Attach the colour texture to the FBOglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, p_texture, 0);// Attach the depth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, p_depth);// Draw your stuff// Now disable FBO rendering. Simply disabling the FBO will not work on the ATI // FireGL V52xx product line, it will crash the driver when you try to use the // colour texture for rendering later on. So you have to first detach ALL // attachments. The detachments have to be done in REVERSE attachment order, // otherwise the X1600/1700 product line will crash on some drivers.// Detach depth bufferglFramebufferRenderbufferEXT(GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, 0);// Detach colour textureglFramebufferTexture2DEXT(GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, 0, 0);// Unbind the FBOglBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0);// The colour texture can now be safely used for texturing.

Welcome to the wonderful world of ATI's OpenGL drivers... If you want to use depth textures instead of render buffers, it becomes even more complicated.

Offtopic: why are your preceding all your member variables with "this->" ?
Thanks for replying Yann :)

could i fix some of my ATI problems by getting the Omega Drivers?

Or should i just hash up some cash and go get an Nvidia card?

Also, i think this card i have has fillrate problems, with a 800x600 window i usually get like 900-1000 fps, soon as i resize to fill screen i get around 70 fps, and thats drawing like a box and thats it.

I'm starting to see why everyone owns NVidia card :(

I made a manager for the FBO stuff it sorta works like a Texture manager works, so i have a manager that holds all my FBO objects, which i can create an FBO Object from Manager. Manager cleans everything up for when its shut down.

So the class holds all my basic information on frame buffer objects, (Texture object, Depth Texture Object and Handle to the FBO ) so they are members of a class.

"this->" is a habit im trying to form, my lead at work says it makes it clearer which methods and members are part of the class without using some standard notation (i.e hungarian).

Plus i use Visual Assist and it basically types for me when i use "this->" haha

This topic is closed to new replies.

Advertisement