Skip to content

Commit

Permalink
#5941: StaticModel now offers a signal_ShadersChanged() signal to not…
Browse files Browse the repository at this point in the history
…ify the owning StaticModelNode about any skin change.

This will reset the shader registration of the node, the next time it is rendered it will attach itself to the correct set of shaders.
  • Loading branch information
codereader committed Apr 17, 2022
1 parent f9ae2b0 commit e1ffa55
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 7 deletions.
7 changes: 7 additions & 0 deletions radiantcore/model/StaticModel.cpp
Expand Up @@ -175,6 +175,13 @@ void StaticModel::captureShaders()
s.shader.reset();
}
}

_sigShadersChanged.emit();
}

sigc::signal<void>& StaticModel::signal_ShadersChanged()
{
return _sigShadersChanged;
}

// Update the list of active materials
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/model/StaticModel.h
Expand Up @@ -89,6 +89,8 @@ class StaticModel :
// Undoable stuff
IUndoStateSaver* _undoStateSaver;

sigc::signal<void> _sigShadersChanged;

private:

// Update the list of materials by querying each surface for its current
Expand Down Expand Up @@ -122,6 +124,9 @@ class StaticModel :

void setRenderSystem(const RenderSystemPtr& renderSystem);

// A signal that is emitted after the captured shaders have been changed (or cleared)
sigc::signal<void>& signal_ShadersChanged();

/**
* Return the number of surfaces in this model.
*/
Expand Down
20 changes: 13 additions & 7 deletions radiantcore/model/StaticModelNode.cpp
Expand Up @@ -19,6 +19,8 @@ StaticModelNode::StaticModelNode(const StaticModelPtr& picoModel) :
_name(picoModel->getFilename()),
_attachedToShaders(false)
{
_model->signal_ShadersChanged().connect(sigc::mem_fun(*this, &StaticModelNode::onModelShadersChanged));

// Update the skin
skinChanged("");
}
Expand Down Expand Up @@ -124,10 +126,8 @@ void StaticModelNode::setRenderSystem(const RenderSystemPtr& renderSystem)
Node::setRenderSystem(renderSystem);

_renderSystem = renderSystem;

// Detach renderables on render system change
detachFromShaders();

// This will trigger onModelShadersChanged() to refresh the renderables
_model->setRenderSystem(renderSystem);
}

Expand Down Expand Up @@ -177,6 +177,13 @@ void StaticModelNode::queueRenderableUpdate()
}
}

void StaticModelNode::onModelShadersChanged()
{
// Detach renderables on model shader change,
// they will be refreshed next time things are rendered
detachFromShaders();
}

// Traceable implementation
bool StaticModelNode::getIntersection(const Ray& ray, Vector3& intersection)
{
Expand All @@ -201,11 +208,10 @@ void StaticModelNode::skinChanged(const std::string& newSkinName)

// greebo: Acquire the ModelSkin reference from the SkinCache
// Note: This always returns a valid reference
ModelSkin& skin = GlobalModelSkinCache().capture(_skin);
_model->applySkin(skin);
auto& skin = GlobalModelSkinCache().capture(_skin);

// Detach from existing shaders, re-acquire them in onPreRender
detachFromShaders();
// Applying the skin might trigger onModelShadersChanged()
_model->applySkin(skin);

// Refresh the scene (TODO: get rid of that)
GlobalSceneGraph().sceneChanged();
Expand Down
1 change: 1 addition & 0 deletions radiantcore/model/StaticModelNode.h
Expand Up @@ -105,6 +105,7 @@ class StaticModelNode final :
void attachToShaders();
void detachFromShaders();
void queueRenderableUpdate();
void onModelShadersChanged();
};

} // namespace model

0 comments on commit e1ffa55

Please sign in to comment.