TDME2  1.9.200
LinesShader.cpp
Go to the documentation of this file.
2 
3 #include <tdme/tdme.h>
5 #include <tdme/engine/Engine.h>
6 #include <tdme/math/Matrix4x4.h>
7 
14 
15 LinesShader::LinesShader(Engine* engine, Renderer* renderer)
16 {
17  this->engine = engine;
18  this->renderer = renderer;
19  isRunning = false;
20  initialized = false;
21 }
22 
24 {
25  return initialized;
26 }
27 
29 {
30  auto shaderVersion = renderer->getShaderVersion();
31  // particles
32  // fragment shader
35  "shader/" + shaderVersion + "/lines",
36  "render_fragmentshader.frag"
37  );
38  if (fragmentShaderId == 0)
39  return;
40  // vertex shader
43  "shader/" + shaderVersion + "/lines",
44  "render_vertexshader.vert"
45  );
46  if (vertexShaderId == 0)
47  return;
48  // create, attach and link program
52  // map inputs to attributes
56  }
57  // link program
58  if (renderer->linkProgram(programId) == false)
59  return;
60 
61  // get uniforms
63  if (uniformMVPMatrix == -1)
64  return;
66  if (uniformDiffuseTextureUnit == -1)
67  return;
69  if (uniformEffectColorMul == -1)
70  return;
72  if (uniformEffectColorAdd == -1)
73  return;
74  initialized = true;
75 }
76 
77 void LinesShader::useProgram(int contextIdx)
78 {
79  isRunning = true;
80  renderer->useProgram(contextIdx, programId);
83 }
84 
85 void LinesShader::updateEffect(int contextIdx)
86 {
87  // skip if not running
88  if (isRunning == false)
89  return;
90  // effect color
93 }
94 
95 void LinesShader::unUseProgram(int contextIdx)
96 {
97  isRunning = false;
98  renderer->setLineWidth(1.0f);
99  renderer->bindTexture(contextIdx, renderer->ID_NONE);
100 }
101 
102 void LinesShader::updateMatrices(int contextIdx)
103 {
104  // skip if not running
105  if (isRunning == false)
106  return;
107  // object to screen matrix
109  // upload matrices
111 }
112 
113 void LinesShader::setParameters(int contextIdx, int32_t textureId, float lineWidth) {
114  renderer->setLineWidth(lineWidth);
115  renderer->bindTexture(contextIdx, textureId);
116 }
Engine main class.
Definition: Engine.h:131
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
Definition: LinesShader.cpp:85
void unUseProgram(int contextIdx)
Unuse particles shader program.
Definition: LinesShader.cpp:95
void setParameters(int contextIdx, int32_t textureId, float lineWidth)
Set parameters.
void useProgram(int contextIdx)
Use lighting program.
Definition: LinesShader.cpp:77
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 > & getEffectColorAdd(int contextIdx)
Get effect color add.
Definition: Renderer.h:1141
virtual void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array< float, 4 > &data)=0
Set up a float vec4 uniform value.
array< float, 4 > & getEffectColorMul(int contextIdx)
Get effect color mul.
Definition: Renderer.h:1131
virtual int32_t createProgram(int type)=0
Creates a shader program.
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 bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
void setLighting(int contextIdx, int32_t lighting)
Set current lighting model.
Definition: Renderer.h:504
virtual void attachShaderToProgram(int32_t programId, int32_t shaderId)=0
Attaches a shader to a program.
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.
virtual void setLineWidth(float lineWidth)=0
Set line width.
virtual void useProgram(int contextIdx, int32_t programId)=0
Use shader program.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
Vector3 multiply(const Vector3 &vector3) const
Multiplies this matrix with vector3.
Definition: Matrix4x4.h:225
Matrix4x4 & set(float r0c0, float r0c1, float r0c2, float r0c3, float r1c0, float r1c1, float r1c2, float r1c3, float r2c0, float r2c1, float r2c2, float r2c3, float r3c0, float r3c1, float r3c2, float r3c3)
Sets this matrix by its components.
Definition: Matrix4x4.h:108
const array< float, 16 > & getArray() const
Definition: Matrix4x4.h:611