Skip to content

Commit

Permalink
Evaluate the editor expression on the fly, not immediately after addi…
Browse files Browse the repository at this point in the history
…ng a layer. This way the editor texture expression will not snap to that layer and can be changed (and react to changes) at runtime
  • Loading branch information
codereader committed Apr 17, 2021
1 parent 15d75c0 commit 1b5111e
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 10 deletions.
38 changes: 35 additions & 3 deletions radiantcore/shaders/CShader.cpp
Expand Up @@ -79,10 +79,24 @@ TexturePtr CShader::getEditorImage()
{
if (!_editorTexture)
{
auto editorTex = _template->getEditorTexture();

if (!editorTex)
{
// If there is no editor expression defined, use the an image from a layer, but no Bump or speculars
for (const auto& layer : _layers)
{
if (layer->getType() != IShaderLayer::BUMP && layer->getType() != IShaderLayer::SPECULAR &&
std::dynamic_pointer_cast<MapExpression>(layer->getMapExpression()))
{
editorTex = std::static_pointer_cast<MapExpression>(layer->getMapExpression());
break;
}
}
}

// Pass the call to the GLTextureManager to realise this image
_editorTexture = GetTextureManager().getBinding(
_template->getEditorTexture()
);
_editorTexture = GetTextureManager().getBinding(editorTex);
}

return _editorTexture;
Expand Down Expand Up @@ -590,9 +604,27 @@ void CShader::subscribeToTemplateChanges()
_templateChanged = _template->sig_TemplateChanged().connect([this]()
{
_sigMaterialModified.emit();

// Check if the editor image needs an update
updateEditorImage();
});
}

void CShader::updateEditorImage()
{
// In case the editor tex is pointing to the fallback "shader not found"
// check if we have some possible replacements
if (!_editorTexture) return;

if (isEditorImageNoTex() || !_template->getEditorTexture())
{
// The editor image is "shader not found", but we might have layers and/or an qer_editorImage defined
// In case we don't have an editor texture expression, remove it from the slot
// we will update it again as soon as it will be requested
_editorTexture.reset();
}
}

void CShader::refreshImageMaps()
{
if (_template->getEditorTexture())
Expand Down
1 change: 1 addition & 0 deletions radiantcore/shaders/CShader.h
Expand Up @@ -162,6 +162,7 @@ class CShader final :
private:
void ensureTemplateCopy();
void subscribeToTemplateChanges();
void updateEditorImage();
};
typedef std::shared_ptr<CShader> CShaderPtr;

Expand Down
7 changes: 0 additions & 7 deletions radiantcore/shaders/ShaderTemplate.cpp
Expand Up @@ -1321,13 +1321,6 @@ void ShaderTemplate::addLayer(const Doom3ShaderLayer::Ptr& layer)
{
// Add the layer
_layers.emplace_back(layer);

// If there is no editor texture yet, use the bindable texture, but no Bump or speculars
if (!_editorTex && layer->getType() != IShaderLayer::BUMP &&
layer->getType() != IShaderLayer::SPECULAR && std::dynamic_pointer_cast<MapExpression>(layer->getMapExpression()))
{
_editorTex = std::static_pointer_cast<MapExpression>(layer->getMapExpression());
}
}

void ShaderTemplate::addLayer(IShaderLayer::Type type, const MapExpressionPtr& mapExpr)
Expand Down

0 comments on commit 1b5111e

Please sign in to comment.