2019-12-18 05:37:38 +00:00
|
|
|
// Modern effects for a modern Streamer
|
|
|
|
// Copyright (C) 2019 Michael Fabian Dirks
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation; either version 2 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with this program; if not, write to the Free Software
|
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
|
|
|
|
|
|
|
#pragma once
|
2020-04-02 15:02:01 +00:00
|
|
|
#include <list>
|
2020-04-05 04:13:14 +00:00
|
|
|
#include <string>
|
2019-12-18 05:37:38 +00:00
|
|
|
#include "obs/gs/gs-effect-parameter.hpp"
|
|
|
|
|
2021-06-08 02:47:04 +00:00
|
|
|
namespace streamfx::gfx {
|
2019-12-18 05:37:38 +00:00
|
|
|
namespace shader {
|
2021-11-25 04:57:37 +00:00
|
|
|
class shader;
|
|
|
|
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
enum class parameter_type {
|
|
|
|
// Unknown type, could be anything.
|
|
|
|
Unknown,
|
|
|
|
// Boolean, either false or true.
|
|
|
|
Boolean,
|
|
|
|
// Single Floating Point
|
|
|
|
Float,
|
|
|
|
// 32-Bit Integer
|
|
|
|
Integer,
|
|
|
|
// UTF-8 Character based String.
|
|
|
|
String,
|
|
|
|
// Texture with dimensions stored in size (1 = Texture1D, 2 = Texture2D, 3 = Texture3D, 6 = TextureCube).
|
|
|
|
Texture,
|
|
|
|
// Sampler for Textures.
|
|
|
|
Sampler
|
|
|
|
};
|
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
parameter_type get_type_from_effect_type(streamfx::obs::gs::effect_parameter::type type);
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
std::size_t get_length_from_effect_type(streamfx::obs::gs::effect_parameter::type type);
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
|
|
|
|
parameter_type get_type_from_string(std::string v);
|
|
|
|
|
2019-12-18 05:37:38 +00:00
|
|
|
class parameter {
|
2021-11-25 04:57:37 +00:00
|
|
|
// Parent Shader
|
|
|
|
streamfx::gfx::shader::shader* _parent;
|
|
|
|
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
// Parameter used for all functionality.
|
2021-06-08 02:38:24 +00:00
|
|
|
streamfx::obs::gs::effect_parameter _param;
|
2019-12-18 05:37:38 +00:00
|
|
|
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
// Real type of the parameter (libobs gets it wrong often).
|
|
|
|
parameter_type _type;
|
|
|
|
|
|
|
|
// Real size of the parameter (libobs gets it wrong often).
|
2020-04-08 21:38:42 +00:00
|
|
|
std::size_t _size;
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
|
|
|
|
// Order of the parameter in a list/map.
|
|
|
|
int32_t _order;
|
|
|
|
|
|
|
|
// Key for the parameter (group) in a list/map.
|
2019-12-24 07:38:01 +00:00
|
|
|
std::string _key;
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
|
|
|
|
// Visibility, name and description.
|
|
|
|
bool _visible;
|
2019-12-25 18:09:30 +00:00
|
|
|
bool _automatic;
|
2019-12-24 07:38:01 +00:00
|
|
|
std::string _name;
|
|
|
|
std::string _description;
|
|
|
|
|
gfx-shader-param: Vastly improve parameter functionality
Allow for overriding type and size of an element, opening the path for `int#[]`, `float#[]`, `int#x#`, `float#x#`, `bool#x#`, `vector<type, #>` and `matrix<type, #, #>`. Also allows for specifying the exact type of texture instead of hoping the user gets it right, as well as samplers.
Parameters are also now created if they are invisible, which means that the properties() function must not be called, but they must still be used like any other. This is due to a problem with default values not being applied all the time, and sometimes just vanishing.
The code also now throws exceptions with reasonable text, which should be caught by the gfx::shader implementation and refuse a load of the effect. No other state should be modified at that point, so care must be taken that up until the moment the complete initialization is done no other state is modified.
2019-12-24 21:02:37 +00:00
|
|
|
protected:
|
2021-11-25 04:57:37 +00:00
|
|
|
parameter(streamfx::gfx::shader::shader* parent, streamfx::obs::gs::effect_parameter param,
|
|
|
|
std::string key_prefix);
|
2019-12-18 05:37:38 +00:00
|
|
|
virtual ~parameter(){};
|
|
|
|
|
2019-12-25 09:09:56 +00:00
|
|
|
public:
|
2019-12-22 05:07:37 +00:00
|
|
|
virtual void defaults(obs_data_t* settings);
|
|
|
|
|
2019-12-18 05:37:38 +00:00
|
|
|
virtual void properties(obs_properties_t* props, obs_data_t* settings);
|
|
|
|
|
|
|
|
virtual void update(obs_data_t* settings);
|
|
|
|
|
|
|
|
virtual void assign();
|
|
|
|
|
2021-10-15 14:30:01 +00:00
|
|
|
virtual void visible(bool visible);
|
|
|
|
|
|
|
|
virtual void active(bool enabled);
|
|
|
|
|
2019-12-24 07:38:01 +00:00
|
|
|
public:
|
2021-11-25 04:57:37 +00:00
|
|
|
inline streamfx::gfx::shader::shader* get_parent()
|
|
|
|
{
|
|
|
|
return _parent;
|
|
|
|
}
|
|
|
|
|
2021-06-08 02:38:24 +00:00
|
|
|
inline streamfx::obs::gs::effect_parameter get_parameter()
|
2020-05-13 06:41:32 +00:00
|
|
|
{
|
|
|
|
return _param;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline parameter_type get_type()
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::size_t get_size()
|
|
|
|
{
|
|
|
|
return _size;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline int32_t get_order()
|
|
|
|
{
|
|
|
|
return _order;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string_view get_key()
|
|
|
|
{
|
|
|
|
return _key;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_visible()
|
|
|
|
{
|
|
|
|
return _visible && !_automatic;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool is_automatic()
|
|
|
|
{
|
|
|
|
return _automatic;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool has_name()
|
|
|
|
{
|
|
|
|
return _name.length() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string_view get_name()
|
|
|
|
{
|
|
|
|
return _name;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline bool has_description()
|
|
|
|
{
|
|
|
|
return _description.length() > 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
inline std::string_view get_description()
|
|
|
|
{
|
|
|
|
return _description;
|
|
|
|
}
|
2019-12-24 07:38:01 +00:00
|
|
|
|
2019-12-18 05:37:38 +00:00
|
|
|
public:
|
2021-11-25 04:57:37 +00:00
|
|
|
static std::shared_ptr<parameter> make_parameter(streamfx::gfx::shader::shader* parent,
|
|
|
|
streamfx::obs::gs::effect_parameter param,
|
2021-06-08 02:38:24 +00:00
|
|
|
std::string prefix);
|
2019-12-18 05:37:38 +00:00
|
|
|
};
|
|
|
|
} // namespace shader
|
2021-06-08 02:47:04 +00:00
|
|
|
} // namespace streamfx::gfx
|