gfx-effect-source: enumerate child sources correctly

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2019-08-07 20:39:55 +02:00
parent 747079b8c6
commit 250dc97603
6 changed files with 97 additions and 12 deletions

View file

@ -114,6 +114,16 @@ filter::shader::shader_factory::shader_factory()
}
return uint32_t(0);
};
_source_info.load = [](void* ptr, obs_data_t* data) {
try {
if (ptr)
reinterpret_cast<filter::shader::shader_instance*>(ptr)->load(data);
} catch (std::exception& ex) {
P_LOG_ERROR("<filter-shader> Failed to load, error: %s", ex.what());
} catch (...) {
P_LOG_ERROR("<filter-shader> Failed to load.");
}
};
_source_info.update = [](void* ptr, obs_data_t* data) {
try {
if (ptr)
@ -164,6 +174,16 @@ filter::shader::shader_factory::shader_factory()
P_LOG_ERROR("<filter-shader> Failed to render.");
}
};
_source_info.enum_active_sources = [](void* ptr, obs_source_enum_proc_t enum_callback, void* param) {
try {
if (ptr)
reinterpret_cast<filter::shader::shader_instance*>(ptr)->enum_active_sources(enum_callback, param);
} catch (std::exception& ex) {
P_LOG_ERROR("<filter-shader> Failed to enumerate sources, error: %s", ex.what());
} catch (...) {
P_LOG_ERROR("<filter-shader> Failed to enumerate sources.");
}
};
obs_register_source(&_source_info);
}
@ -200,6 +220,11 @@ void filter::shader::shader_instance::properties(obs_properties_t* props)
_fx->properties(props);
}
void filter::shader::shader_instance::load(obs_data_t* data)
{
update(data);
}
void filter::shader::shader_instance::update(obs_data_t* data)
{
_fx->update(data);
@ -243,6 +268,11 @@ void filter::shader::shader_instance::override_param(std::shared_ptr<gs::effect>
}
}
void filter::shader::shader_instance::enum_active_sources(obs_source_enum_proc_t r, void* p)
{
_fx->enum_active_sources(r, p);
}
void filter::shader::shader_instance::video_tick(float_t sec_since_last)
{
obs_source_t* target = obs_filter_get_target(_self);

View file

@ -67,6 +67,7 @@ namespace filter {
void properties(obs_properties_t* props);
void load(obs_data_t* data);
void update(obs_data_t* data);
void activate();
@ -75,6 +76,8 @@ namespace filter {
bool valid_param(std::shared_ptr<gs::effect_parameter> param);
void override_param(std::shared_ptr<gs::effect> effect);
void enum_active_sources(obs_source_enum_proc_t, void*);
void video_tick(float_t sec_since_last);
void video_render(gs_effect_t* effect);
};

View file

@ -138,8 +138,8 @@ gfx::effect_source::bool_parameter::bool_parameter(std::shared_ptr<gfx::effect_s
void gfx::effect_source::bool_parameter::defaults(obs_properties_t* props, obs_data_t* data)
{
obs_data_set_default_bool(data, _name.c_str(), _value);
obs_data_set_bool(data, _name.c_str(), _value);
//obs_data_set_default_bool(data, _name.c_str(), _value);
//obs_data_set_bool(data, _name.c_str(), _value);
}
void gfx::effect_source::bool_parameter::properties(obs_properties_t* props)
@ -306,7 +306,7 @@ gfx::effect_source::value_parameter::value_parameter(std::shared_ptr<gfx::effect
void gfx::effect_source::value_parameter::defaults(obs_properties_t* props, obs_data_t* data)
{
bool is_int = false;
/*bool is_int = false;
size_t limit = 0;
switch (_param->get_type()) {
@ -352,7 +352,7 @@ void gfx::effect_source::value_parameter::defaults(obs_properties_t* props, obs_
obs_data_set_default_double(data, _cache.name[idx].c_str(), _value.f[idx]);
obs_data_set_double(data, _cache.name[idx].c_str(), _value.f[idx]);
}
}
}*/
}
void gfx::effect_source::value_parameter::properties(obs_properties_t* props)
@ -615,7 +615,7 @@ gfx::effect_source::matrix_parameter::matrix_parameter(std::shared_ptr<gfx::effe
void gfx::effect_source::matrix_parameter::defaults(obs_properties_t* props, obs_data_t* data)
{
for (size_t x = 0; x < 4; x++) {
/*for (size_t x = 0; x < 4; x++) {
vec4& v_ref = _value.x;
if (x == 0) {
vec4& v_ref = _value.x;
@ -629,10 +629,9 @@ void gfx::effect_source::matrix_parameter::defaults(obs_properties_t* props, obs
for (size_t y = 0; y < 4; y++) {
size_t idx = x * 4 + y;
obs_data_set_double(data, _cache.name[idx].c_str(), v_ref.ptr[y]);
obs_data_set_default_double(data, _cache.name[idx].c_str(), v_ref.ptr[y]);
}
}
}*/
}
void gfx::effect_source::matrix_parameter::properties(obs_properties_t* props)
@ -794,9 +793,9 @@ bool gfx::effect_source::texture_parameter::modified2(obs_properties_t* props, o
void gfx::effect_source::texture_parameter::defaults(obs_properties_t* props, obs_data_t* data)
{
obs_data_set_int(data, _cache.name[0].c_str(), static_cast<int64_t>(_mode));
obs_data_set_string(data, _cache.name[1].c_str(), _file_name.c_str());
obs_data_set_string(data, _cache.name[2].c_str(), _source_name.c_str());
obs_data_set_default_int(data, _cache.name[0].c_str(), static_cast<int64_t>(_mode));
obs_data_set_default_string(data, _cache.name[1].c_str(), _file_name.c_str());
obs_data_set_default_string(data, _cache.name[2].c_str(), _source_name.c_str());
}
void gfx::effect_source::texture_parameter::properties(obs_properties_t* props)
@ -908,6 +907,13 @@ void gfx::effect_source::texture_parameter::assign()
}
}
void gfx::effect_source::texture_parameter::enum_active_sources(obs_source_enum_proc_t p, void* t)
{
if ((_mode == texture_mode::SOURCE) && !_parent.expired() && _source) {
p(_parent.lock()->get_self(), _source->get(), t);
}
}
bool gfx::effect_source::effect_source::modified2(obs_properties_t* props, obs_property_t* property,
obs_data_t* settings)
{
@ -1148,6 +1154,14 @@ obs_source_t* gfx::effect_source::effect_source::get_self()
return _self;
}
void gfx::effect_source::effect_source::enum_active_sources(obs_source_enum_proc_t p, void* t)
{
for (auto& kv : _params) {
if (kv.second)
kv.second->enum_active_sources(p, t);
}
}
void gfx::effect_source::effect_source::set_valid_property_cb(valid_property_cb_t cb)
{
_cb_valid = cb;

View file

@ -98,6 +98,8 @@ namespace gfx {
std::shared_ptr<gs::effect_parameter> get_param();
virtual void enum_active_sources(obs_source_enum_proc_t, void*){};
public:
static std::shared_ptr<gfx::effect_source::parameter>
create(std::shared_ptr<gfx::effect_source::effect_source> parent, std::shared_ptr<gs::effect> effect,
@ -265,6 +267,8 @@ namespace gfx {
virtual void prepare() override;
virtual void assign() override;
virtual void enum_active_sources(obs_source_enum_proc_t, void*) override;
};
typedef std::pair<gs::effect_parameter::type, std::string> param_ident_t;
@ -314,6 +318,8 @@ namespace gfx {
obs_source_t* get_self();
void enum_active_sources(obs_source_enum_proc_t, void*);
public:
void set_valid_property_cb(valid_property_cb_t cb);

View file

@ -118,6 +118,16 @@ source::shader::shader_factory::shader_factory()
}
return uint32_t(0);
};
_source_info.load = [](void* ptr, obs_data_t* data) {
try {
if (ptr)
reinterpret_cast<source::shader::shader_instance*>(ptr)->load(data);
} catch (std::exception& ex) {
P_LOG_ERROR("<source-shader> Failed to load, error: %s", ex.what());
} catch (...) {
P_LOG_ERROR("<source-shader> Failed to load.");
}
};
_source_info.update = [](void* ptr, obs_data_t* data) {
try {
if (ptr)
@ -168,6 +178,16 @@ source::shader::shader_factory::shader_factory()
P_LOG_ERROR("<source-shader> Failed to render.");
}
};
_source_info.enum_active_sources = [](void* ptr, obs_source_enum_proc_t enum_callback, void* param) {
try {
if (ptr)
reinterpret_cast<source::shader::shader_instance*>(ptr)->enum_active_sources(enum_callback, param);
} catch (std::exception& ex) {
P_LOG_ERROR("<source-shader> Failed to enumerate sources, error: %s", ex.what());
} catch (...) {
P_LOG_ERROR("<source-shader> Failed to enumerate sources.");
}
};
obs_register_source(&_source_info);
}
@ -206,6 +226,11 @@ void source::shader::shader_instance::properties(obs_properties_t* props)
_fx->properties(props);
}
void source::shader::shader_instance::load(obs_data_t* data)
{
update(data);
}
void source::shader::shader_instance::update(obs_data_t* data)
{
_width = obs_data_get_int(data, ST_WIDTH);
@ -231,6 +256,10 @@ bool source::shader::shader_instance::valid_param(std::shared_ptr<gs::effect_par
void source::shader::shader_instance::override_param(std::shared_ptr<gs::effect> effect) {}
void source::shader::shader_instance::enum_active_sources(obs_source_enum_proc_t r, void* p) {
_fx->enum_active_sources(r, p);
}
void source::shader::shader_instance::video_tick(float_t sec_since_last)
{
if (_fx->tick(sec_since_last)) {

View file

@ -63,6 +63,7 @@ namespace source {
void properties(obs_properties_t* props);
void load(obs_data_t* data);
void update(obs_data_t* data);
void activate();
@ -71,6 +72,8 @@ namespace source {
bool valid_param(std::shared_ptr<gs::effect_parameter> param);
void override_param(std::shared_ptr<gs::effect> effect);
void enum_active_sources(obs_source_enum_proc_t, void*);
void video_tick(float_t sec_since_last);
void video_render(gs_effect_t* effect);
};