@@ -124,19 +124,6 @@ namespace GfxLayer::Extension
124124
125125 void OverlayRenderer_D3D10::Render (bool renderBar, bool useRainbow, bool enableBackground)
126126 {
127- ID3D10Buffer* pConstantBuffer = nullptr ;
128- if (renderBar) {
129- if (useRainbow) {
130- pConstantBuffer = m_rainbowConstantBufferPtrs[GetRainbowIndex ()].Get ();
131- }
132- else {
133- pConstantBuffer = m_pConstantBufferBar.Get ();
134- }
135- }
136- else {
137- pConstantBuffer = m_pConstantBufferBackground.Get ();
138- }
139-
140127 // Capture the current state
141128
142129 m_pStateBlock->Capture ();
@@ -160,17 +147,33 @@ namespace GfxLayer::Extension
160147 UINT stride = sizeof (Quad::Vertex);
161148 UINT offset = 0 ;
162149
150+ // set common state
163151 m_pDevice->ClearState ();
164- m_pDevice->RSSetViewports (1 , &m_Viewport);
165152 m_pDevice->OMSetRenderTargets (1 , &pRtv, nullptr );
166153 m_pDevice->IASetInputLayout (m_pVertexLayout.Get ());
167154 m_pDevice->IASetVertexBuffers (0 , 1 , &pVertexBuffer, &stride, &offset);
168155 m_pDevice->IASetIndexBuffer (m_pIndexBuffer.Get (), DXGI_FORMAT_R32_UINT, 0 );
169156 m_pDevice->IASetPrimitiveTopology (D3D10_PRIMITIVE_TOPOLOGY_TRIANGLELIST);
170157 m_pDevice->VSSetShader (m_pVertexShader.Get ());
171- m_pDevice->PSSetConstantBuffers (0 , 1 , &pConstantBuffer);
172158 m_pDevice->PSSetShader (m_pPixelShader.Get ());
173- m_pDevice->DrawIndexed (6 , 0 , 0 );
159+ // issue fg/bg draw calls
160+ const auto Draw = [&](ID3D10Buffer* pConstantBuffer, const D3D10_VIEWPORT& vp) {
161+ m_pDevice->RSSetViewports (1 , &vp);
162+ m_pDevice->PSSetConstantBuffers (0 , 1 , &pConstantBuffer);
163+ m_pDevice->DrawIndexed (6 , 0 , 0 );
164+ };
165+ if (renderBar) {
166+ if (enableBackground && m_backgroundViewport.Width > m_foregrountViewport.Width ) {
167+ Draw (m_pConstantBufferBackground.Get (), m_backgroundViewport);
168+ }
169+ Draw (useRainbow ?
170+ m_rainbowConstantBufferPtrs[GetRainbowIndex ()].Get () :
171+ m_pConstantBufferBar.Get (),
172+ m_foregrountViewport);
173+ }
174+ else {
175+ Draw (m_pConstantBufferBackground.Get (), m_backgroundViewport);
176+ }
174177
175178 // Restore the previous state
176179
@@ -179,11 +182,9 @@ namespace GfxLayer::Extension
179182
180183 void OverlayRenderer_D3D10::UpdateViewport (const OverlayConfig& cfg)
181184 {
182- auto rect = GetScissorRects ().fg ;
183- m_Viewport.TopLeftX = rect.left ;
184- m_Viewport.TopLeftY = rect.top ;
185- m_Viewport.Width = rect.right - rect.left ;
186- m_Viewport.Height = rect.bottom - rect.top ;
185+ const auto scissors = GetScissorRects ();
186+ m_foregrountViewport = MakeViewport<D3D10_VIEWPORT>(scissors.fg );
187+ m_backgroundViewport = MakeViewport<D3D10_VIEWPORT>(scissors.bg );
187188 }
188189
189190 void OverlayRenderer_D3D10::UpdateConfig (const OverlayConfig& cfg)
0 commit comments