mirror of
https://github.com/FWGS/xash3d-fwgs.git
synced 2026-08-05 03:24:56 +08:00
ref: gl: simplify backface culling checks in frustum class
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
Reference in New Issue
Block a user