From 71b223dcb5c7366c4c92b8aed1e60cfbde103575 Mon Sep 17 00:00:00 2001 From: Michael Fabian 'Xaymar' Dirks Date: Sun, 4 Aug 2019 23:18:54 +0200 Subject: [PATCH] gs-effect: Add ::create for shared_ptr and remove default constructor --- source/filters/filter-blur.cpp | 8 ++++---- source/filters/filter-color-grade.cpp | 4 ++-- source/filters/filter-displacement.cpp | 2 +- source/filters/filter-dynamic-mask.cpp | 4 ++-- source/filters/filter-sdf-effects.cpp | 6 +++--- source/gfx/blur/gfx-blur-box-linear.cpp | 2 +- source/gfx/blur/gfx-blur-box.cpp | 2 +- source/gfx/blur/gfx-blur-dual-filtering.cpp | 2 +- source/gfx/blur/gfx-blur-gaussian-linear.cpp | 4 ++-- source/gfx/blur/gfx-blur-gaussian.cpp | 4 ++-- source/obs/gs/gs-effect.cpp | 16 ++++++++++++---- source/obs/gs/gs-effect.hpp | 9 ++++++--- source/obs/gs/gs-mipmapper.cpp | 2 +- 13 files changed, 38 insertions(+), 27 deletions(-) diff --git a/source/filters/filter-blur.cpp b/source/filters/filter-blur.cpp index 9ecd49b..4ccba65 100644 --- a/source/filters/filter-blur.cpp +++ b/source/filters/filter-blur.cpp @@ -158,18 +158,18 @@ void filter::blur::blur_factory::on_list_fill() auto gctx = gs::context(); { - char* file = obs_module_file("effects/color-conversion._effect"); + char* file = obs_module_file("effects/color-conversion.effect"); try { - _color_converter_effect = std::make_shared(file); + _color_converter_effect = gs::effect::create(file); } catch (std::runtime_error& ex) { P_LOG_ERROR(" Loading _effect '%s' failed with error(s): %s", file, ex.what()); } bfree(file); } { - char* file = obs_module_file("effects/mask._effect"); + char* file = obs_module_file("effects/mask.effect"); try { - _mask_effect = std::make_shared(file); + _mask_effect = gs::effect::create(file); } catch (std::runtime_error& ex) { P_LOG_ERROR(" Loading _effect '%s' failed with error(s): %s", file, ex.what()); } diff --git a/source/filters/filter-color-grade.cpp b/source/filters/filter-color-grade.cpp index 3706237..3255c0c 100644 --- a/source/filters/filter-color-grade.cpp +++ b/source/filters/filter-color-grade.cpp @@ -374,9 +374,9 @@ filter::color_grade::color_grade_instance::color_grade_instance(obs_data_t* data update(data); { - char* file = obs_module_file("effects/color-grade._effect"); + char* file = obs_module_file("effects/color-grade.effect"); try { - _effect = std::make_shared(file); + _effect = gs::effect::create(file); bfree(file); } catch (std::runtime_error& ex) { P_LOG_ERROR(" Loading _effect '%s' failed with error(s): %s", file, ex.what()); diff --git a/source/filters/filter-displacement.cpp b/source/filters/filter-displacement.cpp index 0b61259..c0f01a1 100644 --- a/source/filters/filter-displacement.cpp +++ b/source/filters/filter-displacement.cpp @@ -203,7 +203,7 @@ filter::displacement::displacement_instance::displacement_instance(obs_data_t* d char* effectFile = obs_module_file("effects/displace.effect"); if (effectFile) { try { - _effect = std::make_shared(effectFile); + _effect = gs::effect::create(effectFile); } catch (...) { P_LOG_ERROR(" Failed to load displacement effect.", obs_source_get_name(_self)); } diff --git a/source/filters/filter-dynamic-mask.cpp b/source/filters/filter-dynamic-mask.cpp index d82a5d1..9d3ddeb 100644 --- a/source/filters/filter-dynamic-mask.cpp +++ b/source/filters/filter-dynamic-mask.cpp @@ -130,9 +130,9 @@ filter::dynamic_mask::dynamic_mask_instance::dynamic_mask_instance(obs_data_t* d this->_final_rt = std::make_shared(GS_RGBA, GS_ZS_NONE); { - char* file = obs_module_file("effects/channel-mask._effect"); + char* file = obs_module_file("effects/channel-mask.effect"); try { - this->_effect = std::make_shared(file); + this->_effect = gs::effect::create(file); } catch (std::exception& ex) { P_LOG_ERROR("Loading channel mask _effect failed with error(s):\n%s", ex.what()); } diff --git a/source/filters/filter-sdf-effects.cpp b/source/filters/filter-sdf-effects.cpp index 08266b5..d13a2e1 100644 --- a/source/filters/filter-sdf-effects.cpp +++ b/source/filters/filter-sdf-effects.cpp @@ -116,8 +116,8 @@ void filter::sdf_effects::sdf_effects_factory::on_list_fill() auto gctx = gs::context(); std::pair&> load_arr[] = { - {"effects/sdf/sdf-producer._effect", this->_sdf_producer_effect}, - {"effects/sdf/sdf-consumer._effect", this->_sdf_consumer_effect}, + {"effects/sdf/sdf-producer.effect", this->_sdf_producer_effect}, + {"effects/sdf/sdf-consumer.effect", this->_sdf_consumer_effect}, }; for (auto& kv : load_arr) { char* path = obs_module_file(kv.first); @@ -126,7 +126,7 @@ void filter::sdf_effects::sdf_effects_factory::on_list_fill() continue; } try { - kv.second = std::make_shared(path); + kv.second = gs::effect::create(path); } catch (std::exception& ex) { P_LOG_ERROR(LOG_PREFIX "Failed to load _effect '%s' (located at '%s') with error(s): %s", kv.first, path, ex.what()); diff --git a/source/gfx/blur/gfx-blur-box-linear.cpp b/source/gfx/blur/gfx-blur-box-linear.cpp index 3b094b6..b4b77f3 100644 --- a/source/gfx/blur/gfx-blur-box-linear.cpp +++ b/source/gfx/blur/gfx-blur-box-linear.cpp @@ -38,7 +38,7 @@ gfx::blur::box_linear_data::box_linear_data() { auto gctx = gs::context(); try { - char* file = obs_module_file("effects/blur/box-linear._effect"); + char* file = obs_module_file("effects/blur/box-linear.effect"); _effect = std::make_shared<::gs::effect>(file); bfree(file); } catch (...) { diff --git a/source/gfx/blur/gfx-blur-box.cpp b/source/gfx/blur/gfx-blur-box.cpp index 6b2a832..603ecba 100644 --- a/source/gfx/blur/gfx-blur-box.cpp +++ b/source/gfx/blur/gfx-blur-box.cpp @@ -38,7 +38,7 @@ gfx::blur::box_data::box_data() { auto gctx = gs::context(); try { - char* file = obs_module_file("effects/blur/box._effect"); + char* file = obs_module_file("effects/blur/box.effect"); _effect = std::make_shared<::gs::effect>(file); bfree(file); } catch (...) { diff --git a/source/gfx/blur/gfx-blur-dual-filtering.cpp b/source/gfx/blur/gfx-blur-dual-filtering.cpp index 788d4d9..8b45875 100644 --- a/source/gfx/blur/gfx-blur-dual-filtering.cpp +++ b/source/gfx/blur/gfx-blur-dual-filtering.cpp @@ -54,7 +54,7 @@ gfx::blur::dual_filtering_data::dual_filtering_data() { auto gctx = gs::context(); try { - char* file = obs_module_file("effects/blur/dual-filtering._effect"); + char* file = obs_module_file("effects/blur/dual-filtering.effect"); _effect = std::make_shared<::gs::effect>(file); bfree(file); } catch (...) { diff --git a/source/gfx/blur/gfx-blur-gaussian-linear.cpp b/source/gfx/blur/gfx-blur-gaussian-linear.cpp index 0ca06f3..c0e7eb3 100644 --- a/source/gfx/blur/gfx-blur-gaussian-linear.cpp +++ b/source/gfx/blur/gfx-blur-gaussian-linear.cpp @@ -45,8 +45,8 @@ gfx::blur::gaussian_linear_data::gaussian_linear_data() auto gctx = gs::context(); { - char* file = obs_module_file("effects/blur/gaussian-linear._effect"); - _effect = std::make_shared(file); + char* file = obs_module_file("effects/blur/gaussian-linear.effect"); + _effect = gs::effect::create(file); bfree(file); } diff --git a/source/gfx/blur/gfx-blur-gaussian.cpp b/source/gfx/blur/gfx-blur-gaussian.cpp index b1f1dc5..eef687f 100644 --- a/source/gfx/blur/gfx-blur-gaussian.cpp +++ b/source/gfx/blur/gfx-blur-gaussian.cpp @@ -45,8 +45,8 @@ gfx::blur::gaussian_data::gaussian_data() { auto gctx = gs::context(); { - char* file = obs_module_file("effects/blur/gaussian._effect"); - _effect = std::make_shared(file); + char* file = obs_module_file("effects/blur/gaussian.effect"); + _effect = gs::effect::create(file); bfree(file); } diff --git a/source/obs/gs/gs-effect.cpp b/source/obs/gs/gs-effect.cpp index 47b6dc5..9dd32e4 100644 --- a/source/obs/gs/gs-effect.cpp +++ b/source/obs/gs/gs-effect.cpp @@ -36,9 +36,7 @@ //#define OBS_LOAD_EFFECT_FILE -gs::effect::effect() : _effect(nullptr) {} - -gs::effect::effect(std::string file) : effect() +gs::effect::effect(std::string file) { #ifdef OBS_LOAD_EFFECT_FILE char* errorMessage = nullptr; @@ -84,7 +82,7 @@ gs::effect::effect(std::string file) : effect() #endif } -gs::effect::effect(std::string code, std::string name) : effect() +gs::effect::effect(std::string code, std::string name) { char* errorMessage = nullptr; auto gctx = gs::context(); @@ -157,6 +155,16 @@ bool gs::effect::has_parameter(std::string name, effect_parameter::type type) return false; } +std::shared_ptr gs::effect::create(std::string file) +{ + return std::shared_ptr(new gs::effect(file)); +} + +std::shared_ptr gs::effect::create(std::string code, std::string name) +{ + return std::shared_ptr(new gs::effect(code, name)); +} + gs::effect_parameter::effect_parameter(std::shared_ptr effect, gs_eparam_t* param) : _effect(effect), _param(param) { diff --git a/source/obs/gs/gs-effect.hpp b/source/obs/gs/gs-effect.hpp index 90503ab..c006614 100644 --- a/source/obs/gs/gs-effect.hpp +++ b/source/obs/gs/gs-effect.hpp @@ -44,8 +44,8 @@ namespace gs { class effect_parameter { std::shared_ptr<::gs::effect> _effect; - gs_eparam_t* _param; - gs_effect_param_info _param_info; + gs_eparam_t* _param; + gs_effect_param_info _param_info; public: enum class type : uint8_t { @@ -147,7 +147,6 @@ namespace gs { gs_effect_t* _effect; public: - effect(); effect(std::string file); effect(std::string code, std::string name); virtual ~effect(); @@ -160,5 +159,9 @@ namespace gs { std::shared_ptr get_parameter(std::string name); bool has_parameter(std::string name); bool has_parameter(std::string name, effect_parameter::type type); + + public: + static std::shared_ptr create(std::string file); + static std::shared_ptr create(std::string code, std::string name); }; } // namespace gs diff --git a/source/obs/gs/gs-mipmapper.cpp b/source/obs/gs/gs-mipmapper.cpp index 69f9581..8969ff4 100644 --- a/source/obs/gs/gs-mipmapper.cpp +++ b/source/obs/gs/gs-mipmapper.cpp @@ -108,7 +108,7 @@ gs::mipmapper::mipmapper() _vb->update(); - char* effect_file = obs_module_file("effects/mipgen._effect"); + char* effect_file = obs_module_file("effects/mipgen.effect"); _effect = std::make_unique(effect_file); bfree(effect_file); }