TDME2  1.9.200
ShaderParameter.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include <array>
4 #include <string>
5 
6 #include <tdme/tdme.h>
7 #include <tdme/engine/Color4.h>
8 #include <tdme/math/Vector2.h>
9 #include <tdme/math/Vector3.h>
10 #include <tdme/math/Vector4.h>
11 #include <tdme/utilities/Console.h>
12 
13 using std::array;
14 using std::string;
15 using std::to_string;
16 
22 
23 /**
24  * Shader parameter model class
25  */
27 public:
29 
30 private:
32  int integerValue { 0 };
33  array<float, 4> floatValues { 0.0f, 0.0f, 0.0f, 0.0f };
34 
35  /**
36  * @return value as string
37  */
38  inline const string toString(float value) const {
39  string floatString = to_string(value);
40  return floatString.substr(0, floatString.length() - 3);
41  }
42 
43 public:
44  /**
45  * Public default constructor
46  */
48  }
49 
50  /**
51  * Public constructor for boolean value
52  * @param booleanValue boolean value
53  */
54  ShaderParameter(bool booleanValue): type(TYPE_BOOLEAN), integerValue(booleanValue == true?1:0) {
55  }
56 
57  /**
58  * Public constructor for int value
59  * @param integerValue int value
60  */
62  }
63 
64  /**
65  * Public constructor for float value
66  * @param floatValue float value
67  */
68  ShaderParameter(float floatValue): type(TYPE_FLOAT), floatValues( { floatValue, 0.0f, 0.0f, 0.0f} ) {
69  }
70 
71  /**
72  * Public constructor for Vector2 value
73  * @param vector2Value Vector2 value
74  */
75  ShaderParameter(const Vector2& vector2Value): type(TYPE_VECTOR2), floatValues( { vector2Value[0], vector2Value[1], 0.0f, 0.0f} ) {
76  }
77 
78  /**
79  * Public constructor for Vector3 value
80  * @param vector3Value Vector3 value
81  */
82  ShaderParameter(const Vector3& vector3Value): type(TYPE_VECTOR3), floatValues( { vector3Value[0], vector3Value[1], vector3Value[2], 0.0f} ) {
83  }
84 
85  /**
86  * Public constructor for Vector4 value
87  * @param vector4Value Vector4 value
88  */
89  ShaderParameter(const Vector4& vector4Value): type(TYPE_VECTOR4), floatValues( { vector4Value[0], vector4Value[1], vector4Value[2], vector4Value[3]} ) {
90  }
91 
92  /**
93  * Public constructor for Color4 value
94  * @param color4Value Color4 value
95  */
96  ShaderParameter(const Color4& color4Value): type(TYPE_COLOR4), floatValues( { color4Value[0], color4Value[1], color4Value[2], color4Value[3]} ) {
97  }
98 
99  /**
100  * @return type
101  */
102  inline Type getType() const {
103  return type;
104  }
105 
106  /**
107  * @return boolean value
108  */
109  inline bool getBooleanValue() const {
110  return integerValue;
111  }
112 
113  /**
114  * @return integer value
115  */
116  inline float getIntegerValue() const {
117  return integerValue;
118  }
119 
120  /**
121  * @return float value
122  */
123  inline float getFloatValue() const {
124  return floatValues[0];
125  }
126 
127  /**
128  * @return Vector2 value
129  */
130  inline const Vector2 getVector2Value() const {
131  return Vector2(floatValues[0], floatValues[1]);
132  }
133 
134  /**
135  * @return Vector2 value array
136  */
137  inline const array<float, 2> getVector2ValueArray() const {
138  return { floatValues[0], floatValues[1] };
139  }
140 
141  /**
142  * @return Vector3 value
143  */
144  inline const Vector3 getVector3Value() const {
145  return Vector3(floatValues[0], floatValues[1], floatValues[2]);
146  }
147 
148  /**
149  * @return Vector3 value array
150  */
151  inline const array<float, 3> getVector3ValueArray() const {
152  return { floatValues[0], floatValues[1], floatValues[2] };
153  }
154 
155  /**
156  * @return Vector4 value
157  */
158  inline const Vector4 getVector4Value() const {
159  return Vector4(floatValues[0], floatValues[1], floatValues[2], floatValues[3]);
160  }
161 
162  /**
163  * @return Vector4 value array
164  */
165  inline const array<float, 4> getVector4ValueArray() const {
166  return { floatValues[0], floatValues[1], floatValues[2], floatValues[3] };
167  }
168 
169  /**
170  * @return Color4 value
171  */
172  inline const Color4 getColor4Value() const {
173  return Color4(floatValues[0], floatValues[1], floatValues[2], floatValues[3]);
174  }
175 
176  /**
177  * @return Color3 value array
178  */
179  inline const array<float, 3> getColor3ValueArray() const {
180  return { floatValues[0], floatValues[1], floatValues[2] };
181  }
182 
183  /**
184  * @return Color4 value array
185  */
186  inline const array<float, 4> getColor4ValueArray() const {
187  return { floatValues[0], floatValues[1], floatValues[2], floatValues[3] };
188  }
189 
190  /**
191  * @return string representation of value
192  */
193  inline const string getValueAsString() const {
194  switch(type) {
196  return string();
198  return integerValue == 1?"true":"false";
200  return toString(integerValue);
202  return toString(floatValues[0]);
204  {
205  string result;
206  for (auto i = 0; i < 2; i++) {
207  if (i != 0) result+= ",";
208  result+= toString(floatValues[i]);
209  }
210  return result;
211  }
213  {
214  string result;
215  for (auto i = 0; i < 3; i++) {
216  if (i != 0) result+= ",";
217  result+= toString(floatValues[i]);
218  }
219  return result;
220  }
223  {
224  string result;
225  for (auto i = 0; i < 4; i++) {
226  if (i != 0) result+= ",";
227  result+= toString(floatValues[i]);
228  }
229  return result;
230  }
231  break;
232  default:
233  return string();
234  }
235  }
236 
237 };
Color 4 definition class.
Definition: Color4.h:18
Shader parameter model class.
ShaderParameter(const Vector2 &vector2Value)
Public constructor for Vector2 value.
ShaderParameter(float floatValue)
Public constructor for float value.
ShaderParameter()
Public default constructor.
const Color4 getColor4Value() const
const array< float, 3 > getColor3ValueArray() const
const Vector3 getVector3Value() const
const array< float, 4 > getColor4ValueArray() const
const string getValueAsString() const
const Vector4 getVector4Value() const
ShaderParameter(bool booleanValue)
Public constructor for boolean value.
ShaderParameter(int integerValue)
Public constructor for int value.
const array< float, 4 > getVector4ValueArray() const
const array< float, 3 > getVector3ValueArray() const
const string toString(float value) const
ShaderParameter(const Vector3 &vector3Value)
Public constructor for Vector3 value.
const array< float, 2 > getVector2ValueArray() const
ShaderParameter(const Color4 &color4Value)
Public constructor for Color4 value.
ShaderParameter(const Vector4 &vector4Value)
Public constructor for Vector4 value.
const Vector2 getVector2Value() const
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20
Vector3 class representing vector3 mathematical structure and operations with x, y,...
Definition: Vector3.h:20
Vector4 class representing vector4 mathematical structure and operations with x, y,...
Definition: Vector4.h:22
Console class.
Definition: Console.h:29