Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: renderer: micro-optimize CPU culling and other things #1125

Draft
wants to merge 23 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 11 additions & 12 deletions src/engine/renderer/tr_decals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -846,36 +846,35 @@ adds a decal surface to the scene

void R_AddDecalSurface( decal_t *decal )
{
int i;
float fade;
srfDecal_t *srf;

/* early outs */
if ( decal->shader == nullptr || decal->parent->viewCount != tr.viewCountNoReset || tr.refdef.numDecals >= MAX_DECALS )
{
return;
}

/* get decal surface */
srf = &tr.refdef.decals[ tr.refdef.numDecals ];
srfDecal_t *srf = &tr.refdef.decals[ tr.refdef.numDecals ];
tr.refdef.numDecals++;

/* set it up */
srf->surfaceType = surfaceType_t::SF_DECAL;
srf->numVerts = decal->numVerts;
memcpy( srf->verts, decal->verts, srf->numVerts * sizeof( *srf->verts ) );
memcpy( srf->verts, decal->verts, srf->numVerts * sizeof( polyVert_t ) );

/* fade colors */
if ( decal->fadeStartTime < tr.refdef.time && decal->fadeStartTime < decal->fadeEndTime )
{
fade = ( float )( decal->fadeEndTime - tr.refdef.time ) / ( float )( decal->fadeEndTime - decal->fadeStartTime );
float fade = ( float )( decal->fadeEndTime - tr.refdef.time ) / ( float )( decal->fadeEndTime - decal->fadeStartTime );

polyVert_t *vert = decal->verts;
polyVert_t *lastVert = vert + decal->numVerts;

for ( i = 0; i < decal->numVerts; i++ )
for ( ; vert < lastVert; vert++ )
{
decal->verts[ i ].modulate[ 0 ] *= fade;
decal->verts[ i ].modulate[ 1 ] *= fade;
decal->verts[ i ].modulate[ 2 ] *= fade;
decal->verts[ i ].modulate[ 3 ] *= fade;
vert->modulate[ 0 ] *= fade;
vert->modulate[ 1 ] *= fade;
vert->modulate[ 2 ] *= fade;
vert->modulate[ 3 ] *= fade;
}
}

Expand Down
36 changes: 14 additions & 22 deletions src/engine/renderer/tr_main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -337,23 +337,20 @@ Returns CULL_IN, CULL_CLIP, or CULL_OUT
*/
cullResult_t R_CullBox( vec3_t worldBounds[ 2 ] )
{
bool anyClip;
cplane_t *frust;
int i, r;

if ( r_nocull->integer )
{
return cullResult_t::CULL_CLIP;
}

// check against frustum planes
anyClip = false;
bool anyClip = false;

for ( i = 0; i < FRUSTUM_PLANES; i++ )
{
frust = &tr.viewParms.frustums[ 0 ][ i ];
cplane_t *frust = &tr.viewParms.frustums[ 0 ][ 0 ];
cplane_t *lastFrust = frust + FRUSTUM_PLANES;

r = BoxOnPlaneSide( worldBounds[ 0 ], worldBounds[ 1 ], frust );
for ( ; frust < lastFrust; frust++ )
{
int r = BoxOnPlaneSide( worldBounds[ 0 ], worldBounds[ 1 ], frust );

if ( r == 2 )
{
Expand Down Expand Up @@ -1971,27 +1968,20 @@ R_AddDrawSurf
*/
void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, int fogNum, bool bspSurface )
{
int index;
drawSurf_t *drawSurf;

// instead of checking for overflow, we just mask the index
// so it wraps around
index = tr.refdef.numDrawSurfs & DRAWSURF_MASK;
int index = tr.refdef.numDrawSurfs & DRAWSURF_MASK;

drawSurf = &tr.refdef.drawSurfs[ index ];
drawSurf_t *drawSurf = &tr.refdef.drawSurfs[ index ];

drawSurf->entity = tr.currentEntity;
drawSurf->surface = surface;
drawSurf->shader = shader;
drawSurf->bspSurface = bspSurface;

int entityNum;
int entityNum = -1;

if ( tr.currentEntity == &tr.worldEntity )
{
entityNum = -1;
}
else
if ( tr.currentEntity != &tr.worldEntity )
{
entityNum = tr.currentEntity - tr.refdef.entities;
}
Expand All @@ -2005,9 +1995,11 @@ void R_AddDrawSurf( surfaceType_t *surface, shader_t *shader, int lightmapNum, i

tr.refdef.numDrawSurfs++;

if ( shader->depthShader != nullptr ) {
R_AddDrawSurf( surface, shader->depthShader, 0, 0, bspSurface );
if ( !shader->depthShader ) {
return;
}

R_AddDrawSurf( surface, shader->depthShader, 0, 0, bspSurface );
}

/*
Expand Down
Loading