Skip to content

Commit

Permalink
Initial cleanup of CamRenderer
Browse files Browse the repository at this point in the history
- Moved CamRenderer into CamWnd.cpp since it is not used from anywhere else.
- Removed the State local class; this is obsolete since CamRenderer no longer
  has a state stack. The two contained boolean members are just regular members
  of CamRenderer now.
- Removed render() method which just called GlobalRenderSystem().render() with
  some stored members and additional method arguments. The calling code now
  calls this directly, allowing the render state flags and viewer members to be
  removed from CamRenderer entirely.
- The shader parameters (for face and primitive highlighting) are received and
  stored as references, rather than shared pointers. This should be safe since
  the CamRenderer is not expected to outlive the global shader objects.
  • Loading branch information
Matthew Mott committed Aug 25, 2020
1 parent 83627e5 commit 0c8d652
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 120 deletions.
1 change: 0 additions & 1 deletion radiant/Makefile.am
Expand Up @@ -59,7 +59,6 @@ darkradiant_SOURCES = main.cpp \
camera/Camera.cpp \
camera/GlobalCamera.cpp \
camera/CameraSettings.cpp \
camera/CamRenderer.cpp \
camera/CamWnd.cpp \
camera/FloatingCamWnd.cpp \
commandsystem/CommandSystem.cpp \
Expand Down
55 changes: 0 additions & 55 deletions radiant/camera/CamRenderer.cpp

This file was deleted.

53 changes: 0 additions & 53 deletions radiant/camera/CamRenderer.h

This file was deleted.

79 changes: 68 additions & 11 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -16,7 +16,6 @@
#include "selectionlib.h"
#include "gamelib.h"
#include "map/Map.h"
#include "CamRenderer.h"
#include "CameraSettings.h"
#include "GlobalCamera.h"
#include "render/RenderStatistics.h"
Expand Down Expand Up @@ -170,12 +169,12 @@ CamWnd::CamWnd(wxWindow* parent) :
_wxGLWidget->Connect(wxEVT_MIDDLE_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_MIDDLE_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_MIDDLE_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX1_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DOWN, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_DCLICK, wxMouseEventHandler(CamWnd::onGLMouseButtonPress), NULL, this);
_wxGLWidget->Connect(wxEVT_AUX2_UP, wxMouseEventHandler(CamWnd::onGLMouseButtonRelease), NULL, this);

// Now add the handlers for the non-freelook mode, the events are activated by this
addHandlersMove();
Expand Down Expand Up @@ -552,6 +551,62 @@ bool CamWnd::freeMoveEnabled() const
return _freeMoveEnabled;
}

namespace
{

// Implementation of RenderableCollector for the 3D camera view.
class CamRenderer: public RenderableCollector
{
// Highlight state
bool _highlightFaces = false;
bool _highlightPrimitives = false;

Shader& _highlightedPrimitiveShader;
Shader& _highlightedFaceShader;

public:

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

// RenderableCollector implementation

bool supportsFullMaterials() const override { return true; }

void setHighlightFlag(Highlight::Flags flags, bool enabled) override
{
if (flags & Highlight::Faces)
{
_highlightFaces = enabled;
}

if (flags & Highlight::Primitives)
{
_highlightPrimitives = enabled;
}
}

void addRenderable(const ShaderPtr& shader, const OpenGLRenderable& renderable,
const Matrix4& world, const LightSources* lights,
const IRenderEntity* entity) override
{
if (_highlightPrimitives)
_highlightedPrimitiveShader.addRenderable(renderable, world,
lights, entity);

if (_highlightFaces)
_highlightedFaceShader.addRenderable(renderable, world,
lights, entity);

shader->addRenderable(renderable, world, lights, entity);
}
};

}

void CamWnd::Cam_Draw()
{
wxSize glSize = _wxGLWidget->GetSize();
Expand Down Expand Up @@ -680,10 +735,10 @@ void CamWnd::Cam_Draw()
| RENDER_POLYGONSTIPPLE;
}

// Main scene render
{
CamRenderer renderer(allowedRenderFlags, _primitiveHighlightShader,
_faceHighlightShader, _view.getViewer());

// Front end (renderable collection from scene)
CamRenderer renderer(*_primitiveHighlightShader, *_faceHighlightShader);
render::RenderableCollectionWalker::CollectRenderablesInScene(renderer, _view);

// Render any active mousetools
Expand All @@ -692,7 +747,9 @@ void CamWnd::Cam_Draw()
i.second->render(GlobalRenderSystem(), renderer, _view);
}

renderer.render(_camera.modelview, _camera.projection);
// Backend (shader rendering)
GlobalRenderSystem().render(allowedRenderFlags, _camera.modelview,
_camera.projection, _view.getViewer());
}

// greebo: Draw the clipper's points (skipping the depth-test)
Expand Down

0 comments on commit 0c8d652

Please sign in to comment.