MCPcopy Create free account
hub / github.com/carbonengine/trinity / SubmitSprites

Method SubmitSprites

trinity/Font/Tr2FontMeasurer.cpp:1045–1123  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1043}
1044
1045void Tr2FontMeasurer::SubmitSprites( Tr2Sprite2dScene* renderer )
1046{
1047 if( !m_vertices || !m_indices )
1048 {
1049 // It's possible this measurer holds an empty string
1050 return;
1051 }
1052
1053 if( m_indexCount == 0 )
1054 {
1055 // This could happen if the measurer only holds spaces
1056 return;
1057 }
1058
1059 // We may need to submit the vertices in batches as there is a limit to the
1060 // vertex buffer size in the sprite renderer. When it is capturing we have
1061 // counted the vertices beforehand so we don't need to break up the draw calls.
1062 unsigned int maxSpriteCount;
1063
1064 if( renderer->IsCapturing() )
1065 {
1066 maxSpriteCount = std::numeric_limits<uint32_t>::max();
1067 }
1068 else
1069 {
1070 maxSpriteCount = renderer->GetMaxVertexCountPerDrawCall() / 4;
1071 }
1072
1073 Tr2Sprite2dD3DVertex* vertices;
1074 unsigned int vertexCount;
1075 unsigned short* indices;
1076 unsigned int indexCount;
1077 unsigned int vertexOffset = 0;
1078
1079 for( auto it = m_drawCalls.begin(); it != m_drawCalls.end(); ++it )
1080 {
1081 auto entry = *it;
1082 renderer->SetTexture( 0, entry.texture, S2D_TS_NONE );
1083
1084 unsigned int startSprite = entry.startSprite;
1085 unsigned int spriteCount = entry.spriteCount;
1086 unsigned short* adjustedIndices = nullptr;
1087
1088 if( spriteCount > maxSpriteCount )
1089 {
1090 adjustedIndices = CCP_NEW( "adjustedIndices" ) unsigned short[maxSpriteCount * 6];
1091 }
1092
1093 // Ensure we don't submit too many vertices at once
1094 while( spriteCount > maxSpriteCount )
1095 {
1096 vertices = &m_vertices[startSprite * 4];
1097 vertexCount = maxSpriteCount * 4;
1098
1099 indexCount = maxSpriteCount * 6;
1100 indices = AdjustIndicesIfNeeded( startSprite, adjustedIndices, indexCount, vertexOffset );
1101
1102 renderer->RenderTriangleVerts( vertices, vertexCount, indices, indexCount );

Callers 1

GatherSpritesMethod · 0.80

Calls 6

RenderTriangleVertsMethod · 0.80
IsCapturingMethod · 0.45
beginMethod · 0.45
endMethod · 0.45
SetTextureMethod · 0.45

Tested by

no test coverage detected