Skip to content
Open
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
14 changes: 7 additions & 7 deletions trinity/Font/Tr2FontMeasurer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -782,8 +782,8 @@ void Tr2FontMeasurer::PrepareSprites( Tr2Sprite2dScene* renderer, const Vector2&
m_vertices = CCP_NEW( "Tr2FontMeasurer/m_vertices" ) Tr2Sprite2dD3DVertex[m_vertexCount];

m_indexCount = spriteCount * 6;
m_indices = CCP_NEW( "Tr2FontMeasurer/m_indices" ) unsigned short[m_indexCount];
unsigned short* curIndex = m_indices;
m_indices = CCP_NEW( "Tr2FontMeasurer/m_indices" ) unsigned int[m_indexCount];
unsigned int* curIndex = m_indices;

Tr2AtlasTexture* currentTexture = nullptr;

Expand Down Expand Up @@ -1072,7 +1072,7 @@ void Tr2FontMeasurer::SubmitSprites( Tr2Sprite2dScene* renderer )

Tr2Sprite2dD3DVertex* vertices;
unsigned int vertexCount;
unsigned short* indices;
unsigned int* indices;
unsigned int indexCount;
unsigned int vertexOffset = 0;

Expand All @@ -1083,11 +1083,11 @@ void Tr2FontMeasurer::SubmitSprites( Tr2Sprite2dScene* renderer )

unsigned int startSprite = entry.startSprite;
unsigned int spriteCount = entry.spriteCount;
unsigned short* adjustedIndices = nullptr;
unsigned int* adjustedIndices = nullptr;

if( spriteCount > maxSpriteCount )
{
adjustedIndices = CCP_NEW( "adjustedIndices" ) unsigned short[maxSpriteCount * 6];
adjustedIndices = CCP_NEW( "adjustedIndices" ) unsigned int[maxSpriteCount * 6];
}

// Ensure we don't submit too many vertices at once
Expand Down Expand Up @@ -1339,9 +1339,9 @@ void Tr2FontMeasurer::SetFadeBottomEnd( float val )
NotifyListenersOfChange();
}

