mirror of
https://github.com/Xaymar/obs-StreamFX
synced 2024-11-11 06:15:05 +00:00
gfx-shader-param: Add support for automatic parameters
Allows other parameters to be a seed to these parameters.
This commit is contained in:
parent
907216f143
commit
1902d005e9
4 changed files with 30 additions and 2 deletions
|
@ -190,6 +190,9 @@ void gfx::shader::bool_parameter::defaults(obs_data_t* settings)
|
||||||
|
|
||||||
void gfx::shader::bool_parameter::properties(obs_properties_t* props, obs_data_t* settings)
|
void gfx::shader::bool_parameter::properties(obs_properties_t* props, obs_data_t* settings)
|
||||||
{
|
{
|
||||||
|
if (!is_visible())
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: Support for bool[]
|
// TODO: Support for bool[]
|
||||||
if (get_size() == 1) {
|
if (get_size() == 1) {
|
||||||
auto p = obs_properties_add_list(props, get_key().c_str(), get_name().c_str(), OBS_COMBO_TYPE_LIST,
|
auto p = obs_properties_add_list(props, get_key().c_str(), get_name().c_str(), OBS_COMBO_TYPE_LIST,
|
||||||
|
@ -203,6 +206,9 @@ void gfx::shader::bool_parameter::properties(obs_properties_t* props, obs_data_t
|
||||||
|
|
||||||
void gfx::shader::bool_parameter::update(obs_data_t* settings)
|
void gfx::shader::bool_parameter::update(obs_data_t* settings)
|
||||||
{
|
{
|
||||||
|
if (is_automatic())
|
||||||
|
return;
|
||||||
|
|
||||||
// TODO: Support for bool[]
|
// TODO: Support for bool[]
|
||||||
if (get_size() == 1) {
|
if (get_size() == 1) {
|
||||||
_data[0] = static_cast<bool>(obs_data_get_int(settings, get_key().c_str()));
|
_data[0] = static_cast<bool>(obs_data_get_int(settings, get_key().c_str()));
|
||||||
|
@ -286,6 +292,9 @@ static inline obs_property_t* build_float_property(gfx::shader::basic_field_type
|
||||||
|
|
||||||
void gfx::shader::float_parameter::properties(obs_properties_t* props, obs_data_t* settings)
|
void gfx::shader::float_parameter::properties(obs_properties_t* props, obs_data_t* settings)
|
||||||
{
|
{
|
||||||
|
if (!is_visible())
|
||||||
|
return;
|
||||||
|
|
||||||
auto grp = obs_properties_create();
|
auto grp = obs_properties_create();
|
||||||
if (get_size() == 1) {
|
if (get_size() == 1) {
|
||||||
auto p = build_float_property(_field_type, props, _keys[0].c_str(), _names[0].c_str(), _min[0].f32, _max[0].f32,
|
auto p = build_float_property(_field_type, props, _keys[0].c_str(), _names[0].c_str(), _min[0].f32, _max[0].f32,
|
||||||
|
@ -316,6 +325,9 @@ void gfx::shader::float_parameter::update(obs_data_t* settings)
|
||||||
|
|
||||||
void gfx::shader::float_parameter::assign()
|
void gfx::shader::float_parameter::assign()
|
||||||
{
|
{
|
||||||
|
if (is_automatic())
|
||||||
|
return;
|
||||||
|
|
||||||
get_parameter().set_value(_data.data(), get_size());
|
get_parameter().set_value(_data.data(), get_size());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
|
|
||||||
#define ANNO_ORDER "order"
|
#define ANNO_ORDER "order"
|
||||||
#define ANNO_VISIBILITY "visible"
|
#define ANNO_VISIBILITY "visible"
|
||||||
|
#define ANNO_AUTOMATIC "automatic"
|
||||||
#define ANNO_NAME "name"
|
#define ANNO_NAME "name"
|
||||||
#define ANNO_DESCRIPTION "description"
|
#define ANNO_DESCRIPTION "description"
|
||||||
#define ANNO_TYPE "type"
|
#define ANNO_TYPE "type"
|
||||||
|
@ -118,6 +119,14 @@ gfx::shader::parameter::parameter(gs::effect_parameter param, std::string key_pr
|
||||||
_name = (_key);
|
_name = (_key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Read Order
|
||||||
|
if (auto anno = _param.get_annotation(ANNO_VISIBILITY); anno) {
|
||||||
|
_visible = anno.get_default_bool();
|
||||||
|
}
|
||||||
|
if (auto anno = _param.get_annotation(ANNO_AUTOMATIC); anno) {
|
||||||
|
_automatic = anno.get_default_bool();
|
||||||
|
}
|
||||||
|
|
||||||
// Read Order
|
// Read Order
|
||||||
if (auto anno = _param.get_annotation(ANNO_ORDER); anno) {
|
if (auto anno = _param.get_annotation(ANNO_ORDER); anno) {
|
||||||
_order = anno.get_default_int();
|
_order = anno.get_default_int();
|
||||||
|
@ -196,6 +205,11 @@ bool gfx::shader::parameter::is_visible()
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool gfx::shader::parameter::is_automatic()
|
||||||
|
{
|
||||||
|
return _automatic;
|
||||||
|
}
|
||||||
|
|
||||||
bool gfx::shader::parameter::has_name()
|
bool gfx::shader::parameter::has_name()
|
||||||
{
|
{
|
||||||
return _name.length() > 0;
|
return _name.length() > 0;
|
||||||
|
|
|
@ -75,6 +75,7 @@ namespace gfx {
|
||||||
|
|
||||||
// Visibility, name and description.
|
// Visibility, name and description.
|
||||||
bool _visible;
|
bool _visible;
|
||||||
|
bool _automatic;
|
||||||
std::string _name;
|
std::string _name;
|
||||||
std::string _description;
|
std::string _description;
|
||||||
|
|
||||||
|
@ -104,6 +105,8 @@ namespace gfx {
|
||||||
|
|
||||||
bool is_visible();
|
bool is_visible();
|
||||||
|
|
||||||
|
bool is_automatic();
|
||||||
|
|
||||||
bool has_name();
|
bool has_name();
|
||||||
|
|
||||||
const std::string& get_name();
|
const std::string& get_name();
|
||||||
|
|
|
@ -243,8 +243,7 @@ bool gfx::shader::shader::on_properties_modified(obs_properties_t* props, obs_pr
|
||||||
|
|
||||||
// Rebuild new parameters.
|
// Rebuild new parameters.
|
||||||
for (auto kv : _shader_params) {
|
for (auto kv : _shader_params) {
|
||||||
if (kv.second->is_visible())
|
kv.second->properties(grp, data);
|
||||||
kv.second->properties(grp, data);
|
|
||||||
kv.second->defaults(data);
|
kv.second->defaults(data);
|
||||||
kv.second->update(data);
|
kv.second->update(data);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue