TDME2 1.9.121
EntityShaderParameters.cpp
Go to the documentation of this file.
2
3#include <map>
4#include <string>
5
6#include <tdme/tdme.h>
9#include <tdme/math/Vector2.h>
10#include <tdme/math/Vector3.h>
11#include <tdme/math/Vector4.h>
15
17
18using std::map;
19using std::string;
20
29
30const ShaderParameter EntityShaderParameters::getShaderParameter(const string& parameterName) const {
31 auto shaderParameterIt = parameters.find(parameterName);
32 if (shaderParameterIt == parameters.end()) {
33 return Engine::getDefaultShaderParameter(shaderId, parameterName);
34 }
35 auto& shaderParameter = shaderParameterIt->second;
36 return shaderParameter;
37}
38
39void EntityShaderParameters::setShaderParameter(const string& parameterName, const ShaderParameter& parameterValue) {
40 auto currentShaderParameter = getShaderParameter(parameterName);
41 if (currentShaderParameter.getType() == ShaderParameter::TYPE_NONE) {
42 Console::println("EntityShaderParameters::setShaderParameter(): no parameter for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
43 return;
44 }
45 if (currentShaderParameter.getType() != parameterValue.getType()) {
46 Console::println("EntityShaderParameters::setShaderParameter(): parameter type mismatch for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
47 }
48 parameters[parameterName] = parameterValue;
49 changed = true;
50}
51
52void EntityShaderParameters::setShaderParameter(const string& parameterName, const string& parameterValueString) {
53 auto currentShaderParameter = getShaderParameter(parameterName);
54 if (currentShaderParameter.getType() == ShaderParameter::TYPE_NONE) {
55 Console::println("EntityShaderParameters::setShaderParameter(): no parameter for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
56 return;
57 }
58 ShaderParameter parameterValue;
59 switch(currentShaderParameter.getType()) {
61 break;
63 parameterValue = ShaderParameter(StringTools::toLowerCase(StringTools::trim(parameterValueString)) == "true");
64 break;
66 parameterValue = ShaderParameter(Integer::parse(StringTools::trim(parameterValueString)));
67 break;
69 parameterValue = ShaderParameter(Float::parse(StringTools::trim(parameterValueString)));
70 break;
72 {
73 auto parameterValueStringArray = StringTools::tokenize(parameterValueString, ",");
74 if (parameterValueStringArray.size() != 2) break;
75 parameterValue = ShaderParameter(
76 Vector2(
77 Float::parse(StringTools::trim(parameterValueStringArray[0])),
78 Float::parse(StringTools::trim(parameterValueStringArray[1]))
79 )
80 );
81 }
82 break;
84 {
85 auto parameterValueStringArray = StringTools::tokenize(parameterValueString, ",");
86 if (parameterValueStringArray.size() != 3) break;
87 parameterValue = ShaderParameter(
88 Vector3(
89 Float::parse(StringTools::trim(parameterValueStringArray[0])),
90 Float::parse(StringTools::trim(parameterValueStringArray[1])),
91 Float::parse(StringTools::trim(parameterValueStringArray[2]))
92 )
93 );
94 }
95 break;
96 default:
97 break;
98 }
99 if (currentShaderParameter.getType() != parameterValue.getType()) {
100 Console::println("EntityShaderParameters::setShaderParameter(): parameter type mismatch for shader registered with id: " + shaderId + ", and parameter name: " + parameterName);
101 }
102 parameters[parameterName] = parameterValue;
103 changed = true;
104}
Engine main class.
Definition: Engine.h:122
static const ShaderParameter getDefaultShaderParameter(const string &shaderId, const string &parameterName)
Returns shader parameter default value for given shader id and parameter name.
Definition: Engine.h:770
TDME2 engine entity shader parameters.
map< string, ShaderParameter > parameters
void setShaderParameter(const string &parameterName, const ShaderParameter &parameterValue)
Set shader parameter for given parameter name.
const ShaderParameter getShaderParameter(const string &parameterName) const
Returns shader parameter for given parameter name, if the value does not exist, the default will be r...
Shader parameter model class.
2D vector 2 class
Definition: Vector2.h:19
3D vector 3 class
Definition: Vector3.h:22
3D vector 4 class
Definition: Vector4.h:19
Float class.
Definition: Float.h:23
Integer class.
Definition: Integer.h:26
String tools class.
Definition: StringTools.h:20