diff --git a/source/graphics/Camera.cpp b/source/graphics/Camera.cpp index 163ea20176..ff61d9b57d 100644 --- a/source/graphics/Camera.cpp +++ b/source/graphics/Camera.cpp @@ -392,69 +392,3 @@ void CCamera::LookAlong(const CVector3D& camera, CVector3D orientation, CVector3 m_Orientation._31 = -s.Z; m_Orientation._32 = up.Z; m_Orientation._33 = orientation.Z; m_Orientation._34 = camera.Z; m_Orientation._41 = 0.0f; m_Orientation._42 = 0.0f; m_Orientation._43 = 0.0f; m_Orientation._44 = 1.0f; } - -// Render the camera's frustum -void CCamera::Render(int intermediates) const -{ -#if CONFIG2_GLES -#warning TODO: implement camera frustum for GLES -#else - Quad nearPoints; - Quad farPoints; - - GetViewQuad(m_NearPlane, nearPoints); - GetViewQuad(m_FarPlane, farPoints); - for(int i = 0; i < 4; i++) - { - nearPoints[i] = m_Orientation.Transform(nearPoints[i]); - farPoints[i] = m_Orientation.Transform(farPoints[i]); - } - - // near plane - glBegin(GL_POLYGON); - glVertex3fv(&nearPoints[0].X); - glVertex3fv(&nearPoints[1].X); - glVertex3fv(&nearPoints[2].X); - glVertex3fv(&nearPoints[3].X); - glEnd(); - - // far plane - glBegin(GL_POLYGON); - glVertex3fv(&farPoints[0].X); - glVertex3fv(&farPoints[1].X); - glVertex3fv(&farPoints[2].X); - glVertex3fv(&farPoints[3].X); - glEnd(); - - // connection lines - glBegin(GL_QUAD_STRIP); - glVertex3fv(&nearPoints[0].X); - glVertex3fv(&farPoints[0].X); - glVertex3fv(&nearPoints[1].X); - glVertex3fv(&farPoints[1].X); - glVertex3fv(&nearPoints[2].X); - glVertex3fv(&farPoints[2].X); - glVertex3fv(&nearPoints[3].X); - glVertex3fv(&farPoints[3].X); - glVertex3fv(&nearPoints[0].X); - glVertex3fv(&farPoints[0].X); - glEnd(); - - // intermediate planes - CVector3D intermediatePoints[4]; - for(int i = 0; i < intermediates; ++i) - { - float t = (i+1.0)/(intermediates+1.0); - - for(int j = 0; j < 4; ++j) - intermediatePoints[j] = nearPoints[j]*t + farPoints[j]*(1.0-t); - - glBegin(GL_POLYGON); - glVertex3fv(&intermediatePoints[0].X); - glVertex3fv(&intermediatePoints[1].X); - glVertex3fv(&intermediatePoints[2].X); - glVertex3fv(&intermediatePoints[3].X); - glEnd(); - } -#endif -} diff --git a/source/graphics/Camera.h b/source/graphics/Camera.h index 9a621a6254..22221aee36 100644 --- a/source/graphics/Camera.h +++ b/source/graphics/Camera.h @@ -108,15 +108,6 @@ class CCamera // Build an orientation matrix from camera position, camera orientation, and up-vector void LookAlong(const CVector3D& camera, CVector3D orientation, CVector3D up); - /** - * Render: Renders the camera's frustum in world space. - * The caller should set the color using glColorXy before calling Render. - * - * @param intermediates determines how many intermediate distance planes should - * be hinted at between the near and far planes - */ - void Render(int intermediates = 0) const; - public: // This is the orientation matrix. The inverse of this // is the view matrix diff --git a/source/maths/BoundingBoxAligned.cpp b/source/maths/BoundingBoxAligned.cpp index 9a87044ed2..77846697d9 100644 --- a/source/maths/BoundingBoxAligned.cpp +++ b/source/maths/BoundingBoxAligned.cpp @@ -23,8 +23,6 @@ #include "BoundingBoxAligned.h" -#include "graphics/ShaderProgram.h" -#include "lib/ogl.h" #include "maths/BoundingBoxOriented.h" #include "maths/Brush.h" #include "maths/Frustum.h" @@ -265,71 +263,3 @@ void CBoundingBoxAligned::Expand(float amount) m_Data[0] -= CVector3D(amount, amount, amount); m_Data[1] += CVector3D(amount, amount, amount); } - -/////////////////////////////////////////////////////////////////////////////// -// Render the bounding box -void CBoundingBoxAligned::Render(CShaderProgramPtr& shader) const -{ - std::vector data; - -#define ADD_FACE(x, y, z) \ - ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \ - ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z); -#define ADD_PT(u_, v_, x, y, z) \ - STMT(int u = u_; int v = v_; \ - data.push_back(u); \ - data.push_back(v); \ - data.push_back(m_Data[x].X); \ - data.push_back(m_Data[y].Y); \ - data.push_back(m_Data[z].Z); \ - ) - - ADD_FACE(u, v, 0); - ADD_FACE(0, u, v); - ADD_FACE(u, 0, 1-v); - ADD_FACE(u, 1-v, 1); - ADD_FACE(1, u, 1-v); - ADD_FACE(u, 1, v); - -#undef ADD_FACE - - shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); - shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); - - shader->AssertPointersBound(); - glDrawArrays(GL_TRIANGLES, 0, 6*6); -} - -void CBoundingBoxAligned::RenderOutline(CShaderProgramPtr& shader) const -{ - std::vector data; - -#define ADD_FACE(x, y, z) \ - ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); \ - ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \ - ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); \ - ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z); -#define ADD_PT(u_, v_, x, y, z) \ - STMT(int u = u_; int v = v_; \ - data.push_back(u); \ - data.push_back(v); \ - data.push_back(m_Data[x].X); \ - data.push_back(m_Data[y].Y); \ - data.push_back(m_Data[z].Z); \ - ) - - ADD_FACE(u, v, 0); - ADD_FACE(0, u, v); - ADD_FACE(u, 0, 1-v); - ADD_FACE(u, 1-v, 1); - ADD_FACE(1, u, 1-v); - ADD_FACE(u, 1, v); - -#undef ADD_FACE - - shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); - shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); - - shader->AssertPointersBound(); - glDrawArrays(GL_LINES, 0, 6*8); -} diff --git a/source/maths/BoundingBoxAligned.h b/source/maths/BoundingBoxAligned.h index a10f8b4648..0252b7d4d2 100644 --- a/source/maths/BoundingBoxAligned.h +++ b/source/maths/BoundingBoxAligned.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2019 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -147,16 +147,6 @@ public: */ CFrustum ToFrustum() const; - /** - * Render the surfaces of the bound object as triangles. - */ - void Render(CShaderProgramPtr& shader) const; - - /** - * Render the outline of the bound object as lines. - */ - void RenderOutline(CShaderProgramPtr& shader) const; - private: // Holds the minimal and maximal coordinate points in m_Data[0] and m_Data[1], respectively. CVector3D m_Data[2]; diff --git a/source/maths/Brush.cpp b/source/maths/Brush.cpp index c2205e5304..667e48191a 100644 --- a/source/maths/Brush.cpp +++ b/source/maths/Brush.cpp @@ -15,21 +15,14 @@ * along with 0 A.D. If not, see . */ -/* - * Implementation of CBrush, a class representing a convex object - */ - #include "precompiled.h" #include "Brush.h" -#include "graphics/ShaderProgram.h" #include "maths/BoundingBoxAligned.h" #include "maths/Frustum.h" -#include "lib/ogl.h" - -#include +CBrush::CBrush() = default; /////////////////////////////////////////////////////////////////////////////// // Convert the given bounds into a brush @@ -380,12 +373,13 @@ void CBrush::Intersect(const CFrustum& frustum, CBrush& result) const ENSURE(prev == &result); } -std::vector CBrush::GetVertices() const + +const std::vector& CBrush::GetVertices() const { return m_Vertices; } -void CBrush::GetFaces(std::vector >& out) const +void CBrush::GetFaces(std::vector>& out) const { // split the back-to-back faces into separate face vectors, so that they're in a // user-friendlier format than the back-to-back vertex index array @@ -415,77 +409,3 @@ void CBrush::GetFaces(std::vector >& out) const faceStartIdx = j + 1; } } - -void CBrush::Render(CShaderProgramPtr& shader) const -{ - std::vector data; - - std::vector > faces; - GetFaces(faces); - -#define ADD_VERT(a) \ - STMT( \ - data.push_back(u); \ - data.push_back(v); \ - data.push_back(m_Vertices[faces[i][a]].X); \ - data.push_back(m_Vertices[faces[i][a]].Y); \ - data.push_back(m_Vertices[faces[i][a]].Z); \ - ) - - for (size_t i = 0; i < faces.size(); ++i) - { - // Triangulate into (0,1,2), (0,2,3), ... - for (size_t j = 1; j < faces[i].size() - 2; ++j) - { - float u = 0; - float v = 0; - ADD_VERT(0); - ADD_VERT(j); - ADD_VERT(j+1); - } - } - -#undef ADD_VERT - - shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); - shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); - - shader->AssertPointersBound(); - glDrawArrays(GL_TRIANGLES, 0, data.size() / 5); -} - -void CBrush::RenderOutline(CShaderProgramPtr& shader) const -{ - std::vector data; - - std::vector > faces; - GetFaces(faces); - -#define ADD_VERT(a) \ - STMT( \ - data.push_back(u); \ - data.push_back(v); \ - data.push_back(m_Vertices[faces[i][a]].X); \ - data.push_back(m_Vertices[faces[i][a]].Y); \ - data.push_back(m_Vertices[faces[i][a]].Z); \ - ) - - for (size_t i = 0; i < faces.size(); ++i) - { - for (size_t j = 0; j < faces[i].size() - 1; ++j) - { - float u = 0; - float v = 0; - ADD_VERT(j); - ADD_VERT(j+1); - } - } - -#undef ADD_VERT - - shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); - shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); - - shader->AssertPointersBound(); - glDrawArrays(GL_LINES, 0, data.size() / 5); -} diff --git a/source/maths/Brush.h b/source/maths/Brush.h index b9172ce811..cbc9afe103 100644 --- a/source/maths/Brush.h +++ b/source/maths/Brush.h @@ -1,4 +1,4 @@ -/* Copyright (C) 2020 Wildfire Games. +/* Copyright (C) 2021 Wildfire Games. * This file is part of 0 A.D. * * 0 A.D. is free software: you can redistribute it and/or modify @@ -19,12 +19,10 @@ * CBrush, a class representing a convex object */ -#ifndef maths_brush_h -#define maths_brush_h +#ifndef INCLUDED_BRUSH +#define INCLUDED_BRUSH -#include "Vector3D.h" - -#include "graphics/ShaderProgramPtr.h" +#include "maths/Vector3D.h" #include @@ -38,10 +36,8 @@ class CPlane; */ class CBrush { - friend class TestBrush; - public: - CBrush() { } + CBrush(); /** * CBrush: Construct a brush from a bounds object. @@ -83,29 +79,17 @@ public: void Intersect(const CFrustum& frustum, CBrush& result) const; /** - * Render the surfaces of the brush as triangles. - */ - void Render(CShaderProgramPtr& shader) const; - - /** - * Render the outline of the brush as lines. - */ - void RenderOutline(CShaderProgramPtr& shader) const; - -private: - - /** - * Returns a copy of the vertices in this brush. Intended for testing purposes; you should not need to use + * Returns vertices in the brush. Intended for testing purposes; you should not need to use * this method directly. */ - std::vector GetVertices() const; + const std::vector& GetVertices() const; /** * Writes a vector of the faces in this brush to @p out. Each face is itself a vector, listing the vertex indices * that make up the face, starting and ending with the same index. Intended for testing purposes; you should not * need to use this method directly. */ - void GetFaces(std::vector >& out) const; + void GetFaces(std::vector>& out) const; private: static const size_t NO_VERTEX = ~0u; @@ -126,4 +110,4 @@ private: struct Helper; }; -#endif // maths_brush_h +#endif // INCLUDED_BRUSH diff --git a/source/renderer/DebugRenderer.cpp b/source/renderer/DebugRenderer.cpp new file mode 100644 index 0000000000..0992c51431 --- /dev/null +++ b/source/renderer/DebugRenderer.cpp @@ -0,0 +1,231 @@ +/* Copyright (C) 2021 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#include "precompiled.h" + +#include "renderer/DebugRenderer.h" + +#include "graphics/Camera.h" +#include "graphics/ShaderProgram.h" +#include "lib/ogl.h" +#include "maths/BoundingBoxAligned.h" +#include "maths/Brush.h" + +void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, int intermediates) const +{ +#if CONFIG2_GLES +#warning TODO: implement camera frustum for GLES +#else + CCamera::Quad nearPoints; + CCamera::Quad farPoints; + + camera.GetViewQuad(camera.GetNearPlane(), nearPoints); + camera.GetViewQuad(camera.GetFarPlane(), farPoints); + for(int i = 0; i < 4; i++) + { + nearPoints[i] = camera.m_Orientation.Transform(nearPoints[i]); + farPoints[i] = camera.m_Orientation.Transform(farPoints[i]); + } + + // near plane + glBegin(GL_POLYGON); + glVertex3fv(&nearPoints[0].X); + glVertex3fv(&nearPoints[1].X); + glVertex3fv(&nearPoints[2].X); + glVertex3fv(&nearPoints[3].X); + glEnd(); + + // far plane + glBegin(GL_POLYGON); + glVertex3fv(&farPoints[0].X); + glVertex3fv(&farPoints[1].X); + glVertex3fv(&farPoints[2].X); + glVertex3fv(&farPoints[3].X); + glEnd(); + + // connection lines + glBegin(GL_QUAD_STRIP); + glVertex3fv(&nearPoints[0].X); + glVertex3fv(&farPoints[0].X); + glVertex3fv(&nearPoints[1].X); + glVertex3fv(&farPoints[1].X); + glVertex3fv(&nearPoints[2].X); + glVertex3fv(&farPoints[2].X); + glVertex3fv(&nearPoints[3].X); + glVertex3fv(&farPoints[3].X); + glVertex3fv(&nearPoints[0].X); + glVertex3fv(&farPoints[0].X); + glEnd(); + + // intermediate planes + CVector3D intermediatePoints[4]; + for(int i = 0; i < intermediates; ++i) + { + float t = (i + 1.0f) / (intermediates + 1.0f); + + for(int j = 0; j < 4; ++j) + intermediatePoints[j] = nearPoints[j] * t + farPoints[j] * (1.0f - t); + + glBegin(GL_POLYGON); + glVertex3fv(&intermediatePoints[0].X); + glVertex3fv(&intermediatePoints[1].X); + glVertex3fv(&intermediatePoints[2].X); + glVertex3fv(&intermediatePoints[3].X); + glEnd(); + } +#endif +} + +void CDebugRenderer::DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const +{ + std::vector data; + +#define ADD_FACE(x, y, z) \ + ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \ + ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z); +#define ADD_PT(u_, v_, x, y, z) \ + STMT(int u = u_; int v = v_; \ + data.push_back(u); \ + data.push_back(v); \ + data.push_back(boundingBox[x].X); \ + data.push_back(boundingBox[y].Y); \ + data.push_back(boundingBox[z].Z); \ + ) + + ADD_FACE(u, v, 0); + ADD_FACE(0, u, v); + ADD_FACE(u, 0, 1-v); + ADD_FACE(u, 1-v, 1); + ADD_FACE(1, u, 1-v); + ADD_FACE(u, 1, v); + +#undef ADD_FACE + + shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); + shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); + + shader->AssertPointersBound(); + glDrawArrays(GL_TRIANGLES, 0, 6*6); +} + +void CDebugRenderer::DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const +{ + std::vector data; + +#define ADD_FACE(x, y, z) \ + ADD_PT(0, 0, x, y, z); ADD_PT(1, 0, x, y, z); \ + ADD_PT(1, 0, x, y, z); ADD_PT(1, 1, x, y, z); \ + ADD_PT(1, 1, x, y, z); ADD_PT(0, 1, x, y, z); \ + ADD_PT(0, 1, x, y, z); ADD_PT(0, 0, x, y, z); +#define ADD_PT(u_, v_, x, y, z) \ + STMT(int u = u_; int v = v_; \ + data.push_back(u); \ + data.push_back(v); \ + data.push_back(boundingBox[x].X); \ + data.push_back(boundingBox[y].Y); \ + data.push_back(boundingBox[z].Z); \ + ) + + ADD_FACE(u, v, 0); + ADD_FACE(0, u, v); + ADD_FACE(u, 0, 1-v); + ADD_FACE(u, 1-v, 1); + ADD_FACE(1, u, 1-v); + ADD_FACE(u, 1, v); + +#undef ADD_FACE + + shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); + shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); + + shader->AssertPointersBound(); + glDrawArrays(GL_LINES, 0, 6*8); +} + +void CDebugRenderer::DrawBrush(const CBrush& brush, const CShaderProgramPtr& shader) const +{ + std::vector data; + + std::vector> faces; + brush.GetFaces(faces); + +#define ADD_VERT(a) \ + STMT( \ + data.push_back(u); \ + data.push_back(v); \ + data.push_back(brush.GetVertices()[faces[i][a]].X); \ + data.push_back(brush.GetVertices()[faces[i][a]].Y); \ + data.push_back(brush.GetVertices()[faces[i][a]].Z); \ + ) + + for (size_t i = 0; i < faces.size(); ++i) + { + // Triangulate into (0,1,2), (0,2,3), ... + for (size_t j = 1; j < faces[i].size() - 2; ++j) + { + float u = 0; + float v = 0; + ADD_VERT(0); + ADD_VERT(j); + ADD_VERT(j+1); + } + } + +#undef ADD_VERT + + shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); + shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); + + shader->AssertPointersBound(); + glDrawArrays(GL_TRIANGLES, 0, data.size() / 5); +} + +void CDebugRenderer::DrawBrushOutline(const CBrush& brush, const CShaderProgramPtr& shader) const +{ + std::vector data; + + std::vector> faces; + brush.GetFaces(faces); + +#define ADD_VERT(a) \ + STMT( \ + data.push_back(u); \ + data.push_back(v); \ + data.push_back(brush.GetVertices()[faces[i][a]].X); \ + data.push_back(brush.GetVertices()[faces[i][a]].Y); \ + data.push_back(brush.GetVertices()[faces[i][a]].Z); \ + ) + + for (size_t i = 0; i < faces.size(); ++i) + { + for (size_t j = 0; j < faces[i].size() - 1; ++j) + { + float u = 0; + float v = 0; + ADD_VERT(j); + ADD_VERT(j+1); + } + } + +#undef ADD_VERT + + shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 5*sizeof(float), &data[0]); + shader->VertexPointer(3, GL_FLOAT, 5*sizeof(float), &data[2]); + + shader->AssertPointersBound(); + glDrawArrays(GL_LINES, 0, data.size() / 5); +} diff --git a/source/renderer/DebugRenderer.h b/source/renderer/DebugRenderer.h new file mode 100644 index 0000000000..4d8750a6dc --- /dev/null +++ b/source/renderer/DebugRenderer.h @@ -0,0 +1,62 @@ +/* Copyright (C) 2021 Wildfire Games. + * This file is part of 0 A.D. + * + * 0 A.D. is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 of the License, or + * (at your option) any later version. + * + * 0 A.D. is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with 0 A.D. If not, see . + */ + +#ifndef INCLUDED_DEBUGRENDERER +#define INCLUDED_DEBUGRENDERER + +#include "graphics/ShaderProgramPtr.h" + +class CBoundingBoxAligned; +class CBrush; +class CCamera; + +// Helper for unoptimized rendering of geometrics primitives. Should not be +// used for regular passes. +class CDebugRenderer +{ +public: + /** + * Render: Renders the camera's frustum in world space. + * The caller should set the color using glColorXy before calling Render. + * + * @param intermediates determines how many intermediate distance planes should + * be hinted at between the near and far planes + */ + void DrawCameraFrustum(const CCamera& camera, int intermediates = 0) const; + + /** + * Render the surfaces of the bound box as triangles. + */ + void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const; + + /** + * Render the outline of the bound box as lines. + */ + void DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const; + + /** + * Render the surfaces of the brush as triangles. + */ + void DrawBrush(const CBrush& brush, const CShaderProgramPtr& shader) const; + + /** + * Render the outline of the brush as lines. + */ + void DrawBrushOutline(const CBrush& brush, const CShaderProgramPtr& shader) const; +}; + +#endif // INCLUDED_DEBUGRENDERER diff --git a/source/renderer/ParticleRenderer.cpp b/source/renderer/ParticleRenderer.cpp index cd5696f792..e4c8b83dfa 100644 --- a/source/renderer/ParticleRenderer.cpp +++ b/source/renderer/ParticleRenderer.cpp @@ -24,6 +24,7 @@ #include "graphics/ShaderManager.h" #include "graphics/TextureManager.h" #include "ps/Profile.h" +#include "renderer/DebugRenderer.h" #include "renderer/Renderer.h" struct ParticleRendererInternals @@ -158,6 +159,6 @@ void ParticleRenderer::RenderBounds(int cullGroup, CShaderProgramPtr& shader) CParticleEmitter* emitter = emitters[i]; CBoundingBoxAligned bounds = emitter->m_Type->CalculateBounds(emitter->GetPosition(), emitter->GetParticleBounds()); - bounds.Render(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBox(bounds, shader); } } diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index b78fe4ec21..b14fbf974d 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -22,12 +22,6 @@ #include "precompiled.h" -#include -#include -#include - -#include - #include "Renderer.h" #include "lib/bits.h" // is_pow2 @@ -58,6 +52,7 @@ #include "graphics/Terrain.h" #include "graphics/Texture.h" #include "graphics/TextureManager.h" +#include "renderer/DebugRenderer.h" #include "renderer/HWLightingModelRenderer.h" #include "renderer/InstancingModelRenderer.h" #include "renderer/ModelRenderer.h" @@ -76,6 +71,11 @@ #include "renderer/WaterManager.h" #include "scriptinterface/ScriptInterface.h" +#include +#include +#include +#include + struct SScreenRect { GLint x1, y1, x2, y2; @@ -298,6 +298,8 @@ public: /// Postprocessing effect manager CPostprocManager postprocManager; + CDebugRenderer debugRenderer; + CFontManager fontManager; SilhouetteRenderer silhouetteRenderer; @@ -1483,12 +1485,12 @@ void CRenderer::DisplayFrustum() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glColor4ub(255,255,255,64); - m_CullCamera.Render(2); + GetDebugRenderer().DrawCameraFrustum(m_CullCamera, 2); glDisable(GL_BLEND); glPolygonMode(GL_FRONT_AND_BACK, GL_LINE); glColor3ub(255,255,255); - m_CullCamera.Render(2); + GetDebugRenderer().DrawCameraFrustum(m_CullCamera, 2); glPolygonMode(GL_FRONT_AND_BACK, GL_FILL); glEnable(GL_CULL_FACE); @@ -1952,6 +1954,11 @@ CPostprocManager& CRenderer::GetPostprocManager() return m->postprocManager; } +CDebugRenderer& CRenderer::GetDebugRenderer() +{ + return m->debugRenderer; +} + CFontManager& CRenderer::GetFontManager() { return m->fontManager; diff --git a/source/renderer/Renderer.h b/source/renderer/Renderer.h index 85ddfcafb4..dfad74f97e 100644 --- a/source/renderer/Renderer.h +++ b/source/renderer/Renderer.h @@ -33,6 +33,7 @@ #include "renderer/RenderingOptions.h" #include "renderer/Scene.h" +class CDebugRenderer; class CFontManager; class CLightEnv; class CMaterial; @@ -276,6 +277,8 @@ public: CPostprocManager& GetPostprocManager(); + CDebugRenderer& GetDebugRenderer(); + /** * GetCapabilities: Return which OpenGL capabilities are available and enabled. * diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index c3f89ea1f5..6d4f697c85 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -33,6 +33,7 @@ #include "ps/CLogger.h" #include "ps/ConfigDB.h" #include "ps/Profile.h" +#include "renderer/DebugRenderer.h" #include "renderer/Renderer.h" #include "renderer/RenderingOptions.h" @@ -676,19 +677,19 @@ void ShadowMap::RenderDebugBounds() shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection() * m->InvLightTransform); shader->Uniform(str_color, 1.0f, 1.0f, 0.0f, 1.0f); - m->ShadowReceiverBound.RenderOutline(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowReceiverBound, shader); shader->Uniform(str_color, 0.0f, 1.0f, 0.0f, 1.0f); - m->ShadowCasterBound.RenderOutline(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowCasterBound, shader); glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 0.25f); - m->ShadowRenderBound.Render(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBox(m->ShadowRenderBound, shader); glDisable(GL_BLEND); shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 1.0f); - m->ShadowRenderBound.RenderOutline(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowRenderBound, shader); // Render light frustum @@ -705,12 +706,11 @@ void ShadowMap::RenderDebugBounds() glEnable(GL_BLEND); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); shader->Uniform(str_color, 1.0f, 0.0f, 0.0f, 0.25f); - frustumBrush.Render(shader); + g_Renderer.GetDebugRenderer().DrawBrush(frustumBrush, shader); glDisable(GL_BLEND); shader->Uniform(str_color, 1.0f, 0.0f, 0.0f, 1.0f); - frustumBrush.RenderOutline(shader); - + g_Renderer.GetDebugRenderer().DrawBrushOutline(frustumBrush, shader); shaderTech->EndPass(); diff --git a/source/renderer/SilhouetteRenderer.cpp b/source/renderer/SilhouetteRenderer.cpp index 548bc40b08..b5144da1a0 100644 --- a/source/renderer/SilhouetteRenderer.cpp +++ b/source/renderer/SilhouetteRenderer.cpp @@ -26,6 +26,7 @@ #include "graphics/ShaderManager.h" #include "maths/MathUtil.h" #include "ps/Profile.h" +#include "renderer/DebugRenderer.h" #include "renderer/Renderer.h" #include "renderer/Scene.h" @@ -455,7 +456,7 @@ void SilhouetteRenderer::RenderDebugOverlays(const CCamera& camera) for (size_t i = 0; i < m_DebugBounds.size(); ++i) { shader->Uniform(str_color, m_DebugBounds[i].color); - m_DebugBounds[i].bounds.RenderOutline(shader); + g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m_DebugBounds[i].bounds, shader); } CMatrix3D m;