From 4a93b23d83d1dd80bb518067d8920489f72ecbfa Mon Sep 17 00:00:00 2001 From: Sam Gateau Date: Tue, 13 Aug 2019 18:47:57 -0700 Subject: [PATCH] Address the procedural to populate all reflection versions with user uniforms bindings and make EnigneInspector works correctly --- .../src/RenderablePolyLineEntityItem.cpp | 3 --- libraries/gpu/src/gpu/Shader.cpp | 16 +++---------- .../procedural/src/procedural/Procedural.cpp | 24 ++++++++++++++----- .../render-utils/src/RenderForwardTask.h | 4 ++-- libraries/shaders/src/shaders/Shaders.cpp | 6 ++--- libraries/shaders/src/shaders/Shaders.h | 2 ++ .../utilities/lib/jet/qml/TaskPropView.qml | 2 +- .../utilities/lib/prop/PropGroup.qml | 2 +- 8 files changed, 30 insertions(+), 29 deletions(-) diff --git a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp index ca0a924d91..1c3e755c7b 100644 --- a/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderablePolyLineEntityItem.cpp @@ -55,7 +55,6 @@ void PolyLineEntityRenderer::buildPipelines() { state->setCullMode(gpu::State::CullMode::CULL_NONE); state->setDepthTest(true, !key.second, gpu::LESS_EQUAL); - // PrepareStencil::testMaskDrawShape(*state); PrepareStencil::testMask(*state); state->setBlendFunction(true, gpu::State::SRC_ALPHA, gpu::State::BLEND_OP_ADD, gpu::State::INV_SRC_ALPHA, @@ -67,12 +66,10 @@ void PolyLineEntityRenderer::buildPipelines() { ItemKey PolyLineEntityRenderer::getKey() { return ItemKey::Builder::transparentShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); - // return ItemKey::Builder::opaqueShape().withTypeMeta().withTagBits(getTagMask()).withLayer(getHifiRenderLayer()); } ShapeKey PolyLineEntityRenderer::getShapeKey() { auto builder = ShapeKey::Builder().withOwnPipeline().withTranslucent().withoutCullFace(); - //auto builder = ShapeKey::Builder().withOwnPipeline().withoutCullFace(); if (_primitiveMode == PrimitiveMode::LINES) { builder.withWireframe(); } diff --git a/libraries/gpu/src/gpu/Shader.cpp b/libraries/gpu/src/gpu/Shader.cpp index dcdbff56d2..6a1ea53cda 100755 --- a/libraries/gpu/src/gpu/Shader.cpp +++ b/libraries/gpu/src/gpu/Shader.cpp @@ -66,21 +66,11 @@ Shader::Reflection Shader::getReflection(shader::Dialect dialect, shader::Varian Shader::Reflection Shader::getReflection() const { - - // FOr sake of convenience i would like to be able to use a "default" dialect that represents the reflection + // For sake of convenience i would like to be able to use a "default" dialect that represents the reflection // of the source of the shader - // What i really want, is a reflection that is designed for the gpu lib interface but we don;t have that yet (glsl45 is the closest to that) + // What i really want, is a reflection that is designed for the gpu lib interface but we don't have that yet (glsl45 is the closest to that) // Until we have an implementation for this, we will return such default reflection from the one available and platform specific - -#if defined(USE_GLES) - auto defaultDialect = shader::Dialect::glsl310es; -#elif defined(Q_OS_MAC) - // Mac only supports 4.1 - auto defaultDialect = shader::Dialect::glsl410; -#else - auto defaultDialect = shader::Dialect::glsl450; -#endif - return getReflection(defaultDialect, shader::Variant::Mono); + return getReflection(shader::DEFAULT_DIALECT, shader::Variant::Mono); } Shader::~Shader() diff --git a/libraries/procedural/src/procedural/Procedural.cpp b/libraries/procedural/src/procedural/Procedural.cpp index 7d0b7c05ea..ce4fbb2a38 100644 --- a/libraries/procedural/src/procedural/Procedural.cpp +++ b/libraries/procedural/src/procedural/Procedural.cpp @@ -264,12 +264,24 @@ void Procedural::prepare(gpu::Batch& batch, fragmentSource.replacements[PROCEDURAL_VERSION] = "#define PROCEDURAL_V" + std::to_string(_data.version); fragmentSource.replacements[PROCEDURAL_BLOCK] = _shaderSource.toStdString(); - // Set any userdata specified uniforms - int customSlot = procedural::slot::uniform::Custom; - for (const auto& key : _data.uniforms.keys()) { - std::string uniformName = key.toLocal8Bit().data(); - // fragmentSource.reflection.uniforms[uniformName] = customSlot; - ++customSlot; + // Set any userdata specified uniforms (if any) + if (!_data.uniforms.empty()) { + // First grab all the possible dialect/variant/Reflections + std::vector allReflections; + for (auto dialectIt = fragmentSource.dialectSources.begin(); dialectIt != fragmentSource.dialectSources.end(); ++dialectIt) { + for (auto variantIt = (*dialectIt).second.variantSources.begin(); variantIt != (*dialectIt).second.variantSources.end(); ++variantIt) { + allReflections.push_back(&(*variantIt).second.reflection); + } + } + // Then fill in every reflections the new custom bindings + int customSlot = procedural::slot::uniform::Custom; + for (const auto& key : _data.uniforms.keys()) { + std::string uniformName = key.toLocal8Bit().data(); + for (auto reflection : allReflections) { + reflection->uniforms[uniformName] = customSlot; + } + ++customSlot; + } } // Leave this here for debugging diff --git a/libraries/render-utils/src/RenderForwardTask.h b/libraries/render-utils/src/RenderForwardTask.h index d225ffb648..647994d3c0 100755 --- a/libraries/render-utils/src/RenderForwardTask.h +++ b/libraries/render-utils/src/RenderForwardTask.h @@ -42,8 +42,8 @@ public: class PreparePrimaryFramebufferMSAAConfig : public render::Job::Config { Q_OBJECT - Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale) - Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples) + Q_PROPERTY(float resolutionScale WRITE setResolutionScale READ getResolutionScale NOTIFY dirty()) + Q_PROPERTY(int numSamples WRITE setNumSamples READ getNumSamples NOTIFY dirty()) public: float getResolutionScale() const { return resolutionScale; } void setResolutionScale(float scale); diff --git a/libraries/shaders/src/shaders/Shaders.cpp b/libraries/shaders/src/shaders/Shaders.cpp index 02a3c9587e..ef67842f84 100644 --- a/libraries/shaders/src/shaders/Shaders.cpp +++ b/libraries/shaders/src/shaders/Shaders.cpp @@ -32,7 +32,7 @@ namespace shader { #if defined(USE_GLES) -static const Dialect DEFAULT_DIALECT = Dialect::glsl310es; +const Dialect DEFAULT_DIALECT = Dialect::glsl310es; const std::vector& allDialects() { static const std::vector ALL_DIALECTS{ { Dialect::glsl310es } }; @@ -41,7 +41,7 @@ const std::vector& allDialects() { #elif defined(Q_OS_MAC) -static const Dialect DEFAULT_DIALECT = Dialect::glsl410; +const Dialect DEFAULT_DIALECT = Dialect::glsl410; const std::vector& allDialects() { static const std::vector ALL_DIALECTS{ Dialect::glsl410 }; @@ -50,7 +50,7 @@ const std::vector& allDialects() { #else -static const Dialect DEFAULT_DIALECT = Dialect::glsl450; +const Dialect DEFAULT_DIALECT = Dialect::glsl450; const std::vector & allDialects() { static const std::vector ALL_DIALECTS{ { Dialect::glsl450, Dialect::glsl410 } }; diff --git a/libraries/shaders/src/shaders/Shaders.h b/libraries/shaders/src/shaders/Shaders.h index 7eb4241de4..701695c3a8 100644 --- a/libraries/shaders/src/shaders/Shaders.h +++ b/libraries/shaders/src/shaders/Shaders.h @@ -42,6 +42,8 @@ enum class Dialect #endif }; +extern const Dialect DEFAULT_DIALECT; + const std::vector& allDialects(); const std::string& dialectPath(Dialect dialect); diff --git a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml index 04a18f8e2a..69902392a5 100644 --- a/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml +++ b/scripts/developer/utilities/lib/jet/qml/TaskPropView.qml @@ -91,7 +91,7 @@ Prop.PropGroup { // console.log(JSON.stringify(props)); if (showProps) { for (var p in props) { - propsModel.push({"object": rootConfig.getConfig(jobPath), "property":props[p] }) + propsModel.push({"object": rootConfig.getConfig(jobPath), "property":props[p]}) } root.updatePropItems(root.propItemsPanel, propsModel); } diff --git a/scripts/developer/utilities/lib/prop/PropGroup.qml b/scripts/developer/utilities/lib/prop/PropGroup.qml index c6b2c694f6..bfae2798eb 100644 --- a/scripts/developer/utilities/lib/prop/PropGroup.qml +++ b/scripts/developer/utilities/lib/prop/PropGroup.qml @@ -68,7 +68,7 @@ PropFolderPanel { "min": (proItem["min"] !== undefined ? proItem.min : 0.0), "max": (proItem["max"] !== undefined ? proItem.max : 1.0), "integer": (proItem["integral"] !== undefined ? proItem.integral : false), - "readOnly": (proItem["readOnly"] !== undefined ? proItem["readOnly"] : false), + "readOnly": (proItem["readOnly"] !== undefined ? proItem["readOnly"] : true), }) } break; case 'PropEnum': {