From bba606e4399e3e34e989a458f03f6b04fa8c6073 Mon Sep 17 00:00:00 2001 From: "coolsoft.rf" Date: Fri, 15 Oct 2021 16:30:01 +0200 Subject: [PATCH] gfx/shader: Support for visible and active tracking in parameters Co-authored-by: Michael Fabian 'Xaymar' Dirks --- source/filters/filter-shader.cpp | 11 +++++++++++ source/filters/filter-shader.hpp | 3 +++ source/gfx/shader/gfx-shader-param.cpp | 4 ++++ source/gfx/shader/gfx-shader-param.hpp | 4 ++++ source/gfx/shader/gfx-shader.cpp | 13 +++++++++++++ source/gfx/shader/gfx-shader.hpp | 3 +++ source/sources/source-shader.cpp | 11 +++++++++++ source/sources/source-shader.hpp | 3 +++ source/transitions/transition-shader.cpp | 2 ++ 9 files changed, 54 insertions(+) diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 8a312c5a..7a191e5d 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -153,6 +153,16 @@ void shader_instance::video_render(gs_effect_t* effect) } } +void streamfx::filter::shader::shader_instance::show() +{ + _fx->set_visible(true); +} + +void streamfx::filter::shader::shader_instance::hide() +{ + _fx->set_visible(false); +} + void streamfx::filter::shader::shader_instance::activate() { _fx->set_active(true); @@ -170,6 +180,7 @@ shader_factory::shader_factory() _info.output_flags = OBS_SOURCE_VIDEO; set_activity_tracking_enabled(true); + set_visibility_tracking_enabled(true); finish_setup(); register_proxy("obs-stream-effects-filter-shader"); } diff --git a/source/filters/filter-shader.hpp b/source/filters/filter-shader.hpp index cc298668..e7850efc 100644 --- a/source/filters/filter-shader.hpp +++ b/source/filters/filter-shader.hpp @@ -44,6 +44,9 @@ namespace streamfx::filter::shader { virtual void video_tick(float_t sec_since_last) override; virtual void video_render(gs_effect_t* effect) override; + void show() override; + void hide() override; + void activate() override; void deactivate() override; }; diff --git a/source/gfx/shader/gfx-shader-param.cpp b/source/gfx/shader/gfx-shader-param.cpp index 3d9db414..9e525465 100644 --- a/source/gfx/shader/gfx-shader-param.cpp +++ b/source/gfx/shader/gfx-shader-param.cpp @@ -176,6 +176,10 @@ void streamfx::gfx::shader::parameter::update(obs_data_t* settings) {} void streamfx::gfx::shader::parameter::assign() {} +void streamfx::gfx::shader::parameter::visible(bool visible) {} + +void streamfx::gfx::shader::parameter::active(bool active) {} + std::shared_ptr streamfx::gfx::shader::parameter::make_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) { diff --git a/source/gfx/shader/gfx-shader-param.hpp b/source/gfx/shader/gfx-shader-param.hpp index 5fb77747..8f4f0d5c 100644 --- a/source/gfx/shader/gfx-shader-param.hpp +++ b/source/gfx/shader/gfx-shader-param.hpp @@ -80,6 +80,10 @@ namespace streamfx::gfx { virtual void assign(); + virtual void visible(bool visible); + + virtual void active(bool enabled); + public: inline streamfx::obs::gs::effect_parameter get_parameter() { diff --git a/source/gfx/shader/gfx-shader.cpp b/source/gfx/shader/gfx-shader.cpp index 930b20d4..128c7e48 100644 --- a/source/gfx/shader/gfx-shader.cpp +++ b/source/gfx/shader/gfx-shader.cpp @@ -592,10 +592,23 @@ void streamfx::gfx::shader::shader::set_transition_size(uint32_t w, uint32_t h) } } +void streamfx::gfx::shader::shader::set_visible(bool visible) +{ + _visible = visible; + + for (auto kv : _shader_params) { + kv.second->visible(visible); + } +} + void streamfx::gfx::shader::shader::set_active(bool active) { _active = active; + for (auto kv : _shader_params) { + kv.second->active(active); + } + // Recreate Per-Activation-Random values. for (size_t idx = 0; idx < 4; idx++) { _random_values[4 + idx] = diff --git a/source/gfx/shader/gfx-shader.hpp b/source/gfx/shader/gfx-shader.hpp index d16b0394..dee907a1 100644 --- a/source/gfx/shader/gfx-shader.hpp +++ b/source/gfx/shader/gfx-shader.hpp @@ -48,6 +48,7 @@ namespace streamfx::gfx { uint32_t _base_width; uint32_t _base_height; bool _active; + bool _visible; // Shader streamfx::obs::gs::effect _shader; @@ -125,6 +126,8 @@ namespace streamfx::gfx { void set_transition_size(uint32_t w, uint32_t h); + void set_visible(bool visible); + void set_active(bool active); }; } // namespace shader diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index 15c64e76..d0bd5b3c 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -106,6 +106,16 @@ void shader_instance::video_render(gs_effect_t* effect) _fx->render(effect); } +void streamfx::source::shader::shader_instance::show() +{ + _fx->set_visible(true); +} + +void streamfx::source::shader::shader_instance::hide() +{ + _fx->set_visible(false); +} + void streamfx::source::shader::shader_instance::activate() { _fx->set_active(true); @@ -123,6 +133,7 @@ shader_factory::shader_factory() _info.output_flags = OBS_SOURCE_VIDEO | OBS_SOURCE_CUSTOM_DRAW; set_activity_tracking_enabled(true); + set_visibility_tracking_enabled(true); finish_setup(); register_proxy("obs-stream-effects-source-shader"); } diff --git a/source/sources/source-shader.hpp b/source/sources/source-shader.hpp index 77fffdc0..8eb013cc 100644 --- a/source/sources/source-shader.hpp +++ b/source/sources/source-shader.hpp @@ -43,6 +43,9 @@ namespace streamfx::source::shader { virtual void video_tick(float_t sec_since_last) override; virtual void video_render(gs_effect_t* effect) override; + void show() override; + void hide() override; + void activate() override; void deactivate() override; }; diff --git a/source/transitions/transition-shader.cpp b/source/transitions/transition-shader.cpp index 00c5de56..49c2cf45 100644 --- a/source/transitions/transition-shader.cpp +++ b/source/transitions/transition-shader.cpp @@ -129,12 +129,14 @@ bool shader_instance::audio_render(uint64_t* ts_out, obs_source_audio_mix* audio void shader_instance::transition_start() { + _fx->set_visible(true); _fx->set_active(true); } void shader_instance::transition_stop() { _fx->set_active(false); + _fx->set_visible(false); } shader_factory::shader_factory()