diff --git a/include/irenderable.h b/include/irenderable.h index 37415a023d..032f9e06c1 100644 --- a/include/irenderable.h +++ b/include/irenderable.h @@ -32,35 +32,9 @@ class RenderableCollector public: virtual ~RenderableCollector() {} - /** - * Submit an OpenGLRenderable object for rendering using the given shader. - * - * \param shader - * The Shader object this Renderable will be attached to. - * - * \param renderable - * The renderable object to submit. - * - * \param world - * The local to world transform that should be applied to this object when - * it is rendered. - * - * \param lights - * Optional LightSources containing lights illuminating this Renderable. - * - * \param entity - * Optional IRenderEntity exposing parameters which affect the rendering of - * this Renderable. - */ - virtual void addRenderable(Shader& shader, - const OpenGLRenderable& renderable, - const Matrix4& world, - const LightSources* lights = nullptr, - const IRenderEntity* entity = nullptr) = 0; - /** * \brief - * Submit a renderable object to be illuminated by scene lights. + * Submit a renderable object * * This method allows renderable geometry to be submitted under the control * of a LitObject which will determine whether and how the renderable is @@ -68,22 +42,36 @@ class RenderableCollector * will be considered for lighting by the lights which are submitted to the * same RenderableCollector using addLight(). * - * Most of the parameters have identical meanings to those in - * addRenderable(). + * Objects may be submitted without a LitObject if they are not affected by + * scene lights. * - * \param litObject - * A LitObject determining lighting interactions for this renderable. This - * may or may not be the same actual object as the OpenGLRenderable, - * depending on how the object tree is set up. If a single LitObject - * contains multiple renderables, a separate call to this method must be - * made for each renderable (with the same litObject parameter). + * \param shader + * The Shader object this Renderable will be attached to. + * + * \param renderable + * The renderable object to submit. * + * \param localToWorld + * The local to world transform that should be applied to this object when + * it is rendered. + * + * \param entity + * Optional IRenderEntity exposing parameters which affect the rendering of + * this Renderable. + * + * \param litObject + * Optional LitObject determining lighting interactions for this + * renderable. This may or may not be the same actual object as the + * OpenGLRenderable, depending on how the object class hierarchy is set up. + * If a single LitObject contains multiple renderables, a separate call to + * this method must be made for each renderable (with the same litObject + * parameter). */ - virtual void addLitRenderable(Shader& shader, - const OpenGLRenderable& renderable, - const Matrix4& localToWorld, - const LitObject& litObject, - const IRenderEntity* entity = nullptr) = 0; + virtual void addRenderable(Shader& shader, + const OpenGLRenderable& renderable, + const Matrix4& localToWorld, + const LitObject* litObject = nullptr, + const IRenderEntity* entity = nullptr) = 0; /** * \brief diff --git a/libs/render/CamRenderer.h b/libs/render/CamRenderer.h index 14964eaebe..9ff8de2224 100644 --- a/libs/render/CamRenderer.h +++ b/libs/render/CamRenderer.h @@ -29,34 +29,13 @@ class CamRenderer: public RenderableCollector // All lights we have received from the scene std::list _sceneLights; - // Legacy lit renderable which provided its own LightSources to - // addRenderable() - struct LegacyLitRenderable - { - const OpenGLRenderable& renderable; - const LightSources* lights = nullptr; - Matrix4 local2World; - const IRenderEntity* entity = nullptr; - - LegacyLitRenderable(const OpenGLRenderable& r, const LightSources* l, - const Matrix4& l2w, const IRenderEntity* e) - : renderable(r), lights(l), local2World(l2w), entity(e) - {} - }; - using LegacyLitRenderables = std::vector; - - // Legacy renderables with their own light lists. No processing needed; - // just store them until it's time to submit to shaders. - using LegacyRenderablesByShader = std::map; - LegacyRenderablesByShader _legacyRenderables; - - // Lit renderable provided via addLitRenderable(), for which we construct - // the light list with lights received via addLight(). + // 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; + const LitObject* litObject = nullptr; Matrix4 local2World; const IRenderEntity* entity = nullptr; @@ -83,7 +62,7 @@ class CamRenderer: public RenderableCollector // the scene for (const RendererLight* l: _sceneLights) { - if (j->litObject.intersectsLight(*l)) + if (j->litObject && j->litObject->intersectsLight(*l)) j->lights.addLight(*l); } } @@ -107,23 +86,6 @@ class CamRenderer: public RenderableCollector // Calculate intersections between lights and renderables we have received calculateLightIntersections(); - // Render legacy renderables with submitted light lists - for (auto i = _legacyRenderables.begin(); - i != _legacyRenderables.end(); - ++i) - { - // Iterate over the list of renderables for this shader, submitting - // each one - Shader* shader = i->first; - wxASSERT(shader); - for (auto j = i->second.begin(); j != i->second.end(); ++j) - { - const LegacyLitRenderable& lr = *j; - shader->addRenderable(lr.renderable, lr.local2World, - lr.lights, lr.entity); - } - } - // Render objects with calculated light lists for (auto i = _litRenderables.begin(); i != _litRenderables.end(); ++i) { @@ -178,47 +140,11 @@ class CamRenderer: public RenderableCollector ++_totalLights; } - void addRenderable(Shader& shader, const OpenGLRenderable& renderable, - const Matrix4& world, const LightSources* lights, - const IRenderEntity* entity) override - { - if (_highlightPrimitives && _highlightedPrimitiveShader) - _highlightedPrimitiveShader->addRenderable(renderable, world, - lights, entity); - - if (_highlightFaces && _highlightedFaceShader) - _highlightedFaceShader->addRenderable(renderable, world, - lights, entity); - - // Construct an entry for this shader in the map if it is the first - // time we've seen it - auto iter = _legacyRenderables.find(&shader); - if (iter == _legacyRenderables.end()) - { - // Add an entry for this shader, and pre-allocate some space in the - // vector to avoid too many expansions during scenegraph traversal. - LegacyLitRenderables emptyList; - emptyList.reserve(1024); - - auto result = _legacyRenderables.insert( - std::make_pair(&shader, std::move(emptyList)) - ); - wxASSERT(result.second); - iter = result.first; - } - wxASSERT(iter != _legacyRenderables.end()); - - // Add the renderable and its lights to the list of lit renderables for - // this shader - wxASSERT(iter->first == &shader); - iter->second.emplace_back(renderable, lights, world, entity); - } - - void addLitRenderable(Shader& shader, - const OpenGLRenderable& renderable, - const Matrix4& localToWorld, - const LitObject& litObject, - const IRenderEntity* entity = nullptr) override + void addRenderable(Shader& shader, + const OpenGLRenderable& renderable, + const Matrix4& localToWorld, + const LitObject* litObject = nullptr, + const IRenderEntity* entity = nullptr) override { if (_highlightPrimitives && _highlightedPrimitiveShader) _highlightedPrimitiveShader->addRenderable(renderable, localToWorld, diff --git a/radiant/xyview/XYRenderer.h b/radiant/xyview/XYRenderer.h index 0182fb2750..b7a341b7ca 100644 --- a/radiant/xyview/XYRenderer.h +++ b/radiant/xyview/XYRenderer.h @@ -55,28 +55,20 @@ class XYRenderer: public RenderableCollector void addRenderable(Shader& shader, const OpenGLRenderable& renderable, - const Matrix4& world, const LightSources*, - const IRenderEntity* entity) override + const Matrix4& localToWorld, + const LitObject* /* litObject */, + const IRenderEntity* entity = nullptr) override { if (_state.highlightPrimitives) { if (_state.highlightAsGroupMember) - _selectedShaderGroup->addRenderable(renderable, world, + _selectedShaderGroup->addRenderable(renderable, localToWorld, nullptr, entity); else - _selectedShader->addRenderable(renderable, world, nullptr, entity); + _selectedShader->addRenderable(renderable, localToWorld, nullptr, entity); } - shader.addRenderable(renderable, world, nullptr, entity); - } - - void addLitRenderable(Shader& shader, - const OpenGLRenderable& renderable, - const Matrix4& localToWorld, - const LitObject& /* litObject */, - const IRenderEntity* entity = nullptr) override - { - addRenderable(shader, renderable, localToWorld, nullptr, entity); + shader.addRenderable(renderable, localToWorld, nullptr, entity); } void render(const Matrix4& modelview, const Matrix4& projection) diff --git a/radiantcore/brush/BrushNode.cpp b/radiantcore/brush/BrushNode.cpp index 48050b516c..99cee19c14 100644 --- a/radiantcore/brush/BrushNode.cpp +++ b/radiantcore/brush/BrushNode.cpp @@ -436,10 +436,10 @@ void BrushNode::renderSolid(RenderableCollector& collector, if (highlight) collector.setHighlightFlag(RenderableCollector::Highlight::Faces, true); - // greebo: BrushNodes have always an identity l2w, don't do any transforms - collector.addLitRenderable( + // greebo: BrushNodes have always an identity l2w, don't do any transforms + collector.addRenderable( *face.getFaceShader().getGLShader(), face.getWinding(), - Matrix4::getIdentity(), *this, _renderEntity + Matrix4::getIdentity(), this, _renderEntity ); if (highlight) diff --git a/radiantcore/model/md5/MD5ModelNode.cpp b/radiantcore/model/md5/MD5ModelNode.cpp index 61729d9470..be8440898d 100644 --- a/radiantcore/model/md5/MD5ModelNode.cpp +++ b/radiantcore/model/md5/MD5ModelNode.cpp @@ -112,10 +112,10 @@ void MD5ModelNode::render(RenderableCollector& collector, const VolumeTest& volu if (surfaceShader->isVisible()) { assert(i->shader); // shader must be captured at this point - collector.addLitRenderable( + collector.addRenderable( collector.supportsFullMaterials() ? *i->shader : *entity.getWireShader(), - *i->surface, localToWorld, *this, &entity + *i->surface, localToWorld, this, &entity ); } } diff --git a/radiantcore/model/picomodel/StaticModel.cpp b/radiantcore/model/picomodel/StaticModel.cpp index bf5c321681..5f11818cd9 100644 --- a/radiantcore/model/picomodel/StaticModel.cpp +++ b/radiantcore/model/picomodel/StaticModel.cpp @@ -111,8 +111,8 @@ void StaticModel::renderSolid(RenderableCollector& rend, foreachVisibleSurface([&](const Surface& s) { // Submit the ordinary shader for material-based rendering - rend.addLitRenderable(*s.shader, *s.surface, localToWorld, - litObject, &entity); + rend.addRenderable(*s.shader, *s.surface, localToWorld, + &litObject, &entity); }); } diff --git a/radiantcore/patch/PatchNode.cpp b/radiantcore/patch/PatchNode.cpp index 406eb77327..e051f234aa 100644 --- a/radiantcore/patch/PatchNode.cpp +++ b/radiantcore/patch/PatchNode.cpp @@ -277,9 +277,9 @@ void PatchNode::renderSolid(RenderableCollector& collector, const VolumeTest& vo assert(_renderEntity); // patches rendered without parent - no way! // Render the patch itself - collector.addLitRenderable( + collector.addRenderable( *m_patch._shader.getGLShader(), m_patch._solidRenderable, - localToWorld(), *this, _renderEntity + localToWorld(), this, _renderEntity ); #if DEBUG_PATCH_NTB_VECTORS