TDME2 1.9.121
GUIShader.cpp
Go to the documentation of this file.
2
3#include <array>
4
5#include <tdme/tdme.h>
7
9#include <tdme/math/Math.h>
12
14
15using std::array;
16
22
23GUIShader::GUIShader(Renderer* renderer)
24{
25 this->renderer = renderer;
26 initialized = false;
27 isRunning = false;
28}
29
31{
32 return initialized;
33}
34
36{
37 auto shaderVersion = renderer->getShaderVersion();
40 "shader/" + shaderVersion + "/gui",
41 "render_vertexshader.vert"
42 );
43 if (vertexShaderId == 0) return;
44
47 "shader/" + shaderVersion + "/gui",
48 "render_fragmentshader.frag"
49 );
50 if (fragmentShaderId == 0) return;
51
59 }
60 if (renderer->linkProgram(programId) == false) return;
61
63 if (uniformDiffuseTextureUnit == -1) return;
64
66 if (uniformDiffuseTextureAvailable == -1) return;
67
69 if (uniformMaskTextureUnit == -1) return;
70
72 if (uniformMaskTextureAvailable == -1) return;
73
75 if (uniformMaskMaxValue == -1) return;
76
78 if (uniformEffectColorMul == -1) return;
79
81 if (uniformEffectColorAdd == -1) return;
82
83 // texture matrix
85 if (uniformTextureMatrix == -1) return;
86
87 // gradients
89 if (uniformGradientAvailable == -1) return;
90 for (auto i = 0; i < uniformGradientColors.size(); i++) {
91 uniformGradientColors[i] = renderer->getProgramUniformLocation(programId, "gradientColors[" + to_string(i) + "]");
92 if (uniformGradientColors[i] == -1) return;
93 }
95 if (uniformGradientColorCount == -1) return;
96 for (auto i = 0; i < uniformGradientColorStarts.size(); i++) {
97 uniformGradientColorStarts[i] = renderer->getProgramUniformLocation(programId, "gradientColorStarts[" + to_string(i) + "]");
98 if (uniformGradientColorStarts[i] == -1) return;
99 }
101 if (uniformInverseGradientTextureMatrix == -1) return;
102
103 //
104 initialized = true;
105}
106
108{
109 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
110 renderer->useProgram(contextIdx, programId);
117 isRunning = true;
118}
119
121{
122 isRunning = false;
123}
124
125void GUIShader::bindTexture(int32_t textureId)
126{
127 if (isRunning == false) return;
129 case 0:
131 break;
132 case 1:
135 break;
136 }
137}
138
140{
141 if (isRunning == false) return;
142
143 // use default context
144 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
145
146 //
149}
150
151
153 if (isRunning == false) return;
154
155 // use default context
156 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
157
158 //
160}
161
162void GUIShader::setGradient(int count, array<GUIColor, 10>& colors, array<float, 10>& colorStarts, float rotationAngle) {
163 // use default context
164 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
165
166 //
167 count = Math::clamp(count, 0, 10);
169 if (count == 0) return;
170 for (auto i = 0; i < count; i++) renderer->setProgramUniformFloatVec4(contextIdx, uniformGradientColors[i], colors[i].getArray());
172 for (auto i = 0; i < count; i++) renderer->setProgramUniformFloat(contextIdx, uniformGradientColorStarts[i], colorStarts[i]);
173 renderer->setProgramUniformFloatMatrix3x3(contextIdx, uniformInverseGradientTextureMatrix, Matrix2D3x3::rotateAroundTextureCenter(-rotationAngle).getArray());
174}
175
177 // use default context
178 auto contextIdx = renderer->CONTEXTINDEX_DEFAULT;
179
180 //
182}
virtual int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string())=0
Loads a shader.
array< float, 4 > & getEffectColorMul(int contextIdx)
Get effect color mul.
Definition: Renderer.h:1116
virtual void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array< float, 4 > &data)=0
Set up a float vec4 uniform value.
virtual int32_t createProgram(int type)=0
Creates a shader program.
virtual int32_t getTextureUnit(int contextIdx)=0
Get texture unit.
virtual void setProgramAttributeLocation(int32_t programId, int32_t location, const string &name)=0
Bind attribute to a input location.
float getMaskMaxValue(int contextIdx)
Get mask max value.
Definition: Renderer.h:1325
virtual void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual bool linkProgram(int32_t programId)=0
Links attached shaders to a program.
virtual void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array< float, 9 > &value)=0
Set up a float matrix 3x3 uniform value.
void setLighting(int contextIdx, int32_t lighting)
Set current lighting model.
Definition: Renderer.h:503
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
Matrix2D3x3 & getTextureMatrix(int contextIdx)
Get texture matrix.
Definition: Renderer.h:578
virtual void useProgram(int contextIdx, int32_t programId)=0
Use shader program.
array< float, 4 > & getEffectColorAdd(int contextIdx)
Get effect color add.
Definition: Renderer.h:1126
virtual void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)=0
Set up a float uniform value.
array< int32_t, 10 > uniformGradientColors
Definition: GUIShader.h:38
void updateEffect()
Update effect to program.
Definition: GUIShader.cpp:139
void setGradient(int count, array< GUIColor, 10 > &colors, array< float, 10 > &colorStarts, float rotationAngle)
Set gradient properties.
Definition: GUIShader.cpp:162
void initialize()
Init shadow mapping.
Definition: GUIShader.cpp:35
int32_t uniformInverseGradientTextureMatrix
Definition: GUIShader.h:41
void unsetGradient()
Disable gradient.
Definition: GUIShader.cpp:176
void bindTexture(int32_t textureId)
Bind texture.
Definition: GUIShader.cpp:125
void useProgram()
Use render GUI program.
Definition: GUIShader.cpp:107
void updateTextureMatrix()
Update texure matrix to program.
Definition: GUIShader.cpp:152
array< int32_t, 10 > uniformGradientColorStarts
Definition: GUIShader.h:40
void unUseProgram()
Un use render GUI program.
Definition: GUIShader.cpp:120
Standard math functions.
Definition: Math.h:21
3x3 2D Matrix class
Definition: Matrix2D3x3.h:22
array< float, 9 > & getArray() const
Returns array data.
Definition: Matrix2D3x3.h:348
Console class.
Definition: Console.h:26