diff --git a/source/graphics/ParticleEmitter.h b/source/graphics/ParticleEmitter.h index 97d0290e37..918aab89b2 100644 --- a/source/graphics/ParticleEmitter.h +++ b/source/graphics/ParticleEmitter.h @@ -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.) diff --git a/source/renderer/DebugRenderer.cpp b/source/renderer/DebugRenderer.cpp index eedd085230..720bb2edd5 100644 --- a/source/renderer/DebugRenderer.cpp +++ b/source/renderer/DebugRenderer.cpp @@ -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& 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& 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 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 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 data; std::vector> 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 data; std::vector> faces; @@ -361,4 +400,6 @@ void CDebugRenderer::DrawBrushOutline(const CBrush& brush, const CShaderProgramP shader->AssertPointersBound(); glDrawArrays(GL_LINES, 0, data.size() / 5); + + shaderTech->EndPass(); } diff --git a/source/renderer/DebugRenderer.h b/source/renderer/DebugRenderer.h index 80faf29346..cfaba6ef27 100644 --- a/source/renderer/DebugRenderer.h +++ b/source/renderer/DebugRenderer.h @@ -18,13 +18,12 @@ #ifndef INCLUDED_DEBUGRENDERER #define INCLUDED_DEBUGRENDERER -#include "graphics/ShaderProgramPtr.h" - #include 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 diff --git a/source/renderer/ParticleRenderer.cpp b/source/renderer/ParticleRenderer.cpp index e4c8b83dfa..fcbfbb9e68 100644 --- a/source/renderer/ParticleRenderer.cpp +++ b/source/renderer/ParticleRenderer.cpp @@ -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& 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)); } } diff --git a/source/renderer/ParticleRenderer.h b/source/renderer/ParticleRenderer.h index 0cde063b8f..18beac5fb7 100644 --- a/source/renderer/ParticleRenderer.h +++ b/source/renderer/ParticleRenderer.h @@ -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; diff --git a/source/renderer/Renderer.cpp b/source/renderer/Renderer.cpp index fc8ac3f87f..f0fadafce4 100644 --- a/source/renderer/Renderer.cpp +++ b/source/renderer/Renderer.cpp @@ -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); } diff --git a/source/renderer/ShadowMap.cpp b/source/renderer/ShadowMap.cpp index 70f5c65c3d..dad62f96b7 100644 --- a/source/renderer/ShadowMap.cpp +++ b/source/renderer/ShadowMap.cpp @@ -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); diff --git a/source/renderer/SilhouetteRenderer.cpp b/source/renderer/SilhouetteRenderer.cpp index fbc965d2e3..b0c634edf4 100644 --- a/source/renderer/SilhouetteRenderer.cpp +++ b/source/renderer/SilhouetteRenderer.cpp @@ -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)