From 7ca88d9e356d09dd923de2eab459b03168922f7f Mon Sep 17 00:00:00 2001 From: codereader Date: Sun, 13 Feb 2022 09:34:04 +0100 Subject: [PATCH] #5893: Disconnect the old lighting mode infrastructure in the CamRenderer. --- include/irenderable.h | 10 -- libs/render/CamRenderer.h | 144 -------------------------- libs/wxutil/preview/RenderPreview.cpp | 2 - radiant/camera/CamWnd.cpp | 6 -- radiant/render/RenderStatistics.h | 17 +-- radiant/xyview/XYRenderer.h | 3 - test/Entity.cpp | 13 --- 7 files changed, 1 insertion(+), 194 deletions(-) diff --git a/include/irenderable.h b/include/irenderable.h index d99a4bac02..9c6f552c98 100644 --- a/include/irenderable.h +++ b/include/irenderable.h @@ -85,16 +85,6 @@ class IRenderableCollector */ virtual void addHighlightRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld) = 0; - /** - * \brief Submit a light source for the render operation. - * - * This is the entry point for lights into the render front-end. Each light - * in the scene graph must be submitted through this method in order to - * provide light for the final render. If the render is in wireframe mode, - * light sources can still be submitted but they will not have any effect. - */ - virtual void addLight(const RendererLight& light) = 0; - /** * \brief Determine if this RenderableCollector can accept renderables for * full materials rendering, or just wireframe rendering. diff --git a/libs/render/CamRenderer.h b/libs/render/CamRenderer.h index 28d3767bda..a64774dd06 100644 --- a/libs/render/CamRenderer.h +++ b/libs/render/CamRenderer.h @@ -6,8 +6,6 @@ #include "VectorLightList.h" -#include - namespace render { @@ -32,55 +30,8 @@ class CamRenderer : IMap::EditMode _editMode; - // Render statistics - int _totalLights = 0; - int _visibleLights = 0; - const HighlightShaders& _shaders; - // All lights we have received from the scene - std::list _sceneLights; - - // Lit renderable provided via addRenderable(), for which we construct the - // light list with lights received via addLight(). - struct LitRenderable - { - // Renderable information submitted with addLitObject() - const OpenGLRenderable& renderable; - const LitObject* litObject = nullptr; - Matrix4 local2World; - const IRenderEntity* entity = nullptr; - - // Calculated list of intersecting lights (initially empty) - render::lib::VectorLightList lights; - }; - using LitRenderables = std::vector; - - // Renderables added with addLitObject() need to be stored until their - // light lists can be calculated, which can't happen until all the lights - // are submitted too. - std::unordered_map _litRenderables; - - // Intersect all received renderables wiith lights - void calculateLightIntersections() - { - // For each shader - for (auto i = _litRenderables.begin(); i != _litRenderables.end(); ++i) - { - // For each renderable associated with this shader - for (auto j = i->second.begin(); j != i->second.end(); ++j) - { - // Test intersection between the LitObject and each light in - // the scene - for (const RendererLight* l: _sceneLights) - { - if (j->litObject && j->litObject->intersectsLight(*l)) - j->lights.addLight(*l); - } - } - } - } - public: /// Initialise CamRenderer with optional highlight shaders @@ -92,91 +43,17 @@ class CamRenderer : void prepare() { - _totalLights = 0; - _visibleLights = 0; _editMode = GlobalMapModule().getEditMode(); } void cleanup() { - // Keep the shader map intact, but clear the renderables vectors, - // so that we don't have to re-allocate the whole memory every frame - // Purge the ones that have not been used in this render round - for (auto i = _litRenderables.begin(); i != _litRenderables.end();) - { - if (i->second.empty()) - { - // This shader has not been used at all in the last frame, free the memory - _litRenderables.erase(i++); - continue; - } - - (i++)->second.clear(); - } - - _sceneLights.clear(); } - /** - * \brief - * Instruct the CamRenderer to push its sorted renderables to their - * respective shaders. - * - * \param useLights - * true if lighting calculations should be performed and light lists sent - * to shaders; false if lights should be ignored (e.g. in fullbright render - * mode). - */ - void submitToShaders(bool useLights = true) - { - if (useLights) - { - // Calculate intersections between lights and renderables we have - // received - calculateLightIntersections(); - } - - // Render objects with calculated light lists - for (const auto& pair : _litRenderables) - { - Shader* shader = pair.first; - assert(shader); - for (const LitRenderable& lr : pair.second) - { - shader->addRenderable(lr.renderable, lr.local2World, - useLights ? &lr.lights : nullptr, - lr.entity); - } - } - } - - /// Obtain the visible light count - int getVisibleLights() const { return _visibleLights; } - - /// Obtain the total light count - int getTotalLights() const { return _totalLights; } - // RenderableCollector implementation bool supportsFullMaterials() const override { return true; } - void addLight(const RendererLight& light) override - { - // Determine if this light is visible within the view frustum - VolumeIntersectionValue viv = _view.TestAABB(light.lightAABB()); - if (viv != VOLUME_OUTSIDE) - { - // Store the light in our list of scene lights - _sceneLights.push_back(&light); - - // Count the light for the stats display - ++_visibleLights; - } - - // Count total lights - ++_totalLights; - } - void addRenderable(Shader& shader, const OpenGLRenderable& renderable, const Matrix4& localToWorld, @@ -184,27 +61,6 @@ class CamRenderer : const IRenderEntity* entity = nullptr) override { addHighlightRenderable(renderable, localToWorld); - - // Construct an entry for this shader in the map if it is the first - // time we've seen it - auto iter = _litRenderables.find(&shader); - if (iter == _litRenderables.end()) - { - // Add an entry for this shader, and pre-allocate some space in the - // vector to avoid too many expansions during scenegraph traversal. - LitRenderables emptyList; - emptyList.reserve(1024); - - auto result = _litRenderables.emplace(&shader, std::move(emptyList)); - assert(result.second); - iter = result.first; - } - assert(iter != _litRenderables.end()); - assert(iter->first == &shader); - - // Store a LitRenderable object for this renderable - LitRenderable lr { renderable, litObject, localToWorld, entity }; - iter->second.emplace_back(std::move(lr)); } void addHighlightRenderable(const OpenGLRenderable& renderable, const Matrix4& localToWorld) override diff --git a/libs/wxutil/preview/RenderPreview.cpp b/libs/wxutil/preview/RenderPreview.cpp index d1520993ac..806bd50b38 100644 --- a/libs/wxutil/preview/RenderPreview.cpp +++ b/libs/wxutil/preview/RenderPreview.cpp @@ -501,7 +501,6 @@ bool RenderPreview::drawPreview() RenderStateFlags flags = getRenderFlagsFill(); // Launch the back end rendering - renderer.submitToShaders(); _renderSystem->render(RenderViewType::Camera, flags, _volumeTest.GetModelview(), projection, _viewOrigin, _volumeTest); // Give subclasses an opportunity to render their own on-screen stuff @@ -526,7 +525,6 @@ void RenderPreview::renderWireFrame() getScene()->foreachVisibleNodeInVolume(_volumeTest, sceneWalker); // Launch the back end rendering - renderer.submitToShaders(); _renderSystem->render(RenderViewType::Camera, flags, _volumeTest.GetModelview(), projection, _viewOrigin, _volumeTest); } diff --git a/radiant/camera/CamWnd.cpp b/radiant/camera/CamWnd.cpp index 669ff61392..ed5d4cce5f 100644 --- a/radiant/camera/CamWnd.cpp +++ b/radiant/camera/CamWnd.cpp @@ -796,8 +796,6 @@ void CamWnd::Cam_Draw() render::RenderableCollectionWalker::CollectRenderablesInScene(*_renderer, _view); // Accumulate render statistics - _renderStats.setLightCount(_renderer->getVisibleLights(), - _renderer->getTotalLights()); _renderStats.frontEndComplete(); // Render any active mousetools @@ -813,10 +811,6 @@ void CamWnd::Cam_Draw() } else { - // Back end (submit to shaders and do the actual render) - _renderer->submitToShaders( - getCameraSettings()->getRenderMode() == RENDER_MODE_LIGHTING - ); GlobalRenderSystem().render(RenderViewType::Camera, allowedRenderFlags, _camera->getModelView(), _camera->getProjection(), _view.getViewer(), _view); } diff --git a/radiant/render/RenderStatistics.h b/radiant/render/RenderStatistics.h index 55e0e606de..d8b394347f 100644 --- a/radiant/render/RenderStatistics.h +++ b/radiant/render/RenderStatistics.h @@ -15,10 +15,6 @@ class RenderStatistics // Time for the render front-end only long _feTime = 0; - // Count of lights - int _visibleLights = 0; - int _totalLights = 0; - public: /// Return the constructed string for display @@ -28,9 +24,7 @@ class RenderStatistics long totTime = _timer.Time(); long beTime = totTime - _feTime; - return "lights: " + std::to_string(_visibleLights) - + " / " + std::to_string(_totalLights) - + " | f/e: " + std::to_string(_feTime) + " ms" + return " | f/e: " + std::to_string(_feTime) + " ms" + " | b/e: " + std::to_string(beTime) + " ms" + " | tot: " + std::to_string(totTime) + " ms" + " | fps: " + (totTime > 0 ? std::to_string(1000 / totTime) : "-"); @@ -42,18 +36,9 @@ class RenderStatistics _feTime = _timer.Time(); } - /// Set the light count - void setLightCount(int visible, int total) - { - _visibleLights += visible; - _totalLights += total; - } - /// Reset statistics at the beginning of a frame render void resetStats() { - _visibleLights = _totalLights = 0; - _feTime = 0; _timer.Start(); } diff --git a/radiant/xyview/XYRenderer.h b/radiant/xyview/XYRenderer.h index 8e1de934a2..14d5be840a 100644 --- a/radiant/xyview/XYRenderer.h +++ b/radiant/xyview/XYRenderer.h @@ -38,9 +38,6 @@ class XYRenderer : return false; } - // Ortho view never processes lights - void addLight(const RendererLight&) override {} - void addRenderable(Shader& shader, const OpenGLRenderable& renderable, const Matrix4& localToWorld, diff --git a/test/Entity.cpp b/test/Entity.cpp index 429fa6b31f..504aa0b6cd 100644 --- a/test/Entity.cpp +++ b/test/Entity.cpp @@ -459,10 +459,6 @@ namespace int renderables = 0; int processedNodes = 0; int highlightRenderables = 0; - int lights = 0; - - // List of actual RendererLight objects - std::list lightPtrs; // List of renderables and their shaders std::vector< std::pair > renderablePtrs; @@ -491,12 +487,6 @@ namespace highlightRenderablePtrs.push_back(&renderable); } - void addLight(const RendererLight& light) override - { - ++lights; - lightPtrs.push_back(&light); - } - bool supportsFullMaterials() const override { return true; } }; @@ -972,7 +962,6 @@ TEST_F(EntityTest, RenderUnselectedLightEntity) // Only the light origin diamond should be rendered EXPECT_EQ(fixture.collector.highlightRenderables, 0); - EXPECT_EQ(fixture.collector.lights, 0); } TEST_F(EntityTest, RenderSelectedLightEntity) @@ -991,7 +980,6 @@ TEST_F(EntityTest, RenderSelectedLightEntity) // With the light selected, we should get the origin diamond, the radius and // the center vertex. EXPECT_EQ(fixture.collector.highlightRenderables, 2); - EXPECT_EQ(fixture.collector.lights, 0); } TEST_F(EntityTest, RenderLightProperties) @@ -1032,7 +1020,6 @@ TEST_F(EntityTest, RenderEmptyFuncStatic) RenderFixture rf; rf.renderSubGraph(funcStatic); EXPECT_EQ(rf.nodesVisited, 1); - EXPECT_EQ(rf.collector.lights, 0); EXPECT_EQ(rf.collector.renderables, 0); }