Skip to content

Commit

Permalink
CamRenderer stores and counts lights
Browse files Browse the repository at this point in the history
CamRenderer stores received RendererLights in an internal list, and increments
a new counter in RenderStatistics which results in the number of lights being
shown on the stats line. This confirms that the CamRenderer is receiving the
expected lights, although they are not currently being used for rendering.
  • Loading branch information
Matthew Mott committed Sep 2, 2020
1 parent 4e0eadc commit 7f489c0
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 6 deletions.
25 changes: 20 additions & 5 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -556,12 +556,18 @@ namespace
// Implementation of RenderableCollector for the 3D camera view.
class CamRenderer: public RenderableCollector
{
// Render statistics
render::RenderStatistics& _renderStats;

// Highlight state
bool _highlightFaces = false;
bool _highlightPrimitives = false;
Shader& _highlightedPrimitiveShader;
Shader& _highlightedFaceShader;

// All lights we have received from the scene
std::list<const RendererLight*> _sceneLights;

// Associate a renderable with the lights which illuminate it
struct LitRenderable
{
Expand All @@ -585,8 +591,10 @@ class CamRenderer: public RenderableCollector
public:

// Initialise CamRenderer with the highlight shaders
CamRenderer(Shader& primHighlightShader, Shader& faceHighlightShader)
: _highlightedPrimitiveShader(primHighlightShader),
CamRenderer(Shader& primHighlightShader, Shader& faceHighlightShader,
render::RenderStatistics& stats)
: _renderStats(stats),
_highlightedPrimitiveShader(primHighlightShader),
_highlightedFaceShader(faceHighlightShader)
{}

Expand Down Expand Up @@ -629,8 +637,14 @@ class CamRenderer: public RenderableCollector
}
}

void addLight(const RendererLight& /* light */) override
{}
void addLight(const RendererLight& light) override
{
// Store the light in our list of scene lights
_sceneLights.push_back(&light);

// Count the light for the stats display
_renderStats.addLight();
}

void addRenderable(Shader& shader, const OpenGLRenderable& renderable,
const Matrix4& world, const LightSources* lights,
Expand Down Expand Up @@ -804,7 +818,8 @@ void CamWnd::Cam_Draw()
// Main scene render
{
// Front end (renderable collection from scene)
CamRenderer renderer(*_primitiveHighlightShader, *_faceHighlightShader);
CamRenderer renderer(*_primitiveHighlightShader, *_faceHighlightShader,
_renderStats);
render::RenderableCollectionWalker::CollectRenderablesInScene(renderer, _view);

// Render any active mousetools
Expand Down
14 changes: 13 additions & 1 deletion radiant/render/RenderStatistics.h
Expand Up @@ -12,19 +12,31 @@ class RenderStatistics
// Timer for measuring render time
wxStopWatch _timer;

// Count of lights
int _lights = 0;

public:

/// Return the constructed string for display
std::string getStatString()
{
long msec = _timer.Time();
return "msec: " + std::to_string(msec)
return "lights: " + std::to_string(_lights)
+ " | msec: " + std::to_string(msec)
+ " | fps: " + (msec > 0 ? std::to_string(1000 / msec) : "-");
}

/// Increment the light count
void addLight()
{
++_lights;
}

/// Reset statistics at the beginning of a frame render
void resetStats()
{
_lights = 0;

_timer.Start();
}
};
Expand Down

0 comments on commit 7f489c0

Please sign in to comment.