mirror of
https://github.com/dhewm/dhewm3.git
synced 2024-11-29 07:32:25 +00:00
Make r_showDepth use currentDepthImage, unless r_skipDepthCapture is 1
This commit is contained in:
parent
5ff59547a4
commit
580257b47e
2 changed files with 61 additions and 24 deletions
|
@ -983,7 +983,8 @@ extern idCVar r_materialOverride; // override all materials
|
||||||
|
|
||||||
extern idCVar r_debugRenderToTexture;
|
extern idCVar r_debugRenderToTexture;
|
||||||
|
|
||||||
extern idCVar r_glDebugContext;
|
extern idCVar r_glDebugContext; // DG: use debug context to call logging callbacks on GL errors
|
||||||
|
extern idCVar r_skipDepthCapture; // DG: disable capturing depth buffer, used for soft particles
|
||||||
|
|
||||||
/*
|
/*
|
||||||
====================================================================
|
====================================================================
|
||||||
|
|
|
@ -437,7 +437,6 @@ Draw the depth buffer as colors
|
||||||
===================
|
===================
|
||||||
*/
|
*/
|
||||||
void RB_ShowDepthBuffer( void ) {
|
void RB_ShowDepthBuffer( void ) {
|
||||||
void *depthReadback;
|
|
||||||
|
|
||||||
if ( !r_showDepth.GetBool() ) {
|
if ( !r_showDepth.GetBool() ) {
|
||||||
return;
|
return;
|
||||||
|
@ -450,21 +449,57 @@ void RB_ShowDepthBuffer( void ) {
|
||||||
qglLoadIdentity();
|
qglLoadIdentity();
|
||||||
qglOrtho( 0, 1, 0, 1, -1, 1 );
|
qglOrtho( 0, 1, 0, 1, -1, 1 );
|
||||||
qglRasterPos2f( 0, 0 );
|
qglRasterPos2f( 0, 0 );
|
||||||
|
|
||||||
|
GL_State( GLS_DEPTHFUNC_ALWAYS );
|
||||||
|
qglColor3f( 1, 1, 1 );
|
||||||
|
|
||||||
|
if ( !r_skipDepthCapture.GetBool() ) {
|
||||||
|
globalImages->currentDepthImage->Bind();
|
||||||
|
|
||||||
|
const float x=0, y=0, w=1, h=1;
|
||||||
|
// debug values:
|
||||||
|
//const float x = 0.1, y = 0.1, w = 0.8, h = 0.8;
|
||||||
|
//qglColor4f( 0.0f, 0.0f, 0.5f, 1.0f );
|
||||||
|
|
||||||
|
const float tx=0, ty=0;
|
||||||
|
// the actual texturesize of currentDepthImage is the next bigger power of two (POT),
|
||||||
|
// so the normalized width/height of the part of it we actually wanna show is the following
|
||||||
|
const float tw = float(glConfig.vidWidth) / float(globalImages->currentDepthImage->uploadWidth);
|
||||||
|
const float th = float(glConfig.vidHeight) / float(globalImages->currentDepthImage->uploadHeight);
|
||||||
|
|
||||||
|
qglBegin( GL_QUADS );
|
||||||
|
qglTexCoord2f(tx, ty);
|
||||||
|
qglVertex2f( x, y ); // ( 0,0 );
|
||||||
|
|
||||||
|
qglTexCoord2f(tx, ty+th);
|
||||||
|
qglVertex2f( x, y+h ); // ( 0,1 );
|
||||||
|
|
||||||
|
qglTexCoord2f(tx+tw, ty+th);
|
||||||
|
qglVertex2f( x+w, y+h ); // ( 1,1 );
|
||||||
|
|
||||||
|
qglTexCoord2f(tx+tw, ty);
|
||||||
|
qglVertex2f( x+w, y ); // ( 1,0 );
|
||||||
|
qglEnd();
|
||||||
|
|
||||||
|
// TODO: probably a shader transforming this to something viewable
|
||||||
|
|
||||||
qglPopMatrix();
|
qglPopMatrix();
|
||||||
qglMatrixMode( GL_MODELVIEW );
|
qglMatrixMode( GL_MODELVIEW );
|
||||||
qglPopMatrix();
|
qglPopMatrix();
|
||||||
|
|
||||||
GL_State( GLS_DEPTHFUNC_ALWAYS );
|
} else {
|
||||||
qglColor3f( 1, 1, 1 );
|
qglPopMatrix();
|
||||||
|
qglMatrixMode( GL_MODELVIEW );
|
||||||
|
qglPopMatrix();
|
||||||
globalImages->BindNull();
|
globalImages->BindNull();
|
||||||
|
|
||||||
depthReadback = R_StaticAlloc( glConfig.vidWidth * glConfig.vidHeight*4 );
|
void* depthReadback = R_StaticAlloc( glConfig.vidWidth * glConfig.vidHeight*4 );
|
||||||
memset( depthReadback, 0, glConfig.vidWidth * glConfig.vidHeight*4 );
|
memset( depthReadback, 0, glConfig.vidWidth * glConfig.vidHeight*4 );
|
||||||
|
|
||||||
qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );
|
qglReadPixels( 0, 0, glConfig.vidWidth, glConfig.vidHeight, GL_DEPTH_COMPONENT , GL_FLOAT, depthReadback );
|
||||||
|
#if 0 // the following looks better, but is different from the !r_skipDepthCapture.GetBool() case above
|
||||||
|
// (which draws the captured depth buffer unaltered, unless we add a shader)
|
||||||
for ( int i = 0 ; i < glConfig.vidWidth * glConfig.vidHeight ; i++ ) {
|
for ( int i = 0, n=glConfig.vidWidth * glConfig.vidHeight; i < n ; i++ ) {
|
||||||
float& px = ((float *)depthReadback)[i];
|
float& px = ((float *)depthReadback)[i];
|
||||||
float d = px;
|
float d = px;
|
||||||
// the following calculation is based on how the TDM soft particle shader translates the depth value to doom units
|
// the following calculation is based on how the TDM soft particle shader translates the depth value to doom units
|
||||||
|
@ -480,9 +515,10 @@ void RB_ShowDepthBuffer( void ) {
|
||||||
d *= (-3.0f / 3000.0f); // now 3000 units is 1.0, i.e. completely white (=> more details for closer distances)
|
d *= (-3.0f / 3000.0f); // now 3000 units is 1.0, i.e. completely white (=> more details for closer distances)
|
||||||
px = d;
|
px = d;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
qglDrawPixels( glConfig.vidWidth, glConfig.vidHeight, GL_LUMINANCE, GL_FLOAT, depthReadback );
|
qglDrawPixels( glConfig.vidWidth, glConfig.vidHeight, GL_LUMINANCE, GL_FLOAT, depthReadback );
|
||||||
R_StaticFree( depthReadback );
|
R_StaticFree( depthReadback );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
Loading…
Reference in a new issue