gfx/shader/param: Track the parent shader object

This commit is contained in:
Michael Fabian 'Xaymar' Dirks 2021-11-25 05:57:37 +01:00
parent 69a72d4975
commit 22786005d6
5 changed files with 48 additions and 24 deletions

View file

@ -76,9 +76,10 @@ streamfx::gfx::shader::basic_field_type streamfx::gfx::shader::get_field_type_fr
return basic_field_type::Input; return basic_field_type::Input;
} }
streamfx::gfx::shader::basic_parameter::basic_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) streamfx::gfx::shader::basic_parameter::basic_parameter(streamfx::gfx::shader::shader* parent,
: parameter(param, prefix), _field_type(basic_field_type::Input), _suffix(), _keys(), _names(), _min(), _max(), streamfx::obs::gs::effect_parameter param, std::string prefix)
_step(), _values() : parameter(parent, param, prefix), _field_type(basic_field_type::Input), _suffix(), _keys(), _names(), _min(),
_max(), _step(), _values()
{ {
char string_buffer[256]; char string_buffer[256];
@ -161,8 +162,9 @@ void streamfx::gfx::shader::basic_parameter::load_parameter_data(streamfx::obs::
parameter.get_default_value(&data.i32, 1); parameter.get_default_value(&data.i32, 1);
} }
streamfx::gfx::shader::bool_parameter::bool_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) streamfx::gfx::shader::bool_parameter::bool_parameter(streamfx::gfx::shader::shader* parent,
: basic_parameter(param, prefix) streamfx::obs::gs::effect_parameter param, std::string prefix)
: basic_parameter(parent, param, prefix)
{ {
_min.resize(0); _min.resize(0);
_max.resize(0); _max.resize(0);
@ -214,8 +216,9 @@ void streamfx::gfx::shader::bool_parameter::assign()
get_parameter().set_value(_data.data(), _data.size()); get_parameter().set_value(_data.data(), _data.size());
} }
streamfx::gfx::shader::float_parameter::float_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) streamfx::gfx::shader::float_parameter::float_parameter(streamfx::gfx::shader::shader* parent,
: basic_parameter(param, prefix) streamfx::obs::gs::effect_parameter param, std::string prefix)
: basic_parameter(parent, param, prefix)
{ {
_data.resize(get_size()); _data.resize(get_size());
@ -341,8 +344,9 @@ static inline obs_property_t* build_int_property(streamfx::gfx::shader::basic_fi
} }
} }
streamfx::gfx::shader::int_parameter::int_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) streamfx::gfx::shader::int_parameter::int_parameter(streamfx::gfx::shader::shader* parent,
: basic_parameter(param, prefix) streamfx::obs::gs::effect_parameter param, std::string prefix)
: basic_parameter(parent, param, prefix)
{ {
_data.resize(get_size()); _data.resize(get_size());

View file

@ -62,7 +62,8 @@ namespace streamfx::gfx {
std::list<basic_enum_data> _values; std::list<basic_enum_data> _values;
public: public:
basic_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix); basic_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
std::string prefix);
virtual ~basic_parameter(); virtual ~basic_parameter();
virtual void load_parameter_data(streamfx::obs::gs::effect_parameter parameter, basic_data& data); virtual void load_parameter_data(streamfx::obs::gs::effect_parameter parameter, basic_data& data);
@ -98,7 +99,8 @@ namespace streamfx::gfx {
std::vector<int32_t> _data; std::vector<int32_t> _data;
public: public:
bool_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix); bool_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
std::string prefix);
virtual ~bool_parameter(); virtual ~bool_parameter();
void defaults(obs_data_t* settings) override; void defaults(obs_data_t* settings) override;
@ -114,7 +116,8 @@ namespace streamfx::gfx {
std::vector<basic_data> _data; std::vector<basic_data> _data;
public: public:
float_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix); float_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
std::string prefix);
virtual ~float_parameter(); virtual ~float_parameter();
void defaults(obs_data_t* settings) override; void defaults(obs_data_t* settings) override;
@ -130,7 +133,8 @@ namespace streamfx::gfx {
std::vector<basic_data> _data; std::vector<basic_data> _data;
public: public:
int_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix); int_parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
std::string prefix);
virtual ~int_parameter(); virtual ~int_parameter();
void defaults(obs_data_t* settings) override; void defaults(obs_data_t* settings) override;

View file

