Some code cleaning in main draw function

This commit is contained in:
MontyTRC89 2021-12-12 14:03:37 +01:00
parent 0e24c03ff2
commit 136de39d7f

View file

@ -2535,8 +2535,12 @@ namespace TEN::Renderer
updateLaraAnimations(false); updateLaraAnimations(false);
updateItemsAnimations(view); updateItemsAnimations(view);
updateEffects(view); updateEffects(view);
// Prepare the shadow map
if (g_Configuration.EnableShadows) if (g_Configuration.EnableShadows)
renderShadowMap(view); renderShadowMap(view);
// Setup Lara item
m_items[Lara.itemNumber].ItemNumber = Lara.itemNumber; m_items[Lara.itemNumber].ItemNumber = Lara.itemNumber;
collectLightsForItem(LaraItem->roomNumber, &m_items[Lara.itemNumber], view); collectLightsForItem(LaraItem->roomNumber, &m_items[Lara.itemNumber], view);
@ -2544,23 +2548,18 @@ namespace TEN::Renderer
m_timeUpdate = (std::chrono::duration_cast<ns>(time2 - time1)).count() / 1000000; m_timeUpdate = (std::chrono::duration_cast<ns>(time2 - time1)).count() / 1000000;
time1 = time2; time1 = time2;
// Draw shadow map
// Reset GPU state // Reset GPU state
m_context->OMSetBlendState(m_states->NonPremultiplied(), NULL, 0xFFFFFFFF); setBlendMode(BLENDMODE_OPAQUE);
m_context->RSSetState(m_states->CullCounterClockwise()); m_context->RSSetState(m_states->CullCounterClockwise());
m_context->OMSetDepthStencilState(m_states->DepthDefault(), 0);
// Bind and clear render target // Bind and clear render target
m_context->ClearRenderTargetView(target, Colors::Black); m_context->ClearRenderTargetView(target, Colors::Black);
m_context->ClearDepthStencilView(depthTarget, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0); m_context->ClearDepthStencilView(depthTarget, D3D11_CLEAR_DEPTH | D3D11_CLEAR_STENCIL, 1.0f, 0);
m_context->OMSetRenderTargets(1, &target, depthTarget); m_context->OMSetRenderTargets(1, &target, depthTarget);
m_context->RSSetViewports(1, &view.viewport); m_context->RSSetViewports(1, &view.viewport);
// Opaque geometry // The camera constant buffer contains matrices, camera position, fog values and other
m_context->OMSetBlendState(m_states->NonPremultiplied(), NULL, 0xFFFFFFFF); // things that are shared for all shaders
CCameraMatrixBuffer cameraConstantBuffer; CCameraMatrixBuffer cameraConstantBuffer;
view.fillConstantBuffer(cameraConstantBuffer); view.fillConstantBuffer(cameraConstantBuffer);
cameraConstantBuffer.Frame = GlobalCounter; cameraConstantBuffer.Frame = GlobalCounter;
@ -2578,9 +2577,11 @@ namespace TEN::Renderer
} }
m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context.Get()); m_cbCameraMatrices.updateData(cameraConstantBuffer, m_context.Get());
m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get()); m_context->VSSetConstantBuffers(0, 1, m_cbCameraMatrices.get());
drawHorizonAndSky(view, depthTarget);
m_context->OMSetBlendState(m_states->NonPremultiplied(), NULL, 0xFFFFFFFF);
// Draw the horizon and the sky
drawHorizonAndSky(view, depthTarget);
// Draw rooms and objects
drawRooms(view); drawRooms(view);
drawStatics(false, view); drawStatics(false, view);
drawLara(false, view); drawLara(false, view);
@ -2596,20 +2597,6 @@ namespace TEN::Renderer
drawScarabs(view); drawScarabs(view);
drawLocusts(view); drawLocusts(view);
// Transparent geometry
m_context->OMSetBlendState(m_states->Additive(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthRead(), 0);
// NOTE: some faces will be drawn immediately, like for additive blending, instead
// other blend modes (like alpha blend) will require collecting the faces and draw them
// sorted in a latter stage
drawStatics(true, view);
drawEffects(view,true);
drawDebris(view,true);
m_context->OMSetBlendState(m_states->Opaque(), NULL, 0xFFFFFFFF);
m_context->OMSetDepthStencilState(m_states->DepthDefault(), 0);
// Do special effects and weather // Do special effects and weather
// NOTE: functions here just fill the sprites to draw array // NOTE: functions here just fill the sprites to draw array
drawFires(view); drawFires(view);