diff --git a/source/filters/filter-shader.cpp b/source/filters/filter-shader.cpp index 2e0ea5fb..e644d418 100644 --- a/source/filters/filter-shader.cpp +++ b/source/filters/filter-shader.cpp @@ -114,6 +114,16 @@ filter::shader::shader_factory::shader_factory() } return uint32_t(0); }; + _source_info.load = [](void* ptr, obs_data_t* data) { + try { + if (ptr) + reinterpret_cast(ptr)->load(data); + } catch (std::exception& ex) { + P_LOG_ERROR(" Failed to load, error: %s", ex.what()); + } catch (...) { + P_LOG_ERROR(" Failed to load."); + } + }; _source_info.update = [](void* ptr, obs_data_t* data) { try { if (ptr) @@ -164,6 +174,16 @@ filter::shader::shader_factory::shader_factory() P_LOG_ERROR(" Failed to render."); } }; + _source_info.enum_active_sources = [](void* ptr, obs_source_enum_proc_t enum_callback, void* param) { + try { + if (ptr) + reinterpret_cast(ptr)->enum_active_sources(enum_callback, param); + } catch (std::exception& ex) { + P_LOG_ERROR(" Failed to enumerate sources, error: %s", ex.what()); + } catch (...) { + P_LOG_ERROR(" Failed to enumerate sources."); + } + }; obs_register_source(&_source_info); } @@ -177,7 +197,7 @@ filter::shader::shader_instance::shader_instance(obs_data_t* data, obs_source_t* _fx->set_valid_property_cb(std::bind(&filter::shader::shader_instance::valid_param, this, std::placeholders::_1)); _fx->set_override_cb(std::bind(&filter::shader::shader_instance::override_param, this, std::placeholders::_1)); - _rt = std::make_shared(GS_RGBA, GS_ZS_NONE); + _rt = std::make_shared(GS_RGBA, GS_ZS_NONE); _rt2 = std::make_shared(GS_RGBA, GS_ZS_NONE); update(data); @@ -200,6 +220,11 @@ void filter::shader::shader_instance::properties(obs_properties_t* props) _fx->properties(props); } +void filter::shader::shader_instance::load(obs_data_t* data) +{ + update(data); +} + void filter::shader::shader_instance::update(obs_data_t* data) { _fx->update(data); @@ -243,6 +268,11 @@ void filter::shader::shader_instance::override_param(std::shared_ptr } } +void filter::shader::shader_instance::enum_active_sources(obs_source_enum_proc_t r, void* p) +{ + _fx->enum_active_sources(r, p); +} + void filter::shader::shader_instance::video_tick(float_t sec_since_last) { obs_source_t* target = obs_filter_get_target(_self); @@ -258,7 +288,7 @@ void filter::shader::shader_instance::video_tick(float_t sec_since_last) obs_data_release(data); } - _rt_updated = false; + _rt_updated = false; _rt2_updated = false; } diff --git a/source/filters/filter-shader.hpp b/source/filters/filter-shader.hpp index 0152d39a..789cf13a 100644 --- a/source/filters/filter-shader.hpp +++ b/source/filters/filter-shader.hpp @@ -67,6 +67,7 @@ namespace filter { void properties(obs_properties_t* props); + void load(obs_data_t* data); void update(obs_data_t* data); void activate(); @@ -75,6 +76,8 @@ namespace filter { bool valid_param(std::shared_ptr param); void override_param(std::shared_ptr effect); + void enum_active_sources(obs_source_enum_proc_t, void*); + void video_tick(float_t sec_since_last); void video_render(gs_effect_t* effect); }; diff --git a/source/gfx/gfx-effect-source.cpp b/source/gfx/gfx-effect-source.cpp index 86c3e696..c40f2493 100644 --- a/source/gfx/gfx-effect-source.cpp +++ b/source/gfx/gfx-effect-source.cpp @@ -138,8 +138,8 @@ gfx::effect_source::bool_parameter::bool_parameter(std::shared_ptrget_type()) { @@ -352,7 +352,7 @@ void gfx::effect_source::value_parameter::defaults(obs_properties_t* props, obs_ obs_data_set_default_double(data, _cache.name[idx].c_str(), _value.f[idx]); obs_data_set_double(data, _cache.name[idx].c_str(), _value.f[idx]); } - } + }*/ } void gfx::effect_source::value_parameter::properties(obs_properties_t* props) @@ -615,7 +615,7 @@ gfx::effect_source::matrix_parameter::matrix_parameter(std::shared_ptr(_mode)); - obs_data_set_string(data, _cache.name[1].c_str(), _file_name.c_str()); - obs_data_set_string(data, _cache.name[2].c_str(), _source_name.c_str()); + obs_data_set_default_int(data, _cache.name[0].c_str(), static_cast(_mode)); + obs_data_set_default_string(data, _cache.name[1].c_str(), _file_name.c_str()); + obs_data_set_default_string(data, _cache.name[2].c_str(), _source_name.c_str()); } void gfx::effect_source::texture_parameter::properties(obs_properties_t* props) @@ -908,6 +907,13 @@ void gfx::effect_source::texture_parameter::assign() } } +void gfx::effect_source::texture_parameter::enum_active_sources(obs_source_enum_proc_t p, void* t) +{ + if ((_mode == texture_mode::SOURCE) && !_parent.expired() && _source) { + p(_parent.lock()->get_self(), _source->get(), t); + } +} + bool gfx::effect_source::effect_source::modified2(obs_properties_t* props, obs_property_t* property, obs_data_t* settings) { @@ -1148,6 +1154,14 @@ obs_source_t* gfx::effect_source::effect_source::get_self() return _self; } +void gfx::effect_source::effect_source::enum_active_sources(obs_source_enum_proc_t p, void* t) +{ + for (auto& kv : _params) { + if (kv.second) + kv.second->enum_active_sources(p, t); + } +} + void gfx::effect_source::effect_source::set_valid_property_cb(valid_property_cb_t cb) { _cb_valid = cb; diff --git a/source/gfx/gfx-effect-source.hpp b/source/gfx/gfx-effect-source.hpp index 92e9055e..65d76917 100644 --- a/source/gfx/gfx-effect-source.hpp +++ b/source/gfx/gfx-effect-source.hpp @@ -98,6 +98,8 @@ namespace gfx { std::shared_ptr get_param(); + virtual void enum_active_sources(obs_source_enum_proc_t, void*){}; + public: static std::shared_ptr create(std::shared_ptr parent, std::shared_ptr effect, @@ -265,6 +267,8 @@ namespace gfx { virtual void prepare() override; virtual void assign() override; + + virtual void enum_active_sources(obs_source_enum_proc_t, void*) override; }; typedef std::pair param_ident_t; @@ -314,6 +318,8 @@ namespace gfx { obs_source_t* get_self(); + void enum_active_sources(obs_source_enum_proc_t, void*); + public: void set_valid_property_cb(valid_property_cb_t cb); diff --git a/source/sources/source-shader.cpp b/source/sources/source-shader.cpp index 5c6f24f9..91f553ca 100644 --- a/source/sources/source-shader.cpp +++ b/source/sources/source-shader.cpp @@ -118,6 +118,16 @@ source::shader::shader_factory::shader_factory() } return uint32_t(0); }; + _source_info.load = [](void* ptr, obs_data_t* data) { + try { + if (ptr) + reinterpret_cast(ptr)->load(data); + } catch (std::exception& ex) { + P_LOG_ERROR(" Failed to load, error: %s", ex.what()); + } catch (...) { + P_LOG_ERROR(" Failed to load."); + } + }; _source_info.update = [](void* ptr, obs_data_t* data) { try { if (ptr) @@ -168,6 +178,16 @@ source::shader::shader_factory::shader_factory() P_LOG_ERROR(" Failed to render."); } }; + _source_info.enum_active_sources = [](void* ptr, obs_source_enum_proc_t enum_callback, void* param) { + try { + if (ptr) + reinterpret_cast(ptr)->enum_active_sources(enum_callback, param); + } catch (std::exception& ex) { + P_LOG_ERROR(" Failed to enumerate sources, error: %s", ex.what()); + } catch (...) { + P_LOG_ERROR(" Failed to enumerate sources."); + } + }; obs_register_source(&_source_info); } @@ -206,6 +226,11 @@ void source::shader::shader_instance::properties(obs_properties_t* props) _fx->properties(props); } +void source::shader::shader_instance::load(obs_data_t* data) +{ + update(data); +} + void source::shader::shader_instance::update(obs_data_t* data) { _width = obs_data_get_int(data, ST_WIDTH); @@ -231,6 +256,10 @@ bool source::shader::shader_instance::valid_param(std::shared_ptr effect) {} +void source::shader::shader_instance::enum_active_sources(obs_source_enum_proc_t r, void* p) { + _fx->enum_active_sources(r, p); +} + void source::shader::shader_instance::video_tick(float_t sec_since_last) { if (_fx->tick(sec_since_last)) { diff --git a/source/sources/source-shader.hpp b/source/sources/source-shader.hpp index 92660957..7c9316f8 100644 --- a/source/sources/source-shader.hpp +++ b/source/sources/source-shader.hpp @@ -63,6 +63,7 @@ namespace source { void properties(obs_properties_t* props); + void load(obs_data_t* data); void update(obs_data_t* data); void activate(); @@ -71,6 +72,8 @@ namespace source { bool valid_param(std::shared_ptr param); void override_param(std::shared_ptr effect); + void enum_active_sources(obs_source_enum_proc_t, void*); + void video_tick(float_t sec_since_last); void video_render(gs_effect_t* effect); };