Skip to content

Commit

Permalink
#5584: Use the same RenderableWinding structure for brushes in wirefr…
Browse files Browse the repository at this point in the history
…ame rendering
  • Loading branch information
codereader committed Nov 14, 2021
1 parent 478dbe8 commit b49f973
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 21 deletions.
13 changes: 10 additions & 3 deletions radiantcore/brush/BrushNode.cpp
Expand Up @@ -351,6 +351,8 @@ bool BrushNode::intersectsLight(const RendererLight& light) const {

void BrushNode::onPreRender(const VolumeTest& volume)
{
assert(_renderEntity);

// Every intersecting face is asked to run the rendering preparations
// to submit their geometry to the active shader
for (auto& faceInstance : m_faceInstances)
Expand All @@ -359,7 +361,14 @@ void BrushNode::onPreRender(const VolumeTest& volume)

if (face.intersectVolume(volume))
{
face.getWindingSurface().update(face.getFaceShader().getGLShader());
if (volume.fill())
{
face.getWindingSurfaceSolid().update(face.getFaceShader().getGLShader());
}
else
{
face.getWindingSurfaceWireframe().update(_renderEntity->getWireShader());
}
}
}
}
Expand Down Expand Up @@ -538,8 +547,6 @@ void BrushNode::renderSolid(RenderableCollector& collector,
Matrix4::getIdentity(), this, _renderEntity
);
#endif
const_cast<Face&>(face).getWindingSurface().update(face.getFaceShader().getGLShader());

