1
0
forked from 0ad/0ad

Removes ShaderProgramPtr argument from DebugRenderer methods.

This was SVN commit r25329.
This commit is contained in:
Vladislav Belov 2021-04-27 19:23:37 +00:00
parent cd6a554198
commit 5b33d3a76c
8 changed files with 89 additions and 83 deletions

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2011 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
@ -90,7 +90,7 @@ public:
m_Rot = rot;
}
CQuaternion GetRotation() const
const CQuaternion& GetRotation() const
{
return m_Rot;
}
@ -98,7 +98,7 @@ public:
/**
* Get the bounding box of the center points of particles at their current positions.
*/
CBoundingBoxAligned GetParticleBounds() { return m_ParticleBounds; }
const CBoundingBoxAligned& GetParticleBounds() const { return m_ParticleBounds; }
/**
* Push a new particle onto the ring buffer. (May overwrite an old particle.)

View File

@ -26,6 +26,7 @@
#include "lib/ogl.h"
#include "maths/BoundingBoxAligned.h"
#include "maths/Brush.h"
#include "maths/Matrix3D.h"
#include "maths/Vector3D.h"
#include "renderer/Renderer.h"
@ -47,9 +48,8 @@ void CDebugRenderer::DrawLine(const std::vector<CVector3D>& line, const CColor&
CShaderTechniquePtr debugLineTech =
g_Renderer.GetShaderManager().LoadEffect(str_debug_line);
debugLineTech->BeginPass();
CShaderProgramPtr debugLineShader = debugLineTech->GetShader();
debugLineShader->Bind();
CShaderProgramPtr debugLineShader = debugLineTech->GetShader();
debugLineShader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
debugLineShader->Uniform(str_color, color);
@ -86,7 +86,6 @@ void CDebugRenderer::DrawLine(const std::vector<CVector3D>& line, const CColor&
debugLineShader->AssertPointersBound();
glDrawArrays(GL_TRIANGLES, 0, vertices.size() / 3);
debugLineShader->Unbind();
debugLineTech->EndPass();
#endif
}
@ -99,11 +98,10 @@ void CDebugRenderer::DrawCircle(const CVector3D& origin, const float radius, con
CShaderTechniquePtr debugCircleTech =
g_Renderer.GetShaderManager().LoadEffect(str_debug_line);
debugCircleTech->BeginPass();
CShaderProgramPtr debugCircleShader = debugCircleTech->GetShader();
const CCamera& camera = g_Renderer.GetViewCamera();
debugCircleShader->Bind();
CShaderProgramPtr debugCircleShader = debugCircleTech->GetShader();
debugCircleShader->Uniform(str_transform, camera.GetViewProjection());
debugCircleShader->Uniform(str_color, color);
@ -132,12 +130,11 @@ void CDebugRenderer::DrawCircle(const CVector3D& origin, const float radius, con
debugCircleShader->AssertPointersBound();
glDrawArrays(GL_TRIANGLE_FAN, 0, vertices.size() / 3);
debugCircleShader->Unbind();
debugCircleTech->EndPass();
#endif
}
void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& color, int intermediates) const
void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& color, int intermediates)
{
#if CONFIG2_GLES
#warning TODO: implement camera frustum for GLES
@ -156,9 +153,8 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo
CShaderTechniquePtr overlayTech =
g_Renderer.GetShaderManager().LoadEffect(str_debug_line);
overlayTech->BeginPass();
CShaderProgramPtr overlayShader = overlayTech->GetShader();
overlayShader->Bind();
CShaderProgramPtr overlayShader = overlayTech->GetShader();
overlayShader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
overlayShader->Uniform(str_color, color);
@ -218,13 +214,24 @@ void CDebugRenderer::DrawCameraFrustum(const CCamera& camera, const CColor& colo
glDrawArrays(GL_QUAD_STRIP, 0, vertices.size() / 3);
#undef ADD
overlayShader->Unbind();
overlayTech->EndPass();
#endif
}
void CDebugRenderer::DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const
void CDebugRenderer::DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color)
{
DrawBoundingBox(boundingBox, color, g_Renderer.GetViewCamera().GetViewProjection());
}
void CDebugRenderer::DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform)
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_color, color);
shader->Uniform(str_transform, transform);
std::vector<float> data;
#define ADD_FACE(x, y, z) \
@ -253,10 +260,24 @@ void CDebugRenderer::DrawBoundingBox(const CBoundingBoxAligned& boundingBox, con
shader->AssertPointersBound();
glDrawArrays(GL_TRIANGLES, 0, 6*6);
shaderTech->EndPass();
}
void CDebugRenderer::DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const
void CDebugRenderer::DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CColor& color)
{
DrawBoundingBoxOutline(boundingBox, color, g_Renderer.GetViewCamera().GetViewProjection());
}
void CDebugRenderer::DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform)
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_color, color);
shader->Uniform(str_transform, transform);
std::vector<float> data;
#define ADD_FACE(x, y, z) \
@ -287,10 +308,19 @@ void CDebugRenderer::DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingB
shader->AssertPointersBound();
glDrawArrays(GL_LINES, 0, 6*8);
shaderTech->EndPass();
}
void CDebugRenderer::DrawBrush(const CBrush& brush, const CShaderProgramPtr& shader) const
void CDebugRenderer::DrawBrush(const CBrush& brush, const CColor& color)
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_color, color);
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
std::vector<float> data;
std::vector<std::vector<size_t>> faces;
@ -325,10 +355,19 @@ void CDebugRenderer::DrawBrush(const CBrush& brush, const CShaderProgramPtr& sha
shader->AssertPointersBound();
glDrawArrays(GL_TRIANGLES, 0, data.size() / 5);
shaderTech->EndPass();
}
void CDebugRenderer::DrawBrushOutline(const CBrush& brush, const CShaderProgramPtr& shader) const
void CDebugRenderer::DrawBrushOutline(const CBrush& brush, const CColor& color)
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_color, color);
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
std::vector<float> data;
std::vector<std::vector<size_t>> faces;
@ -361,4 +400,6 @@ void CDebugRenderer::DrawBrushOutline(const CBrush& brush, const CShaderProgramP
shader->AssertPointersBound();
glDrawArrays(GL_LINES, 0, data.size() / 5);
shaderTech->EndPass();
}

View File

@ -18,13 +18,12 @@
#ifndef INCLUDED_DEBUGRENDERER
#define INCLUDED_DEBUGRENDERER
#include "graphics/ShaderProgramPtr.h"
#include <vector>
class CBoundingBoxAligned;
class CBrush;
class CCamera;
class CMatrix3D;
class CVector3D;
struct CColor;
@ -52,27 +51,29 @@ 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) const;
void DrawCameraFrustum(const CCamera& camera, const CColor& color, int intermediates = 0);
/**
* Render the surfaces of the bound box as triangles.
*/
void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const;
void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color);
void DrawBoundingBox(const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform);
/**
* Render the outline of the bound box as lines.
*/
void DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CShaderProgramPtr& shader) const;
void DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CColor& color);
void DrawBoundingBoxOutline(const CBoundingBoxAligned& boundingBox, const CColor& color, const CMatrix3D& transform);
/**
* Render the surfaces of the brush as triangles.
*/
void DrawBrush(const CBrush& brush, const CShaderProgramPtr& shader) const;
void DrawBrush(const CBrush& brush, const CColor& color);
/**
* Render the outline of the brush as lines.
*/
void DrawBrushOutline(const CBrush& brush, const CShaderProgramPtr& shader) const;
void DrawBrushOutline(const CBrush& brush, const CColor& color);
};
#endif // INCLUDED_DEBUGRENDERER

