Skip to content

Commit a922702

Browse files
committed
perf: RenderSpriteCard backport from CSGO
* skips render if alpha is 0 * combines nSequence calculation * uses FastQuad
1 parent c18f6dd commit a922702

File tree

2 files changed

+12
-10
lines changed

2 files changed

+12
-10
lines changed

src/particles/builtin_particle_render_ops.cpp

+6-10
Original file line numberDiff line numberDiff line change
@@ -905,6 +905,9 @@ void C_OP_RenderSprites::RenderUnsortedNonSpriteCardOriented( CParticleCollectio
905905
void C_OP_RenderSprites::RenderSpriteCard( CMeshBuilder &meshBuilder, C_OP_RenderSpritesContext_t *pCtx, SpriteRenderInfo_t& info, int hParticle, ParticleRenderData_t const *pSortList, Vector *pCamera ) const
906906
{
907907
Assert( hParticle != -1 );
908+
unsigned char ac = pSortList->m_nAlpha;
909+
if (! ac )
910+
return;
908911
int nGroup = hParticle / 4;
909912
int nOffset = hParticle & 0x3;
910913

@@ -921,7 +924,6 @@ void C_OP_RenderSprites::RenderSpriteCard( CMeshBuilder &meshBuilder, C_OP_Rende
921924
unsigned char rc = FastFToC( r );
922925
unsigned char gc = FastFToC( g );
923926
unsigned char bc = FastFToC( b );
924-
unsigned char ac = pSortList->m_nAlpha;
925927

926928
float rad = pSortList->m_flRadius;
927929
if ( !IsFinite( rad ) )
@@ -959,16 +961,15 @@ void C_OP_RenderSprites::RenderSpriteCard( CMeshBuilder &meshBuilder, C_OP_Rende
959961
// float flLifetime = SubFloat( pLifeDuration[ nGroup * ld_stride ], nOffset );
960962
// flAgeScale = ( flLifetime > 0.0f ) ? ( 1.0f / flLifetime ) * SEQUENCE_SAMPLE_COUNT : 0.0f;
961963
// }
964+
int nSequence = SubFloat( info.m_pSequenceNumber[ nGroup * info.m_nSequenceStride ], nOffset );
962965
if ( m_bAnimateInFPS )
963966
{
964-
int nSequence = SubFloat( info.m_pSequenceNumber[ nGroup * info.m_nSequenceStride ], nOffset );
965967
flAgeScale = flAgeScale / info.m_pParticles->m_Sheet()->m_flFrameSpan[nSequence];
966968
}
967969
pSample = GetSampleForSequence( info.m_pSheet,
968970
SubFloat( info.m_pCreationTimeStamp[ nGroup * info.m_nCreationTimeStride ], nOffset ),
969971
info.m_pParticles->m_flCurTime,
970-
flAgeScale,
971-
SubFloat( info.m_pSequenceNumber[ nGroup * info.m_nSequenceStride ], nOffset ) );
972+
flAgeScale, nSequence );
972973
}
973974

974975
const SequenceSampleTextureCoords_t *pSample0 = &(pSample->m_TextureCoordData[0]);
@@ -1015,12 +1016,7 @@ void C_OP_RenderSprites::RenderSpriteCard( CMeshBuilder &meshBuilder, C_OP_Rende
10151016
meshBuilder.TexCoord4f( 4, pSecondTexture0->m_fLeft_U0, pSecondTexture0->m_fTop_V0, pSecondTexture0->m_fRight_U0, pSecondTexture0->m_fBottom_V0 );
10161017
meshBuilder.AdvanceVertex();
10171018

1018-
meshBuilder.FastIndex( info.m_nVertexOffset );
1019-
meshBuilder.FastIndex( info.m_nVertexOffset + 1 );
1020-
meshBuilder.FastIndex( info.m_nVertexOffset + 2 );
1021-
meshBuilder.FastIndex( info.m_nVertexOffset );
1022-
meshBuilder.FastIndex( info.m_nVertexOffset + 2 );
1023-
meshBuilder.FastIndex( info.m_nVertexOffset + 3 );
1019+
meshBuilder.FastQuad( info.m_nVertexOffset );
10241020
info.m_nVertexOffset += 4;
10251021
}
10261022
}

src/public/materialsystem/imesh.h

+6
Original file line numberDiff line numberDiff line change
@@ -3206,6 +3206,7 @@ class CMeshBuilder : public MeshDesc_t
32063206

32073207
// Fast Index! No need to call advance index, and no random access allowed
32083208
void FastIndex( unsigned short index );
3209+
void FastQuad( int index );
32093210

32103211
// Fast Vertex! No need to call advance vertex, and no random access allowed.
32113212
// WARNING - these are low level functions that are intended only for use
@@ -3775,6 +3776,11 @@ FORCEINLINE void CMeshBuilder::FastIndex2( unsigned short nIndex1, unsigned shor
37753776
m_IndexBuilder.FastIndex2( nIndex1, nIndex2 );
37763777
}
37773778

3779+
FORCEINLINE void CMeshBuilder::FastQuad( int nIndex )
3780+
{
3781+
m_IndexBuilder.FastQuad( nIndex );
3782+
}
3783+
37783784
//-----------------------------------------------------------------------------
37793785
// For use with the FastVertex methods, advances the current vertex by N
37803786
//-----------------------------------------------------------------------------

0 commit comments

Comments
 (0)