Splits PrepareScene and remove intermediates

We don't need to have intermediate functions as they don't add something
useful.
This commit is contained in:
Vladislav Belov 2026-07-13 00:40:36 +02:00
parent 43dd988ee7
commit d2375de187
No known key found for this signature in database
GPG key ID: 353545E45DB9CCB3
6 changed files with 67 additions and 63 deletions

View file

@ -196,9 +196,16 @@ const CCamera& CGameView::GetCamera() const
return m->ViewCamera; return m->ViewCamera;
} }
const CCamera& CGameView::GetCullCamera() const
{
return m->CullCamera;
}
void CGameView::SetCamera(const CCamera& camera) void CGameView::SetCamera(const CCamera& camera)
{ {
m->ViewCamera = camera; m->ViewCamera = camera;
UpdateCullCamera();
} }
CCinemaManager* CGameView::GetCinema() CCinemaManager* CGameView::GetCinema()
@ -236,22 +243,9 @@ void CGameView::RegisterInit()
}, L"TerrainTextures", 61); }, L"TerrainTextures", 61);
} }
void CGameView::BeginFrame() void CGameView::EnumerateSceneObjects()
{ {
if (m->LockCullCamera == false) g_Renderer.GetSceneRenderer().EnumerateSceneObjects(*this);
{
// Set up cull camera
m->CullCamera = m->ViewCamera;
}
g_Renderer.GetSceneRenderer().SetSceneCamera(m->ViewCamera, m->CullCamera);
m->Game->CachePlayerColors();
}
void CGameView::Prepare(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
{
g_Renderer.GetSceneRenderer().PrepareScene(deviceCommandContext, *this);
} }
/////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////
@ -297,6 +291,12 @@ void CGameView::Update(const float deltaRealTime)
{ {
m->MiniMapTexture.Update(deltaRealTime); m->MiniMapTexture.Update(deltaRealTime);
UpdateCamera(deltaRealTime);
UpdateCullCamera();
}
void CGameView::UpdateCamera(const float deltaRealTime)
{
m->CinemaManager.Update(deltaRealTime, m->ViewCamera); m->CinemaManager.Update(deltaRealTime, m->ViewCamera);
if (m->CinemaManager.IsPlaying()) if (m->CinemaManager.IsPlaying())
return; return;
@ -311,6 +311,12 @@ void CGameView::Update(const float deltaRealTime)
m->CameraController->Update(deltaRealTime); m->CameraController->Update(deltaRealTime);
} }
void CGameView::UpdateCullCamera()
{
if (!m->LockCullCamera)
m->CullCamera = m->ViewCamera;
}
CVector3D CGameView::GetCameraPivot() const CVector3D CGameView::GetCameraPivot() const
{ {
return m->CameraController->GetCameraPivot(); return m->CameraController->GetCameraPivot();
@ -334,6 +340,8 @@ float CGameView::GetCameraZoom() const
void CGameView::SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom) void CGameView::SetCamera(const CVector3D& pos, float rotX, float rotY, float zoom)
{ {
m->CameraController->SetCamera(pos, rotX, rotY, zoom); m->CameraController->SetCamera(pos, rotX, rotY, zoom);
UpdateCullCamera();
} }
void CGameView::MoveCameraTarget(const CVector3D& target) void CGameView::MoveCameraTarget(const CVector3D& target)

View file

@ -52,8 +52,7 @@ public:
*/ */
void Update(const float deltaRealTime); void Update(const float deltaRealTime);
void BeginFrame(); void EnumerateSceneObjects();
void Prepare(Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
CVector3D GetCameraPivot() const; CVector3D GetCameraPivot() const;
CVector3D GetCameraPosition() const; CVector3D GetCameraPosition() const;
@ -79,6 +78,8 @@ public:
const CCamera& GetCamera() const; const CCamera& GetCamera() const;
void SetCamera(const CCamera& camera); void SetCamera(const CCamera& camera);
const CCamera& GetCullCamera() const;
CCinemaManager* GetCinema(); CCinemaManager* GetCinema();
CObjectManager& GetObjectManager(); CObjectManager& GetObjectManager();
@ -91,6 +92,8 @@ public:
private: private:
// Unloads all graphics resources loaded by RegisterInit. // Unloads all graphics resources loaded by RegisterInit.
void UnloadResources(); void UnloadResources();
void UpdateCamera(const float deltaRealTime);
void UpdateCullCamera();
CGameViewImpl* m; CGameViewImpl* m;
}; };

View file

@ -565,7 +565,12 @@ void CRenderer::RenderFrameImpl(
// prepare before starting the renderer frame // prepare before starting the renderer frame
if (g_Game && g_Game->IsGameStarted()) if (g_Game && g_Game->IsGameStarted())
g_Game->GetView()->BeginFrame(); {
const CGameView& gameView{*g_Game->GetView()};
m->sceneRenderer.SetSceneCamera(gameView.GetCamera(), gameView.GetCullCamera());
g_Game->CachePlayerColors();
}
if (g_Game) if (g_Game)
m->sceneRenderer.SetSimulation(g_Game->GetSimulation2()); m->sceneRenderer.SetSimulation(g_Game->GetSimulation2());
@ -575,9 +580,10 @@ void CRenderer::RenderFrameImpl(
if (g_Game && g_Game->IsGameStarted()) if (g_Game && g_Game->IsGameStarted())
{ {
ENSURE(g_Game->GetView());
CGameView& gameView{*g_Game->GetView()}; CGameView& gameView{*g_Game->GetView()};
gameView.Prepare(m->deviceCommandContext.get()); gameView.EnumerateSceneObjects();
m->sceneRenderer.PrepareSubmissions(m->deviceCommandContext.get());
CPostprocManager& postprocManager{GetPostprocManager()}; CPostprocManager& postprocManager{GetPostprocManager()};
if (postprocManager.IsEnabled()) if (postprocManager.IsEnabled())
@ -632,7 +638,7 @@ void CRenderer::RenderGameAndGUI(
m->deviceCommandContext->BeginFramebufferPass(framebuffer); m->deviceCommandContext->BeginFramebufferPass(framebuffer);
m->deviceCommandContext->SetViewports(1, &viewportRect); m->deviceCommandContext->SetViewports(1, &viewportRect);
m->sceneRenderer.RenderScene(m->deviceCommandContext.get()); m->sceneRenderer.RenderSubmissions(m->deviceCommandContext.get());
RenderGameOverlays(gameView); RenderGameOverlays(gameView);
Render2D(renderGUI, renderLogger); Render2D(renderGUI, renderLogger);
@ -662,7 +668,7 @@ void CRenderer::RenderGameWithPostProcessingAndGUI(
m->deviceCommandContext->BeginFramebufferPass(framebuffer); m->deviceCommandContext->BeginFramebufferPass(framebuffer);
m->deviceCommandContext->SetViewports(1, &viewportRect); m->deviceCommandContext->SetViewports(1, &viewportRect);
m->sceneRenderer.RenderScene(m->deviceCommandContext.get()); m->sceneRenderer.RenderSubmissions(m->deviceCommandContext.get());
m->deviceCommandContext->EndFramebufferPass(); m->deviceCommandContext->EndFramebufferPass();

View file

@ -749,12 +749,17 @@ void CSceneRenderer::RenderParticles(
} }
void CSceneRenderer::PrepareSubmissions( void CSceneRenderer::PrepareSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
const CBoundingBoxAligned& waterScissor)
{ {
PROFILE3_GPU(deviceCommandContext, "prepare submissions"); PROFILE3_GPU(deviceCommandContext, "prepare submissions");
GPU_SCOPED_LABEL(deviceCommandContext, "Prepare submissions"); GPU_SCOPED_LABEL(deviceCommandContext, "Prepare submissions");
if (m->waterManager.m_RenderWater && m_WaterScissor.GetVolume() > 0 && m->waterManager.WillRenderFancyWater())
{
// Render the waves to the Fancy effects texture
m->waterManager.RenderWaves(deviceCommandContext, m_CullCamera.GetFrustum());
}
m->skyManager.LoadAndUploadSkyTexturesIfNeeded(deviceCommandContext); m->skyManager.LoadAndUploadSkyTexturesIfNeeded(deviceCommandContext);
GetScene().GetLOSTexture().InterpolateLOS(deviceCommandContext); GetScene().GetLOSTexture().InterpolateLOS(deviceCommandContext);
@ -802,16 +807,16 @@ void CSceneRenderer::PrepareSubmissions(
if (m->waterManager.m_RenderWater) if (m->waterManager.m_RenderWater)
{ {
if (waterScissor.GetVolume() > 0 && m->waterManager.WillRenderFancyWater()) if (m_WaterScissor.GetVolume() > 0 && m->waterManager.WillRenderFancyWater())
{ {
m->waterManager.UpdateQuality(); m->waterManager.UpdateQuality();
PROFILE3_GPU(deviceCommandContext, "water scissor"); PROFILE3_GPU(deviceCommandContext, "water scissor");
if (g_RenderingOptions.GetWaterReflection()) if (g_RenderingOptions.GetWaterReflection())
RenderReflections(deviceCommandContext, context, waterScissor); RenderReflections(deviceCommandContext, context, m_WaterScissor);
if (g_RenderingOptions.GetWaterRefraction()) if (g_RenderingOptions.GetWaterRefraction())
RenderRefractions(deviceCommandContext, context, waterScissor); RenderRefractions(deviceCommandContext, context, m_WaterScissor);
if (g_RenderingOptions.GetWaterFancyEffects()) if (g_RenderingOptions.GetWaterFancyEffects())
m->terrainRenderer.RenderWaterFoamOccluders(deviceCommandContext, CULL_DEFAULT); m->terrainRenderer.RenderWaterFoamOccluders(deviceCommandContext, CULL_DEFAULT);
@ -820,12 +825,13 @@ void CSceneRenderer::PrepareSubmissions(
} }
void CSceneRenderer::RenderSubmissions( void CSceneRenderer::RenderSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
const CBoundingBoxAligned& waterScissor)
{ {
PROFILE3("render submissions"); PROFILE3("render submissions");
GPU_SCOPED_LABEL(deviceCommandContext, "Render submissions"); GPU_SCOPED_LABEL(deviceCommandContext, "Render submissions");
ENSURE(m_CurrentScene);
CShaderDefines context = m->globalContext; CShaderDefines context = m->globalContext;
constexpr int cullGroup = CULL_DEFAULT; constexpr int cullGroup = CULL_DEFAULT;
@ -845,7 +851,7 @@ void CSceneRenderer::RenderSubmissions(
RenderModels(deviceCommandContext, context, cullGroup); RenderModels(deviceCommandContext, context, cullGroup);
// render water // render water
if (m->waterManager.m_RenderWater && g_Game && waterScissor.GetVolume() > 0) if (m->waterManager.m_RenderWater && g_Game && m_WaterScissor.GetVolume() > 0)
{ {
if (m->waterManager.WillRenderFancyWater()) if (m->waterManager.WillRenderFancyWater())
{ {
@ -1041,12 +1047,11 @@ void CSceneRenderer::SubmitNonRecursive(CModel* model)
} }
} }
void CSceneRenderer::PrepareScene( void CSceneRenderer::EnumerateSceneObjects(Scene& scene)
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene)
{ {
m_CurrentScene = &scene; m_CurrentScene = &scene;
CFrustum frustum = m_CullCamera.GetFrustum(); const CFrustum& frustum{m_CullCamera.GetFrustum()};
m_CurrentCullGroup = CULL_DEFAULT; m_CurrentCullGroup = CULL_DEFAULT;
@ -1103,24 +1108,12 @@ void CSceneRenderer::PrepareScene(
scene.EnumerateObjects(refractionCamera.GetFrustum(), this); scene.EnumerateObjects(refractionCamera.GetFrustum(), this);
} }
// Render the waves to the Fancy effects texture
m->waterManager.RenderWaves(deviceCommandContext, frustum);
} }
} }
else else
m_WaterScissor = CBoundingBoxAligned{}; m_WaterScissor = CBoundingBoxAligned{};
m_CurrentCullGroup = -1; m_CurrentCullGroup = -1;
PrepareSubmissions(deviceCommandContext, m_WaterScissor);
}
void CSceneRenderer::RenderScene(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext)
{
ENSURE(m_CurrentScene);
RenderSubmissions(deviceCommandContext, m_WaterScissor);
} }
void CSceneRenderer::RenderSceneOverlays( void CSceneRenderer::RenderSceneOverlays(

View file

@ -92,15 +92,20 @@ public:
/** /**
* Enumerate and submit all objects of the given scene which should be rendered. * Enumerate and submit all objects of the given scene which should be rendered.
* Must be called before RenderScene. * Must be called before PrepareSubmissions and RenderScene.
*/ */
void PrepareScene( void EnumerateSceneObjects(Scene& scene);
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Scene& scene);
/**
* Update and upload all needed data for submitted objects.
*/
void PrepareSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
/** /**
* Render submitted objects of the previously given scene. * Render submitted objects of the previously given scene.
*/ */
void RenderScene( void RenderSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext); Renderer::Backend::IDeviceCommandContext* deviceCommandContext);
/** /**
@ -204,18 +209,6 @@ protected:
void Submit(SOverlaySphere* overlay) override; void Submit(SOverlaySphere* overlay) override;
void SubmitNonRecursive(CModel* model) override; void SubmitNonRecursive(CModel* model) override;
/**
* Update and upload all needed data for submitted objects.
*/
void PrepareSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
const CBoundingBoxAligned& waterScissor);
// render any batched objects
void RenderSubmissions(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext,
const CBoundingBoxAligned& waterScissor);
// patch rendering stuff // patch rendering stuff
void RenderPatches( void RenderPatches(
Renderer::Backend::IDeviceCommandContext* deviceCommandContext, Renderer::Backend::IDeviceCommandContext* deviceCommandContext,

View file

@ -557,7 +557,8 @@ void ActorViewer::Render()
Renderer::Backend::IDeviceCommandContext* deviceCommandContext = Renderer::Backend::IDeviceCommandContext* deviceCommandContext =
g_Renderer.GetDeviceCommandContext(); g_Renderer.GetDeviceCommandContext();
sceneRenderer.PrepareScene(deviceCommandContext, m); sceneRenderer.EnumerateSceneObjects(m);
sceneRenderer.PrepareSubmissions(deviceCommandContext);
Renderer::Backend::IFramebuffer* backbuffer = Renderer::Backend::IFramebuffer* backbuffer =
swapChain->GetCurrentBackbuffer( swapChain->GetCurrentBackbuffer(
@ -572,7 +573,7 @@ void ActorViewer::Render()
viewportRect.height = backbuffer->GetHeight(); viewportRect.height = backbuffer->GetHeight();
deviceCommandContext->SetViewports(1, &viewportRect); deviceCommandContext->SetViewports(1, &viewportRect);
sceneRenderer.RenderScene(deviceCommandContext); sceneRenderer.RenderSubmissions(deviceCommandContext);
sceneRenderer.RenderSceneOverlays(deviceCommandContext); sceneRenderer.RenderSceneOverlays(deviceCommandContext);
{ {