View File

@ -150,15 +150,12 @@ void ParticleRenderer::RenderParticles(int cullGroup, bool solidColor)
shader->EndPass();
}
void ParticleRenderer::RenderBounds(int cullGroup, CShaderProgramPtr& shader)
void ParticleRenderer::RenderBounds(int cullGroup)
{
std::vector<CParticleEmitter*>& emitters = m->emitters[cullGroup];
for (size_t i = 0; i < emitters.size(); ++i)
for (const CParticleEmitter* emitter : m->emitters[cullGroup])
{
CParticleEmitter* emitter = emitters[i];
CBoundingBoxAligned bounds = emitter->m_Type->CalculateBounds(emitter->GetPosition(), emitter->GetParticleBounds());
g_Renderer.GetDebugRenderer().DrawBoundingBox(bounds, shader);
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));
}
}

View File

@ -1,4 +1,4 @@
/* Copyright (C) 2013 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
@ -22,8 +22,6 @@ class CParticleEmitter;
class CShaderDefines;
struct ParticleRendererInternals;
#include "graphics/ShaderProgramPtr.h"
/**
* Render particles.
*/
@ -60,7 +58,7 @@ public:
/**
* Render bounding boxes for all the submitted emitters.
*/
void RenderBounds(int cullGroup, CShaderProgramPtr& shader);
void RenderBounds(int cullGroup);
private:
ParticleRendererInternals* m;

View File

