filter-shadow-sdf: Remove shadow_sdf namespace, rename shadow_sdf_instance to shadow_sdf

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-01-25 00:55:40 +01:00
parent 7708dd0792
commit 3ac7e46628
2 changed files with 116 additions and 120 deletions

View file

@ -41,11 +41,11 @@
// Initializer & Finalizer
INITIALIZER(filterShadowFactoryInitializer)
{
initializerFunctions.push_back([] { filter::shadow_sdf::shadow_sdf_factory::initialize(); });
finalizerFunctions.push_back([] { filter::shadow_sdf::shadow_sdf_factory::finalize(); });
initializerFunctions.push_back([] { filter::shadow_sdf_factory::initialize(); });
finalizerFunctions.push_back([] { filter::shadow_sdf_factory::finalize(); });
}
bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_inside(void*, obs_properties_t* props, obs_property*,
bool filter::shadow_sdf::cb_modified_inside(void*, obs_properties_t* props, obs_property*,
obs_data_t* settings)
{
bool v = obs_data_get_bool(settings, P_INNER);
@ -58,7 +58,7 @@ bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_inside(void*, obs_prop
return true;
}
bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_outside(void*, obs_properties_t* props, obs_property*,
bool filter::shadow_sdf::cb_modified_outside(void*, obs_properties_t* props, obs_property*,
obs_data_t* settings)
{
bool v = obs_data_get_bool(settings, P_OUTER);
@ -71,7 +71,7 @@ bool filter::shadow_sdf::shadow_sdf_instance::cb_modified_outside(void*, obs_pro
return true;
}
filter::shadow_sdf::shadow_sdf_instance::shadow_sdf_instance(obs_data_t* settings, obs_source_t* self)
filter::shadow_sdf::shadow_sdf(obs_data_t* settings, obs_source_t* self)
: m_self(self), m_source_rendered(false)
{
this->m_source_rt = std::make_shared<gs::rendertarget>(GS_RGBA, GS_ZS_NONE);
@ -86,9 +86,9 @@ filter::shadow_sdf::shadow_sdf_instance::shadow_sdf_instance(obs_data_t* setting
this->update(settings);
}
filter::shadow_sdf::shadow_sdf_instance::~shadow_sdf_instance() {}
filter::shadow_sdf::~shadow_sdf() {}
obs_properties_t* filter::shadow_sdf::shadow_sdf_instance::get_properties()
obs_properties_t* filter::shadow_sdf::get_properties()
{
obs_properties_t* props = obs_properties_create();
obs_property_t* p = nullptr;
@ -144,7 +144,7 @@ obs_properties_t* filter::shadow_sdf::shadow_sdf_instance::get_properties()
return props;
}
void filter::shadow_sdf::shadow_sdf_instance::update(obs_data_t* data)
void filter::shadow_sdf::update(obs_data_t* data)
{
this->m_inner_shadow = obs_data_get_bool(data, P_INNER);
this->m_inner_range_min = float_t(obs_data_get_double(data, P_INNER_RANGE_MINIMUM));
@ -169,27 +169,27 @@ void filter::shadow_sdf::shadow_sdf_instance::update(obs_data_t* data)
| (int32_t(obs_data_get_double(data, P_OUTER_ALPHA) * 2.55) << 24);
}
uint32_t filter::shadow_sdf::shadow_sdf_instance::get_width()
uint32_t filter::shadow_sdf::get_width()
{
return uint32_t(0);
}
uint32_t filter::shadow_sdf::shadow_sdf_instance::get_height()
uint32_t filter::shadow_sdf::get_height()
{
return uint32_t(0);
}
void filter::shadow_sdf::shadow_sdf_instance::activate() {}
void filter::shadow_sdf::activate() {}
void filter::shadow_sdf::shadow_sdf_instance::deactivate() {}
void filter::shadow_sdf::deactivate() {}
void filter::shadow_sdf::shadow_sdf_instance::video_tick(float time)
void filter::shadow_sdf::video_tick(float time)
{
this->m_tick += time;
m_source_rendered = false;
}
void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*)
void filter::shadow_sdf::video_render(gs_effect_t*)
{
obs_source_t* parent = obs_filter_get_parent(this->m_self);
obs_source_t* target = obs_filter_get_target(this->m_self);
@ -239,7 +239,7 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*)
}
std::shared_ptr<gs::effect> sdf_effect =
filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_generator_effect();
filter::shadow_sdf_factory::get()->get_sdf_generator_effect();
if (!sdf_effect) {
throw std::runtime_error("SDF Effect no loaded");
}
@ -275,7 +275,7 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*)
{
std::shared_ptr<gs::effect> shadow_effect =
filter::shadow_sdf::shadow_sdf_factory::get()->get_sdf_shadow_effect();
filter::shadow_sdf_factory::get()->get_sdf_shadow_effect();
if (!shadow_effect) {
throw std::runtime_error("Shadow Effect no loaded");
}
@ -339,7 +339,7 @@ void filter::shadow_sdf::shadow_sdf_instance::video_render(gs_effect_t*)
gs_enable_depth_test(false);
}
filter::shadow_sdf::shadow_sdf_factory::shadow_sdf_factory()
filter::shadow_sdf_factory::shadow_sdf_factory()
{
memset(&source_info, 0, sizeof(obs_source_info));
source_info.id = "obs-stream-effects-filter-shadow-sdf";
@ -360,9 +360,9 @@ filter::shadow_sdf::shadow_sdf_factory::shadow_sdf_factory()
obs_register_source(&source_info);
}
filter::shadow_sdf::shadow_sdf_factory::~shadow_sdf_factory() {}
filter::shadow_sdf_factory::~shadow_sdf_factory() {}
void filter::shadow_sdf::shadow_sdf_factory::on_list_fill()
void filter::shadow_sdf_factory::on_list_fill()
{
{
char* file = obs_module_file("effects/sdf-generator.effect");
@ -384,25 +384,25 @@ void filter::shadow_sdf::shadow_sdf_factory::on_list_fill()
}
}
void filter::shadow_sdf::shadow_sdf_factory::on_list_empty()
void filter::shadow_sdf_factory::on_list_empty()
{
sdf_generator_effect.reset();
sdf_shadow_effect.reset();
}
void* filter::shadow_sdf::shadow_sdf_factory::create(obs_data_t* data, obs_source_t* parent)
void* filter::shadow_sdf_factory::create(obs_data_t* data, obs_source_t* parent)
{
if (get()->sources.empty()) {
get()->on_list_fill();
}
filter::shadow_sdf::shadow_sdf_instance* ptr = new filter::shadow_sdf::shadow_sdf_instance(data, parent);
filter::shadow_sdf* ptr = new filter::shadow_sdf(data, parent);
get()->sources.push_back(ptr);
return ptr;
}
void filter::shadow_sdf::shadow_sdf_factory::destroy(void* inptr)
void filter::shadow_sdf_factory::destroy(void* inptr)
{
filter::shadow_sdf::shadow_sdf_instance* ptr = reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr);
filter::shadow_sdf* ptr = reinterpret_cast<filter::shadow_sdf*>(inptr);
get()->sources.remove(ptr);
if (get()->sources.empty()) {
get()->on_list_empty();
@ -410,7 +410,7 @@ void filter::shadow_sdf::shadow_sdf_factory::destroy(void* inptr)
delete ptr;
}
void filter::shadow_sdf::shadow_sdf_factory::get_defaults(obs_data_t* data)
void filter::shadow_sdf_factory::get_defaults(obs_data_t* data)
{
obs_data_set_bool(data, P_INNER, false);
obs_data_set_double(data, P_INNER_RANGE_MINIMUM, 0.0);
@ -429,74 +429,74 @@ void filter::shadow_sdf::shadow_sdf_factory::get_defaults(obs_data_t* data)
obs_data_set_double(data, P_OUTER_ALPHA, 100.0);
}
obs_properties_t* filter::shadow_sdf::shadow_sdf_factory::get_properties(void* inptr)
obs_properties_t* filter::shadow_sdf_factory::get_properties(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_properties();
return reinterpret_cast<filter::shadow_sdf*>(inptr)->get_properties();
}
void filter::shadow_sdf::shadow_sdf_factory::update(void* inptr, obs_data_t* settings)
void filter::shadow_sdf_factory::update(void* inptr, obs_data_t* settings)
{
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->update(settings);
reinterpret_cast<filter::shadow_sdf*>(inptr)->update(settings);
}
const char* filter::shadow_sdf::shadow_sdf_factory::get_name(void*)
const char* filter::shadow_sdf_factory::get_name(void*)
{
return P_TRANSLATE(SOURCE_NAME);
}
uint32_t filter::shadow_sdf::shadow_sdf_factory::get_width(void* inptr)
uint32_t filter::shadow_sdf_factory::get_width(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_width();
return reinterpret_cast<filter::shadow_sdf*>(inptr)->get_width();
}
uint32_t filter::shadow_sdf::shadow_sdf_factory::get_height(void* inptr)
uint32_t filter::shadow_sdf_factory::get_height(void* inptr)
{
return reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->get_height();
return reinterpret_cast<filter::shadow_sdf*>(inptr)->get_height();
}
void filter::shadow_sdf::shadow_sdf_factory::activate(void* inptr)
void filter::shadow_sdf_factory::activate(void* inptr)
{
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->activate();
reinterpret_cast<filter::shadow_sdf*>(inptr)->activate();
}
void filter::shadow_sdf::shadow_sdf_factory::deactivate(void* inptr)
void filter::shadow_sdf_factory::deactivate(void* inptr)
{
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->deactivate();
reinterpret_cast<filter::shadow_sdf*>(inptr)->deactivate();
}
void filter::shadow_sdf::shadow_sdf_factory::video_tick(void* inptr, float delta)
void filter::shadow_sdf_factory::video_tick(void* inptr, float delta)
{
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->video_tick(delta);
reinterpret_cast<filter::shadow_sdf*>(inptr)->video_tick(delta);
}
void filter::shadow_sdf::shadow_sdf_factory::video_render(void* inptr, gs_effect_t* effect)
void filter::shadow_sdf_factory::video_render(void* inptr, gs_effect_t* effect)
{
reinterpret_cast<filter::shadow_sdf::shadow_sdf_instance*>(inptr)->video_render(effect);
reinterpret_cast<filter::shadow_sdf*>(inptr)->video_render(effect);
}
std::shared_ptr<gs::effect> filter::shadow_sdf::shadow_sdf_factory::get_sdf_generator_effect()
std::shared_ptr<gs::effect> filter::shadow_sdf_factory::get_sdf_generator_effect()
{
return sdf_generator_effect;
}
std::shared_ptr<gs::effect> filter::shadow_sdf::shadow_sdf_factory::get_sdf_shadow_effect()
std::shared_ptr<gs::effect> filter::shadow_sdf_factory::get_sdf_shadow_effect()
{
return sdf_shadow_effect;
}
static filter::shadow_sdf::shadow_sdf_factory* factory_instance = nullptr;
static filter::shadow_sdf_factory* factory_instance = nullptr;
void filter::shadow_sdf::shadow_sdf_factory::initialize()
void filter::shadow_sdf_factory::initialize()
{
factory_instance = new filter::shadow_sdf::shadow_sdf_factory();
factory_instance = new filter::shadow_sdf_factory();
}
void filter::shadow_sdf::shadow_sdf_factory::finalize()
void filter::shadow_sdf_factory::finalize()
{
delete factory_instance;
}
filter::shadow_sdf::shadow_sdf_factory* filter::shadow_sdf::shadow_sdf_factory::get()
filter::shadow_sdf_factory* filter::shadow_sdf_factory::get()
{
return factory_instance;
}

View file

@ -40,99 +40,95 @@
#endif
namespace filter {
namespace shadow_sdf {
class shadow_sdf_instance {
obs_source_t* m_self;
class shadow_sdf {
obs_source_t* m_self;
// Input
std::shared_ptr<gs::rendertarget> m_source_rt;
std::shared_ptr<gs::texture> m_source_texture;
bool m_source_rendered;
// Input
std::shared_ptr<gs::rendertarget> m_source_rt;
std::shared_ptr<gs::texture> m_source_texture;
bool m_source_rendered;
// Distance Field
std::shared_ptr<gs::rendertarget> m_sdf_write, m_sdf_read;
std::shared_ptr<gs::texture> m_sdf_texture;
// Distance Field
std::shared_ptr<gs::rendertarget> m_sdf_write, m_sdf_read;
std::shared_ptr<gs::texture> m_sdf_texture;
float_t m_tick = 0.;
float_t m_tick = 0.;
bool m_inner_shadow;
float_t m_inner_range_min;
float_t m_inner_range_max;
float_t m_inner_offset_x;
float_t m_inner_offset_y;
uint32_t m_inner_color;
bool m_outer_shadow;
float_t m_outer_range_min;
float_t m_outer_range_max;
float_t m_outer_offset_x;
float_t m_outer_offset_y;
uint32_t m_outer_color;
bool m_inner_shadow;
float_t m_inner_range_min;
float_t m_inner_range_max;
float_t m_inner_offset_x;
float_t m_inner_offset_y;
uint32_t m_inner_color;
bool m_outer_shadow;
float_t m_outer_range_min;
float_t m_outer_range_max;
float_t m_outer_offset_x;
float_t m_outer_offset_y;
uint32_t m_outer_color;
static bool cb_modified_inside(void* ptr, obs_properties_t* props, obs_property* prop,
obs_data_t* settings);
static bool cb_modified_inside(void* ptr, obs_properties_t* props, obs_property* prop, obs_data_t* settings);
static bool cb_modified_outside(void* ptr, obs_properties_t* props, obs_property* prop,
obs_data_t* settings);
static bool cb_modified_outside(void* ptr, obs_properties_t* props, obs_property* prop, obs_data_t* settings);
public:
shadow_sdf_instance(obs_data_t* settings, obs_source_t* self);
~shadow_sdf_instance();
public:
shadow_sdf(obs_data_t* settings, obs_source_t* self);
~shadow_sdf();
obs_properties_t* get_properties();
void update(obs_data_t*);
obs_properties_t* get_properties();
void update(obs_data_t*);
uint32_t get_width();
uint32_t get_height();
uint32_t get_width();
uint32_t get_height();
void activate();
void deactivate();
void activate();
void deactivate();
void video_tick(float);
void video_render(gs_effect_t*);
};
void video_tick(float);
void video_render(gs_effect_t*);
};
class shadow_sdf_factory {
obs_source_info source_info;
std::list<shadow_sdf_instance*> sources;
class shadow_sdf_factory {
obs_source_info source_info;
std::list<shadow_sdf*> sources;
std::shared_ptr<gs::effect> sdf_generator_effect;
std::shared_ptr<gs::effect> sdf_shadow_effect;
std::shared_ptr<gs::effect> sdf_generator_effect;
std::shared_ptr<gs::effect> sdf_shadow_effect;
private:
shadow_sdf_factory();
~shadow_sdf_factory();
private:
shadow_sdf_factory();
~shadow_sdf_factory();
void on_list_fill();
void on_list_empty();
void on_list_fill();
void on_list_empty();
protected:
static void* create(obs_data_t* settings, obs_source_t* self);
static void destroy(void* source);
protected:
static void* create(obs_data_t* settings, obs_source_t* self);
static void destroy(void* source);
static void get_defaults(obs_data_t* settings);
static obs_properties_t* get_properties(void* source);
static void update(void* source, obs_data_t* settings);
static void get_defaults(obs_data_t* settings);
static obs_properties_t* get_properties(void* source);
static void update(void* source, obs_data_t* settings);
static const char* get_name(void* source);
static uint32_t get_width(void* source);
static uint32_t get_height(void* source);
static const char* get_name(void* source);
static uint32_t get_width(void* source);
static uint32_t get_height(void* source);
static void activate(void* source);
static void deactivate(void* source);
static void activate(void* source);
static void deactivate(void* source);
static void video_tick(void* source, float delta);
static void video_render(void* source, gs_effect_t* effect);
static void video_tick(void* source, float delta);
static void video_render(void* source, gs_effect_t* effect);
public:
std::shared_ptr<gs::effect> get_sdf_generator_effect();
std::shared_ptr<gs::effect> get_sdf_shadow_effect();
public:
std::shared_ptr<gs::effect> get_sdf_generator_effect();
std::shared_ptr<gs::effect> get_sdf_shadow_effect();
public: // Singleton
static void initialize();
static void finalize();
static shadow_sdf_factory* get();
};
} // namespace shadow_sdf
public: // Singleton
static void initialize();
static void finalize();
static shadow_sdf_factory* get();
};
} // namespace filter
#endif