Skip to content

Commit

Permalink
#5912: Notify the parent brush if any face needs a renderable update,…
Browse files Browse the repository at this point in the history
… this way the BrushNode::onPreRender method is much faster for untouched brushes.
  • Loading branch information
codereader committed Mar 4, 2022
1 parent 6ba8fa9 commit 5e42809
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 11 deletions.
5 changes: 5 additions & 0 deletions radiantcore/brush/Brush.cpp
Expand Up @@ -196,6 +196,11 @@ void Brush::updateFaceVisibility()
_owner.updateFaceVisibility();
}

void Brush::onFaceNeedsRenderableUpdate()
{
_owner.onFaceNeedsRenderableUpdate();
}

Brush::DetailFlag Brush::getDetailFlag() const
{
return _detailFlag;
Expand Down
1 change: 1 addition & 0 deletions radiantcore/brush/Brush.h
Expand Up @@ -181,6 +181,7 @@ class Brush :
void onFaceShaderChanged();
void onFaceConnectivityChanged();
void onFaceEvaluateTransform();
void onFaceNeedsRenderableUpdate();

// Sets the shader of all faces to the given name
void setShader(const std::string& newShader) override;
Expand Down
36 changes: 25 additions & 11 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -17,7 +17,8 @@ BrushNode::BrushNode() :
m_brush(*this),
_renderableComponentsNeedUpdate(true),
_untransformedOriginChanged(true),
_renderableVertices(m_brush, _selectedPoints)
_renderableVertices(m_brush, _selectedPoints),
_facesNeedRenderableUpdate(true)
{
m_brush.attach(*this); // BrushObserver

Expand All @@ -41,7 +42,8 @@ BrushNode::BrushNode(const BrushNode& other) :
m_brush(*this, other.m_brush),
_renderableComponentsNeedUpdate(true),
_untransformedOriginChanged(true),
_renderableVertices(m_brush, _selectedPoints)
_renderableVertices(m_brush, _selectedPoints),
_facesNeedRenderableUpdate(true)
{
m_brush.attach(*this); // BrushObserver
}
Expand Down Expand Up @@ -340,27 +342,39 @@ void BrushNode::DEBUG_verify() {
ASSERT_MESSAGE(m_faceInstances.size() == m_brush.DEBUG_size(), "FATAL: mismatch");
}

void BrushNode::onFaceNeedsRenderableUpdate()
{
_facesNeedRenderableUpdate = true;
}

void BrushNode::onPreRender(const VolumeTest& volume)
{
m_brush.evaluateBRep();

assert(_renderEntity);

auto brushIsSelected = isSelected();
auto isCameraView = volume.fill();

// Every face is asked to run the rendering preparations
// to link/unlink their geometry to/from the active shader
for (auto& faceInstance : m_faceInstances)
// Run the face updates only if requested
if (_facesNeedRenderableUpdate)
{
auto& face = faceInstance.getFace();
_facesNeedRenderableUpdate = false;

// Always update the solid renderables, even in ortho rendering, since we need the solid renderable for highlighting
face.getWindingSurfaceSolid().update(face.getFaceShader().getGLShader(), *_renderEntity);
auto isCameraView = volume.fill();

if (!isCameraView)
// Every face is asked to run the rendering preparations
// to link/unlink their geometry to/from the active shader
for (auto& faceInstance : m_faceInstances)
{
face.getWindingSurfaceWireframe().update(_renderEntity->getWireShader(), *_renderEntity);
auto& face = faceInstance.getFace();

// Always update the solid renderables, even in ortho rendering, since we need the solid renderable for highlighting
face.getWindingSurfaceSolid().update(face.getFaceShader().getGLShader(), *_renderEntity);

if (!isCameraView)
{
face.getWindingSurfaceWireframe().update(_renderEntity->getWireShader(), *_renderEntity);
}
}
}

Expand Down
3 changes: 3 additions & 0 deletions radiantcore/brush/BrushNode.h
Expand Up @@ -60,6 +60,8 @@ class BrushNode :

brush::RenderableBrushVertices _renderableVertices;

bool _facesNeedRenderableUpdate;

public:
// Constructor
BrushNode();
Expand Down Expand Up @@ -138,6 +140,7 @@ class BrushNode :
void renderHighlights(IRenderableCollector& collector, const VolumeTest& volume) override;
void setRenderSystem(const RenderSystemPtr& renderSystem) override;
std::size_t getHighlightFlags() override;
void onFaceNeedsRenderableUpdate();

void evaluateTransform();

Expand Down
2 changes: 2 additions & 0 deletions radiantcore/brush/Face.cpp
Expand Up @@ -355,6 +355,8 @@ void Face::updateRenderables()
{
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();

_owner.onFaceNeedsRenderableUpdate();
}

void Face::updateWinding()
Expand Down

0 comments on commit 5e42809

Please sign in to comment.