Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
#5584: Move some common code to a RenderableGeometry base class
- Loading branch information
1 parent
593ccd1
commit 1afccd0
Showing
5 changed files
with
80 additions
and
55 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
#pragma once | ||
|
||
#include "igeometryrenderer.h" | ||
#include "irender.h" | ||
|
||
namespace render | ||
{ | ||
|
||
/** | ||
* Geometry base type, taking care of adding/removing/updating | ||
* indexed vertex data to an IGeometryRenderer instance. | ||
* | ||
* It implements the OpenGLRenderable interface which will instruct | ||
* the shader to render just the geometry batch managed by this object. | ||
* This is used to render highlights (such as selection overlays). | ||
*/ | ||
class RenderableGeometry : | ||
public OpenGLRenderable | ||
{ | ||
protected: | ||
ShaderPtr _shader; | ||
IGeometryRenderer::Slot _surfaceSlot; | ||
|
||
protected: | ||
RenderableGeometry() : | ||
_surfaceSlot(IGeometryRenderer::InvalidSlot) | ||
{} | ||
|
||
public: | ||
// Removes any geometry attached to a shader | ||
virtual void clear() | ||
{ | ||
if (_shader && _surfaceSlot != IGeometryRenderer::InvalidSlot) | ||
{ | ||
_shader->removeGeometry(_surfaceSlot); | ||
} | ||
|
||
_shader.reset(); | ||
_surfaceSlot = IGeometryRenderer::InvalidSlot; | ||
} | ||
|
||
virtual void render(const RenderInfo& info) const override | ||
{ | ||
if (_surfaceSlot != IGeometryRenderer::InvalidSlot && _shader) | ||
{ | ||
_shader->renderGeometry(_surfaceSlot); | ||
} | ||
} | ||
|
||
protected: | ||
virtual void addOrUpdateGeometry(const ShaderPtr& shader, GeometryType type, | ||
const std::vector<ArbitraryMeshVertex>& vertices, | ||
const std::vector<unsigned int>& indices) | ||
{ | ||
if (_surfaceSlot == IGeometryRenderer::InvalidSlot) | ||
{ | ||
_surfaceSlot = shader->addGeometry(type, vertices, indices); | ||
} | ||
else | ||
{ | ||
shader->updateGeometry(_surfaceSlot, vertices, indices); | ||
} | ||
} | ||
}; | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters