From 02b61b145afb914c6d72e05d506967833e6d08ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fernando=20Garc=C3=ADa=20Li=C3=B1=C3=A1n?= Date: Sat, 26 Oct 2019 01:53:30 +0200 Subject: [PATCH] Compositor: Shaders are looked for in $FG_ROOT/Compositor/Shaders when the compositor is enabled. Fixed Compositor/ always being added to the effect filename. Now it is only added when the base folder is Effects/. --- simgear/scene/material/Effect.cxx | 7 ++++++- simgear/scene/material/makeEffect.cxx | 6 +++++- simgear/scene/viewer/CompositorPass.cxx | 18 +++++++++--------- 3 files changed, 20 insertions(+), 11 deletions(-) diff --git a/simgear/scene/material/Effect.cxx b/simgear/scene/material/Effect.cxx index c2240c05..6c486b0b 100644 --- a/simgear/scene/material/Effect.cxx +++ b/simgear/scene/material/Effect.cxx @@ -918,8 +918,13 @@ void ShaderProgramBuilder::buildAttribute(Effect* effect, Pass* pass, resolvedKey.attributes = prgKey.attributes; BOOST_FOREACH(const ShaderKey& shaderKey, prgKey.shaders) { - const string& shaderName = shaderKey.first; + // FIXME orig: const string& shaderName = shaderKey.first; + string shaderName = shaderKey.first; Shader::Type stype = (Shader::Type)shaderKey.second; + if (getPropertyRoot()->getBoolValue("/sim/version/compositor-support", false) && + shaderName.substr(0, shaderName.find("/")) == "Shaders") { + shaderName = "Compositor/" + shaderName; + } string fileName = SGModelLib::findDataFile(shaderName, options); if (fileName.empty()) { diff --git a/simgear/scene/material/makeEffect.cxx b/simgear/scene/material/makeEffect.cxx index 35591c51..7877378e 100644 --- a/simgear/scene/material/makeEffect.cxx +++ b/simgear/scene/material/makeEffect.cxx @@ -130,8 +130,12 @@ Effect* makeEffect(const string& name, string effectFileName; // Use getPropertyRoot() because the SGReaderWriterOptions might not have a // valid property tree - if (getPropertyRoot()->getBoolValue("/sim/version/compositor-support", false)) + if (getPropertyRoot()->getBoolValue("/sim/version/compositor-support", false) && + name.substr(0, name.find("/")) == "Effects") { + // Temporarily append the Compositor/ directory to every effect that should + // be inside Effects/. effectFileName += "Compositor/"; + } effectFileName += name; effectFileName += ".eff"; string absFileName diff --git a/simgear/scene/viewer/CompositorPass.cxx b/simgear/scene/viewer/CompositorPass.cxx index 7e82765d..d2d7a6db 100644 --- a/simgear/scene/viewer/CompositorPass.cxx +++ b/simgear/scene/viewer/CompositorPass.cxx @@ -112,15 +112,15 @@ PassBuilder::build(Compositor *compositor, const SGPropertyNode *root, camera->setClearStencil(root->getIntValue("clear-stencil", 0)); GLbitfield clear_mask = 0; - if (root->getBoolValue("clear-color-bit", true)) - clear_mask |= GL_COLOR_BUFFER_BIT; - if (root->getBoolValue("clear-accum-bit", false)) - clear_mask |= GL_ACCUM_BUFFER_BIT; - if (root->getBoolValue("clear-depth-bit", true)) - clear_mask |= GL_DEPTH_BUFFER_BIT; - if (root->getBoolValue("clear-stencil-bit", false)) - clear_mask |= GL_STENCIL_BUFFER_BIT; - // Default clear mask is GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT, as in OSG + std::stringstream ss; + std::string bit; + // Default clear mask as in OSG + ss << root->getStringValue("clear-mask", "color depth"); + while (ss >> bit) { + if (bit == "color") clear_mask |= GL_COLOR_BUFFER_BIT; + else if (bit == "depth") clear_mask |= GL_DEPTH_BUFFER_BIT; + else if (bit == "stencil") clear_mask |= GL_STENCIL_BUFFER_BIT; + } camera->setClearMask(clear_mask); PropertyList p_bindings = root->getChildren("binding");