Rumba C++ SDK
Shader.h
Go to the documentation of this file.
1 /* *
2  ***
3  *****
4  ********************* Mercenaries Engineering SARL
5  ***************** Copyright (C) 2020
6  *************
7  ********* http://www.mercenaries-engineering.com
8  ***********
9  **** ****
10  ** **/
11 # pragma once
12 
13 # include "Maquina/Dict.h"
14 # include <gsl/span>
15 
16  namespace maquina {
17 
19  enum class ShaderParamType
20  {
21  Bool = 0,
22  Int,
23  Float,
24  V2i,
25  V3i,
26  V4i,
27  V2f,
28  V3f,
29  V4f,
30  M44f,
31  _LastPOD = M44f,
32  Texture, // A texture filename in ExprCall, a sampler2D in GLSL
33  Token, // A string in ExprCall, an integer in GLSL
34  InternalExpression, // Do not appear in ExprCall, a raw GLSL expression
35  Ignore // Anything in ExprCall, ignored in GLSL, the argument is not inserted
36  };
37 
40  {
41  public:
44  std::string name,
45  const Value& default_value
46  );
47 
48  // TODO doc
50  std::string name,
51  ShaderParamType type,
52  const Value& default_value
53  );
54 
55  std::string name;
57  int offset=-1;
59  };
60 
63  {
64  std::string name;
66  };
67 
70  {
71  enum Type
72  {
73  Geometry = 0,
77  };
78  std::string code;
80  std::string decl_code;
81  };
82 
84 
91  std::string name,
92  bool stream,
93  std::vector<ShaderParam> parameters,
94  std::vector<ShaderProgram> programs
95  );
96 
98  std::string name,
99  std::vector<ShaderParam> parameters,
100  ShaderParamType output_type,
101  std::string post_fix=""
102  );
103 
104  MAQUINA_EXPORT void register_shading_token(const std::string& s, int token);
105 
106  MAQUINA_EXPORT void add_shader_glsl(const std::string_view& code);
107 
109  class MAQUINA_EXPORT Shader : public Value
110  {
111  public:
112  // Create a new shader
113  Shader();
114 
115  Shader(const Value& value);
116 
118  std::string program() const;
119 
121  void set_program(std::string name) const;
122 
124  Dict parameters() const;
125 
127  void set_parameters(const Dict& parameters) const;
128 
130  void set_expressions(const Dict& expressions) const;
131 
133  static const Shader default_value;
134 
136  Shader(std::shared_ptr<Impl> impl) { _impl=std::move(impl); }
137  };
138 
139  // Preprocess a GLSL shader code to expand the include macros //!include_*!//
140  MAQUINA_EXPORT std::string preprocess_shader_code(std::string code);
141  }
static const Shader default_value
The default value.
Definition: Shader.h:133
MAQUINA_EXPORT void add_shader_glsl(const std::string_view &code)
Type type
The program type.
Definition: Shader.h:79
A raw OpenGL fragment program.
Definition: Shader.h:75
A raw OpenGL geometry program.
Definition: Shader.h:73
std::string name
The texture slot name.
Definition: Shader.h:64
A shader texture slot descriptor.
Definition: Shader.h:62
This version of the SDK is unstable, i-e, it may change with no warning.
Definition: AddCurveAction.h:20
std::string decl_code
The GLSL declaration code (for SurfaceFragment)
Definition: Shader.h:80
Type
Definition: Shader.h:71
MAQUINA_EXPORT Value default_value(const maquina::StringView &type_name)
Return the default value of a type.
MAQUINA_EXPORT void register_shading_node(std::string name, std::vector< ShaderParam > parameters, ShaderParamType output_type, std::string post_fix="")
ShaderParamType type
The parameter type (computed by the constructor)
Definition: Shader.h:58
bool color_managed
true if the texture data are color managed (colors), false if the texture data are not color managed ...
Definition: Shader.h:65
MAQUINA_EXPORT void register_shading_token(const std::string &s, int token)
Gather shading parameters.
Definition: Shader.h:109
#define MAQUINA_EXPORT
Definition: Export.h:31
std::string name
The parameter&#39;s name.
Definition: Shader.h:55
MAQUINA_EXPORT std::string preprocess_shader_code(std::string code)
A shader parameter descriptor.
Definition: Shader.h:39
ShaderParamType
The shader parameter types.
Definition: Shader.h:19
std::string code
The GLSL program code.
Definition: Shader.h:78
A shader texture slot descriptor.
Definition: Shader.h:69
A simplified OpenGL surface fragment program.
Definition: Shader.h:76
A dictionnary to associate strings to values.
Definition: Dict.h:24
MAQUINA_EXPORT void register_shader(std::string name, bool stream, std::vector< ShaderParam > parameters, std::vector< ShaderProgram > programs)
Register a new hardware shader.
A raw OpenGL vertex program.
Definition: Shader.h:74
Base class of all Rumba values.
Definition: Value.h:34
Value default_value
The parameter&#39;s default value if not provided in the shader instance.
Definition: Shader.h:56