TDME2 1.9.121
EZRShaderBaseImplementation.cpp
Go to the documentation of this file.
2
3#include <tdme/tdme.h>
13
24
25EZRShaderBaseImplementation::EZRShaderBaseImplementation(Renderer* renderer)
26{
27 this->renderer = renderer;
28 initialized = false;
29}
30
32}
33
35{
36 return initialized;
37}
38
40{
41 // map inputs to attributes
45 }
46 // link
47 if (renderer->linkProgram(programId) == false) return;
48
49 // uniforms
51 // uniforms
53 if (uniformProjectionMatrix == -1) return;
55 if (uniformCameraMatrix == -1) return;
56 } else {
57 // uniforms
59 if (uniformMVPMatrix == -1) return;
60 }
62 if (uniformTextureMatrix == -1) return;
64 if (uniformTextureAtlasSize == -1) return;
66 if (uniformTextureAtlasPixelDimension == -1) return;
68 if (uniformDiffuseTextureUnit == -1) return;
70 if (uniformDiffuseTextureAvailable == -1) return;
75
76 //
78
79 //
80 initialized = true;
81}
82
84{
85 renderer->useProgram(contextIdx, programId);
87 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureUnit, LightingShaderConstants::SPECULAR_TEXTUREUNIT_DIFFUSE);
88 if (uniformFrame != -1) renderer->setProgramUniformInteger(contextIdx, uniformFrame, engine->getTiming()->getFrame());
89}
90
92{
93}
94
96{
100 } else {
101 // matrices
102 Matrix4x4 mvpMatrix;
103 // mvp matrix
105 // upload
107 }
108}
109
112}
113
115{
116 auto material = renderer->getSpecularMaterial(contextIdx);
117 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureMaskedTransparency, material.diffuseTextureMaskedTransparency);
118 renderer->setProgramUniformFloat(contextIdx, uniformDiffuseTextureMaskedTransparencyThreshold, material.diffuseTextureMaskedTransparencyThreshold);
119 renderer->setProgramUniformInteger(contextIdx, uniformTextureAtlasSize, material.textureAtlasSize);
120 renderer->setProgramUniformFloatVec2(contextIdx, uniformTextureAtlasPixelDimension, material.textureAtlasPixelDimension);
121}
122
124}
125
126void EZRShaderBaseImplementation::bindTexture(Renderer* renderer, int contextIdx, int32_t textureId)
127{
128 switch (renderer->getTextureUnit(contextIdx)) {
129 case LightingShaderConstants::SPECULAR_TEXTUREUNIT_DIFFUSE:
130 renderer->setProgramUniformInteger(contextIdx, uniformDiffuseTextureAvailable, textureId == 0 ? 0 : 1);
131 break;
132 }
133}
Engine main class.
Definition: Engine.h:122
Timing * getTiming()
Definition: Engine.h:900
Timing class.
Definition: Timing.h:17
int64_t getFrame()
Definition: Timing.h:47
virtual void updateTextureMatrix(Renderer *renderer, int contextIdx) override
update texture matrix
virtual void updateMaterial(Renderer *renderer, int contextIdx) override
Update material.
virtual void updateMatrices(Renderer *renderer, int contextIdx) override
Update matrices.
virtual void initialize() override
Init EZR render shader program implementation.
virtual void bindTexture(Renderer *renderer, int contextIdx, int32_t textureId) override
Bind texture.
virtual void unUseProgram(int contextIdx) override
Unuse EZR render shader program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use EZR render shader program.
virtual void updateShaderParameters(Renderer *renderer, int contextIdx) override=0
Update shader parameters.
Interface to lighting shader program.
Renderer_SpecularMaterial & getSpecularMaterial(int contextIdx)
Get specular material.
Definition: Renderer.h:1142
virtual void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array< float, 2 > &data)=0
Set up a float vec2 uniform value.
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.
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 bool isInstancedRenderingAvailable()=0
Checks if instanced rendering is available.
virtual void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array< float, 16 > &value)=0
Set up a float matrix 4x4 uniform value.
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.
virtual void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)=0
Set up a float uniform value.
array< float, 9 > & getArray() const
Returns array data.
Definition: Matrix2D3x3.h:348
4x4 3D Matrix class
Definition: Matrix4x4.h:24
Matrix4x4 & set(float r0c0, float r1c0, float r2c0, float r3c0, float r0c1, float r1c1, float r2c1, float r3c1, float r0c2, float r1c2, float r2c2, float r3c2, float r0c3, float r1c3, float r2c3, float r3c3)
Set up matrix by values.
Definition: Matrix4x4.h:95
Vector3 multiply(const Vector3 &v) const
Multiplies a vector3 with this matrix into destination vector.
Definition: Matrix4x4.h:351
array< float, 16 > & getArray() const
Returns array data.
Definition: Matrix4x4.h:616
File system singleton class.
Definition: FileSystem.h:14
Console class.
Definition: Console.h:26