Skip to content

Commit

Permalink
#5893: Fix NullModel rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
codereader committed Jan 26, 2022
1 parent 25e7ecd commit 21c10ae
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
13 changes: 11 additions & 2 deletions libs/render/RenderableSurface.h
Expand Up @@ -39,22 +39,30 @@ class RenderableSurface :

virtual ~RenderableSurface()
{
clear();
detach();
}

// (Non-virtual) update method handling any possible shader change
// The surface is withdrawn from the given shader if it turns out
// to be different from the last update.
void attachToShader(const ShaderPtr& shader, IRenderEntity* entity)
{
if (entity && _entity != entity)
{
// Detach if the render entity is changin
detach();
}

if (_shaders.count(shader) > 0)
{
return; // already attached
}

_entity = entity;
_shaders[shader] = shader->addSurface(*this, entity);
}

#if 0 // seems to be unneeded
void detachFromShader(const ShaderPtr& shader)
{
auto handle = _shaders.find(shader);
Expand All @@ -64,6 +72,7 @@ class RenderableSurface :
detachFromShader(handle);
}
}
#endif

// Notifies all the attached shaders that the surface geometry changed
void queueUpdate()
Expand All @@ -75,7 +84,7 @@ class RenderableSurface :
}

// Removes the surface from all shaders
void clear()
void detach()
{
while (!_shaders.empty())
{
Expand Down
15 changes: 4 additions & 11 deletions radiantcore/model/NullModelNode.cpp
Expand Up @@ -101,22 +101,15 @@ void NullModelNode::attachToShaders()

if (!renderSystem) return;

if (_fillShader)
{
_fillShader->addSurface(_renderableBox, _renderEntity);
}

if (_wireShader)
{
_wireShader->addSurface(_renderableBox, _renderEntity);
}
_renderableBox.attachToShader(_fillShader, _renderEntity);
_renderableBox.attachToShader(_wireShader, _renderEntity);

_attachedToShaders = true;
}

void NullModelNode::detachFromShaders()
{
_renderableBox.clear();
_renderableBox.detach();
_attachedToShaders = false;
}

Expand Down Expand Up @@ -144,7 +137,7 @@ void NullModelNode::onRemoveFromScene(scene::IMapRootNode& root)
{
Node::onRemoveFromScene(root);

_renderableBox.clear();
_renderableBox.detach();
}

void NullModelNode::onVisibilityChanged(bool isVisibleNow)
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/StaticModelNode.cpp
Expand Up @@ -127,7 +127,7 @@ void StaticModelNode::detachFromShaders()
// the node will re-attach in the next pre-render phase
for (auto& surface : _renderableSurfaces)
{
surface->clear();
surface->detach();
}

_attachedToShaders = false;
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/model/md5/MD5ModelNode.cpp
Expand Up @@ -143,7 +143,7 @@ void MD5ModelNode::detachFromShaders()
// the node will re-attach in the next pre-render phase
for (auto& surface : _renderableSurfaces)
{
surface->clear();
surface->detach();
}

_attachedToShaders = false;
Expand Down

0 comments on commit 21c10ae

Please sign in to comment.