TDME2  1.9.200
LightingShaderTerrainEditorImplementation.cpp
Go to the documentation of this file.
2 
3 #include <string>
4 
5 #include <tdme/tdme.h>
9 #include <tdme/engine/Engine.h>
10 #include <tdme/math/Matrix3x3.h>
11 #include <tdme/math/Vector2.h>
12 
13 using std::string;
14 using std::to_string;
15 
23 
24 LightingShaderTerrainEditorImplementation::LightingShaderTerrainEditorImplementation(Renderer* renderer): LightingShaderTerrainImplementation(renderer)
25 {
26  additionalDefinitions = "\n#define HAVE_TERRAIN_SHADER_EDITOR";
27 }
28 
30  return "terraineditor";
31 }
32 
34 {
36 
37  if (initialized == false) return;
38 
39  //
40  initialized = false;
41 
43  if (uniformBrushEnabled == -1) return;
44 
46  if (uniformBrushTextureMatrix == -1) return;
47 
49  if (uniformBrushTextureUnit == -1) return;
50 
52  if (uniformBrushPosition == -1) return;
53 
55  if (uniformBrushTextureDimension == -1) return;
56 
57  //
58  initialized = true;
59 }
60 
63  Engine::ShaderType::SHADERTYPE_OBJECT,
64  getId(),
65  {
66  { "brushEnabled", ShaderParameter(true) },
67  { "brushDimension", ShaderParameter(Vector2(0.0f, 0.0f)) },
68  { "brushTexture", ShaderParameter(0) },
69  { "brushRotation", ShaderParameter(0.0f) },
70  { "brushScale", ShaderParameter(Vector2(1.0f, 1.0f)) },
71  { "brushPosition", ShaderParameter(Vector2(0.0f, 0.0f)) }
72  },
73  true
74  );
75 }
76 
79 
80  //
81  auto currentTextureUnit = renderer->getTextureUnit(contextIdx);
83  renderer->bindTexture(contextIdx, engine->getShaderParameter(getId(), "brushTexture").getIntegerValue());
84  renderer->setTextureUnit(contextIdx, currentTextureUnit);
85 
86  //
87  Matrix3x3 brushTextureMatrix;
88  brushTextureMatrix.identity();
89  brushTextureMatrix.multiply((Matrix3x3()).identity().setTranslation(Vector2(0.5f, 0.5f)));
90  brushTextureMatrix.multiply((Matrix3x3()).identity().scale(
91  Vector2(
92  1.0f / engine->getShaderParameter(getId(), "brushScale").getVector2Value().getX(),
93  1.0f / engine->getShaderParameter(getId(), "brushScale").getVector2Value().getY()
94  )
95  ));
96  brushTextureMatrix.multiply((Matrix3x3()).identity().setAxes(engine->getShaderParameter(getId(), "brushRotation").getFloatValue()));
97 
98  //
99  renderer->setProgramUniformInteger(contextIdx, uniformBrushEnabled, engine->getShaderParameter(getId(), "brushEnabled").getBooleanValue() == true?1:0);
102  renderer->setProgramUniformFloatVec2(contextIdx, uniformBrushTextureDimension, engine->getShaderParameter(getId(), "brushDimension").getVector2Value().getArray());
103  renderer->setProgramUniformFloatVec2(contextIdx, uniformBrushPosition, engine->getShaderParameter(getId(), "brushPosition").getVector2Value().getArray());
104 }
Engine main class.
Definition: Engine.h:131
const ShaderParameter getShaderParameter(const string &shaderId, const string &parameterName)
Returns shader parameter for given shader id and parameter name, if the value does not exist,...
Definition: Engine.h:941
static void registerShader(ShaderType type, const string &shaderId, const vector< Shader::ParameterDefaults > &parameterDefaults={}, bool internal=false)
Register shader.
Definition: Engine.h:856
Shader parameter model class.
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
virtual void setTextureUnit(int contextIdx, int32_t textureUnit)=0
Sets up texture unit.
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 setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)=0
Set up a integer uniform value.
virtual void bindTexture(int contextIdx, int32_t textureId)=0
Binds a texture with given id or unbinds when using ID_NONE.
virtual void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array< float, 9 > &value)=0
Set up a float matrix 3x3 uniform value.
virtual int32_t getProgramUniformLocation(int32_t programId, const string &name)=0
Returns location of given uniform variable.
Matrix3x3 class representing matrix3x3 mathematical structure and operations for 2d space.
Definition: Matrix3x3.h:20
Matrix3x3 & identity()
Creates identity matrix.
Definition: Matrix3x3.h:128
const array< float, 9 > & getArray() const
Definition: Matrix3x3.h:369
Matrix3x3 & multiply(const Matrix3x3 &matrix)
Multiplies this matrix with given matrix.
Definition: Matrix3x3.h:176
Vector2 class representing vector2 mathematical structure and operations with x, y components.
Definition: Vector2.h:20