mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-12-03 16:47:26 +00:00
gfx/shader/param: Track the parent shader object
This commit is contained in:
parent
69a72d4975
commit
22786005d6
5 changed files with 48 additions and 24 deletions
|
@ -76,9 +76,10 @@ streamfx::gfx::shader::basic_field_type streamfx::gfx::shader::get_field_type_fr
|
|||
return basic_field_type::Input;
|
||||
}
|
||||
|
||||
streamfx::gfx::shader::basic_parameter::basic_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: parameter(param, prefix), _field_type(basic_field_type::Input), _suffix(), _keys(), _names(), _min(), _max(),
|
||||
_step(), _values()
|
||||
streamfx::gfx::shader::basic_parameter::basic_parameter(streamfx::gfx::shader::shader* parent,
|
||||
streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: parameter(parent, param, prefix), _field_type(basic_field_type::Input), _suffix(), _keys(), _names(), _min(),
|
||||
_max(), _step(), _values()
|
||||
{
|
||||
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);
|
||||
}
|
||||
|
||||
streamfx::gfx::shader::bool_parameter::bool_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: basic_parameter(param, prefix)
|
||||
streamfx::gfx::shader::bool_parameter::bool_parameter(streamfx::gfx::shader::shader* parent,
|
||||
streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: basic_parameter(parent, param, prefix)
|
||||
{
|
||||
_min.resize(0);
|
||||
_max.resize(0);
|
||||
|
@ -214,8 +216,9 @@ void streamfx::gfx::shader::bool_parameter::assign()
|
|||
get_parameter().set_value(_data.data(), _data.size());
|
||||
}
|
||||
|
||||
streamfx::gfx::shader::float_parameter::float_parameter(streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: basic_parameter(param, prefix)
|
||||
streamfx::gfx::shader::float_parameter::float_parameter(streamfx::gfx::shader::shader* parent,
|
||||
streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: basic_parameter(parent, param, prefix)
|
||||
{
|
||||
_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)
|
||||
: basic_parameter(param, prefix)
|
||||
streamfx::gfx::shader::int_parameter::int_parameter(streamfx::gfx::shader::shader* parent,
|
||||
streamfx::obs::gs::effect_parameter param, std::string prefix)
|
||||
: basic_parameter(parent, param, prefix)
|
||||
{
|
||||
_data.resize(get_size());
|
||||
|
||||
|
|
|
@ -62,7 +62,8 @@ namespace streamfx::gfx {
|
|||
std::list<basic_enum_data> _values;
|
||||
|
||||
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 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;
|
||||
|
||||
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();
|
||||
|
||||
void defaults(obs_data_t* settings) override;
|
||||
|
@ -114,7 +116,8 @@ namespace streamfx::gfx {
|
|||
std::vector<basic_data> _data;
|
||||
|
||||
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();
|
||||
|
||||
void defaults(obs_data_t* settings) override;
|
||||
|
@ -130,7 +133,8 @@ namespace streamfx::gfx {
|
|||
std::vector<basic_data> _data;
|
||||
|
||||
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();
|
||||
|
||||
void defaults(obs_data_t* settings) override;
|
||||
|
|
|
@ -111,8 +111,10 @@ streamfx::gfx::shader::parameter_type streamfx::gfx::shader::get_type_from_strin
|
|||
throw std::invalid_argument("Invalid parameter type string.");
|
||||
}
|
||||
|
||||
streamfx::gfx::shader::parameter::parameter(streamfx::obs::gs::effect_parameter param, std::string key_prefix)
|
||||
: _param(param), _order(0), _key(_param.get_name()), _visible(true), _automatic(false), _name(_key), _description()
|
||||
streamfx::gfx::shader::parameter::parameter(streamfx::gfx::shader::shader* parent,
|
||||
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;
|
||||
|
@ -181,9 +183,10 @@ void streamfx::gfx::shader::parameter::visible(bool visible) {}
|
|||
void streamfx::gfx::shader::parameter::active(bool active) {}
|
||||
|
||||
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.");
|
||||
}
|
||||
|
||||
|
@ -195,11 +198,11 @@ std::shared_ptr<streamfx::gfx::shader::parameter>
|
|||
|
||||
switch (real_type) {
|
||||
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:
|
||||
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:
|
||||
return std::make_shared<streamfx::gfx::shader::float_parameter>(param, prefix);
|
||||
return std::make_shared<streamfx::gfx::shader::float_parameter>(parent, param, prefix);
|
||||
default:
|
||||
return nullptr;
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
|
||||
namespace streamfx::gfx {
|
||||
namespace shader {
|
||||
class shader;
|
||||
|
||||
enum class parameter_type {
|
||||
// Unknown type, could be anything.
|
||||
Unknown,
|
||||
|
@ -46,6 +48,9 @@ namespace streamfx::gfx {
|
|||
parameter_type get_type_from_string(std::string v);
|
||||
|
||||
class parameter {
|
||||
// Parent Shader
|
||||
streamfx::gfx::shader::shader* _parent;
|
||||
|
||||
// Parameter used for all functionality.
|
||||
streamfx::obs::gs::effect_parameter _param;
|
||||
|
||||
|
@ -68,7 +73,8 @@ namespace streamfx::gfx {
|
|||
std::string _description;
|
||||
|
||||
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(){};
|
||||
|
||||
public:
|
||||
|
@ -85,6 +91,11 @@ namespace streamfx::gfx {
|
|||
virtual void active(bool enabled);
|
||||
|
||||
public:
|
||||
inline streamfx::gfx::shader::shader* get_parent()
|
||||
{
|
||||
return _parent;
|
||||
}
|
||||
|
||||
inline streamfx::obs::gs::effect_parameter get_parameter()
|
||||
{
|
||||
return _param;
|
||||
|
@ -141,7 +152,8 @@ namespace streamfx::gfx {
|
|||
}
|
||||
|
||||
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);
|
||||
};
|
||||
} // namespace shader
|
||||
|
|
|
@ -152,7 +152,7 @@ try {
|
|||
if (fnd != _shader_params.end())
|
||||
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) {
|
||||
_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;
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue