Loading [MathJax]/extensions/TeX/AMSmath.js
Radium Engine  1.7.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
RenderParameters.hpp
1#pragma once
2
3#include <Engine/RaEngine.hpp>
4
5#include <vector>
6
7#include <nlohmann/json.hpp>
8
9#include <Core/Types.hpp>
10#include <Core/Utils/Color.hpp>
11#include <Core/Utils/EnumConverter.hpp>
12#include <Core/Utils/Log.hpp>
13#include <Core/Utils/StdOptional.hpp>
14
15#include <Core/Containers/VariableSet.hpp>
16
17#include <Engine/Data/ShaderProgram.hpp>
18
19namespace Ra {
20namespace Engine {
21namespace Data {
22
23class Texture;
24
34class RA_ENGINE_API RenderParameters final : public Core::VariableSet
35{
36 public:
41
43 using BindableTypes = Core::Utils::TypeList<bool,
45 int,
46 uint,
47 Scalar,
52 Core::Vector2,
53 Core::Vector3,
54 Core::Vector4,
55 Core::Matrix2,
56 Core::Matrix3,
57 Core::Matrix4,
59
70 template <typename T,
72 void setTexture( const std::string& name, T* tex, int texUnit = -1 ) {
73 setVariable( name, TextureInfo { tex, texUnit } );
74 }
75
76 using VariableSet::setVariable;
77
79 void setVariable( const std::string& name, RenderParameters& rp ) {
80 VariableSet::setVariable( name, std::ref( rp ) );
81 }
82 void setVariable( const std::string& name, const RenderParameters& rp ) {
83 VariableSet::setVariable( name, std::cref( rp ) );
84 }
85
91 void bind( const Data::ShaderProgram* shader ) const {
92 visit( StaticParameterBinder {}, shader );
93 }
94
95 private:
100 class StaticParameterBinder
101 {
102 public:
104 using types = BindableTypes;
105
108 void operator()( const std::string& name,
109 const Ra::Core::Utils::Color& p,
110 const Data::ShaderProgram* shader ) {
111 shader->setUniform( name.c_str(), Ra::Core::Utils::Color::VectorType( p ) );
112 }
113
116 void operator()( const std::string& name,
117 const RenderParameters::TextureInfo& p,
118 const Data::ShaderProgram* shader ) {
119 auto [tex, texUnit] = p;
120 if ( texUnit == -1 ) { shader->setUniformTexture( name.c_str(), tex ); }
121 else { shader->setUniform( name.c_str(), tex, texUnit ); }
122 }
123
128 void operator()( const std::string& /*name*/,
129 const RenderParameters& p,
130 const Data::ShaderProgram* shader ) {
131 p.bind( shader );
132 }
133
136 template <typename T>
137 void operator()( const std::string& name, const T& p, const Data::ShaderProgram* shader ) {
138 shader->setUniform( name.c_str(), p );
139 }
140 };
141};
142
147{
148 public:
149 virtual ~ParameterSetEditingInterface() = default;
150
155 virtual nlohmann::json getParametersMetadata() const = 0;
156
158 static void loadMetaData( const std::string& basename, nlohmann::json& destination );
159};
160
168class RA_ENGINE_API ShaderParameterProvider
169{
170 public:
171 virtual ~ShaderParameterProvider() = default;
172 virtual RenderParameters& getParameters() { return m_renderParameters; }
173 virtual const RenderParameters& getParameters() const { return m_renderParameters; }
174
181 virtual void updateGL() = 0;
182
186 virtual void updateFromParameters() {};
187
197 virtual std::list<std::string> getPropertyList() const { return {}; };
198
199 private:
201 RenderParameters m_renderParameters;
202};
203
204} // namespace Data
205} // namespace Engine
206} // namespace Ra
T c_str(T... args)
Heterogeneous container storing "Variables", that maps a name (std::string) to a value (of any type T...
Interface to define metadata (constraints, description, ...) for the editing of parameter set.
virtual nlohmann::json getParametersMetadata() const =0
Get a json containing metadata about the parameters.
Management of shader parameters with automatic binding of a named parameter to the corresponding glsl...
void setVariable(const std::string &name, RenderParameters &rp)
overload create ref wrapper for RenderParameters variable
Core::Utils::TypeList< bool, Core::Utils::Color, int, uint, Scalar, TextureInfo, std::vector< int >, std::vector< uint >, std::vector< Scalar >, Core::Vector2, Core::Vector3, Core::Vector4, Core::Matrix2, Core::Matrix3, Core::Matrix4, RenderParameters > BindableTypes
List of bindable types, to be used with static visitors.
void bind(const Data::ShaderProgram *shader) const
Bind the parameter uniform on the shader program.
void setTexture(const std::string &name, T *tex, int texUnit=-1)
Adding a texture parameter.
Shader program parameter provider.
virtual void updateFromParameters()
Update the attributes of the ShaderParameterProvider to their actual values stored in the renderParam...
virtual void updateGL()=0
Update the OpenGL states used by the ShaderParameterProvider.
virtual std::list< std::string > getPropertyList() const
Get the list of properties the provider might use in a shader.
void setUniform(const char *name, const T &value) const
Uniform setters.
void setUniformTexture(const char *name, Texture *tex) const
hepler function to manage enum as underlying types in VariableSet
Definition Cage.cpp:4
T ref(T... args)