Line data Source code
1 : /* Copyright (C) 2026 Wildfire Games. 2 : * This file is part of 0 A.D. 3 : * 4 : * 0 A.D. is free software: you can redistribute it and/or modify 5 : * it under the terms of the GNU General Public License as published by 6 : * the Free Software Foundation, either version 2 of the License, or 7 : * (at your option) any later version. 8 : * 9 : * 0 A.D. is distributed in the hope that it will be useful, 10 : * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 : * GNU General Public License for more details. 13 : * 14 : * You should have received a copy of the GNU General Public License 15 : * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>. 16 : */ 17 : 18 : #ifndef INCLUDED_DEBUGRENDERER 19 : #define INCLUDED_DEBUGRENDERER 20 : 21 : #include "graphics/ShaderTechniquePtr.h" 22 : #include "ps/CStrIntern.h" 23 : 24 : #include <cstddef> 25 : #include <unordered_map> 26 : #include <vector> 27 : 28 : class CBoundingBoxAligned; 29 : class CBrush; 30 : class CCamera; 31 : class CMatrix3D; 32 : class CVector3D; 33 : namespace Renderer::Backend { class IDeviceCommandContext; } 34 : namespace Renderer::Backend { class IVertexInputLayout; } 35 : struct CColor; 36 : 37 : // Helper for unoptimized rendering of geometrics primitives. Should not be 38 : // used for regular passes. 39 10 : class CDebugRenderer 40 : { 41 : public: 42 : void Initialize(); 43 : 44 : /** 45 : * Render the line in world space. 46 : */ 47 : void DrawLine(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CVector3D& from, const CVector3D& to, 48 : const CColor& color, const float width, const bool depthTestEnabled = true); 49 : void DrawLine(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const std::vector<CVector3D>& line, 50 : const CColor& color, const float width, const bool depthTestEnabled = true); 51 : 52 : /** 53 : * Render the circle in world space oriented to the view camera. 54 : */ 55 : void DrawCircle(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CVector3D& origin, const float radius, const CColor& color); 56 : 57 : /** 58 : * Render: Renders the camera's frustum in world space. 59 : * 60 : * @param intermediates determines how many intermediate distance planes should 61 : * be hinted at between the near and far planes 62 : */ 63 : void DrawCameraFrustum(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CCamera& camera, const CColor& color, int intermediates = 0, bool wireframe = false); 64 : 65 : /** 66 : * Render the surfaces of the bound box as triangles. 67 : */ 68 : void DrawBoundingBox(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, bool wireframe = false); 69 : void DrawBoundingBox(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform, bool wireframe = false); 70 : 71 : /** 72 : * Render the surfaces of the brush as triangles. 73 : */ 74 : void DrawBrush(Renderer::Backend::IDeviceCommandContext& deviceCommandContext, const CBrush& brush, const CColor& color, bool wireframe = false); 75 : 76 : private: 77 : const CShaderTechniquePtr& GetShaderTechnique( 78 : const CStrIntern name, const CColor& color, const bool depthTestEnabled = true, 79 : const bool wireframe = false); 80 : 81 : struct ShaderTechniqueKey 82 : { 83 : CStrIntern name; 84 : bool transparent; 85 : bool depthTestEnabled; 86 : bool wireframe; 87 : }; 88 : struct ShaderTechniqueKeyHash 89 : { 90 : size_t operator()(const ShaderTechniqueKey& key) const; 91 : }; 92 : struct ShaderTechniqueKeyEqual 93 : { 94 : bool operator()(const ShaderTechniqueKey& lhs, const ShaderTechniqueKey& rhs) const; 95 : }; 96 : std::unordered_map<ShaderTechniqueKey, CShaderTechniquePtr, ShaderTechniqueKeyHash, ShaderTechniqueKeyEqual> 97 : m_ShaderTechniqueMapping; 98 : 99 : Renderer::Backend::IVertexInputLayout* m_VertexInputLayout = nullptr; 100 : }; 101 : 102 : #endif // INCLUDED_DEBUGRENDERER