From 13afccfe10d6a3c6fea0c25407121a2f73a06ef3 Mon Sep 17 00:00:00 2001 From: Chris Danford Date: Sat, 2 Feb 2002 07:42:52 +0000 Subject: [PATCH] Bitmap Text speedup --- stepmania/src/BitmapText.cpp | 333 ++++++++++++++--------------------- stepmania/src/BitmapText.h | 5 +- 2 files changed, 132 insertions(+), 206 deletions(-) diff --git a/stepmania/src/BitmapText.cpp b/stepmania/src/BitmapText.cpp index 8890de1a98..f228109758 100644 --- a/stepmania/src/BitmapText.cpp +++ b/stepmania/src/BitmapText.cpp @@ -29,14 +29,21 @@ BitmapText::BitmapText() m_HorizAlign = align_center; m_VertAlign = align_middle; - // allocate a vertex buffer - HRESULT hr; - if( FAILED( hr = SCREEN->GetDevice()->CreateVertexBuffer( - MAX_NUM_VERTICIES * sizeof(CUSTOMVERTEX), - D3DUSAGE_WRITEONLY, D3DFVF_CUSTOMVERTEX, - D3DPOOL_MANAGED, &m_pVB ) ) ) - RageErrorHr( "Vertex Buffer Could Not Be Created", hr ); +// m_bHasShadow = false; + // create the vertex buffer + HRESULT hr = SCREEN->GetDevice()->CreateVertexBuffer( + MAX_NUM_VERTICIES * sizeof(CUSTOMVERTEX), + D3DUSAGE_WRITEONLY, + D3DFVF_CUSTOMVERTEX, + D3DPOOL_MANAGED, + &m_pVB ); + + if( FAILED( hr ) ) + { + RageErrorHr( "Vertex Buffer Could Not Be Created", hr ); + } + m_iNumV = 0; } BitmapText::~BitmapText() @@ -190,6 +197,106 @@ float BitmapText::GetLineWidthInSourcePixels( int iLineNo ) } +void BitmapText::RebuildVertexBuffer() +{ + // make the object in logical units centered at the origin + LPDIRECT3DVERTEXBUFFER8 pVB = m_pVB; + CUSTOMVERTEX* v; + pVB->Lock( 0, 0, (BYTE**)&v, 0 ); + + + + + m_iNumV = 0; // the current vertex number + + float fHeight = GetUnzoomedHeight(); + float fY; + switch( m_VertAlign ) + { + case align_top: fY = -(m_sTextLines.GetSize()) * fHeight / 2; break; + case align_middle: fY = 0; break; + case align_bottom: fY = (m_sTextLines.GetSize()) * fHeight / 2; break; + default: ASSERT( true ); + } + + + for( int i=0; i 1-fPercentageOfFrame ) + fPercentExtra = 1-fPercentageOfFrame; + + + // set vertex positions + + v[m_iNumV++].p = D3DXVECTOR3( fX, fY+fHeight/2, 0 ); // bottom left + v[m_iNumV++].p = D3DXVECTOR3( fX, fY-fHeight/2, 0 ); // top left + + fX += fCharWidth; + + float fExtraPixels = fPercentExtra * GetUnzoomedWidth(); + + v[m_iNumV++].p = D3DXVECTOR3( fX+fExtraPixels, fY+fHeight/2, 0 ); // bottom right + v[m_iNumV++].p = D3DXVECTOR3( fX+fExtraPixels, fY-fHeight/2, 0 ); // top right + + + // set texture coordinates + m_iNumV -= 4; + + FRECT* pTexCoordRect = m_pTexture->GetTextureCoordRect( iFrameNo ); + + float fExtraTexCoords = fPercentExtra * m_pTexture->GetTextureFrameWidth() / m_pTexture->GetTextureWidth(); + + v[m_iNumV].tu = pTexCoordRect->left; v[m_iNumV++].tv = pTexCoordRect->bottom; // bottom left + v[m_iNumV].tu = pTexCoordRect->left; v[m_iNumV++].tv = pTexCoordRect->top; // top left + v[m_iNumV].tu = pTexCoordRect->right + fExtraTexCoords; v[m_iNumV++].tv = pTexCoordRect->bottom; // bottom right + v[m_iNumV].tu = pTexCoordRect->right + fExtraTexCoords; v[m_iNumV++].tv = pTexCoordRect->top; // top right + + + } + + fY += fHeight; + } + + + + pVB->Unlock(); + + +} + // draw text at x, y using colorTop blended down to colorBottom, with size multiplied by scale void BitmapText::RenderPrimitives() @@ -242,107 +349,14 @@ void BitmapText::RenderPrimitives() break; } - pd3dDevice->SetRenderState( D3DRS_SRCBLEND, m_bBlendAdd ? D3DBLEND_ONE : D3DBLEND_SRCALPHA ); - pd3dDevice->SetRenderState( D3DRS_DESTBLEND, m_bBlendAdd ? D3DBLEND_ONE : D3DBLEND_INVSRCALPHA ); - // make the object in logical units centered at the origin + +// RebuildVertexBuffer(); + + + LPDIRECT3DVERTEXBUFFER8 pVB = m_pVB; CUSTOMVERTEX* v; - m_pVB->Lock( 0, 0, (BYTE**)&v, 0 ); - - - - - int &iVNum = m_iNumVerticies; // the current vertex number - iVNum = 0; - - - float fHeight = GetUnzoomedHeight(); - float fY; - switch( m_VertAlign ) - { - case align_top: fY = -(m_sTextLines.GetSize()) * fHeight / 2; break; break; - case align_middle: fY = 0; break; - case align_bottom: fY = (m_sTextLines.GetSize()) * fHeight / 2; break; - default: ASSERT( true ); - } - - - for( i=0; i 1-fPercentageOfFrame ) - fPercentExtra = 1-fPercentageOfFrame; - - - // set vertex positions - - v[iVNum++].p = D3DXVECTOR3( fX, fY+fHeight/2, 0 ); // bottom left - v[iVNum++].p = D3DXVECTOR3( fX, fY-fHeight/2, 0 ); // top left - - fX += fCharWidth; - - float fExtraPixels = fPercentExtra * GetUnzoomedWidth(); - - v[iVNum++].p = D3DXVECTOR3( fX+fExtraPixels, fY+fHeight/2, 0 ); // bottom right - v[iVNum++].p = D3DXVECTOR3( fX+fExtraPixels, fY-fHeight/2, 0 ); // top right - - - // set texture coordinates - iVNum -= 4; - - FRECT* pTexCoordRect = m_pTexture->GetTextureCoordRect( iFrameNo ); - - float fExtraTexCoords = fPercentExtra * m_pTexture->GetTextureFrameWidth() / m_pTexture->GetTextureWidth(); - - v[iVNum].tu = pTexCoordRect->left; v[iVNum++].tv = pTexCoordRect->bottom; // bottom left - v[iVNum].tu = pTexCoordRect->left; v[iVNum++].tv = pTexCoordRect->top; // top left - v[iVNum].tu = pTexCoordRect->right + fExtraTexCoords; v[iVNum++].tv = pTexCoordRect->bottom; // bottom right - v[iVNum].tu = pTexCoordRect->right + fExtraTexCoords; v[iVNum++].tv = pTexCoordRect->top; // top right - - - } - - fY += fHeight; - } - - - - pVB->Unlock(); - - // Set the stage... @@ -373,7 +387,7 @@ void BitmapText::RenderPrimitives() pVB->Lock( 0, 0, (BYTE**)&v, 0 ); - for( int i=0; iUnlock(); @@ -385,7 +399,7 @@ void BitmapText::RenderPrimitives() pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - for( i=0; iDrawPrimitive( D3DPT_TRIANGLESTRIP, i, 2 ); SCREEN->PopMatrix(); @@ -397,9 +411,9 @@ void BitmapText::RenderPrimitives() ////////////////////// pVB->Lock( 0, 0, (BYTE**)&v, 0 ); - for( int i=0; iSetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );//bBlendAdd ? D3DTOP_ADD : D3DTOP_MODULATE ); - for( i=0; iDrawPrimitive( D3DPT_TRIANGLESTRIP, i, 2 ); } @@ -429,7 +443,7 @@ void BitmapText::RenderPrimitives() { pVB->Lock( 0, 0, (BYTE**)&v, 0 ); - for( int i=0; iUnlock(); @@ -441,7 +455,7 @@ void BitmapText::RenderPrimitives() pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE ); pd3dDevice->SetTextureStageState( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE ); - for( i=0; iDrawPrimitive( D3DPT_TRIANGLESTRIP, i, 2 ); } @@ -460,6 +474,9 @@ void BitmapText::SetText( CString sText ) m_sTextLines.RemoveAll(); split( sText, "\n", m_sTextLines, false ); + + + RebuildVertexBuffer(); } CString BitmapText::GetText() @@ -467,95 +484,3 @@ CString BitmapText::GetText() return join( "\n", m_sTextLines ); } -void BitmapText::RebuildVertexBuffer() -{ - // make the object in logical units centered at the origin - CUSTOMVERTEX* v; - m_pVB->Lock( 0, 0, (BYTE**)&v, 0 ); - - - int &iVNum = m_iNumVerticies; // the current vertex number - iVNum = 0; - - - float fHeight = GetUnzoomedHeight(); - float fY; - switch( m_VertAlign ) - { - case align_top: fY = -(m_sTextLines.GetSize()) * fHeight / 2; break; break; - case align_middle: fY = 0; break; - case align_bottom: fY = (m_sTextLines.GetSize()) * fHeight / 2; break; - default: ASSERT( true ); - } - - - for( i=0; i 1-fPercentageOfFrame ) - fPercentExtra = 1-fPercentageOfFrame; - - - // set vertex positions - - v[iVNum++].p = D3DXVECTOR3( fX, fY+fHeight/2, 0 ); // bottom left - v[iVNum++].p = D3DXVECTOR3( fX, fY-fHeight/2, 0 ); // top left - - fX += fCharWidth; - - float fExtraPixels = fPercentExtra * GetUnzoomedWidth(); - - v[iVNum++].p = D3DXVECTOR3( fX+fExtraPixels, fY+fHeight/2, 0 ); // bottom right - v[iVNum++].p = D3DXVECTOR3( fX+fExtraPixels, fY-fHeight/2, 0 ); // top right - - - // set texture coordinates - iVNum -= 4; - - FRECT* pTexCoordRect = m_pTexture->GetTextureCoordRect( iFrameNo ); - - float fExtraTexCoords = fPercentExtra * m_pTexture->GetTextureFrameWidth() / m_pTexture->GetTextureWidth(); - - v[iVNum].tu = pTexCoordRect->left; v[iVNum++].tv = pTexCoordRect->bottom; // bottom left - v[iVNum].tu = pTexCoordRect->left; v[iVNum++].tv = pTexCoordRect->top; // top left - v[iVNum].tu = pTexCoordRect->right + fExtraTexCoords; v[iVNum++].tv = pTexCoordRect->bottom; // bottom right - v[iVNum].tu = pTexCoordRect->right + fExtraTexCoords; v[iVNum++].tv = pTexCoordRect->top; // top right - - - } - - fY += fHeight; - } - - - - m_pVB->Unlock(); - -} \ No newline at end of file diff --git a/stepmania/src/BitmapText.h b/stepmania/src/BitmapText.h index d21f635e20..3ee01e2b9a 100644 --- a/stepmania/src/BitmapText.h +++ b/stepmania/src/BitmapText.h @@ -25,6 +25,7 @@ protected: public: BitmapText(); + ~BitmapText(); virtual void RenderPrimitives(); @@ -47,8 +48,8 @@ protected: LPDIRECT3DVERTEXBUFFER8 m_pVB; // our vertex buffer only needs to be rebuilt when the text changes - int m_iNumVerticies; - RebuildVertexBuffer(); // this should be called when the + int m_iNumV; // number of verticies used in the vertex buffer + void RebuildVertexBuffer(); // this should be called when the text changes CStringArray m_sTextLines; };