ref: gl: simplify backface culling checks in frustum class

This commit is contained in:
Alibek Omarov
2026-04-06 08:25:41 +05:00
parent ef513f27ac
commit cbbae0c9bf
2 changed files with 20 additions and 37 deletions

View File

@@ -67,10 +67,10 @@ int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint cli
{
cl_entity_t *e = RI.currententity;
if( !e || !surf || !surf->texinfo || !surf->texinfo->texture )
if( unlikely( !e || !surf || !surf->texinfo || !surf->texinfo->texture ))
return CULL_OTHER;
if( r_nocull.value )
if( unlikely( r_nocull.value ))
return CULL_VISIBLE;
// world surfaces can be culled by vis frame too
@@ -78,9 +78,10 @@ int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint cli
return CULL_VISFRAME;
// only static ents can be culled by frustum
if( !R_StaticEntity( e )) frustum = NULL;
if( !R_StaticEntity( e ))
frustum = NULL;
if( !VectorIsNull( surf->plane->normal ))
if( glState.faceCull != GL_NONE && !VectorIsNull( surf->plane->normal ))
{
float dist;
@@ -95,35 +96,22 @@ int R_CullSurface( const msurface_t *surf, const gl_frustum_t *frustum, uint cli
}
else dist = PlaneDiff( tr.modelorg, surf->plane );
if( FBitSet( surf->flags, SURF_PLANEBACK ))
dist = -dist;
if( glState.faceCull == GL_FRONT )
{
if( FBitSet( surf->flags, SURF_PLANEBACK ))
{
if( dist >= -BACKFACE_EPSILON )
return CULL_BACKSIDE; // wrong side
}
else
{
if( dist <= BACKFACE_EPSILON )
return CULL_BACKSIDE; // wrong side
}
if( dist <= BACKFACE_EPSILON )
return CULL_BACKSIDE;
}
else if( glState.faceCull == GL_BACK )
else // if( glState.faceCull == GL_BACK )
{
if( FBitSet( surf->flags, SURF_PLANEBACK ))
{
if( dist <= BACKFACE_EPSILON )
return CULL_BACKSIDE; // wrong side
}
else
{
if( dist >= -BACKFACE_EPSILON )
return CULL_BACKSIDE; // wrong side
}
if( dist >= -BACKFACE_EPSILON )
return CULL_BACKSIDE;
}
}
if( frustum && GL_FrustumCullBox( frustum, surf->info->mins, surf->info->maxs, clipflags ))
if( frustum && clipflags && GL_FrustumCullBox( frustum, surf->info->mins, surf->info->maxs, clipflags ))
return CULL_FRUSTUM;
return CULL_VISIBLE;

View File

@@ -99,15 +99,14 @@ void GL_FrustumInitOrtho( gl_frustum_t *out, float xLeft, float xRight, float yT
// cull methods
qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const vec3_t maxs, int userClipFlags )
{
int iClipFlags;
int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags;
int i, bit;
if( r_nocull.value )
if( unlikely( r_nocull.value ))
return false;
if( userClipFlags != 0 )
iClipFlags = userClipFlags;
else iClipFlags = out->clipFlags;
if( !iClipFlags )
return false;
for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
{
@@ -160,16 +159,12 @@ qboolean GL_FrustumCullBox( const gl_frustum_t *out, const vec3_t mins, const ve
qboolean GL_FrustumCullSphere( const gl_frustum_t *out, const vec3_t center, float radius, int userClipFlags )
{
int iClipFlags;
int iClipFlags = userClipFlags != 0 ? userClipFlags : out->clipFlags;
int i, bit;
if( r_nocull.value )
if( unlikely( r_nocull.value ))
return false;
if( userClipFlags != 0 )
iClipFlags = userClipFlags;
else iClipFlags = out->clipFlags;
for( i = FRUSTUM_PLANES, bit = 1; i > 0; i--, bit <<= 1 )
{
const mplane_t *p = &out->planes[FRUSTUM_PLANES - i];