Code:
// Initialize resources such as textures (managed and unmanaged), vertex
// buffers, and other D3D resources
HRESULT D3D9Mgr::Initialize()
{
// Create new GUI manager
m_pD3D9Helper.reset(new D3D9Helper());
m_pD3D9Helper->OnInitialize(m_pParent, m_pD3D9Helper);
// Create state block
m_pDevice->CreateStateBlock(D3DSBT_ALL, &m_pStateBlock);
// Call registered callbacks
m_CallsOnInitialize(m_pParent, m_pD3D9Helper);
// Return success
return S_OK;
}
// Release all unmanaged resources
HRESULT D3D9Mgr::PreReset()
{
// Release state block
m_pStateBlock->Release();
// Prevent double-free
m_pStateBlock = NULL;
// D3D9 Helper
m_pD3D9Helper->OnLostDevice(m_pParent, m_pD3D9Helper);
// Call registered callbacks
m_CallsOnLostDevice(m_pParent, m_pD3D9Helper);
// Return success
return S_OK;
}
// Re-initialize all unmanaged resources
HRESULT D3D9Mgr::PostReset()
{
// Create state block
m_pDevice->CreateStateBlock(D3DSBT_ALL, &m_pStateBlock);
// D3D9 Helper
m_pD3D9Helper->OnResetDevice(m_pParent, m_pD3D9Helper);
// Call registered callbacks
m_CallsOnResetDevice(m_pParent, m_pD3D9Helper);
// Return success
return S_OK;
}
// DrawIndexedPrimitive proxy
HRESULT D3D9Mgr::DrawIndexedPrimitive(D3DPRIMITIVETYPE Type, INT BaseVertexIndex,
UINT MinVertexIndex, UINT NumVertices, UINT startIndex, UINT primCount)
{
// Data for DrawIndexedPrimitive
DipData Data;
Data.Type = Type;
Data.BaseVertexIndex = BaseVertexIndex;
Data.MinVertexIndex = MinVertexIndex;
Data.NumVertices = NumVertices;
Data.startIndex = startIndex;
Data.primCount = primCount;
// Call registered callbacks
bool Blocked = m_CallsOnDrawIndexedPrimitive(m_pParent, m_pD3D9Helper,
&Data);
if (Blocked)
return 1;
// Return success
return S_OK;
}
// Do rendering
HRESULT D3D9Mgr::Render()
{
// Capture state block
m_pStateBlock->Capture();
// Call registered callbacks
m_CallsOnFrame(m_pParent, m_pD3D9Helper);
// Apply captured state block
m_pStateBlock->Apply();
// Return success
return S_OK;
}