View Full Version : FBO, floating point buffers, and clamping

05-04-2005, 07:13 AM
I have a program that is using FBO to set up a floating point frame buffer. I am using a 6800 GT with 76.91 beta drivers. This is the setup code:

glGenFramebuffersEXT( 1, &mSceneData.mFrontBuffer );
glGenTextures( 1, &mSceneData.mFrontBufferTexture );
glGenRenderbuffersEXT( 1, &mSceneData.mDepthBuffer );

glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, mSceneData.mFrontBuffer );

glBindTexture( GL_TEXTURE_2D, mSceneData.mFrontBufferTexture );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, mSizeX, mSizeY, 0, GL_RGBA, GL_FLOAT, NULL );

glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, mSceneData.mFrontBufferTexture, 0 );

glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, mSceneData.mDepthBuffer );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT24, mSizeX, mSizeY );
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, mSceneData.mDepthBuffer );I render into this buffer using a GLSL fragment shader, then using this buffer as a texture, I render it into the main frame buffer, also using a GLSL fragment shader. Problem is even though I have used glClampColorARB( GL_CLAMP_FRAGMENT_COLOR_ARB, FALSE ) everywhere I think it might be appropiate to do it, I can't seem to get unclamped values. I don't know if its getting clamped when getting written to the frame buffer object, or if it is getting clamped when I try to read it for the final rendering. Also tried glClampColorARB( GL_CLAMP_READ_COLOR_ARB, FALSE ) just in case but that had no effect either.

Anyone with an idea what the problem might be?

05-04-2005, 08:59 AM
I've also experienced some problems with undesired clamping behavior while using FBOs...
However, in my case it happens only when my input data is not floating point.
I don't know what you're rendering on the FBO, but if you're passing the data to the first GLSL fragment program as a floating point texture (GL_RGB16F, GL_RGB32F, GL_RGBA16F or GL_RGBA32F) it shouldn't be clamped at all (at least it hasn't been in my tests).
By the way, when using a floating point texture as input, the

glClampColorARB( GL_CLAMP_FRAGMENT_COLOR_ARB, GL_FALSE )didn't seem to have any influence on the result written by the fragment shader. Not sure if that's the expected behavior anyway...
But you still need to disable the clamping when reading back the content of the fbo with glReadPixels, just as you said:

glClampColorARB( GL_CLAMP_READ_COLOR_ARB, GL_FALSE )Are you setting the render target properly with glDrawBuffersARB? Of course if you're not, you would be rendering to the framebuffer, which as a fixed point buffer, can only work with clamped values.
I hope it helps ;)

05-04-2005, 09:37 AM
The GLSL script I have that generates the values outside 0-1 does not reference any textures, and at the moment pretty much just sets a constant color value (25, 1, 0), which then gets scaled by 1/25 in the final fragment program. I am getting pure really dark green instead of mostly red.

05-04-2005, 10:28 AM
Fixed it. Took another stab in the dark and issued a glClampColorARB( GL_CLAMP_VERTEX_COLOR_ARB, GL_FIXED_ONLY_ARB ). Once I did this, everything worked as expected. Actually, it was the only thing I needed to do. Not sure why having it set to TRUE messed things up, but it did.