unsigned short* Tr2FontMeasurer::AdjustIndicesIfNeeded( unsigned int startSprite, unsigned short* adjustedIndices, unsigned int indexCount, unsigned int vertexOffset )
unsigned int* Tr2FontMeasurer::AdjustIndicesIfNeeded( unsigned int startSprite, unsigned int* adjustedIndices, unsigned int indexCount, unsigned int vertexOffset )
{
unsigned short* indices;
unsigned int* indices;
if( startSprite > 0 && adjustedIndices )
{
indices = adjustedIndices;
Expand Down
4 changes: 2 additions & 2 deletions trinity/Font/Tr2FontMeasurer.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ class Tr2FontMeasurer : public IRoot
float CalcAlphaForHorizontal( float x );
float CalcAlphaForVertical( float y );

unsigned short* AdjustIndicesIfNeeded( unsigned int startSprite, unsigned short* adjustedIndices, unsigned int indexCount, unsigned int vertexOffset );
unsigned int* AdjustIndicesIfNeeded( unsigned int startSprite, unsigned int* adjustedIndices, unsigned int indexCount, unsigned int vertexOffset );

protected:
std::string m_font;
Expand Down Expand Up @@ -169,7 +169,7 @@ class Tr2FontMeasurer : public IRoot
FTC_ImageTypeRec m_imgTypeFallback;

struct Tr2Sprite2dD3DVertex* m_vertices;
unsigned short* m_indices;
unsigned int* m_indices;
unsigned int m_vertexCount;
unsigned int m_indexCount;

Expand Down
47 changes: 42 additions & 5 deletions trinity/Sprite2d/Tr2Sprite2dScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -997,7 +997,7 @@ bool Tr2Sprite2dScene::PrepareTriangleVerts( Tr2Sprite2dD3DVertex* destVerts, Tr
return true;
}

void Tr2Sprite2dScene::RenderTriangleVerts( Tr2Sprite2dD3DVertex* verticesSrc, unsigned int vertexCount, unsigned short* indices, unsigned short indexCount )
void Tr2Sprite2dScene::RenderTriangleVerts( Tr2Sprite2dD3DVertex* verticesSrc, unsigned int vertexCount, unsigned short* indices, unsigned int indexCount )
{
if( m_transformCurrent >= TR2_SS_MAX_TRANSFORM_COUNT - 1 )
{
Expand All @@ -1018,7 +1018,30 @@ void Tr2Sprite2dScene::RenderTriangleVerts( Tr2Sprite2dD3DVertex* verticesSrc, u
CopyIndicesWithOffset( indices, indexCount, vertexOffset );
}

void Tr2Sprite2dScene::RenderTriangleVerts( Tr2BufferAL& verticesSrc, unsigned int vertexCount, Tr2BufferAL& indices, unsigned short indexCount )
// 32-bit index overload for large text batches: glyph index counts AND values can exceed 65535
// (e.g. huge contract / acceleration-gate popups). The GPU index buffer is already 32-bit.
void Tr2Sprite2dScene::RenderTriangleVerts( Tr2Sprite2dD3DVertex* verticesSrc, unsigned int vertexCount, unsigned int* indices, unsigned int indexCount )
{
if( m_transformCurrent >= TR2_SS_MAX_TRANSFORM_COUNT - 1 )
{
// Buffers are full, kick off what we've got
IssueDrawCall();
}

// Offset applied to indices
int vertexOffset;

bool canRender = EnsureBufferSpace( vertexCount, indexCount, vertexOffset );
if( !canRender )
{
return;
}

ProcessVertices( verticesSrc, vertexCount );
CopyIndicesWithOffset( indices, indexCount, vertexOffset );
}

void Tr2Sprite2dScene::RenderTriangleVerts( Tr2BufferAL& verticesSrc, unsigned int vertexCount, Tr2BufferAL& indices, unsigned int indexCount )
{
CCP_ASSERT( !m_captureDisplayList );

Expand Down Expand Up @@ -2478,7 +2501,7 @@ void Tr2Sprite2dScene::GrowCaptureVertexBuffer( unsigned int vertexCount )

// Grow the index buffer used for capturing display lists. 'indexCount' is the number
// indices that need to be added.
void Tr2Sprite2dScene::GrowCaptureIndexBuffer( unsigned short indexCount )
void Tr2Sprite2dScene::GrowCaptureIndexBuffer( unsigned int indexCount )
{
CCP_STATS_ZONE( __FUNCTION__ );

Expand All @@ -2495,7 +2518,7 @@ void Tr2Sprite2dScene::GrowCaptureIndexBuffer( unsigned short indexCount )
}

// Copy indices to current index data, adding the given vertex offset
void Tr2Sprite2dScene::CopyIndicesWithOffset( unsigned short* indices, unsigned short indexCount, int vertexOffset )
void Tr2Sprite2dScene::CopyIndicesWithOffset( unsigned short* indices, unsigned int indexCount, int vertexOffset )
{
unsigned short* curIndex = indices;
for( unsigned int i = 0; i < indexCount; ++i )
Expand All @@ -2508,7 +2531,21 @@ void Tr2Sprite2dScene::CopyIndicesWithOffset( unsigned short* indices, unsigned
m_indexCount += indexCount;
}

bool Tr2Sprite2dScene::EnsureBufferSpace( unsigned int vertexCount, unsigned short indexCount, int& vertexOffset )
// 32-bit index overload (see the 32-bit RenderTriangleVerts above). m_currentIndexData is uint32.
void Tr2Sprite2dScene::CopyIndicesWithOffset( unsigned int* indices, unsigned int indexCount, int vertexOffset )
{
unsigned int* curIndex = indices;
for( unsigned int i = 0; i < indexCount; ++i )
{
*m_currentIndexData = *curIndex + vertexOffset;
++m_currentIndexData;
++curIndex;
}

m_indexCount += indexCount;
}

bool Tr2Sprite2dScene::EnsureBufferSpace( unsigned int vertexCount, unsigned int indexCount, int& vertexOffset )
{
if( m_captureDisplayList )
{
Expand Down
18 changes: 13 additions & 5 deletions trinity/Sprite2d/Tr2Sprite2dScene.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,15 +115,22 @@ class Tr2Sprite2dScene : public ITr2Scene,
Tr2Sprite2dD3DVertex* verticesSrc,
unsigned int vertexCount,
unsigned short* indices,
unsigned short indexCount );
unsigned int indexCount );

void RenderTriangleVerts(
Tr2BufferAL& verticesSrc,
unsigned int vertexCount,
Tr2BufferAL& indices,
unsigned short indexCount );
unsigned int indexCount );

bool EnsureBufferSpace( unsigned int vertexCount, unsigned short indexCount, int& vertexOffset );
// 32-bit index overload for large text batches (glyph index counts/values can exceed 65535)
void RenderTriangleVerts(
Tr2Sprite2dD3DVertex* verticesSrc,
unsigned int vertexCount,
unsigned int* indices,
unsigned int indexCount );

bool EnsureBufferSpace( unsigned int vertexCount, unsigned int indexCount, int& vertexOffset );

bool IsCapturing() const;
bool StartCapture( ITr2SpriteObject* owner );
Expand Down Expand Up @@ -157,7 +164,8 @@ class Tr2Sprite2dScene : public ITr2Scene,

// Copies vertices from source to destination and adds clipping and transform information
void ProcessVertices( Tr2Sprite2dD3DVertex* verticesSrc, unsigned int vertexCount );
void CopyIndicesWithOffset( unsigned short* indices, unsigned short indexCount, int vertexOffset );
void CopyIndicesWithOffset( unsigned short* indices, unsigned int indexCount, int vertexOffset );
void CopyIndicesWithOffset( unsigned int* indices, unsigned int indexCount, int vertexOffset );

void FlashDefaultTexture();
void RemoveFinishedCurveSets();
Expand All @@ -169,7 +177,7 @@ class Tr2Sprite2dScene : public ITr2Scene,
void PrepareRenderContextForRendering( Tr2RenderContext& renderContext );
void CleanUpStacksAfterRender();
void PrepareStacksBeforeRender();
void GrowCaptureIndexBuffer( unsigned short indexCount );
void GrowCaptureIndexBuffer( unsigned int indexCount );
void GrowCaptureVertexBuffer( unsigned int vertexCount );


Expand Down