From 0a2f37f9a08cac291e0c687694b072cc66e69d65 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 18 Jun 2019 15:36:32 -0700 Subject: [PATCH 1/2] Q_OBJECT and template classes don't mix --- libraries/shared/src/Preferences.h | 117 ++++++++++++++++++++--------- 1 file changed, 81 insertions(+), 36 deletions(-) diff --git a/libraries/shared/src/Preferences.h b/libraries/shared/src/Preferences.h index 9f84d9c8b7..9147117792 100644 --- a/libraries/shared/src/Preferences.h +++ b/libraries/shared/src/Preferences.h @@ -115,48 +115,39 @@ protected: const Lambda _triggerHandler; }; - -template -class TypedPreference : public Preference { -public: - using Getter = std::function; - using Setter = std::function; - - TypedPreference(const QString& category, const QString& name, Getter getter, Setter setter) - : Preference(category, name), _getter(getter), _setter(setter) { } - - T getValue() const { return _value; } - void setValue(const T& value) { if (_value != value) { _value = value; emitValueChanged(); } } - void load() override { _value = _getter(); } - void save() const override { - T oldValue = _getter(); - if (_value != oldValue) { - _setter(_value); - } - } - -protected: - T _value; - const Getter _getter; - const Setter _setter; -}; - -class BoolPreference : public TypedPreference { +class BoolPreference : public Preference { Q_OBJECT Q_PROPERTY(bool value READ getValue WRITE setValue NOTIFY valueChanged) public: + using Getter = std::function; + using Setter = std::function; + BoolPreference(const QString& category, const QString& name, Getter getter, Setter setter) - : TypedPreference(category, name, getter, setter) { } + : Preference(category, name), _getter(getter), _setter(setter) { } + + bool getValue() const { return _value; } + void setValue(const bool& value) { if (_value != value) { _value = value; emitValueChanged(); } } + void load() override { _value = _getter(); } + void save() const override { + bool oldValue = _getter(); + if (_value != oldValue) { + _setter(_value); + } + } signals: void valueChanged(); protected: + bool _value; + const Getter _getter; + const Setter _setter; + void emitValueChanged() override { emit valueChanged(); } }; -class FloatPreference : public TypedPreference { +class FloatPreference : public Preference { Q_OBJECT Q_PROPERTY(float value READ getValue WRITE setValue NOTIFY valueChanged) Q_PROPERTY(float min READ getMin CONSTANT) @@ -165,8 +156,21 @@ class FloatPreference : public TypedPreference { Q_PROPERTY(float decimals READ getDecimals CONSTANT) public: + using Getter = std::function; + using Setter = std::function; + FloatPreference(const QString& category, const QString& name, Getter getter, Setter setter) - : TypedPreference(category, name, getter, setter) { } + : Preference(category, name), _getter(getter), _setter(setter) { } + + float getValue() const { return _value; } + void setValue(const float& value) { if (_value != value) { _value = value; emitValueChanged(); } } + void load() override { _value = _getter(); } + void save() const override { + float oldValue = _getter(); + if (_value != oldValue) { + _setter(_value); + } + } float getMin() const { return _min; } void setMin(float min) { _min = min; }; @@ -186,14 +190,17 @@ signals: protected: void emitValueChanged() override { emit valueChanged(); } + float _value; + const Getter _getter; + const Setter _setter; + float _decimals { 0 }; float _min { 0 }; float _max { 1 }; float _step { 0.1f }; }; - -class IntPreference : public TypedPreference { +class IntPreference : public Preference { Q_OBJECT Q_PROPERTY(float value READ getValue WRITE setValue NOTIFY valueChanged) Q_PROPERTY(float min READ getMin CONSTANT) @@ -202,8 +209,21 @@ class IntPreference : public TypedPreference { Q_PROPERTY(int decimals READ getDecimals CONSTANT) public: + using Getter = std::function; + using Setter = std::function; + IntPreference(const QString& category, const QString& name, Getter getter, Setter setter) - : TypedPreference(category, name, getter, setter) { } + : Preference(category, name), _getter(getter), _setter(setter) { } + + int getValue() const { return _value; } + void setValue(const int& value) { if (_value != value) { _value = value; emitValueChanged(); } } + void load() override { _value = _getter(); } + void save() const override { + int oldValue = _getter(); + if (_value != oldValue) { + _setter(_value); + } + } float getMin() const { return _min; } void setMin(float min) { _min = min; }; @@ -221,6 +241,10 @@ signals: void valueChanged(); protected: + int _value; + const Getter _getter; + const Setter _setter; + void emitValueChanged() override { emit valueChanged(); } int _min { std::numeric_limits::min() }; @@ -229,19 +253,37 @@ protected: int _decimals { 0 }; }; -class StringPreference : public TypedPreference { +class StringPreference : public Preference { Q_OBJECT Q_PROPERTY(QString value READ getValue WRITE setValue NOTIFY valueChanged) public: + using Getter = std::function; + using Setter = std::function; + StringPreference(const QString& category, const QString& name, Getter getter, Setter setter) - : TypedPreference(category, name, getter, setter) { } + : Preference(category, name), _getter(getter), _setter(setter) { } + + + QString getValue() const { return _value; } + void setValue(const QString& value) { if (_value != value) { _value = value; emitValueChanged(); } } + void load() override { _value = _getter(); } + void save() const override { + QString oldValue = _getter(); + if (_value != oldValue) { + _setter(_value); + } + } signals: void valueChanged(); protected: void emitValueChanged() override { emit valueChanged(); } + + QString _value; + const Getter _getter; + const Setter _setter; }; class SliderPreference : public FloatPreference { @@ -303,7 +345,7 @@ public: ComboBoxPreference(const QString& category, const QString& name, Getter getter, Setter setter) : EditPreference(category, name, getter, setter) { } Type getType() override { return ComboBox; } - + const QStringList& getItems() { return _items; } void setItems(const QStringList& items) { _items = items; } @@ -342,6 +384,9 @@ class CheckPreference : public BoolPreference { Q_OBJECT Q_PROPERTY(bool indented READ getIndented CONSTANT) public: + using Getter = std::function; + using Setter = std::function; + CheckPreference(const QString& category, const QString& name, Getter getter, Setter setter) : BoolPreference(category, name, getter, setter) { } Type getType() override { return Checkbox; } From 3ff81607ab36bed17f29ae4ffeb7685d7f03c835 Mon Sep 17 00:00:00 2001 From: SamGondelman Date: Tue, 18 Jun 2019 17:17:21 -0700 Subject: [PATCH 2/2] fix deferred rendering on macbook air --- .../render-utils/src/DeferredBufferWrite.slh | 7 ++- .../src/DeferredLightingEffect.cpp | 45 ++++--------------- .../render-utils/src/DeferredLightingEffect.h | 13 ------ libraries/render-utils/src/deferred_light.slv | 4 +- 4 files changed, 14 insertions(+), 55 deletions(-) diff --git a/libraries/render-utils/src/DeferredBufferWrite.slh b/libraries/render-utils/src/DeferredBufferWrite.slh index fc9310a520..de4581d66e 100644 --- a/libraries/render-utils/src/DeferredBufferWrite.slh +++ b/libraries/render-utils/src/DeferredBufferWrite.slh @@ -37,7 +37,6 @@ void packDeferredFragment(vec3 normal, float alpha, vec3 albedo, float roughness _fragColor0 = vec4(albedo, mix(packShadedMetallic(metallic), packScatteringMetallic(metallic), check)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor2 = vec4(mix(emissive, vec3(scattering), check), occlusion); - _fragColor3 = vec4(isEmissiveEnabled() * emissive, 1.0); } @@ -49,7 +48,6 @@ void packDeferredFragmentLightmap(vec3 normal, float alpha, vec3 albedo, float r _fragColor0 = vec4(albedo, packLightmappedMetallic(metallic)); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); _fragColor2 = vec4(isLightmapEnabled() * lightmap, 1.0); - _fragColor3 = vec4(isLightmapEnabled() * lightmap * albedo, 1.0); } @@ -59,7 +57,7 @@ void packDeferredFragmentUnlit(vec3 normal, float alpha, vec3 color) { } _fragColor0 = vec4(color, packUnlit()); _fragColor1 = vec4(packNormal(normal), 1.0); - // _fragColor2 = vec4(vec3(0.0), 1.0); + _fragColor2 = vec4(vec3(0.0), 1.0); _fragColor3 = vec4(color, 1.0); } @@ -69,7 +67,8 @@ void packDeferredFragmentTranslucent(vec3 normal, float alpha, vec3 albedo, floa } _fragColor0 = vec4(albedo.rgb, alpha); _fragColor1 = vec4(packNormal(normal), clamp(roughness, 0.0, 1.0)); - + _fragColor2 = vec4(vec3(0.0), 1.0); + _fragColor3 = vec4(0.0); } <@endif@> diff --git a/libraries/render-utils/src/DeferredLightingEffect.cpp b/libraries/render-utils/src/DeferredLightingEffect.cpp index 82b7f3102a..51729fc5cf 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.cpp +++ b/libraries/render-utils/src/DeferredLightingEffect.cpp @@ -41,33 +41,17 @@ namespace gr { using namespace render; -struct LightLocations { - bool shadowTransform{ false }; - void initialize(const gpu::ShaderPointer& program) { - shadowTransform = program->getReflection().validUniformBuffer(ru::Buffer::ShadowParams); - } -}; - -static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& program, LightLocationsPtr& locations); +static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& program); void DeferredLightingEffect::init() { - _directionalAmbientSphereLightLocations = std::make_shared(); - _directionalSkyboxLightLocations = std::make_shared(); + loadLightProgram(shader::render_utils::program::directional_ambient_light, false, _directionalAmbientSphereLight); + loadLightProgram(shader::render_utils::program::directional_skybox_light, false, _directionalSkyboxLight); - _directionalAmbientSphereLightShadowLocations = std::make_shared(); - _directionalSkyboxLightShadowLocations = std::make_shared(); + loadLightProgram(shader::render_utils::program::directional_ambient_light_shadow, false, _directionalAmbientSphereLightShadow); + loadLightProgram(shader::render_utils::program::directional_skybox_light_shadow, false, _directionalSkyboxLightShadow); - _localLightLocations = std::make_shared(); - _localLightOutlineLocations = std::make_shared(); - - loadLightProgram(shader::render_utils::program::directional_ambient_light, false, _directionalAmbientSphereLight, _directionalAmbientSphereLightLocations); - loadLightProgram(shader::render_utils::program::directional_skybox_light, false, _directionalSkyboxLight, _directionalSkyboxLightLocations); - - loadLightProgram(shader::render_utils::program::directional_ambient_light_shadow, false, _directionalAmbientSphereLightShadow, _directionalAmbientSphereLightShadowLocations); - loadLightProgram(shader::render_utils::program::directional_skybox_light_shadow, false, _directionalSkyboxLightShadow, _directionalSkyboxLightShadowLocations); - - loadLightProgram(shader::render_utils::program::local_lights_shading, true, _localLight, _localLightLocations); - loadLightProgram(shader::render_utils::program::local_lights_drawOutline, true, _localLightOutline, _localLightOutlineLocations); + loadLightProgram(shader::render_utils::program::local_lights_shading, true, _localLight); + loadLightProgram(shader::render_utils::program::local_lights_drawOutline, true, _localLightOutline); } // FIXME: figure out how to move lightFrame into a varying in GeometryCache and RenderPipelines @@ -123,15 +107,9 @@ void DeferredLightingEffect::unsetLocalLightsBatch(gpu::Batch& batch) { batch.setUniformBuffer(ru::Buffer::LightClusterFrustumGrid, nullptr); } -static gpu::ShaderPointer makeLightProgram(int programId, LightLocationsPtr& locations) { +static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& pipeline) { + gpu::ShaderPointer program = gpu::Shader::createProgram(programId); - locations->initialize(program); - return program; -} - -static void loadLightProgram(int programId, bool lightVolume, gpu::PipelinePointer& pipeline, LightLocationsPtr& locations) { - - gpu::ShaderPointer program = makeLightProgram(programId, locations); auto state = std::make_shared(); state->setColorWriteMask(true, true, true, false); @@ -456,7 +434,6 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // Setup the global directional pass pipeline auto program = deferredLightingEffect->_directionalSkyboxLight; - LightLocationsPtr locations = deferredLightingEffect->_directionalSkyboxLightLocations; { if (keyLightCastShadows) { @@ -464,20 +441,16 @@ void RenderDeferredSetup::run(const render::RenderContextPointer& renderContext, // otherwise use the ambient sphere version if (hasAmbientMap) { program = deferredLightingEffect->_directionalSkyboxLightShadow; - locations = deferredLightingEffect->_directionalSkyboxLightShadowLocations; } else { program = deferredLightingEffect->_directionalAmbientSphereLightShadow; - locations = deferredLightingEffect->_directionalAmbientSphereLightShadowLocations; } } else { // If the keylight has an ambient Map then use the Skybox version of the pass // otherwise use the ambient sphere version if (hasAmbientMap) { program = deferredLightingEffect->_directionalSkyboxLight; - locations = deferredLightingEffect->_directionalSkyboxLightLocations; } else { program = deferredLightingEffect->_directionalAmbientSphereLight; - locations = deferredLightingEffect->_directionalAmbientSphereLightLocations; } } diff --git a/libraries/render-utils/src/DeferredLightingEffect.h b/libraries/render-utils/src/DeferredLightingEffect.h index 1cc6ca4767..84b3127443 100644 --- a/libraries/render-utils/src/DeferredLightingEffect.h +++ b/libraries/render-utils/src/DeferredLightingEffect.h @@ -37,10 +37,6 @@ #include "SubsurfaceScattering.h" #include "AmbientOcclusionEffect.h" - -struct LightLocations; -using LightLocationsPtr = std::shared_ptr; - // THis is where we currently accumulate the local lights, let s change that sooner than later class DeferredLightingEffect : public Dependency { SINGLETON_DEPENDENCY @@ -72,15 +68,6 @@ private: gpu::PipelinePointer _localLight; gpu::PipelinePointer _localLightOutline; - LightLocationsPtr _directionalSkyboxLightLocations; - LightLocationsPtr _directionalAmbientSphereLightLocations; - - LightLocationsPtr _directionalSkyboxLightShadowLocations; - LightLocationsPtr _directionalAmbientSphereLightShadowLocations; - - LightLocationsPtr _localLightLocations; - LightLocationsPtr _localLightOutlineLocations; - friend class LightClusteringPass; friend class RenderDeferredSetup; friend class RenderDeferredLocals; diff --git a/libraries/render-utils/src/deferred_light.slv b/libraries/render-utils/src/deferred_light.slv index 164fd9fb3b..2a68aa0e27 100644 --- a/libraries/render-utils/src/deferred_light.slv +++ b/libraries/render-utils/src/deferred_light.slv @@ -18,7 +18,7 @@ layout(location=RENDER_UTILS_ATTR_TEXCOORD01) out vec4 _texCoord01; void main(void) { const float depth = 1.0; - const vec4 UNIT_QUAD[4] = vec4[4]( + const mat4 UNIT_QUAD = mat4( vec4(-1.0, -1.0, depth, 1.0), vec4(1.0, -1.0, depth, 1.0), vec4(-1.0, 1.0, depth, 1.0), @@ -26,7 +26,7 @@ void main(void) { ); vec4 pos = UNIT_QUAD[gl_VertexID]; - _texCoord01.xy = (pos.xy + 1.0) * 0.5; + _texCoord01 = vec4((pos.xy + 1.0) * 0.5, 0.0, 0.0); gl_Position = pos; }