@ -111,8 +111,10 @@ streamfx::gfx::shader::parameter_type streamfx::gfx::shader::get_type_from_strin
throw std::invalid_argument("Invalid parameter type string."); throw std::invalid_argument("Invalid parameter type string.");
} }
streamfx::gfx::shader::parameter::parameter(streamfx::obs::gs::effect_parameter param, std::string key_prefix) streamfx::gfx::shader::parameter::parameter(streamfx::gfx::shader::shader* parent,
: _param(param), _order(0), _key(_param.get_name()), _visible(true), _automatic(false), _name(_key), _description() streamfx::obs::gs::effect_parameter param, std::string key_prefix)
: _parent(parent), _param(param), _order(0), _key(_param.get_name()), _visible(true), _automatic(false),
_name(_key), _description()
{ {
{ {
std::stringstream ss; std::stringstream ss;
@ -181,9 +183,10 @@ void streamfx::gfx::shader::parameter::visible(bool visible) {}
void streamfx::gfx::shader::parameter::active(bool active) {} void streamfx::gfx::shader::parameter::active(bool active) {}
std::shared_ptr<streamfx::gfx::shader::parameter> std::shared_ptr<streamfx::gfx::shader::parameter>
streamfx::gfx::shader::parameter::make_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix) streamfx::gfx::shader::parameter::make_parameter(streamfx::gfx::shader::shader* parent,
streamfx::obs::gs::effect_parameter param, std::string prefix)
{ {
if (!param) { if (!parent || !param) {
throw std::runtime_error("Bad call to make_parameter. This is a bug in the plugin."); throw std::runtime_error("Bad call to make_parameter. This is a bug in the plugin.");
} }
@ -195,11 +198,11 @@ std::shared_ptr<streamfx::gfx::shader::parameter>
switch (real_type) { switch (real_type) {
case parameter_type::Boolean: case parameter_type::Boolean:
return std::make_shared<streamfx::gfx::shader::bool_parameter>(param, prefix); return std::make_shared<streamfx::gfx::shader::bool_parameter>(parent, param, prefix);
case parameter_type::Integer: case parameter_type::Integer:
return std::make_shared<streamfx::gfx::shader::int_parameter>(param, prefix); return std::make_shared<streamfx::gfx::shader::int_parameter>(parent, param, prefix);
case parameter_type::Float: case parameter_type::Float:
return std::make_shared<streamfx::gfx::shader::float_parameter>(param, prefix); return std::make_shared<streamfx::gfx::shader::float_parameter>(parent, param, prefix);
default: default:
return nullptr; return nullptr;
} }

View file

@ -22,6 +22,8 @@
namespace streamfx::gfx { namespace streamfx::gfx {
namespace shader { namespace shader {
class shader;
enum class parameter_type { enum class parameter_type {
// Unknown type, could be anything. // Unknown type, could be anything.
Unknown, Unknown,
@ -46,6 +48,9 @@ namespace streamfx::gfx {
parameter_type get_type_from_string(std::string v); parameter_type get_type_from_string(std::string v);
class parameter { class parameter {
// Parent Shader
streamfx::gfx::shader::shader* _parent;
// Parameter used for all functionality. // Parameter used for all functionality.
streamfx::obs::gs::effect_parameter _param; streamfx::obs::gs::effect_parameter _param;
@ -68,7 +73,8 @@ namespace streamfx::gfx {
std::string _description; std::string _description;
protected: protected:
parameter(streamfx::obs::gs::effect_parameter param, std::string key_prefix); parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
std::string key_prefix);
virtual ~parameter(){}; virtual ~parameter(){};
public: public:
@ -85,6 +91,11 @@ namespace streamfx::gfx {
virtual void active(bool enabled); virtual void active(bool enabled);
public: public:
inline streamfx::gfx::shader::shader* get_parent()
{
return _parent;
}
inline streamfx::obs::gs::effect_parameter get_parameter() inline streamfx::obs::gs::effect_parameter get_parameter()
{ {
return _param; return _param;
@ -141,7 +152,8 @@ namespace streamfx::gfx {
} }
public: public:
static std::shared_ptr<parameter> make_parameter(streamfx::obs::gs::effect_parameter param, static std::shared_ptr<parameter> make_parameter(streamfx::gfx::shader::shader* parent,
streamfx::obs::gs::effect_parameter param,
std::string prefix); std::string prefix);
}; };
} // namespace shader } // namespace shader

View file

@ -152,7 +152,7 @@ try {
if (fnd != _shader_params.end()) if (fnd != _shader_params.end())
continue; continue;
auto param = streamfx::gfx::shader::parameter::make_parameter(el, ST_KEY_PARAMETERS); auto param = streamfx::gfx::shader::parameter::make_parameter(this, el, ST_KEY_PARAMETERS);
if (param) { if (param) {
_shader_params.insert_or_assign(el_name, param); _shader_params.insert_or_assign(el_name, param);
@ -616,6 +616,7 @@ void streamfx::gfx::shader::shader::set_active(bool active)
} }
} }
obs_source_t* streamfx::gfx::shader::shader::get() { obs_source_t* streamfx::gfx::shader::shader::get()
{
return _self; return _self;
} }