| 741 | } |
| 742 | |
| 743 | void Tr2FontMeasurer::PrepareSprites( Tr2Sprite2dScene* renderer, const Vector2& translation, const Color& color, Tr2SpriteObjectEffect sfx, Tr2SpriteObjectBlendMode blendMode, Tr2SpriteTarget target, float glowBrightness, bool dropShadow, const Vector2& shadowOffset, const Color& shadowColor, Tr2SpriteObjectEffect shadowSfx ) |
| 744 | { |
| 745 | CCP_STATS_ZONE( __FUNCTION__ ); |
| 746 | |
| 747 | if( m_vertices ) |
| 748 | { |
| 749 | CCP_DELETE[] m_vertices; |
| 750 | m_vertices = nullptr; |
| 751 | m_vertexCount = 0; |
| 752 | |
| 753 | CCP_DELETE[] m_indices; |
| 754 | m_indices = nullptr; |
| 755 | m_indexCount = 0; |
| 756 | } |
| 757 | |
| 758 | unsigned int spriteCount = 0; |
| 759 | for( auto it = m_committedRenderData.begin(); it != m_committedRenderData.end(); ++it ) |
| 760 | { |
| 761 | Tr2FontRenderData* rd = *it; |
| 762 | spriteCount += rd->bitmapCount; |
| 763 | if( rd->underline ) |
| 764 | { |
| 765 | ++spriteCount; |
| 766 | } |
| 767 | } |
| 768 | |
| 769 | if( spriteCount == 0 ) |
| 770 | { |
| 771 | return; |
| 772 | } |
| 773 | |
| 774 | if( dropShadow ) |
| 775 | { |
| 776 | spriteCount *= 2; |
| 777 | } |
| 778 | |
| 779 | m_drawCalls.clear(); |
| 780 | |
| 781 | m_vertexCount = spriteCount * 4; |
| 782 | m_vertices = CCP_NEW( "Tr2FontMeasurer/m_vertices" ) Tr2Sprite2dD3DVertex[m_vertexCount]; |
| 783 | |
| 784 | m_indexCount = spriteCount * 6; |
| 785 | m_indices = CCP_NEW( "Tr2FontMeasurer/m_indices" ) unsigned short[m_indexCount]; |
| 786 | unsigned short* curIndex = m_indices; |
| 787 | |
| 788 | Tr2AtlasTexture* currentTexture = nullptr; |
| 789 | |
| 790 | // Index of current sprite in the loop |
| 791 | unsigned int spriteIx = 0; |
| 792 | |
| 793 | // Index of start of run with current texture |
| 794 | unsigned int startIx = 0; |
| 795 | |
| 796 | // Index of vertex. This is reset for each drawcall, as the vertex buffer |
| 797 | // is segmented for each drawcall. |
| 798 | int vertexIx = 0; |
| 799 | |
| 800 | auto addSprites = [&]( const Vector2& offset, const Color& currentColor, Tr2SpriteObjectEffect currentSfx ) { |
no test coverage detected