if (highlight)
collector.setHighlightFlag(RenderableCollector::Highlight::Faces, false);
}
Expand Down
51 changes: 35 additions & 16 deletions radiantcore/brush/Face.cpp
Expand Up @@ -36,7 +36,8 @@ Face::Face(Brush& owner) :
_shader(texdef_name_default(), _owner.getBrushNode().getRenderSystem()),
_undoStateSaver(nullptr),
_faceIsVisible(true),
_windingSurface(m_winding)
_windingSurfaceSolid(m_winding),
_windingSurfaceWireframe(m_winding)
{
setupSurfaceShader();

Expand All @@ -60,7 +61,8 @@ Face::Face(
_texdef(projection),
_undoStateSaver(nullptr),
_faceIsVisible(true),
_windingSurface(m_winding)
_windingSurfaceSolid(m_winding),
_windingSurfaceWireframe(m_winding)
{
setupSurfaceShader();
m_plane.initialiseFromPoints(p0, p1, p2);
Expand All @@ -73,7 +75,8 @@ Face::Face(Brush& owner, const Plane3& plane) :
_shader("", _owner.getBrushNode().getRenderSystem()),
_undoStateSaver(nullptr),
_faceIsVisible(true),
_windingSurface(m_winding)
_windingSurfaceSolid(m_winding),
_windingSurfaceWireframe(m_winding)
{
setupSurfaceShader();
m_plane.setPlane(plane);
Expand All @@ -86,7 +89,8 @@ Face::Face(Brush& owner, const Plane3& plane, const Matrix3& textureProjection,
_shader(material, _owner.getBrushNode().getRenderSystem()),
_undoStateSaver(nullptr),
_faceIsVisible(true),
_windingSurface(m_winding)
_windingSurfaceSolid(m_winding),
_windingSurfaceWireframe(m_winding)
{
setupSurfaceShader();
m_plane.setPlane(plane);
Expand All @@ -106,7 +110,8 @@ Face::Face(Brush& owner, const Face& other) :
_texdef(other.getProjection()),
_undoStateSaver(nullptr),
_faceIsVisible(other._faceIsVisible),
_windingSurface(m_winding)
_windingSurfaceSolid(m_winding),
_windingSurfaceWireframe(m_winding)
{
setupSurfaceShader();
planepts_assign(m_move_planepts, other.m_move_planepts);
Expand All @@ -118,7 +123,8 @@ Face::~Face()
_surfaceShaderRealised.disconnect();

// Deallocate the winding surface
_windingSurface.clear();
_windingSurfaceSolid.clear();
_windingSurfaceWireframe.clear();
}

void Face::setupSurfaceShader()
Expand All @@ -145,7 +151,8 @@ Brush& Face::getBrushInternal()

void Face::planeChanged()
{
_windingSurface.queueUpdate();
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();

revertTransform();
_owner.onFacePlaneChanged();
Expand All @@ -162,7 +169,8 @@ void Face::connectUndoSystem(IUndoSystem& undoSystem)

_shader.setInUse(true);

_windingSurface.queueUpdate();
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();
_undoStateSaver = undoSystem.getStateSaver(*this);
}

Expand All @@ -173,7 +181,8 @@ void Face::disconnectUndoSystem(IUndoSystem& undoSystem)
undoSystem.releaseStateSaver(*this);

// Disconnect the renderable winding vertices from the scene
_windingSurface.clear();
_windingSurfaceSolid.clear();
_windingSurfaceWireframe.clear();
_shader.setInUse(false);
}

Expand Down Expand Up @@ -255,7 +264,8 @@ void Face::setRenderSystem(const RenderSystemPtr& renderSystem)

_faceIsVisible = shader && shader->getMaterial()->isVisible();

_windingSurface.clear();
_windingSurfaceSolid.clear();
_windingSurfaceWireframe.clear();
}

void Face::transformTexDefLocked(const Matrix4& transform)
Expand Down Expand Up @@ -340,7 +350,8 @@ void Face::freezeTransform()

void Face::updateWinding()
{
_windingSurface.queueUpdate();
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();
m_winding.updateNormals(m_plane.getPlane().normal());
}

Expand Down Expand Up @@ -390,7 +401,8 @@ void Face::shaderChanged()
const ShaderPtr& shader = getFaceShader().getGLShader();
_faceIsVisible = shader && shader->getMaterial()->isVisible();

_windingSurface.queueUpdate();
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();
planeChanged();
SceneChangeNotify();
}
Expand Down Expand Up @@ -677,9 +689,14 @@ Winding& Face::getWinding() {
return m_winding;
}

render::RenderableWinding& Face::getWindingSurface()
render::RenderableWinding& Face::getWindingSurfaceSolid()
{
return _windingSurface;
return _windingSurfaceSolid;
}

render::RenderableWinding& Face::getWindingSurfaceWireframe()
{
return _windingSurfaceWireframe;
}

const Plane3& Face::plane3() const
Expand Down Expand Up @@ -735,12 +752,14 @@ void Face::onBrushVisibilityChanged(bool visible)
if (!visible)
{
// Disconnect our renderable when the owning brush goes invisible
_windingSurface.clear();
_windingSurfaceSolid.clear();
_windingSurfaceWireframe.clear();
}
else
{
// Update the vertex buffers next time we need to render
_windingSurface.queueUpdate();
_windingSurfaceSolid.queueUpdate();
_windingSurfaceWireframe.queueUpdate();
}
}

Expand Down
6 changes: 4 additions & 2 deletions radiantcore/brush/Face.h
Expand Up @@ -61,7 +61,8 @@ class Face :
// Cached visibility flag, queried during front end rendering
bool _faceIsVisible;

render::RenderableWinding _windingSurface;
render::RenderableWinding _windingSurfaceSolid;
render::RenderableWinding _windingSurfaceWireframe;

public:

Expand Down Expand Up @@ -191,7 +192,8 @@ class Face :
const Winding& getWinding() const;
Winding& getWinding();

render::RenderableWinding& getWindingSurface();
render::RenderableWinding& getWindingSurfaceSolid();
render::RenderableWinding& getWindingSurfaceWireframe();

const Plane3& plane3() const;

Expand Down

0 comments on commit b49f973

Please sign in to comment.