Skip to content

Commit d121f7a

Browse files
committed
Refactor glTextureBarrier code into function
Since it's about to be used more times. I named it like PrepareForSamplingDepthMap instead of something about texture barrier, because I may want to add more stuff in for #1814 where there is the possibility to use a copy of the depth texture instead. Also, always mark depth buffer dirtiness with material system.
1 parent 8868983 commit d121f7a

File tree

4 files changed

+28
-14
lines changed

4 files changed

+28
-14
lines changed

src/engine/renderer/Material.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2000,6 +2000,11 @@ void MaterialSystem::RenderMaterials( const shaderSort_t fromSort, const shaderS
20002000
}
20012001
}
20022002

2003+
// All material packs currently render depth-writing shaders.
2004+
// If we were to render depth fade or anything else sampling u_DepthMap with the material system,
2005+
// we would need to track this on a per-material basis.
2006+
backEnd.dirtyDepthBuffer = true;
2007+
20032008
GL_BindVAO( backEnd.defaultVAO );
20042009

20052010
// Draw the skybox here because we skipped R_AddWorldSurfaces()

src/engine/renderer/tr_backend.cpp

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1210,6 +1210,25 @@ void RB_RunVisTests( )
12101210
}
12111211
}
12121212

1213+
void RB_PrepareForSamplingDepthMap()
1214+
{
1215+
if ( !glConfig.textureBarrierAvailable )
1216+
{
1217+
return;
1218+
}
1219+
1220+
if ( !backEnd.dirtyDepthBuffer )
1221+
{
1222+
return;
1223+
}
1224+
1225+
// Flush depth buffer to make sure it is available for reading in the depth fade
1226+
// GLSL - prevents https://github.com/DaemonEngine/Daemon/issues/1676
1227+
glTextureBarrier();
1228+
1229+
backEnd.dirtyDepthBuffer = false;
1230+
}
1231+
12131232
static void RenderDepthTiles()
12141233
{
12151234
GL_State( GLS_DEPTHTEST_DISABLE );
@@ -1534,12 +1553,7 @@ void RB_RenderSSAO()
15341553

15351554
GLIMP_LOGCOMMENT( "--- RB_RenderSSAO ---" );
15361555

1537-
// Assume depth is dirty since we just rendered depth pass and everything opaque
1538-
if ( glConfig.textureBarrierAvailable )
1539-
{
1540-
glTextureBarrier();
1541-
backEnd.dirtyDepthBuffer = false;
1542-
}
1556+
RB_PrepareForSamplingDepthMap();
15431557

15441558
GL_State( GLS_DEPTHTEST_DISABLE | GLS_SRCBLEND_DST_COLOR | GLS_DSTBLEND_ZERO );
15451559
GL_Cull( cullType_t::CT_TWO_SIDED );
@@ -2706,9 +2720,6 @@ static void RB_RenderView( bool depthPass )
27062720
// draw everything that is translucent
27072721
if ( glConfig.usingMaterialSystem ) {
27082722
materialSystem.RenderMaterials( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, backEnd.viewParms.viewID );
2709-
2710-
// HACK: assume surfaces with depth fade don't use the material system
2711-
backEnd.dirtyDepthBuffer = true;
27122723
}
27132724
RB_RenderDrawSurfaces( shaderSort_t::SS_ENVIRONMENT_NOFOG, shaderSort_t::SS_POST_PROCESS, DRAWSURFACES_ALL );
27142725

src/engine/renderer/tr_local.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2923,6 +2923,7 @@ void GL_TexImage3D( GLenum target, GLint level, GLint internalFormat, GLsizei wi
29232923
void GL_CompressedTexImage2D( GLenum target, GLint level, GLenum internalformat, GLsizei width, GLsizei height, GLint border, GLsizei imageSize, const void *data, bool isSRGB );
29242924
void GL_CompressedTexSubImage3D( GLenum target, GLint level, GLint xOffset, GLint yOffset, GLint zOffset, GLsizei width, GLsizei height, GLsizei depth, GLenum internalFormat, GLsizei size, const void *data, bool isSRGB );
29252925
void R_ShutdownBackend();
2926+
void RB_PrepareForSamplingDepthMap();
29262927

29272928
/*
29282929
====================================================================

src/engine/renderer/tr_shade.cpp

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -874,12 +874,9 @@ void Render_generic3D( shaderStage_t *pStage )
874874
bool hasDepthFade = pStage->hasDepthFade;
875875
bool needDepthMap = pStage->hasDepthFade;
876876

877-
if ( needDepthMap && backEnd.dirtyDepthBuffer && glConfig.textureBarrierAvailable )
877+
if ( needDepthMap )
878878
{
879-
// Flush depth buffer to make sure it is available for reading in the depth fade
880-
// GLSL - prevents https://github.com/DaemonEngine/Daemon/issues/1676
881-
glTextureBarrier();
882-
backEnd.dirtyDepthBuffer = false;
879+
RB_PrepareForSamplingDepthMap();
883880
}
884881

885882
// choose right shader program ----------------------------------

0 commit comments

Comments
 (0)