Skip to content

Commit

Permalink
#5893: Disconnect the old lighting mode infrastructure in the CamRend…
Browse files Browse the repository at this point in the history
…erer.
  • Loading branch information
codereader committed Feb 13, 2022
1 parent a01caa9 commit 7ca88d9
Show file tree
Hide file tree
Showing 7 changed files with 1 addition and 194 deletions.
10 changes: 0 additions & 10 deletions include/irenderable.h
Expand Up @@ -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.
Expand Down
144 changes: 0 additions & 144 deletions libs/render/CamRenderer.h
Expand Up @@ -6,8 +6,6 @@

#include "VectorLightList.h"

#include <unordered_map>

namespace render
{

Expand All @@ -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<const RendererLight*> _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<LitRenderable>;

// 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<Shader*, LitRenderables> _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
Expand All @@ -92,119 +43,24 @@ 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,
const LitObject* litObject = nullptr,
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
Expand Down
2 changes: 0 additions & 2 deletions libs/wxutil/preview/RenderPreview.cpp
Expand Up @@ -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
Expand All @@ -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);
}

Expand Down
6 changes: 0 additions & 6 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -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
Expand All @@ -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);
}
Expand Down
17 changes: 1 addition & 16 deletions radiant/render/RenderStatistics.h
Expand Up @@ -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
Expand All @@ -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) : "-");
Expand All @@ -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();
}
Expand Down
3 changes: 0 additions & 3 deletions radiant/xyview/XYRenderer.h
Expand Up @@ -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,
Expand Down
13 changes: 0 additions & 13 deletions test/Entity.cpp
Expand Up @@ -459,10 +459,6 @@ namespace
int renderables = 0;
int processedNodes = 0;
int highlightRenderables = 0;
int lights = 0;

// List of actual RendererLight objects
std::list<const RendererLight*> lightPtrs;

// List of renderables and their shaders
std::vector< std::pair<const Shader*, const OpenGLRenderable*> > renderablePtrs;
Expand Down Expand Up @@ -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; }
};

Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down Expand Up @@ -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);
}

Expand Down

0 comments on commit 7ca88d9

Please sign in to comment.