Removes low-level GL calls from graphics and geometrics primitives and adds DebugRenderer.
Tested By: Freagarach Differential Revision: https://code.wildfiregames.com/D3857 This was SVN commit r25269.
This commit is contained in:
parent
f1a1cf11d3
commit
389a5a4379
@ -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
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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<float> 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<float> 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);
|
||||
}
|
||||
|
@ -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];
|
||||
|
@ -15,21 +15,14 @@
|
||||
* along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
/*
|
||||
* 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 <float.h>
|
||||
|
||||
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<CVector3D> CBrush::GetVertices() const
|
||||
|
||||
const std::vector<CVector3D>& CBrush::GetVertices() const
|
||||
{
|
||||
return m_Vertices;
|
||||
}
|
||||
|
||||
void CBrush::GetFaces(std::vector<std::vector<size_t> >& out) const
|
||||
void CBrush::GetFaces(std::vector<std::vector<size_t>>& 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<std::vector<size_t> >& out) const
|
||||
faceStartIdx = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void CBrush::Render(CShaderProgramPtr& shader) const
|
||||
{
|
||||
std::vector<float> data;
|
||||
|
||||
std::vector<std::vector<size_t> > 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<float> data;
|
||||
|
||||
std::vector<std::vector<size_t> > 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);
|
||||
}
|
||||
|
@ -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 <vector>
|
||||
|
||||
@ -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<CVector3D> GetVertices() const;
|
||||
const std::vector<CVector3D>& 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<std::vector<size_t> >& out) const;
|
||||
void GetFaces(std::vector<std::vector<size_t>>& out) const;
|
||||
|
||||
private:
|
||||
static const size_t NO_VERTEX = ~0u;
|
||||
@ -126,4 +110,4 @@ private:
|
||||
struct Helper;
|
||||
};
|
||||
|
||||
#endif // maths_brush_h
|
||||
#endif // INCLUDED_BRUSH
|
||||
|
231
source/renderer/DebugRenderer.cpp
Normal file
231
source/renderer/DebugRenderer.cpp
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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<float> 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<float> 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<float> data;
|
||||
|
||||
std::vector<std::vector<size_t>> 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<float> data;
|
||||
|
||||
std::vector<std::vector<size_t>> 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);
|
||||
}
|
62
source/renderer/DebugRenderer.h
Normal file
62
source/renderer/DebugRenderer.h
Normal file
@ -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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#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
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
@ -22,12 +22,6 @@
|
||||
|
||||
#include "precompiled.h"
|
||||
|
||||
#include <map>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
|
||||
#include <boost/algorithm/string.hpp>
|
||||
|
||||
#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 <algorithm>
|
||||
#include <boost/algorithm/string.hpp>
|
||||
#include <map>
|
||||
#include <set>
|
||||
|
||||
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;
|
||||
|
@ -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.
|
||||
*
|
||||
|
@ -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();
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user