TDME2 1.9.121
DeferredLightingShaderTerrainImplementation.cpp
Go to the documentation of this file.
2
3#include <string>
4
5#include <tdme/tdme.h>
11#include <tdme/engine/Engine.h>
14
15using std::string;
16using std::to_string;
17
27
28bool DeferredLightingShaderTerrainImplementation::isSupported(Renderer* renderer) {
29 return renderer->isDeferredShadingAvailable() == true;
30}
31
33{
34}
35
37 return "defer_terrain";
38}
39
41{
42 auto shaderVersion = renderer->getShaderVersion();
43
44 // lighting
45 // vertex shader
48 "shader/" + shaderVersion + "/lighting/specular",
49 "render_vertexshader.vert",
50 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define HAVE_TERRAIN_SHADER\n#define HAVE_DEPTH_FOG\n" + additionalDefinitions
51 );
52 if (vertexShaderId == 0) return;
53
54 // fragment shader
57 "shader/" + shaderVersion + "/lighting/specular",
58 "defer_fragmentshader.frag",
59 "#define LIGHT_COUNT " + to_string(Engine::LIGHTS_MAX) + "\n#define HAVE_TERRAIN_SHADER\n#define HAVE_DEPTH_FOG\n" + additionalDefinitions,
60 FileSystem::getInstance()->getContentAsString(
61 "shader/" + shaderVersion + "/functions",
62 "terrain.inc.glsl"
63 ) + "\n" +
64 FileSystem::getInstance()->getContentAsString(
65 "shader/" + shaderVersion + "/functions/specular",
66 "specular_lighting.inc.glsl"
67 ) + "\n"
68 );
69 if (fragmentShaderId == 0) return;
70
71 // create, attach and link program
75
76 //
78 if (initialized == false) return;
79
80 //
81 initialized = false;
82
84
86 if (uniformGrasTextureUnit == -1) return;
87
89 if (uniformDirtTextureUnit == -1) return;
90
92 if (uniformSnowTextureUnit == -1) return;
93
95 if (uniformStoneTextureUnit == -1) return;
96
97 //
98 grasTextureId = Engine::getInstance()->getTextureManager()->addTexture(TextureReader::read("resources/engine/textures", "terrain_gras.png"), renderer->CONTEXTINDEX_DEFAULT);
99 dirtTextureId = Engine::getInstance()->getTextureManager()->addTexture(TextureReader::read("resources/engine/textures", "terrain_dirt.png"), renderer->CONTEXTINDEX_DEFAULT);
100 snowTextureId = Engine::getInstance()->getTextureManager()->addTexture(TextureReader::read("resources/engine/textures", "terrain_snow.png"), renderer->CONTEXTINDEX_DEFAULT);
101 stoneTextureId = Engine::getInstance()->getTextureManager()->addTexture(TextureReader::read("resources/engine/textures", "terrain_stone.png"), renderer->CONTEXTINDEX_DEFAULT);
102
103 //
104 initialized = true;
105}
106
108}
109
112
113 //
114 auto currentTextureUnit = renderer->getTextureUnit(contextIdx);
116 renderer->bindTexture(contextIdx, grasTextureId);
118 renderer->bindTexture(contextIdx, dirtTextureId);
120 renderer->bindTexture(contextIdx, snowTextureId);
122 renderer->bindTexture(contextIdx, stoneTextureId);
124 renderer->setTextureUnit(contextIdx, currentTextureUnit);
125
126 //
131}
132
134 //
135 auto currentTextureUnit = renderer->getTextureUnit(contextIdx);
137 renderer->bindTexture(contextIdx, renderer->ID_NONE);
139 renderer->bindTexture(contextIdx, renderer->ID_NONE);
141 renderer->bindTexture(contextIdx, renderer->ID_NONE);
143 renderer->bindTexture(contextIdx, renderer->ID_NONE);
144 renderer->setTextureUnit(contextIdx, currentTextureUnit);
145
146 //
148}
149
153}
154
156}
Engine main class.
Definition: Engine.h:122
static TextureManager * getTextureManager()
Definition: Engine.h:564
static constexpr int LIGHTS_MAX
Definition: Engine.h:173
static Engine * getInstance()
Returns engine instance.
Definition: Engine.h:554
virtual void updateMatrices(Renderer *renderer, int contextIdx) override
Update matrices to program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
virtual void updateShaderParameters(Renderer *renderer, int contextIdx) override
Update shader parameters.
virtual void updateMatrices(Renderer *renderer, int contextIdx) override
Update matrices to program.
virtual void unUseProgram(int contextIdx) override
Unuse lighting program.
virtual void useProgram(Engine *engine, int contextIdx) override
Use lighting program.
TextureManager_TextureManaged * addTexture(const string &id, bool &created)
Adds a texture to manager.
virtual void setTextureUnit(int contextIdx, int32_t textureUnit)=0
Sets up texture unit.
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.
virtual int32_t createProgram(int type)=0
Creates a shader program.
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 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.
array< float, 16 > & getArray() const
Returns array data.
Definition: Matrix4x4.h:616
File system singleton class.
Definition: FileSystem.h:14