PDA

View Full Version : glCopyTexImage2D with GL_DEPTH_COMPONENT



pkuloop
10-20-2003, 03:55 PM
how to use glCopyTexImage2D copy GL_DEPTH_COMPONENT to a texture?

What should we do when creat the txeture and update the texture at each frame? can anyone gives soem details?
Thanks alot

CatAtWork
10-20-2003, 04:00 PM
This is a quick cut-and-paste from old code. Should work.





void draw_light_depth_NV10() {


glBindTexture(GL_TEXTURE_2D, depth_texture );
// release the pbuffer from the render texture object
if (wglReleaseTexImageARB(pbuffer.hpbuffer, WGL_DEPTH_COMPONENT_NV ) == FALSE)
WGL_GetLastError();

glBindTexture( GL_TEXTURE_2D, 0 );


// Make the pbuffer rendering context current
if (GL_MakeCurrent( pbuffer.hdc, pbuffer.hglrc) == FALSE)
WGL_GetLastError();

glClear(GL_DEPTH_BUFFER_BIT);
glClearDepth( 1.0 );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glViewport( 0, 0, pbuffer.width, pbuffer.height );
//glEnable( GL_CULL_FACE );
//glCullFace( GL_FRONT );

glDisable( GL_LIGHTING );


glEnable( GL_DEPTH_TEST );
GLfloat po_scale = 2.0f;
GLfloat po_bias = 4.0f;
glPolygonOffset(po_scale, po_bias);
glEnable(GL_POLYGON_OFFSET_FILL);

draw_light_view();



glDisable(GL_POLYGON_OFFSET_FILL);


if (GL_MakeCurrent( appWindow.hDC, appWindow.hRC ) == FALSE)
WGL_GetLastError();




//bind the pbuffer to thhe render texture object
//glBindTexture( GL_TEXTURE_2D, depth_texture );
//if (wglBindTexImageARB(pbuffer.hpbuffer, WGL_DEPTH_COMPONENT_NV ) == FALSE)
// WGL_GetLastError();

}

void draw_light_depth_R200() {



if( GL_MakeCurrent(pbuffer.hdc, pbuffer.hglrc) == GL_FALSE )
WGL_GetLastError();

glViewport( 0, 0, pbuffer.width, pbuffer.height );
glClearDepth( 1.0 );
glClear(GL_DEPTH_BUFFER_BIT);
glEnable( GL_DEPTH_TEST );


glBindTexture(GL_TEXTURE_2D, 0 );
glDisable( GL_TEXTURE_2D );
glColorMask( GL_FALSE, GL_FALSE, GL_FALSE, GL_FALSE );
glEnable( GL_CULL_FACE );
glCullFace( GL_FRONT );
glDisable( GL_LIGHTING );

// TODO: tweak for Radeon 9700
GLfloat scale = 2.0f; // these values need to be different for NVidia and ATi implementations
GLfloat bias = 4.0f;
scale = cvarMap["scale"]->scalarFloat;
bias = cvarMap["bias" ]->scalarFloat;
glPolygonOffset(scale, bias);

glEnable(GL_POLYGON_OFFSET_FILL);
draw_light_view();
glDisable(GL_POLYGON_OFFSET_FILL);
//glEnable( GL_TEXTURE_2D );
glBindTexture(GL_TEXTURE_2D, depth_texture );
glCopyTexSubImage2D( GL_TEXTURE_2D, 0, 0, 0, 0, 0, pbuffer.width, pbuffer.height );
glBindTexture( GL_TEXTURE_2D, 0 );
//glDisable( GL_TEXTURE_2D );


if( GL_MakeCurrent(appWindow.hDC, appWindow.hRC) == GL_FALSE )
WGL_GetLastError();
}


Need this to initialize the depth texture:



glBindTexture( GL_TEXTURE_2D, depth_texture );
if( RCP_R200 == R_codepath ) {
glTexImage2D(GL_TEXTURE_2D, 0, depth_format, pbuffer.width, pbuffer.height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, 0);
}
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
// set up hardware shadow mapping
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_MODE_ARB, GL_COMPARE_R_TO_TEXTURE_ARB );
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_COMPARE_FUNC_ARB, GL_LEQUAL );


[This message has been edited by CatAtWork (edited 10-20-2003).]

pkuloop
10-20-2003, 04:17 PM
Thanks!

can I don't use the pbuffer? Directly read from the depth buffer?

CatAtWork
10-20-2003, 04:26 PM
What video cards are you planning on supporting? ATi doesn't support pbuffers as depth texture targets.

pkuloop
10-20-2003, 06:26 PM
I use NV FX5900, creat pbuffer it slittle complicated. Can I avoid this? just creat a texture and copy what's in the depth buffer to that texture?

CatAtWork
10-20-2003, 06:47 PM
Yes, the R200 code works on your card. I probably should have renamed that.

cass
10-20-2003, 07:10 PM
Just to clarify, if the texture internal format is a DEPTH_COMPONENT variety, then CopyTex{Sub}Image2D() copies from the depth buffer.

Thanks -
Cass