Hi,
I’ve a floating point texture ( GL_RGBA16F_ARB ) and a Renderbuffer ( GL_DEPTH_COMPONENT16 ) bound to a framebuffer object (ATI card). I want to write the gl_DepthComponent with a fragment shader, but this doesn’t work ( the depth values are not changed by the shader ). If I change the internal format of the texture to GL_RGB everything works. But I need the floating point format. Here are some snippets of my code:
The init:
// create renderbuffer and framebuffer
glGenFramebuffersEXT( 1, &fb );
// render buffer
glGenRenderbuffersEXT( 1, &depth_rb );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb );
glRenderbufferStorageEXT( GL_RENDERBUFFER_EXT, GL_DEPTH_COMPONENT16, 512, 512 );
// texture
glGenTextures( 1, &tex );
glBindTexture( GL_TEXTURE_2D, tex );
glTexImage2D( GL_TEXTURE_2D, 0, GL_RGBA16F_ARB, 512, 512, 0, GL_RGBA, GL_FLOAT, 0 );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST );
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
And the drawing routine for drawing to the framebuffer object:
fbo->enable();
if ( i == 0 )
glClear( GL_DEPTH_BUFFER_BIT | GL_COLOR_BUFFER_BIT );
glColor3f( 1.0, 1.0, 1.0 );
glEnable( GL_DEPTH_TEST );
shader->install();
glUniform1fARB( shader->getUniformLocation( "s_div" ), float(i) );
glBegin( GL_QUADS );
{
glVertex3f( 0, 0, depth_value );
glVertex3f( 1, 0, depth_value );
glVertex3f( 1, 1, depth_value );
glVertex3f( 0, 1, depth_value );
}
glEnd();
shader->uninstall();
glDisable( GL_DEPTH_TEST );
printf("HW Iteration: %d", i );
printDepth();
fbo->disable();
…where fbo->enable() is:
glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, fb );
glBindRenderbufferEXT( GL_RENDERBUFFER_EXT, depth_rb );
glFramebufferTexture2DEXT( GL_FRAMEBUFFER_EXT, GL_COLOR_ATTACHMENT0_EXT, GL_TEXTURE_2D, tex, 0);
glFramebufferRenderbufferEXT( GL_FRAMEBUFFER_EXT, GL_DEPTH_ATTACHMENT_EXT, GL_RENDERBUFFER_EXT, depth_rb );
Any ideas?