mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 02:21:25 +00:00
code: Migrate filter::shader to new dynamic loader
This commit is contained in:
parent
cfa2806e89
commit
8bec18600f
3 changed files with 20 additions and 28 deletions
|
@ -217,26 +217,27 @@ bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
|||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<shader_factory> _filter_shader_factory_instance = nullptr;
|
||||
|
||||
void streamfx::filter::shader::shader_factory::initialize()
|
||||
std::shared_ptr<shader_factory> shader_factory::instance()
|
||||
{
|
||||
try {
|
||||
if (!_filter_shader_factory_instance)
|
||||
_filter_shader_factory_instance = std::make_shared<shader_factory>();
|
||||
} catch (const std::exception& ex) {
|
||||
D_LOG_ERROR("Failed to initialize due to error: %s", ex.what());
|
||||
} catch (...) {
|
||||
D_LOG_ERROR("Failed to initialize due to unknown error.", "");
|
||||
static std::weak_ptr<shader_factory> winst;
|
||||
static std::mutex mtx;
|
||||
|
||||
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||
auto instance = winst.lock();
|
||||
if (!instance) {
|
||||
instance = std::shared_ptr<shader_factory>(new shader_factory());
|
||||
winst = instance;
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
void streamfx::filter::shader::shader_factory::finalize()
|
||||
{
|
||||
_filter_shader_factory_instance.reset();
|
||||
}
|
||||
static std::shared_ptr<shader_factory> loader_instance;
|
||||
|
||||
std::shared_ptr<shader_factory> streamfx::filter::shader::shader_factory::get()
|
||||
{
|
||||
return _filter_shader_factory_instance;
|
||||
}
|
||||
static auto loader = streamfx::loader(
|
||||
[]() { // Initalizer
|
||||
loader_instance = shader_factory::instance();
|
||||
},
|
||||
[]() { // Finalizer
|
||||
loader_instance.reset();
|
||||
},
|
||||
streamfx::loader_priority::NORMAL);
|
||||
|
|
|
@ -57,6 +57,6 @@ namespace streamfx::filter::shader {
|
|||
|
||||
static void finalize();
|
||||
|
||||
static std::shared_ptr<shader_factory> get();
|
||||
static std::shared_ptr<shader_factory> instance();
|
||||
};
|
||||
} // namespace streamfx::filter::shader
|
||||
|
|
|
@ -34,9 +34,6 @@
|
|||
#ifdef ENABLE_FILTER_SDF_EFFECTS
|
||||
#include "filters/filter-sdf-effects.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_SHADER
|
||||
#include "filters/filter-shader.hpp"
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_TRANSFORM
|
||||
#include "filters/filter-transform.hpp"
|
||||
#endif
|
||||
|
@ -168,9 +165,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
|||
#ifdef ENABLE_FILTER_SDF_EFFECTS
|
||||
streamfx::filter::sdf_effects::sdf_effects_factory::initialize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_SHADER
|
||||
streamfx::filter::shader::shader_factory::initialize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_TRANSFORM
|
||||
streamfx::filter::transform::transform_factory::initialize();
|
||||
#endif
|
||||
|
@ -232,9 +226,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
|||
#ifdef ENABLE_FILTER_SDF_EFFECTS
|
||||
streamfx::filter::sdf_effects::sdf_effects_factory::finalize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_SHADER
|
||||
streamfx::filter::shader::shader_factory::finalize();
|
||||
#endif
|
||||
#ifdef ENABLE_FILTER_TRANSFORM
|
||||
streamfx::filter::transform::transform_factory::finalize();
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue