From 5daae13525b75c9736ed2a47372399849574d8cc Mon Sep 17 00:00:00 2001 From: Chrzanof Date: Sun, 21 Dec 2025 12:57:42 +0100 Subject: [PATCH] Pass device command context by reference in DebugRenderer Improve the DebugRenderer API by passing the IDeviceCommandContext as a reference instead of calling g_Renderer. Fixes: #6650 --- .../public/gui/credits/texts/programming.json | 1 + source/graphics/CinemaManager.cpp | 26 ++-- source/graphics/CinemaManager.h | 10 +- source/renderer/DebugRenderer.cpp | 118 +++++++++--------- source/renderer/DebugRenderer.h | 18 +-- source/renderer/OverlayRenderer.cpp | 4 +- source/renderer/ParticleRenderer.cpp | 7 +- source/renderer/ParticleRenderer.h | 4 +- source/renderer/PatchRData.cpp | 6 +- source/renderer/PatchRData.h | 4 +- source/renderer/Renderer.cpp | 6 +- source/renderer/SceneRenderer.cpp | 14 +-- source/renderer/SceneRenderer.h | 4 +- source/renderer/ShadowMap.cpp | 11 +- source/renderer/ShadowMap.h | 4 +- source/renderer/SilhouetteRenderer.cpp | 6 +- source/renderer/TerrainRenderer.cpp | 4 +- source/tools/atlas/GameInterface/View.cpp | 5 +- source/tools/atlas/GameInterface/View.h | 6 +- 19 files changed, 133 insertions(+), 125 deletions(-) diff --git a/binaries/data/mods/public/gui/credits/texts/programming.json b/binaries/data/mods/public/gui/credits/texts/programming.json index 33d7dba280..2bfcea593a 100644 --- a/binaries/data/mods/public/gui/credits/texts/programming.json +++ b/binaries/data/mods/public/gui/credits/texts/programming.json @@ -63,6 +63,7 @@ { "name": "Cédric Houbart" }, { "nick": "Ceres" }, { "nick": "Chakakhan", "name": "Kenny Long" }, + { "nick": "Chrzanof", "name": "Filip Chrzanowski" }, { "nick": "Clockwork-Muse", "name": "Stephen A. Imhoff" }, { "nick": "cpc", "name": "Clément Pit-Claudel" }, { "nick": "Cracker78", "name": "Chad Heim" }, diff --git a/source/graphics/CinemaManager.cpp b/source/graphics/CinemaManager.cpp index 4d2a8f75ea..9f8ac7a5a2 100644 --- a/source/graphics/CinemaManager.cpp +++ b/source/graphics/CinemaManager.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -54,13 +54,13 @@ void CCinemaManager::Update(const float deltaRealTime) const cmpCinemaManager->PlayQueue(deltaRealTime, g_Game->GetView()->GetCamera()); } -void CCinemaManager::Render() const +void CCinemaManager::Render(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const { if (!IsEnabled() && m_DrawPaths) - DrawPaths(); + DrawPaths(deviceCommandContext); } -void CCinemaManager::DrawPaths() const +void CCinemaManager::DrawPaths(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const { CmpPtr cmpCinemaManager(g_Game->GetSimulation2()->GetSimContext().GetSystemEntity()); if (!cmpCinemaManager) @@ -68,18 +68,18 @@ void CCinemaManager::DrawPaths() const for (const std::pair& p : cmpCinemaManager->GetPaths()) { - DrawSpline(p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 128); - DrawNodes(p.second, CColor(0.1f, 1.f, 0.f, 1.f)); + DrawSpline(deviceCommandContext, p.second, CColor(0.2f, 0.2f, 1.f, 0.9f), 128); + DrawNodes(deviceCommandContext, p.second, CColor(0.1f, 1.f, 0.f, 1.f)); if (p.second.GetTargetSpline().GetAllNodes().empty()) continue; - DrawSpline(p.second.GetTargetSpline(), CColor(1.f, 0.3f, 0.4f, 0.9f), 128); - DrawNodes(p.second.GetTargetSpline(), CColor(1.f, 0.1f, 0.f, 1.f)); + DrawSpline(deviceCommandContext, p.second.GetTargetSpline(), CColor(1.f, 0.3f, 0.4f, 0.9f), 128); + DrawNodes(deviceCommandContext, p.second.GetTargetSpline(), CColor(1.f, 0.1f, 0.f, 1.f)); } } -void CCinemaManager::DrawSpline(const RNSpline& spline, const CColor& splineColor, int smoothness) const +void CCinemaManager::DrawSpline(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& splineColor, int smoothness) const { if (spline.GetAllNodes().size() < 2) return; @@ -94,7 +94,8 @@ void CCinemaManager::DrawSpline(const RNSpline& spline, const CColor& splineColo const float time = start * i / spline.MaxDistance.ToFloat(); line.emplace_back(spline.GetPosition(time)); } - g_Renderer.GetDebugRenderer().DrawLine(line, splineColor, 0.2f, false); + + g_Renderer.GetDebugRenderer().DrawLine(deviceCommandContext, line, splineColor, 0.2f, false); // Height indicator if (g_Game && g_Game->GetWorld()) @@ -104,16 +105,17 @@ void CCinemaManager::DrawSpline(const RNSpline& spline, const CColor& splineColo const float time = start * i / spline.MaxDistance.ToFloat(); const CVector3D tmp = spline.GetPosition(time); const float groundY = g_Game->GetWorld()->GetTerrain().GetExactGroundLevel(tmp.X, tmp.Z); - g_Renderer.GetDebugRenderer().DrawLine(tmp, CVector3D(tmp.X, groundY, tmp.Z), splineColor, 0.1f, false); + g_Renderer.GetDebugRenderer().DrawLine(deviceCommandContext, tmp, CVector3D(tmp.X, groundY, tmp.Z), splineColor, 0.1f, false); } } } -void CCinemaManager::DrawNodes(const RNSpline& spline, const CColor& nodeColor) const +void CCinemaManager::DrawNodes(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& nodeColor) const { for (const SplineData& node : spline.GetAllNodes()) { g_Renderer.GetDebugRenderer().DrawCircle( + deviceCommandContext, CVector3D(node.Position.X.ToFloat(), node.Position.Y.ToFloat(), node.Position.Z.ToFloat()), 0.5f, nodeColor); } diff --git a/source/graphics/CinemaManager.h b/source/graphics/CinemaManager.h index 73812e98ce..6c7a4d9d7c 100644 --- a/source/graphics/CinemaManager.h +++ b/source/graphics/CinemaManager.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2021 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -34,7 +34,7 @@ public: /** * Renders paths and their nodes (if enabled). */ - void Render() const; + void Render(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const; bool IsPlaying() const; bool IsEnabled() const; @@ -49,9 +49,9 @@ public: void SetPathsDrawing(const bool drawPath); private: - void DrawPaths() const; - void DrawSpline(const RNSpline& spline, const CColor& splineColor, int smoothness) const; - void DrawNodes(const RNSpline& spline, const CColor& nodesColor) const; + void DrawPaths(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) const; + void DrawSpline(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& splineColor, int smoothness) const; + void DrawNodes(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const RNSpline& spline, const CColor& nodesColor) const; bool m_DrawPaths; }; diff --git a/source/renderer/DebugRenderer.cpp b/source/renderer/DebugRenderer.cpp index 1790f26f3d..6bf5ebea60 100644 --- a/source/renderer/DebugRenderer.cpp +++ b/source/renderer/DebugRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -52,38 +52,37 @@ void CDebugRenderer::Initialize() } void CDebugRenderer::DrawLine( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CVector3D& from, const CVector3D& to, const CColor& color, const float width, const bool depthTestEnabled) { if (from == to) return; - DrawLine({from, to}, color, width, depthTestEnabled); + DrawLine(deviceCommandContext, {from, to}, color, width, depthTestEnabled); } void CDebugRenderer::DrawLine( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const std::vector& line, const CColor& color, const float width, const bool depthTestEnabled) { if (line.size() <= 1) return; - Renderer::Backend::IDeviceCommandContext* deviceCommandContext = - g_Renderer.GetDeviceCommandContext(); - CShaderTechniquePtr debugLineTech = GetShaderTechnique(str_debug_line, color, depthTestEnabled); - deviceCommandContext->SetGraphicsPipelineState( + deviceCommandContext.SetGraphicsPipelineState( debugLineTech->GetGraphicsPipelineState()); - deviceCommandContext->BeginPass(); + deviceCommandContext.BeginPass(); const CCamera& viewCamera = g_Renderer.GetSceneRenderer().GetViewCamera(); Renderer::Backend::IShaderProgram* debugLineShader = debugLineTech->GetShader(); const CMatrix3D transform = viewCamera.GetViewProjection(); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( debugLineShader->GetBindingSlot(str_transform), transform.AsFloatArray()); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( debugLineShader->GetBindingSlot(str_color), color.AsFloatArray()); const CVector3D cameraIn = viewCamera.GetOrientation().GetIn(); @@ -115,35 +114,34 @@ void CDebugRenderer::DrawLine( #undef ADD - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, vertices.data(), vertices.size() * sizeof(vertices[0])); - deviceCommandContext->Draw(0, vertices.size() / 3); + deviceCommandContext.Draw(0, vertices.size() / 3); - deviceCommandContext->EndPass(); + deviceCommandContext.EndPass(); } -void CDebugRenderer::DrawCircle(const CVector3D& origin, const float radius, const CColor& color) +void CDebugRenderer::DrawCircle( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, + const CVector3D& origin, const float radius, const CColor& color) { CShaderTechniquePtr debugCircleTech = GetShaderTechnique(str_debug_line, color); - Renderer::Backend::IDeviceCommandContext* deviceCommandContext = - g_Renderer.GetDeviceCommandContext(); - - deviceCommandContext->SetGraphicsPipelineState( + deviceCommandContext.SetGraphicsPipelineState( debugCircleTech->GetGraphicsPipelineState()); - deviceCommandContext->BeginPass(); + deviceCommandContext.BeginPass(); const CCamera& camera = g_Renderer.GetSceneRenderer().GetViewCamera(); Renderer::Backend::IShaderProgram* debugCircleShader = debugCircleTech->GetShader(); const CMatrix3D transform = camera.GetViewProjection(); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( debugCircleShader->GetBindingSlot(str_transform), transform.AsFloatArray()); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( debugCircleShader->GetBindingSlot(str_color), color.AsFloatArray()); const CVector3D cameraUp = camera.GetOrientation().GetUp(); @@ -169,16 +167,17 @@ void CDebugRenderer::DrawCircle(const CVector3D& origin, const float radius, con #undef ADD - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, vertices.data(), vertices.size() * sizeof(vertices[0])); - deviceCommandContext->Draw(0, vertices.size() / 3); + deviceCommandContext.Draw(0, vertices.size() / 3); - deviceCommandContext->EndPass(); + deviceCommandContext.EndPass(); } -void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& color, int intermediates, bool wireframe) +void CDebugRenderer::DrawCameraFrustum(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, + const CCamera& camera, const CColor& color, int intermediates, bool wireframe) { CCamera::Quad nearPoints{camera.GetViewQuad(camera.GetNearPlane())}; for (CVector3D& point : nearPoints) @@ -190,18 +189,16 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo CShaderTechniquePtr overlayTech = GetShaderTechnique(str_debug_line, color, true, wireframe); - Renderer::Backend::IDeviceCommandContext* deviceCommandContext = - g_Renderer.GetDeviceCommandContext(); - deviceCommandContext->SetGraphicsPipelineState( + deviceCommandContext.SetGraphicsPipelineState( overlayTech->GetGraphicsPipelineState()); - deviceCommandContext->BeginPass(); + deviceCommandContext.BeginPass(); Renderer::Backend::IShaderProgram* overlayShader = overlayTech->GetShader(); const CMatrix3D transform = g_Renderer.GetSceneRenderer().GetViewCamera().GetViewProjection(); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( overlayShader->GetBindingSlot(str_transform), transform.AsFloatArray()); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( overlayShader->GetBindingSlot(str_color), color.AsFloatArray()); std::vector vertices; @@ -243,11 +240,11 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo ADD(intermediatePoints[3]); } - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, vertices.data(), vertices.size() * sizeof(vertices[0])); - deviceCommandContext->Draw(0, vertices.size() / 3); + deviceCommandContext.Draw(0, vertices.size() / 3); vertices.clear(); @@ -263,43 +260,44 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo ADD(farPoints[nextI]); } - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, vertices.data(), vertices.size() * sizeof(vertices[0])); - deviceCommandContext->Draw(0, vertices.size() / 3); + deviceCommandContext.Draw(0, vertices.size() / 3); #undef ADD - deviceCommandContext->EndPass(); + deviceCommandContext.EndPass(); } void CDebugRenderer::DrawBoundingBox( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, bool wireframe) { DrawBoundingBox( + deviceCommandContext, boundingBox, color, g_Renderer.GetSceneRenderer().GetViewCamera().GetViewProjection(), wireframe); } void CDebugRenderer::DrawBoundingBox( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform, bool wireframe) { CShaderTechniquePtr shaderTech = GetShaderTechnique(str_debug_line, color, true, wireframe); - Renderer::Backend::IDeviceCommandContext* deviceCommandContext = - g_Renderer.GetDeviceCommandContext(); - deviceCommandContext->SetGraphicsPipelineState( + deviceCommandContext.SetGraphicsPipelineState( shaderTech->GetGraphicsPipelineState()); - deviceCommandContext->BeginPass(); + deviceCommandContext.BeginPass(); Renderer::Backend::IShaderProgram* shader = shaderTech->GetShader(); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( shader->GetBindingSlot(str_transform), transform.AsFloatArray()); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( shader->GetBindingSlot(str_color), color.AsFloatArray()); std::vector data; @@ -323,32 +321,32 @@ void CDebugRenderer::DrawBoundingBox( #undef ADD_FACE - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, data.data(), data.size() * sizeof(data[0])); - deviceCommandContext->Draw(0, 6 * 6); + deviceCommandContext.Draw(0, 6 * 6); - deviceCommandContext->EndPass(); + deviceCommandContext.EndPass(); } -void CDebugRenderer::DrawBrush(const CBrush& brush, const CColor& color, bool wireframe) +void CDebugRenderer::DrawBrush( + Renderer::Backend::IDeviceCommandContext& deviceCommandContext, + const CBrush& brush, const CColor& color, bool wireframe) { CShaderTechniquePtr shaderTech = GetShaderTechnique(str_debug_line, color, true, wireframe); - Renderer::Backend::IDeviceCommandContext* deviceCommandContext = - g_Renderer.GetDeviceCommandContext(); - deviceCommandContext->SetGraphicsPipelineState( + deviceCommandContext.SetGraphicsPipelineState( shaderTech->GetGraphicsPipelineState()); - deviceCommandContext->BeginPass(); + deviceCommandContext.BeginPass(); Renderer::Backend::IShaderProgram* shader = shaderTech->GetShader(); const CMatrix3D transform = g_Renderer.GetSceneRenderer().GetViewCamera().GetViewProjection(); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( shader->GetBindingSlot(str_transform), transform.AsFloatArray()); - deviceCommandContext->SetUniform( + deviceCommandContext.SetUniform( shader->GetBindingSlot(str_color), color.AsFloatArray()); std::vector data; @@ -376,13 +374,13 @@ void CDebugRenderer::DrawBrush(const CBrush& brush, const CColor& color, bool wi #undef ADD_VERT - deviceCommandContext->SetVertexInputLayout(m_VertexInputLayout); - deviceCommandContext->SetVertexBufferData( + deviceCommandContext.SetVertexInputLayout(m_VertexInputLayout); + deviceCommandContext.SetVertexBufferData( 0, data.data(), data.size() * sizeof(data[0])); - deviceCommandContext->Draw(0, data.size() / 5); + deviceCommandContext.Draw(0, data.size() / 5); - deviceCommandContext->EndPass(); + deviceCommandContext.EndPass(); } size_t CDebugRenderer::ShaderTechniqueKeyHash::operator()( diff --git a/source/renderer/DebugRenderer.h b/source/renderer/DebugRenderer.h index 6caff98ca8..4e21d07ecf 100644 --- a/source/renderer/DebugRenderer.h +++ b/source/renderer/DebugRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -43,15 +43,15 @@ public: /** * Render the line in world space. */ - void DrawLine(const CVector3D& from, const CVector3D& to, - const CColor& color, const float width, const bool depthTestEnabled = true); - void DrawLine(const std::vector& line, + void DrawLine(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CVector3D& from, const CVector3D& to, + const CColor& color, const float width, const bool depthTestEnabled = true); + void DrawLine(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const std::vector& line, const CColor& color, const float width, const bool depthTestEnabled = true); /** * Render the circle in world space oriented to the view camera. */ - void DrawCircle(const CVector3D& origin, const float radius, const CColor& color); + void DrawCircle(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CVector3D& origin, const float radius, const CColor& color); /** * Render: Renders the camera's frustum in world space. @@ -59,18 +59,18 @@ public: * @param intermediates determines how many intermediate distance planes should * be hinted at between the near and far planes */ - void DrawCameraFrustum(const CCamera& camera, const CColor& color, int intermediates = 0, bool wireframe = false); + void DrawCameraFrustum(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CCamera& camera, const CColor& color, int intermediates = 0, bool wireframe = false); /** * Render the surfaces of the bound box as triangles. */ - void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color, bool wireframe = false); - void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform, bool wireframe = false); + void DrawBoundingBox(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, bool wireframe = false); + void DrawBoundingBox(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform, bool wireframe = false); /** * Render the surfaces of the brush as triangles. */ - void DrawBrush(const CBrush& brush, const CColor& color, bool wireframe = false); + void DrawBrush(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBrush& brush, const CColor& color, bool wireframe = false); private: const CShaderTechniquePtr& GetShaderTechnique( diff --git a/source/renderer/OverlayRenderer.cpp b/source/renderer/OverlayRenderer.cpp index 951848259c..dbff0efefd 100644 --- a/source/renderer/OverlayRenderer.cpp +++ b/source/renderer/OverlayRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -509,7 +509,7 @@ void OverlayRenderer::RenderOverlaysBeforeWater( if (line->m_Coords.empty()) continue; - g_Renderer.GetDebugRenderer().DrawLine(line->m_Coords, line->m_Color, static_cast(line->m_Thickness)); + g_Renderer.GetDebugRenderer().DrawLine(*deviceCommandContext, line->m_Coords, line->m_Color, static_cast(line->m_Thickness)); } } diff --git a/source/renderer/ParticleRenderer.cpp b/source/renderer/ParticleRenderer.cpp index c4d670f2ce..bee033acd7 100644 --- a/source/renderer/ParticleRenderer.cpp +++ b/source/renderer/ParticleRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -198,12 +198,13 @@ void ParticleRenderer::RenderParticles( deviceCommandContext->EndPass(); } -void ParticleRenderer::RenderBounds(int cullGroup) +void ParticleRenderer::RenderBounds(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, int cullGroup) { for (const CParticleEmitter* emitter : m->emitters[cullGroup]) { const CBoundingBoxAligned bounds = emitter->m_Type->CalculateBounds(emitter->GetPosition(), emitter->GetParticleBounds()); - g_Renderer.GetDebugRenderer().DrawBoundingBox(bounds, CColor(0.0f, 1.0f, 0.0f, 1.0f), true); + + g_Renderer.GetDebugRenderer().DrawBoundingBox(deviceCommandContext, bounds, CColor(0.0f, 1.0f, 0.0f, 1.0f), true); } } diff --git a/source/renderer/ParticleRenderer.h b/source/renderer/ParticleRenderer.h index c3bde08a14..ca5af071fe 100644 --- a/source/renderer/ParticleRenderer.h +++ b/source/renderer/ParticleRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -70,7 +70,7 @@ public: /** * Render bounding boxes for all the submitted emitters. */ - void RenderBounds(int cullGroup); + void RenderBounds(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, int cullGroup); private: ParticleRendererInternals* m; diff --git a/source/renderer/PatchRData.cpp b/source/renderer/PatchRData.cpp index a37cf5ceda..68d87f2f0c 100644 --- a/source/renderer/PatchRData.cpp +++ b/source/renderer/PatchRData.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -1299,7 +1299,7 @@ void CPatchRData::RenderStreams( } } -void CPatchRData::RenderOutline() +void CPatchRData::RenderOutline(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) { CTerrain* terrain = m_Patch->m_Parent; ssize_t gx = m_Patch->m_X * PATCH_SIZE; @@ -1328,7 +1328,7 @@ void CPatchRData::RenderOutline() line.push_back(pos); } - g_Renderer.GetDebugRenderer().DrawLine(line, CColor(0.0f, 0.0f, 1.0f, 1.0f), 0.1f); + g_Renderer.GetDebugRenderer().DrawLine(deviceCommandContext, line, CColor(0.0f, 0.0f, 1.0f, 1.0f), 0.1f); } void CPatchRData::RenderSides( diff --git a/source/renderer/PatchRData.h b/source/renderer/PatchRData.h index 541129ac41..3db47b207f 100644 --- a/source/renderer/PatchRData.h +++ b/source/renderer/PatchRData.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -59,7 +59,7 @@ public: static Renderer::Backend::IVertexInputLayout* GetWaterShoreVertexInputLayout(); void Update(CSimulation2* simulation); - void RenderOutline(); + void RenderOutline(Renderer::Backend::IDeviceCommandContext& deviceCommandContext); void RenderPriorities(CTextRenderer& textRenderer); void RenderWaterSurface( diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index ab80ba8169..6c379f2390 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -573,7 +573,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger) g_Game->GetView()->RenderOverlays(m->deviceCommandContext.get()); - g_Game->GetView()->GetCinema()->Render(); + g_Game->GetView()->GetCinema()->Render(*m->deviceCommandContext); } else { @@ -603,7 +603,7 @@ void CRenderer::RenderFrameImpl(const bool renderGUI, const bool renderLogger) // If we're in Atlas game view, render special tools if (g_AtlasGameLoop && g_AtlasGameLoop->view) { - g_AtlasGameLoop->view->DrawCinemaPathTool(); + g_AtlasGameLoop->view->DrawCinemaPathTool(*m->deviceCommandContext); } RenderFrame2D(renderGUI, renderLogger); diff --git a/source/renderer/SceneRenderer.cpp b/source/renderer/SceneRenderer.cpp index 317574a0e8..083554bb13 100644 --- a/source/renderer/SceneRenderer.cpp +++ b/source/renderer/SceneRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -781,7 +781,7 @@ void CSceneRenderer::RenderParticles( { m->particleRenderer.RenderParticles( deviceCommandContext, cullGroup, true); - m->particleRenderer.RenderBounds(cullGroup); + m->particleRenderer.RenderBounds(*deviceCommandContext, cullGroup); } } @@ -921,10 +921,10 @@ void CSceneRenderer::RenderSubmissions( // render debug lines if (g_RenderingOptions.GetDisplayFrustum()) - DisplayFrustum(); + DisplayFrustum(*deviceCommandContext); if (g_RenderingOptions.GetDisplayShadowsFrustum()) - m->shadow.RenderDebugBounds(); + m->shadow.RenderDebugBounds(*deviceCommandContext); m->silhouetteRenderer.RenderDebugBounds(deviceCommandContext); } @@ -946,10 +946,10 @@ void CSceneRenderer::EndFrame() m->Model.TranspUnskinned->EndFrame(); } -void CSceneRenderer::DisplayFrustum() +void CSceneRenderer::DisplayFrustum(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) { - g_Renderer.GetDebugRenderer().DrawCameraFrustum(m_CullCamera, CColor(1.0f, 1.0f, 1.0f, 0.25f), 2); - g_Renderer.GetDebugRenderer().DrawCameraFrustum(m_CullCamera, CColor(1.0f, 1.0f, 1.0f, 1.0f), 2, true); + g_Renderer.GetDebugRenderer().DrawCameraFrustum(deviceCommandContext, m_CullCamera, CColor(1.0f, 1.0f, 1.0f, 0.25f), 2); + g_Renderer.GetDebugRenderer().DrawCameraFrustum(deviceCommandContext, m_CullCamera, CColor(1.0f, 1.0f, 1.0f, 1.0f), 2, true); } // Text overlay rendering diff --git a/source/renderer/SceneRenderer.h b/source/renderer/SceneRenderer.h index 5924661685..fc111dc8d9 100644 --- a/source/renderer/SceneRenderer.h +++ b/source/renderer/SceneRenderer.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -254,7 +254,7 @@ protected: void ComputeRefractionCamera(CCamera& camera, const CBoundingBoxAligned& scissor) const; // debugging - void DisplayFrustum(); + void DisplayFrustum(Renderer::Backend::IDeviceCommandContext& deviceCommandContext); // enable oblique frustum clipping with the given clip plane void SetObliqueFrustumClipping(CCamera& camera, const CVector4D& clipPlane) const; diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index ef77b436e9..2156fc8fb4 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -720,7 +720,7 @@ void ShadowMap::SetDepthTextureBits(int bits) } } -void ShadowMap::RenderDebugBounds() +void ShadowMap::RenderDebugBounds(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) { // Render various shadow bounds: // Yellow = bounds of objects in view frustum that receive shadows @@ -730,13 +730,16 @@ void ShadowMap::RenderDebugBounds() const CMatrix3D transform = g_Renderer.GetSceneRenderer().GetViewCamera().GetViewProjection() * m->InvLightTransform; g_Renderer.GetDebugRenderer().DrawBoundingBox( + deviceCommandContext, m->ShadowReceiverBound, CColor(1.0f, 1.0f, 0.0f, 1.0f), transform, true); for (int cascade = 0; cascade < GetCascadeCount(); ++cascade) { g_Renderer.GetDebugRenderer().DrawBoundingBox( + deviceCommandContext, m->Cascades[cascade].ShadowRenderBound, CColor(0.0f, 0.0f, 1.0f, 0.10f), transform); g_Renderer.GetDebugRenderer().DrawBoundingBox( + deviceCommandContext, m->Cascades[cascade].ShadowRenderBound, CColor(0.0f, 0.0f, 1.0f, 0.5f), transform, true); const CFrustum frustum = GetShadowCasterCullFrustum(cascade); @@ -747,8 +750,8 @@ void ShadowMap::RenderDebugBounds() CBrush frustumBrush; brush.Intersect(frustum, frustumBrush); - g_Renderer.GetDebugRenderer().DrawBrush(frustumBrush, CColor(1.0f, 0.0f, 0.0f, 0.1f)); - g_Renderer.GetDebugRenderer().DrawBrush(frustumBrush, CColor(1.0f, 0.0f, 0.0f, 0.1f), true); + g_Renderer.GetDebugRenderer().DrawBrush(deviceCommandContext, frustumBrush, CColor(1.0f, 0.0f, 0.0f, 0.1f)); + g_Renderer.GetDebugRenderer().DrawBrush(deviceCommandContext, frustumBrush, CColor(1.0f, 0.0f, 0.0f, 0.1f), true); } } diff --git a/source/renderer/ShadowMap.h b/source/renderer/ShadowMap.h index 2add8f5d0a..f788197925 100644 --- a/source/renderer/ShadowMap.h +++ b/source/renderer/ShadowMap.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -130,7 +130,7 @@ public: * Visualize shadow mapping calculations to help in * debugging and optimal shadow map usage. */ - void RenderDebugBounds(); + void RenderDebugBounds(Renderer::Backend::IDeviceCommandContext& deviceCommandContext); private: ShadowMapInternals* m; diff --git a/source/renderer/SilhouetteRenderer.cpp b/source/renderer/SilhouetteRenderer.cpp index dffc18e41f..ec20bb8ef3 100644 --- a/source/renderer/SilhouetteRenderer.cpp +++ b/source/renderer/SilhouetteRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -464,13 +464,13 @@ void SilhouetteRenderer::RenderSubmitCasters(SceneCollector& collector) collector.SubmitNonRecursive(m_VisibleModelCasters[i]); } -void SilhouetteRenderer::RenderDebugBounds(Renderer::Backend::IDeviceCommandContext*) +void SilhouetteRenderer::RenderDebugBounds(Renderer::Backend::IDeviceCommandContext* deviceCommandContext) { if (m_DebugBounds.empty()) return; for (size_t i = 0; i < m_DebugBounds.size(); ++i) - g_Renderer.GetDebugRenderer().DrawBoundingBox(m_DebugBounds[i].bounds, m_DebugBounds[i].color, true); + g_Renderer.GetDebugRenderer().DrawBoundingBox(*deviceCommandContext, m_DebugBounds[i].bounds, m_DebugBounds[i].color, true); } void SilhouetteRenderer::RenderDebugOverlays( diff --git a/source/renderer/TerrainRenderer.cpp b/source/renderer/TerrainRenderer.cpp index 987bde0274..9b545fd131 100644 --- a/source/renderer/TerrainRenderer.cpp +++ b/source/renderer/TerrainRenderer.cpp @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -407,7 +407,7 @@ void TerrainRenderer::RenderOutlines( GPU_SCOPED_LABEL(deviceCommandContext, "Render terrain outlines"); for (size_t i = 0; i < visiblePatches.size(); ++i) - visiblePatches[i]->RenderOutline(); + visiblePatches[i]->RenderOutline(*deviceCommandContext); } diff --git a/source/tools/atlas/GameInterface/View.cpp b/source/tools/atlas/GameInterface/View.cpp index c4078b9ac6..dca1ae1781 100644 --- a/source/tools/atlas/GameInterface/View.cpp +++ b/source/tools/atlas/GameInterface/View.cpp @@ -244,7 +244,7 @@ void AtlasViewGame::Render() g_VideoMode.GetBackendDevice()->Present(); } -void AtlasViewGame::DrawCinemaPathTool() +void AtlasViewGame::DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext& deviceCommandContext) { if (!m_DrawMoveTool) return; @@ -256,12 +256,15 @@ void AtlasViewGame::DrawCinemaPathTool() const float lineWidth = scale / 1e3f; g_Renderer.GetDebugRenderer().DrawLine( + deviceCommandContext, focus, focus + CVector3D(axisLength, 0, 0), CColor(1.0f, 0.0f, 0.0f, 1.0f), lineWidth, false); g_Renderer.GetDebugRenderer().DrawLine( + deviceCommandContext, focus, focus + CVector3D(0, axisLength, 0), CColor(0.0f, 1.0f, 0.0f, 1.0f), lineWidth, false); g_Renderer.GetDebugRenderer().DrawLine( + deviceCommandContext, focus, focus + CVector3D(0, 0, axisLength), CColor(0.0f, 0.0f, 1.0f, 1.0f), lineWidth, false); } diff --git a/source/tools/atlas/GameInterface/View.h b/source/tools/atlas/GameInterface/View.h index ec7ba199e1..c5331c6c21 100644 --- a/source/tools/atlas/GameInterface/View.h +++ b/source/tools/atlas/GameInterface/View.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2025 Wildfire Games. +/* Copyright (C) 2026 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -42,7 +42,7 @@ public: virtual ~AtlasView(); virtual void Update(float /*realFrameLength*/) { }; virtual void Render() { }; - virtual void DrawCinemaPathTool() { }; + virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext&) { }; virtual void DrawOverlays(CCanvas2D& /*canvas*/) { }; virtual CCamera& GetCamera() = 0; virtual CSimulation2* GetSimulation2() { return NULL; } @@ -90,7 +90,7 @@ public: virtual ~AtlasViewGame(); virtual void Update(float realFrameLength); virtual void Render(); - virtual void DrawCinemaPathTool(); + virtual void DrawCinemaPathTool(Renderer::Backend::IDeviceCommandContext& deviceCommandContext); virtual void DrawOverlays(CCanvas2D& canvas); virtual CCamera& GetCamera(); virtual CSimulation2* GetSimulation2();