@ -1223,20 +1223,8 @@ void CRenderer::RenderParticles(int cullGroup)
{
glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
glDisable(GL_TEXTURE_2D);
glColor3f(0.0f, 0.5f, 0.0f);
m->particleRenderer.RenderParticles(true);
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_color, 0.0f, 1.0f, 0.0f, 1.0f);
shader->Uniform(str_transform, m_ViewCamera.GetViewProjection());
m->particleRenderer.RenderBounds(cullGroup, shader);
shaderTech->EndPass();
m->particleRenderer.RenderBounds(cullGroup);
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
}

View File

@ -654,10 +654,6 @@ void ShadowMap::SetDepthTextureBits(int bits)
void ShadowMap::RenderDebugBounds()
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
glDepthMask(0);
glDisable(GL_CULL_FACE);
@ -667,27 +663,18 @@ void ShadowMap::RenderDebugBounds()
// Green = bounds of objects in culling frustum that cast shadows
// Blue = frustum used for rendering the shadow map
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection() * m->InvLightTransform);
shader->Uniform(str_color, 1.0f, 1.0f, 0.0f, 1.0f);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowReceiverBound, shader);
shader->Uniform(str_color, 0.0f, 1.0f, 0.0f, 1.0f);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowCasterBound, shader);
const CMatrix3D transform = g_Renderer.GetViewCamera().GetViewProjection() * m->InvLightTransform;
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowReceiverBound, CColor(1.0f, 1.0f, 0.0f, 1.0f), transform);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowCasterBound, CColor(0.0f, 1.0f, 0.0f, 1.0f), transform);
glEnable(GL_BLEND);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 0.25f);
g_Renderer.GetDebugRenderer().DrawBoundingBox(m->ShadowRenderBound, shader);
g_Renderer.GetDebugRenderer().DrawBoundingBox(m->ShadowRenderBound, CColor(0.0f, 0.0f, 1.0f, 0.25f), transform);
glDisable(GL_BLEND);
shader->Uniform(str_color, 0.0f, 0.0f, 1.0f, 1.0f);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowRenderBound, shader);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m->ShadowRenderBound, CColor(0.0f, 0.0f, 1.0f, 1.0f), transform);
// Render light frustum
shader->Uniform(str_transform, g_Renderer.GetViewCamera().GetViewProjection());
CFrustum frustum = GetShadowCasterCullFrustum();
// We don't have a function to create a brush directly from a frustum, so use
// the ugly approach of creating a large cube and then intersecting with the frustum
@ -698,14 +685,9 @@ 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);
g_Renderer.GetDebugRenderer().DrawBrush(frustumBrush, shader);
g_Renderer.GetDebugRenderer().DrawBrush(frustumBrush, CColor(1.0f, 0.0f, 0.0f, 0.25f));
glDisable(GL_BLEND);
shader->Uniform(str_color, 1.0f, 0.0f, 0.0f, 1.0f);
g_Renderer.GetDebugRenderer().DrawBrushOutline(frustumBrush, shader);
shaderTech->EndPass();
g_Renderer.GetDebugRenderer().DrawBrushOutline(frustumBrush, CColor(1.0f, 0.0f, 0.0f, 1.0f));
glEnable(GL_CULL_FACE);
glDepthMask(1);

View File

@ -444,20 +444,14 @@ void SilhouetteRenderer::RenderSubmitCasters(SceneCollector& collector)
void SilhouetteRenderer::RenderDebugOverlays(const CCamera& camera)
{
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
if (m_DebugBounds.empty() && m_DebugRects.empty())
return;
glDepthMask(0);
glDisable(GL_CULL_FACE);
shader->Uniform(str_transform, camera.GetViewProjection());
for (size_t i = 0; i < m_DebugBounds.size(); ++i)
{
shader->Uniform(str_color, m_DebugBounds[i].color);
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m_DebugBounds[i].bounds, shader);
}
g_Renderer.GetDebugRenderer().DrawBoundingBoxOutline(m_DebugBounds[i].bounds, m_DebugBounds[i].color);
CMatrix3D m;
m.SetIdentity();
@ -468,6 +462,11 @@ void SilhouetteRenderer::RenderDebugOverlays(const CCamera& camera)
proj.SetOrtho(0.f, g_MaxCoord, 0.f, g_MaxCoord, -1.f, 1000.f);
m = proj * m;
CShaderTechniquePtr shaderTech = g_Renderer.GetShaderManager().LoadEffect(str_gui_solid);
shaderTech->BeginPass();
CShaderProgramPtr shader = shaderTech->GetShader();
shader->Uniform(str_transform, proj);
for (size_t i = 0; i < m_DebugRects.size(); ++i)