Skip to content
Permalink
Browse files

Tile batcher performance tweak

  • Loading branch information...
ccw808 committed Oct 27, 2019
1 parent 7f423d0 commit c461a6cfb29885809bad6420b44fbee86dcb8865
Showing with 13 additions and 21 deletions.
  1. +13 −21 Client/core/Graphics/CTileBatcher.cpp
@@ -126,28 +126,21 @@ void CTileBatcher::Flush()
{
if (!m_Vertices.empty())
{
//
// TODO - Optimize all this
//

// Save render states
IDirect3DStateBlock9* pSavedStateBlock = nullptr;
m_pDevice->CreateStateBlock(D3DSBT_ALL, &pSavedStateBlock);

if (m_bUseCustomMatrices && m_bZBufferDirty)
{
// Shaders with transforms will probably need a clear zbuffer
m_pDevice->Clear(0, nullptr, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1, 0);
m_bZBufferDirty = false;
}

// Set states
if (g_pDeviceState->AdapterState.bRequiresClipping)
m_pDevice->SetRenderState(D3DRS_CLIPPING, TRUE);
m_pDevice->SetRenderState(D3DRS_ZENABLE, m_bUseCustomMatrices ? D3DZB_TRUE : D3DZB_FALSE);

if (m_bUseCustomMatrices)
{
// Shaders with transforms will probably use the zbuffer
if (m_bZBufferDirty)
{
m_pDevice->Clear(0, nullptr, D3DCLEAR_ZBUFFER, D3DCOLOR_ARGB(0, 0, 0, 0), 1, 0);
m_bZBufferDirty = false;
}
m_pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_TRUE);

// Set custom transforms
m_pDevice->SetTransform(D3DTS_WORLD, &m_MatCustomWorld);
m_pDevice->SetTransform(D3DTS_VIEW, &m_MatView);
m_pDevice->SetTransform(D3DTS_PROJECTION, &m_MatCustomProjection);
@@ -245,11 +238,10 @@ void CTileBatcher::Flush()
m_fCurrentRotCenY = 0;

// Restore render states
if (pSavedStateBlock)
{
pSavedStateBlock->Apply();
SAFE_RELEASE(pSavedStateBlock);
}
if (g_pDeviceState->AdapterState.bRequiresClipping)
m_pDevice->SetRenderState(D3DRS_CLIPPING, FALSE);
if (m_bUseCustomMatrices)
m_pDevice->SetRenderState(D3DRS_ZENABLE, D3DZB_FALSE);
}
}

0 comments on commit c461a6c

Please sign in to comment.
You can’t perform that action at this time.