mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-28 02:21:25 +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"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_TRANSITION_SHADER
|
||||
#include "transitions/transition-shader.hpp"
|
||||
#endif
|
||||
|
||||
#ifdef ENABLE_FRONTEND
|
||||
#include "ui/ui.hpp"
|
||||
#endif
|
||||
|
@ -205,13 +201,6 @@ MODULE_EXPORT bool obs_module_load(void)
|
|||
#endif
|
||||
}
|
||||
|
||||
// Transitions
|
||||
{
|
||||
#ifdef ENABLE_TRANSITION_SHADER
|
||||
streamfx::transition::shader::shader_factory::initialize();
|
||||
#endif
|
||||
}
|
||||
|
||||
DLOG_INFO("Loaded Version %s", STREAMFX_VERSION_STRING);
|
||||
return true;
|
||||
} catch (std::exception const& ex) {
|
||||
|
@ -228,13 +217,6 @@ MODULE_EXPORT void obs_module_unload(void)
|
|||
try {
|
||||
DLOG_INFO("Unloading Version %s", STREAMFX_VERSION_STRING);
|
||||
|
||||
// Transitions
|
||||
{
|
||||
#ifdef ENABLE_TRANSITION_SHADER
|
||||
streamfx::transition::shader::shader_factory::finalize();
|
||||
#endif
|
||||
}
|
||||
|
||||
// Sources
|
||||
{
|
||||
#ifdef ENABLE_SOURCE_MIRROR
|
||||
|
|
|
@ -178,26 +178,27 @@ bool shader_factory::on_manual_open(obs_properties_t* props, obs_property_t* pro
|
|||
}
|
||||
#endif
|
||||
|
||||
std::shared_ptr<shader_factory> _transition_shader_factory_instance = nullptr;
|
||||
|
||||
void streamfx::transition::shader::shader_factory::initialize()
|
||||
std::shared_ptr<shader_factory> shader_factory::instance()
|
||||
{
|
||||
try {
|
||||
if (!_transition_shader_factory_instance)
|
||||
_transition_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::transition::shader::shader_factory::finalize()
|
||||
{
|
||||
_transition_shader_factory_instance.reset();
|
||||
}
|
||||
static std::shared_ptr<shader_factory> loader_instance;
|
||||
|
||||
std::shared_ptr<shader_factory> streamfx::transition::shader::shader_factory::get()
|
||||
{
|
||||
return _transition_shader_factory_instance;
|
||||
}
|
||||
static auto loader = streamfx::loader(
|
||||
[]() { // Initalizer
|
||||
loader_instance = shader_factory::instance();
|
||||
},
|
||||
[]() { // Finalizer
|
||||
loader_instance.reset();
|
||||
},
|
||||
streamfx::loader_priority::NORMAL);
|
||||
|
|
|
@ -52,10 +52,6 @@ namespace streamfx::transition::shader {
|
|||
#endif
|
||||
|
||||
public: // Singleton
|
||||
static void initialize();
|
||||
|
||||
static void finalize();
|
||||
|
||||
static std::shared_ptr<shader_factory> get();
|
||||
static std::shared_ptr<shader_factory> instance();
|
||||
};
|
||||
} // namespace streamfx::transition::shader
|
||||
|
|
Loading…
Reference in a new issue