TDME2 1.9.121
EngineGL2Renderer.cpp
Go to the documentation of this file.
2
3#define GLFW_INCLUDE_NONE
4#include <GLFW/glfw3.h>
5
6#if !defined(__APPLE__)
7 #define GLEW_NO_GLU
8 #include <GL/glew.h>
9 #if defined(_WIN32)
10 #include <GL/wglew.h>
11 #endif
12#endif
13
14#include <string>
15
16#include <tdme/tdme.h>
22#include <tdme/engine/Engine.h>
23#include <tdme/engine/Version.h>
25
27
28using std::string;
29
38
39EngineGL2Renderer::EngineGL2Renderer()
40{
41}
42
44 if (tryIdx > 0) return false;
45 glfwWindowHint(GLFW_OPENGL_FORWARD_COMPAT, GLFW_FALSE);
46 glfwWindowHint(GLFW_OPENGL_PROFILE, GLFW_OPENGL_ANY_PROFILE);
47 glfwWindowHint(GLFW_CONTEXT_VERSION_MAJOR, 3);
48 glfwWindowHint(GLFW_CONTEXT_VERSION_MINOR, 1);
49 return true;
50}
51
53 glfwMakeContextCurrent(glfwWindow);
54 if (glfwGetCurrentContext() == nullptr) {
55 Console::println("EngineGL2Renderer::initializeWindowSystemRendererContext(): glfwMakeContextCurrent(): Error: No window attached to context");
56 return false;
57 }
58 #if !defined(__APPLE__)
59 glewExperimental = true;
60 GLenum glewInitStatus = glewInit();
61 if (glewInitStatus != GLEW_OK) {
62 Console::println("EngineGL2Renderer::initializeWindowSystemRendererContext(): glewInit(): Error: " + (string((char*)glewGetErrorString(glewInitStatus))));
63 return false;
64 }
65 #endif
66 return true;
67}
68
70{
71 if (Engine::lightingShader != nullptr)
73
74 if (Engine::particlesShader != nullptr)
76
77 if (Engine::linesShader != nullptr)
79
80 if (Engine::Engine::currentEngine->shadowMapping != nullptr)
82
83 if (Engine::ezrShader != nullptr)
85}
86
88{
89 if (Engine::lightingShader != nullptr)
91
92 if (Engine::particlesShader != nullptr)
94
95 if (Engine::linesShader != nullptr)
97
98 if (Engine::currentEngine->shadowMapping != nullptr)
100
101 if (Engine::ezrShader != nullptr)
103}
104
106{
107 if (Engine::lightingShader != nullptr)
109
110 if (Engine::particlesShader != nullptr)
112
113 if (Engine::linesShader != nullptr)
115
116 if (Engine::currentEngine->shadowMapping != nullptr)
118
119 if (Engine::ezrShader != nullptr)
121}
122
123void EngineGL2Renderer::onBindTexture(int contextIdx, int32_t textureId)
124{
125 if (Engine::lightingShader != nullptr)
126 Engine::lightingShader->bindTexture(contextIdx, textureId);
127
128 if (Engine::guiShader != nullptr)
129 Engine::guiShader->bindTexture(textureId);
130
131 if (Engine::currentEngine->shadowMapping != nullptr)
132 Engine::currentEngine->shadowMapping->bindTexture(contextIdx, textureId);
133
134 if (Engine::ezrShader != nullptr)
135 Engine::ezrShader->bindTexture(contextIdx, textureId);
136}
137
139{
140 if (Engine::lightingShader != nullptr)
142
143 if (Engine::currentEngine->shadowMapping != nullptr)
145
146 if (Engine::guiShader != nullptr)
148
149 if (Engine::ezrShader != nullptr)
151}
152
154{
155 if (Engine::lightingShader != nullptr)
157
158 if (Engine::particlesShader != nullptr)
160
161 if (Engine::linesShader != nullptr)
163
164 if (Engine::guiShader != nullptr)
166}
167
168void EngineGL2Renderer::onUpdateLight(int contextIdx, int32_t lightId)
169{
170 if (Engine::lightingShader != nullptr)
171 Engine::lightingShader->updateLight(contextIdx, lightId);
172
173 if (Engine::currentEngine->shadowMapping != nullptr)
174 Engine::currentEngine->shadowMapping->updateLight(contextIdx, lightId);
175}
176
178{
179 if (Engine::lightingShader != nullptr)
181
182 if (Engine::currentEngine->shadowMapping != nullptr)
184
185 if (Engine::ezrShader != nullptr)
187}
188
190 if (Engine::lightingShader != nullptr)
191 Engine::lightingShader->setShader(contextIdx, getShader(contextIdx));
192
193 if (Engine::currentEngine->shadowMapping != nullptr)
194 Engine::currentEngine->shadowMapping->setShader(contextIdx, getShader(contextIdx));
195
196 if (Engine::ezrShader != nullptr)
197 Engine::ezrShader->setShader(contextIdx, getShader(contextIdx));
198}
199
201 if (Engine::lightingShader != nullptr)
203
204 if (Engine::currentEngine->shadowMapping != nullptr)
206
207 if (Engine::ezrShader != nullptr)
209}
210
211// end point for engine to create renderer
213{
215 Console::println("EngineGL2Renderer::createInstance(): Engine and renderer version do not match: '" + EngineGL2Renderer::getRendererVersion() + "' != '" + Version::getVersion() + "'");
216 return nullptr;
217 }
218 Console::println("EngineGL2Renderer::createInstance(): Creating EngineGL2Renderer instance");
219 return new EngineGL2Renderer();
220}
EngineGL2Renderer * createInstance()
Engine main class.
Definition: Engine.h:122
static STATIC_DLL_IMPEXT Engine * currentEngine
Definition: Engine.h:180
static STATIC_DLL_IMPEXT EZRShader * ezrShader
Definition: Engine.h:193
static STATIC_DLL_IMPEXT LightingShader * lightingShader
Definition: Engine.h:196
static STATIC_DLL_IMPEXT LinesShader * linesShader
Definition: Engine.h:198
static STATIC_DLL_IMPEXT GUIShader * guiShader
Definition: Engine.h:200
static STATIC_DLL_IMPEXT ParticlesShader * particlesShader
Definition: Engine.h:197
ShadowMapping * shadowMapping
Definition: Engine.h:266
void updateMatrices(int contextIdx)
Update program matrices.
Definition: EZRShader.cpp:79
void setShader(int contextIdx, const string &id)
Set shader.
Definition: EZRShader.cpp:112
void updateTextureMatrix(int contextIdx)
Set up program texture matrix.
Definition: EZRShader.cpp:86
void updateShaderParameters(int contextIdx)
Update shader parameters.
Definition: EZRShader.cpp:106
void updateMaterial(int contextIdx)
Update material.
Definition: EZRShader.cpp:92
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
Definition: EZRShader.cpp:99
Interface to lighting shader program.
void updateLight(int contextIdx, int32_t lightId)
Update light to program.
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Update texture matrix to program.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material to program.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
Definition: LinesShader.cpp:85
void updateMatrices(int contextIdx)
Update matrices to program.
void updateEffect(int contextIdx)
Update effect to program.
Engine connector of GL2 renderer to other engine functionality.
void onUpdateCameraMatrix(int contextIdx) override
Update camera matrix event.
void onUpdateModelViewMatrix(int contextIdx) override
Update model view matrix event.
void onUpdateProjectionMatrix(int contextIdx) override
Update projection matrix event.
void onUpdateTextureMatrix(int contextIdx) override
Update texture matrix for active texture unit event.
void onBindTexture(int contextIdx, int32_t textureId) override
On bind texture event.
void onUpdateMaterial(int contextIdx) override
On update material.
bool prepareWindowSystemRendererContext(int tryIdx) override
Prepare window system renderer context.
void onUpdateEffect(int contextIdx) override
Update material.
bool initializeWindowSystemRendererContext(GLFWwindow *glfwWindow) override
Initialize window system renderer context.
void onUpdateLight(int contextIdx, int32_t lightId) override
Update light.
void onUpdateShaderParameters(int contextIdx) override
On update shader parameters.
void onUpdateShader(int contextIdx) override
On update shader.
const string & getShader(int contextIdx)
Get shader.
Definition: Renderer.h:1167
void updateLight(int contextIdx, int32_t lightId)
Update light.
void updateMatrices(int contextIdx)
Update matrices.
void setShader(int contextIdx, const string &id)
Set shader.
void updateTextureMatrix(int contextIdx)
Update texture matrix.
void updateShaderParameters(int contextIdx)
Update shader parameters.
void updateMaterial(int contextIdx)
Update material.
void bindTexture(int contextIdx, int32_t textureId)
Bind texture.
void updateEffect()
Update effect to program.
Definition: GUIShader.cpp:139
void bindTexture(int32_t textureId)
Bind texture.
Definition: GUIShader.cpp:125
void updateTextureMatrix()
Update texure matrix to program.
Definition: GUIShader.cpp:152
static string getVersion()
Definition: Version.cpp:11