mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-29 11:01:23 +00:00
code: Migrate transition::shader to new dynamic loader
This commit is contained in:
parent
b4e6bb57e4
commit
1363b14288
3 changed files with 20 additions and 41 deletions
|
@ -57,10 +57,6 @@
|
||||||
#include "sources/source-shader.hpp"
|
#include "sources/source-shader.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifdef ENABLE_TRANSITION_SHADER
|
|
||||||
#include "transitions/transition-shader.hpp"
|
|
||||||
#endif
|
|
||||||
|
|
||||||
#ifdef ENABLE_FRONTEND
|
#ifdef ENABLE_FRONTEND
|
||||||
#include "ui/ui.hpp"
|
#include "ui/ui.hpp"
|
||||||
#endif
|
#endif
|
||||||
|
@ -205,13 +201,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
// Transitions
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_TRANSITION_SHADER
|
|
||||||
streamfx::transition::shader::shader_factory::initialize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
||||||
return true;
|
return true;
|
||||||
} catch (std::exception const& ex) {
|
} catch (std::exception const& ex) {
|
||||||
|
@ -228,13 +217,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
||||||
try {
|
try {
|
||||||
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
||||||
|
|
||||||
// Transitions
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_TRANSITION_SHADER
|
|
||||||
streamfx::transition::shader::shader_factory::finalize();
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
// Sources
|
// Sources
|
||||||
{
|
{
|
||||||
#ifdef ENABLE_SOURCE_MIRROR
|
#ifdef ENABLE_SOURCE_MIRROR
|
||||||
|
|
|
@ -178,26 +178,27 @@ bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
std::shared_ptr<shader_factory> _transition_shader_factory_instance = nullptr;
|
std::shared_ptr<shader_factory> shader_factory::instance()
|
||||||
|
|
||||||
void streamfx::transition::shader::shader_factory::initialize()
|
|
||||||
{
|
{
|
||||||
try {
|
static std::weak_ptr<shader_factory> winst;
|
||||||
if (!_transition_shader_factory_instance)
|
static std::mutex mtx;
|
||||||
_transition_shader_factory_instance = std::make_shared<shader_factory>();
|
|
||||||
} catch (const std::exception& ex) {
|
std::unique_lock<decltype(mtx)> lock(mtx);
|
||||||
D_LOG_ERROR("Failed to initialize due to error: %s", ex.what());
|
auto instance = winst.lock();
|
||||||
} catch (...) {
|
if (!instance) {
|
||||||
D_LOG_ERROR("Failed to initialize due to unknown error.", "");
|
instance = std::shared_ptr<shader_factory>(new shader_factory());
|
||||||
|
winst = instance;
|
||||||
}
|
}
|
||||||
|
return instance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void streamfx::transition::shader::shader_factory::finalize()
|
static std::shared_ptr<shader_factory> loader_instance;
|
||||||
{
|
|
||||||
_transition_shader_factory_instance.reset();
|
|
||||||
}
|
|
||||||
|
|
||||||
std::shared_ptr<shader_factory> streamfx::transition::shader::shader_factory::get()
|
static auto loader = streamfx::loader(
|
||||||
{
|
[]() { // Initalizer
|
||||||
return _transition_shader_factory_instance;
|
loader_instance = shader_factory::instance();
|
||||||
}
|
},
|
||||||
|
[]() { // Finalizer
|
||||||
|
loader_instance.reset();
|
||||||
|
},
|
||||||
|
streamfx::loader_priority::NORMAL);
|
||||||
|
|
|
@ -52,10 +52,6 @@ namespace streamfx::transition::shader {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
public: // Singleton
|
public: // Singleton
|
||||||
static void initialize();
|
static std::shared_ptr<shader_factory> instance();
|
||||||
|
|
||||||
static void finalize();
|
|
||||||
|
|
||||||
static std::shared_ptr<shader_factory> get();
|
|
||||||
};
|
};
|
||||||
} // namespace streamfx::transition::shader
|
} // namespace streamfx::transition::shader
|
||||||
|
|
Loading…
Reference in a new issue