TDME2  1.9.200
GLES2Renderer.cpp
Go to the documentation of this file.
2 
3 #define GL_GLEXT_PROTOTYPES
4 #include <GLES2/gl2.h>
5 
6 #include <string.h>
7 
8 #include <array>
9 #include <map>
10 #include <string>
11 #include <vector>
12 
13 #include <tdme/tdme.h>
14 #include <tdme/engine/Texture.h>
15 #include <tdme/engine/Engine.h>
17 #include <tdme/math/Matrix4x4.h>
20 #include <tdme/utilities/Buffer.h>
22 #include <tdme/utilities/Console.h>
27 #include <tdme/utilities/Time.h>
28 
29 using std::array;
30 using std::map;
31 using std::string;
32 using std::to_string;
33 using std::vector;
34 
36 
51 
52 GLES2Renderer::GLES2Renderer()
53 {
55  // setup GLES2 consts
56  ID_NONE = 0;
57  CLEAR_DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT;
58  CLEAR_COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT;
59  CULLFACE_FRONT = GL_FRONT;
60  CULLFACE_BACK = GL_BACK;
61  FRONTFACE_CW = GL_CW;
62  FRONTFACE_CCW = GL_CCW;
63  SHADER_FRAGMENT_SHADER = GL_FRAGMENT_SHADER;
64  SHADER_VERTEX_SHADER = GL_VERTEX_SHADER;
66  DEPTHFUNCTION_ALWAYS = GL_ALWAYS;
67  DEPTHFUNCTION_EQUAL = GL_EQUAL;
68  DEPTHFUNCTION_LESSEQUAL = GL_LEQUAL;
69  DEPTHFUNCTION_GREATEREQUAL = GL_GEQUAL;
70  CUBEMAPTEXTUREINDEX_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
71  CUBEMAPTEXTUREINDEX_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
72  CUBEMAPTEXTUREINDEX_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
73  CUBEMAPTEXTUREINDEX_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
74  CUBEMAPTEXTUREINDEX_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
75  CUBEMAPTEXTUREINDEX_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
77 }
78 
79 const string GLES2Renderer::getVendor() {
80  auto vendor = (char*)glGetString(GL_VENDOR);
81  return string(vendor);
82 }
83 
85  auto renderer = (char*)glGetString(GL_RENDERER);
86  return string(renderer) + " [GLES2]";
87 }
88 
90 {
91  return "gl2";
92 }
93 
95  return false;
96 }
97 
99 {
100  glGetError();
101  // get default framebuffer
102  FRAMEBUFFER_DEFAULT = 0; // getContext()->getDefaultDrawFramebuffer();
103  checkGLError();
104  // setup open gl
105  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
106  glClearDepthf(1.0f);
107  glEnable(GL_DEPTH_TEST);
108  glEnable(GL_CULL_FACE);
109  glDepthFunc(GL_LEQUAL);
110  glBlendEquation(GL_FUNC_ADD);
111  glDisable(GL_BLEND);
112  // renderer contexts
113  rendererContexts.resize(1);
114  for (auto& rendererContext: rendererContexts) {
115  for (auto i = 0; i < rendererContext.lights.size(); i++) {
116  rendererContext.lights[i].spotCosCutoff = static_cast<float>(Math::cos(Math::PI / 180.0f * 180.0f));
117  }
118  rendererContext.textureMatrix.identity();
119  }
120 }
121 
123 {
124 }
125 
127 {
128 }
129 
131 {
132  return false;
133 }
134 
136 {
137  return true;
138 }
139 
141  return false;
142 }
143 
144 
146 {
147  return false;
148 }
149 
151 {
152  return false;
153 }
154 
156  return false;
157 }
158 
160 {
161  return false;
162 }
163 
165  return false;
166 }
167 
169  return false;
170 }
171 
173  return true;
174 }
175 
177  return false;
178 }
179 
181 {
182  return -1;
183 }
184 
185 int32_t GLES2Renderer::loadShader(int32_t type, const string& pathName, const string& fileName, const string& definitions, const string& functions)
186 {
187  // create shader
188  int32_t shaderId = glCreateShader(type);
189  // exit if no handle returned
190  if (shaderId == 0) return 0;
191  // shader source
192  auto shaderSource = StringTools::replace(
193  StringTools::replace(
194  FileSystem::getInstance()->getContentAsString(pathName, fileName),
195  "{$DEFINITIONS}",
196  definitions + "\n\n"
197  ),
198  "{$FUNCTIONS}",
199  functions + "\n\n"
200  );
201  auto shaderSourceNullTerminated = shaderSource + "\0";
202  // load source
203  array<const char*, 1> shaderSourceNullTerminatedArray = { shaderSourceNullTerminated.data() };
204  glShaderSource(shaderId, 1, shaderSourceNullTerminatedArray.data(), nullptr);
205  // compile
206  glCompileShader(shaderId);
207  // check state
208  int32_t compileStatus;
209  glGetShaderiv(shaderId, GL_COMPILE_STATUS, &compileStatus);
210  if (compileStatus == 0) {
211  // get error
212  int32_t infoLogLength;
213  glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
214  string infoLog(infoLogLength, static_cast<char>(0));
215  glGetShaderInfoLog(shaderId, infoLogLength, &infoLogLength, infoLog.data());
216  // be verbose
217  Console::println(
218  string(
219  string("GLES2Renderer::loadShader") +
220  string("[") +
221  to_string(shaderId) +
222  string("]") +
223  pathName +
224  string("/") +
225  fileName +
226  string(": failed: ") +
227  infoLog
228  )
229  );
230  Console::println(shaderSource);
231  // remove shader
232  glDeleteShader(shaderId);
233  //
234  return 0;
235  }
236  //
237  return shaderId;
238 }
239 
240 void GLES2Renderer::useProgram(int contextIdx, int32_t programId)
241 {
242  glUseProgram(programId);
243 }
244 
246 {
247  return glCreateProgram();
248 }
249 
250 void GLES2Renderer::attachShaderToProgram(int32_t programId, int32_t shaderId)
251 {
252  glAttachShader(programId, shaderId);
253 }
254 
255 bool GLES2Renderer::linkProgram(int32_t programId)
256 {
257  glLinkProgram(programId);
258  // check state
259  int32_t linkStatus;
260  glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus);
261  if (linkStatus == 0) {
262  // get error
263  int32_t infoLogLength;
264  glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &infoLogLength);
265  string infoLog(infoLogLength, static_cast<char>(0));
266  glGetProgramInfoLog(programId, infoLogLength, &infoLogLength, infoLog.data());
267  // be verbose
268  Console::println(
269  string(
270  string("GLES2Renderer::linkProgram") +
271  "[" +
272  to_string(programId) +
273  "]: failed: " +
274  infoLog
275  )
276  );
277  //
278  return false;
279  }
280  //
281  return true;
282 }
283 
284 int32_t GLES2Renderer::getProgramUniformLocation(int32_t programId, const string& name)
285 {
286  auto uniformLocation = glGetUniformLocation(programId, name.c_str());
287  // if (uniformLocation == -1) Console::println("GLES2Renderer::getProgramUniformLocation(): " + to_string(programId) + ": " + name + ": not found");
288  return uniformLocation;
289 }
290 
291 void GLES2Renderer::setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)
292 {
293  glUniform1i(uniformId, value);
294 }
295 
296 void GLES2Renderer::setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)
297 {
298  glUniform1f(uniformId, value);
299 }
300 
301 void GLES2Renderer::setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array<float, 9>& data)
302 {
303  glUniformMatrix3fv(uniformId, 1, false, data.data());
304 }
305 
306 void GLES2Renderer::setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array<float, 16>& data)
307 {
308  glUniformMatrix4fv(uniformId, 1, false, data.data());
309 }
310 
311 void GLES2Renderer::setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer* data)
312 {
313  glUniformMatrix4fv(uniformId, count, false, (float*)data->getBuffer());
314 }
315 
316 void GLES2Renderer::setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array<float, 4>& data)
317 {
318  glUniform4fv(uniformId, 1, data.data());
319 }
320 
321 void GLES2Renderer::setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array<float, 3>& data)
322 {
323  glUniform3fv(uniformId, 1, data.data());
324 }
325 
326 void GLES2Renderer::setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array<float, 2>& data)
327 {
328  glUniform2fv(uniformId, 1, data.data());
329 }
330 
331 void GLES2Renderer::setProgramAttributeLocation(int32_t programId, int32_t location, const string& name)
332 {
333  glBindAttribLocation(programId, location, (name).c_str());
334 }
335 
336 void GLES2Renderer::setViewPort(int32_t width, int32_t height)
337 {
338  this->viewPortWidth = width;
339  this->viewPortHeight = height;
340 }
341 
343 {
344  glViewport(0, 0, viewPortWidth, viewPortHeight);
345 }
346 
347 void GLES2Renderer::setClearColor(float red, float green, float blue, float alpha)
348 {
349  glClearColor(red, green, blue, alpha);
350 }
351 
352 void GLES2Renderer::enableCulling(int contextIdx)
353 {
354  glEnable(GL_CULL_FACE);
355 }
356 
357 void GLES2Renderer::disableCulling(int contextIdx)
358 {
359  glDisable(GL_CULL_FACE);
360 }
361 
362 void GLES2Renderer::setFrontFace(int contextIdx, int32_t frontFace)
363 {
364  glFrontFace(frontFace);
365 }
366 
367 void GLES2Renderer::setCullFace(int32_t cullFace)
368 {
369  glCullFace(cullFace);
370 }
371 
373 {
374  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
375  glEnable(GL_BLEND);
376 }
377 
379  glBlendFunc(GL_ONE, GL_ONE);
380  glEnable(GL_BLEND);
381 }
382 
384 {
385  glDisable(GL_BLEND);
386 }
387 
389 {
390  glDepthMask(true);
391 }
392 
394 {
395  glDepthMask(false);
396 }
397 
399 {
400  glDisable(GL_DEPTH_TEST);
401 }
402 
404 {
405  glEnable(GL_DEPTH_TEST);
406 }
407 
408 
409 void GLES2Renderer::setDepthFunction(int32_t depthFunction)
410 {
411  glDepthFunc(depthFunction);
412 }
413 
414 void GLES2Renderer::setColorMask(bool red, bool green, bool blue, bool alpha)
415 {
416  glColorMask(red, green, blue, alpha);
417 }
418 
419 void GLES2Renderer::clear(int32_t mask)
420 {
421  glClear(mask);
423 }
424 
426 {
427  uint32_t textureId;
428  glGenTextures(1, &textureId);
429  return textureId;
430 }
431 
432 int32_t GLES2Renderer::createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
433 {
434  uint32_t depthTextureId;
435  // create depth texture
436  glGenTextures(1, &depthTextureId);
437  glBindTexture(GL_TEXTURE_2D, depthTextureId);
438  // create depth texture
439  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
440  // depth texture parameter
441  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
442  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
443  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
444  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
445  // unbind, return
446  glBindTexture(GL_TEXTURE_2D, ID_NONE);
447  return depthTextureId;
448 }
449 
450 int32_t GLES2Renderer::createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
451 {
452  uint32_t colorBufferTextureId;
453  // create color texture
454  glGenTextures(1, &colorBufferTextureId);
455  glBindTexture(GL_TEXTURE_2D, colorBufferTextureId);
456  // create color texture
457  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
458  // color texture parameter
459  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
460  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
461  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
462  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
463  // unbind, return
464  glBindTexture(GL_TEXTURE_2D, ID_NONE);
465  return colorBufferTextureId;
466 }
467 
468 int32_t GLES2Renderer::createGBufferGeometryTexture(int32_t width, int32_t height) {
469  Console::println("GLES2Renderer::createGBufferGeometryTexture(): Not implemented");
470  return ID_NONE;
471 }
472 
473 int32_t GLES2Renderer::createGBufferColorTexture(int32_t width, int32_t height) {
474  Console::println("GLES2Renderer::createGBufferColorTexture(): Not implemented");
475  return ID_NONE;
476 }
477 
478 void GLES2Renderer::uploadTexture(int contextIdx, Texture* texture)
479 {
480  //
481  auto textureTextureData = texture->getRGBTextureData();
482  //
483  glTexImage2D(
484  GL_TEXTURE_2D,
485  0,
486  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
487  texture->getTextureWidth(),
488  texture->getTextureHeight(),
489  0,
490  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
491  GL_UNSIGNED_BYTE,
492  textureTextureData.getBuffer()
493  );
494  //
495  if (texture->getAtlasSize() > 1) {
496  if (texture->isUseMipMap() == true) {
497  glGenerateMipmap(GL_TEXTURE_2D);
498  }
499  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
500  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
501  } else {
502  if (texture->isUseMipMap() == true) glGenerateMipmap(GL_TEXTURE_2D);
503  if (texture->isRepeat() == true) {
504  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
505  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
506  } else {
507  // TODO: this feature does not seem to exist with GLES2
508  /*
509  float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
510  if (texture->getClampMode() == Texture::CLAMPMODE_TRANSPARENTPIXEL) glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
511  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
512  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
513  */
514  }
515  }
516  switch (texture->getMinFilter()) {
518  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); break;
520  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); break;
522  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
524  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
526  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
528  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
529  }
530  switch (texture->getMagFilter()) {
532  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); break;
534  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break;
536  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
538  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
540  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
542  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
543  }
545 }
546 
547 void GLES2Renderer::uploadCubeMapTexture(int contextIdx, Texture* textureLeft, Texture* textureRight, Texture* textureTop, Texture* textureBottom, Texture* textureFront, Texture* textureBack) {
548  {
549  //
550  auto textureTextureData = textureLeft->getRGBTextureData();
551  //
552  glTexImage2D(
553  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
554  0,
555  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
556  textureLeft->getTextureWidth(),
557  textureLeft->getTextureHeight(),
558  0,
559  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
560  GL_UNSIGNED_BYTE,
561  textureTextureData.getBuffer()
562  );
563  }
564  {
565  //
566  auto textureTextureData = textureRight->getRGBTextureData();
567  //
568  glTexImage2D(
569  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
570  0,
571  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
572  textureRight->getTextureWidth(),
573  textureRight->getTextureHeight(),
574  0,
575  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
576  GL_UNSIGNED_BYTE,
577  textureTextureData.getBuffer()
578  );
579  }
580  {
581  //
582  auto textureTextureData = textureTop->getRGBTextureData();
583  //
584  glTexImage2D(
585  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
586  0,
587  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
588  textureTop->getTextureWidth(),
589  textureTop->getTextureHeight(),
590  0,
591  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
592  GL_UNSIGNED_BYTE,
593  textureTextureData.getBuffer()
594  );
595  }
596  {
597  //
598  auto textureTextureData = textureBottom->getRGBTextureData();
599  //
600  glTexImage2D(
601  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
602  0,
603  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
604  textureBottom->getTextureWidth(),
605  textureBottom->getTextureHeight(),
606  0,
607  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
608  GL_UNSIGNED_BYTE,
609  textureTextureData.getBuffer()
610  );
611  }
612  {
613  //
614  auto textureTextureData = textureFront->getRGBTextureData();
615  //
616  glTexImage2D(
617  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
618  0,
619  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
620  textureFront->getTextureWidth(),
621  textureFront->getTextureHeight(),
622  0,
623  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
624  GL_UNSIGNED_BYTE,
625  textureTextureData.getBuffer()
626  );
627  }
628  {
629  //
630  auto textureTextureData = textureBack->getRGBTextureData();
631  //
632  glTexImage2D(
633  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
634  0,
635  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
636  textureBack->getTextureWidth(),
637  textureBack->getTextureHeight(),
638  0,
639  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
640  GL_UNSIGNED_BYTE,
641  textureTextureData.getBuffer()
642  );
643  }
644  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
645  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
646  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
647  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
649 }
650 
651 int32_t GLES2Renderer::createCubeMapTexture(int contextIdx, int32_t width, int32_t height) {
652  // generate open gl texture
653  uint32_t textureId;
654  glGenTextures(1, &textureId);
655  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
656  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
657  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
658  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
659  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
660  glTexImage2D(
661  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
662  0,
663  GL_RGBA,
664  width,
665  height,
666  0,
667  GL_RGBA,
668  GL_UNSIGNED_BYTE,
669  nullptr
670  );
671  glTexImage2D(
672  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
673  0,
674  GL_RGBA,
675  width,
676  height,
677  0,
678  GL_RGBA,
679  GL_UNSIGNED_BYTE,
680  nullptr
681  );
682  glTexImage2D(
683  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
684  0,
685  GL_RGBA,
686  width,
687  height,
688  0,
689  GL_RGBA,
690  GL_UNSIGNED_BYTE,
691  nullptr
692  );
693  glTexImage2D(
694  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
695  0,
696  GL_RGBA,
697  width,
698  height,
699  0,
700  GL_RGBA,
701  GL_UNSIGNED_BYTE,
702  nullptr
703  );
704  glTexImage2D(
705  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
706  0,
707  GL_RGBA,
708  width,
709  height,
710  0,
711  GL_RGBA,
712  GL_UNSIGNED_BYTE,
713  nullptr
714  );
715  glTexImage2D(
716  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
717  0,
718  GL_RGBA,
719  width,
720  height,
721  0,
722  GL_RGBA,
723  GL_UNSIGNED_BYTE,
724  nullptr
725  );
726  glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
727  return textureId;
728 }
729 
730 void GLES2Renderer::resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height)
731 {
732  glBindTexture(GL_TEXTURE_2D, textureId);
733  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_UNSIGNED_INT, nullptr);
734  glBindTexture(GL_TEXTURE_2D, 0);
735 }
736 
737 void GLES2Renderer::resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height)
738 {
739  glBindTexture(GL_TEXTURE_2D, textureId);
740  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
741  glBindTexture(GL_TEXTURE_2D, 0);
742 }
743 
744 void GLES2Renderer::resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) {
745  Console::println("GLES2Renderer::resizeGBufferGeometryTexture(): Not implemented");
746 }
747 
748 void GLES2Renderer::resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) {
749  Console::println("GLES2Renderer::resizeGBufferColorTexture(): Not implemented");
750 }
751 
752 void GLES2Renderer::bindTexture(int contextIdx, int32_t textureId)
753 {
754  glBindTexture(GL_TEXTURE_2D, textureId);
755  onBindTexture(contextIdx, textureId);
756 }
757 
758 void GLES2Renderer::bindCubeMapTexture(int contextIdx, int32_t textureId) {
759  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
760  onBindTexture(contextIdx, textureId);
761 }
762 
763 void GLES2Renderer::disposeTexture(int32_t textureId)
764 {
765  glDeleteTextures(1, (const uint32_t*)&textureId);
767 }
768 
769 int32_t GLES2Renderer::createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
770 {
771  uint32_t frameBufferId;
772  // create a frame buffer object
773  glGenFramebuffers(1, &frameBufferId);
774  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
775  // attach the depth buffer texture to FBO
776  if (depthBufferTextureId != ID_NONE) {
777  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthBufferTextureId, 0);
778  }
779  // attach the depth buffer texture to FBO
780  if (colorBufferTextureId != ID_NONE) {
781  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBufferTextureId, 0);
782  // glDrawBuffer(GL_COLOR_ATTACHMENT0);
783  // glReadBuffer(GL_COLOR_ATTACHMENT0);
784  } else
785  if (cubeMapTextureId != ID_NONE) {
786  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cubeMapTextureIndex, cubeMapTextureId, 0);
787  } else {
788  // glDrawBuffer(GL_NONE);
789  // glReadBuffer(GL_NONE);
790  }
791  // check FBO status
792  auto fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
793  if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
794  Console::println(string("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO: "+ to_string(fboStatus)));
795  }
796  // switch back to window-system-provided framebuffer
797  glBindFramebuffer(GL_FRAMEBUFFER, 0);
798  return frameBufferId;
799 }
800 
802  int32_t depthBufferTextureId,
803  int32_t geometryBufferTextureId1,
804  int32_t geometryBufferTextureId2,
805  int32_t geometryBufferTextureId3,
806  int32_t colorBufferTextureId1,
807  int32_t colorBufferTextureId2,
808  int32_t colorBufferTextureId3,
809  int32_t colorBufferTextureId4,
810  int32_t colorBufferTextureId5
811 ) {
812  Console::println(string("GLES2Renderer::createGeometryBufferObject()::not implemented yet"));
813  return ID_NONE;
814 }
815 
816 void GLES2Renderer::bindFrameBuffer(int32_t frameBufferId)
817 {
818  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
819 }
820 
821 void GLES2Renderer::disposeFrameBufferObject(int32_t frameBufferId)
822 {
823  glDeleteFramebuffers(1, (const uint32_t*)&frameBufferId);
824 }
825 
826 vector<int32_t> GLES2Renderer::createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared)
827 {
828  vector<int32_t> bufferObjectIds;
829  bufferObjectIds.resize(buffers);
830  glGenBuffers(buffers, (uint32_t*)bufferObjectIds.data());
831  for (auto bufferObjectId: bufferObjectIds) vbosUsage[bufferObjectId] = useGPUMemory == true?GL_STATIC_DRAW:GL_STREAM_DRAW;
832  return bufferObjectIds;
833 }
834 
835 void GLES2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data)
836 {
837  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
838  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
839  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
841 }
842 
843 void GLES2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
844 {
845  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
846  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
847  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
849 }
850 
851 void GLES2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
852 {
853  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
854  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
855  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
857 }
858 
859 void GLES2Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
860 {
861  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
862  glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
863  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID_NONE);
865 }
866 
867 void GLES2Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
868 {
869  Console::println("GLES2Renderer::uploadIndicesBufferObject()::not implemented");
870 }
871 
872 void GLES2Renderer::bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId)
873 {
874  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
875 }
876 
877 void GLES2Renderer::bindSolidColorsBufferObject(int contextIdx, int32_t bufferObjectId)
878 {
879  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
880  glEnableVertexAttribArray(1);
881  glVertexAttribPointer(1, 1, GL_FLOAT, false, 0, 0LL);
882 }
883 
884 void GLES2Renderer::bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId)
885 {
886  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
887  glEnableVertexAttribArray(2);
888  glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0LL);
889 }
890 
891 void GLES2Renderer::bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId)
892 {
893  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
894  glEnableVertexAttribArray(0);
895  glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0LL);
896 }
897 
898 void GLES2Renderer::bindVertices2BufferObject(int contextIdx, int32_t bufferObjectId)
899 {
900  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
901  glEnableVertexAttribArray(0);
902  glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0LL);
903 }
904 
905 void GLES2Renderer::bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId)
906 {
907  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
908  glEnableVertexAttribArray(1);
909  glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0LL);
910 }
911 
912 void GLES2Renderer::bindColorsBufferObject(int contextIdx, int32_t bufferObjectId)
913 {
914  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
915  glEnableVertexAttribArray(3);
916  glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0LL);
917 }
918 
919 void GLES2Renderer::bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId)
920 {
921  Console::println("GLES2Renderer::bindTangentsBufferObject()::not implemented");
922 }
923 
924 void GLES2Renderer::bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId)
925 {
926  Console::println("GLES2Renderer::bindBitangentsBufferObject()::not implemented");
927 }
928 
929 void GLES2Renderer::bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
930  Console::println(string("GLES2Renderer::bindModelViewMatricesBufferObject()::not implemented yet"));
931 }
932 
933 void GLES2Renderer::bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
934  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
935  glEnableVertexAttribArray(10);
936  glVertexAttribPointer(10, 4, GL_FLOAT, false, 0, 0LL);
937 }
938 
939 void GLES2Renderer::bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
940  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
941  glEnableVertexAttribArray(11);
942  glVertexAttribPointer(11, 4, GL_FLOAT, false, 0, 0LL);
943 }
944 
945 void GLES2Renderer::bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) {
946  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
947  glEnableVertexAttribArray(4);
948  glVertexAttribPointer(4, 3, GL_FLOAT, false, 0, 0LL);
949 }
950 
951 void GLES2Renderer::bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) {
952  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
953  glEnableVertexAttribArray(1);
954  glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0LL);
955 }
956 
957 void GLES2Renderer::bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) {
958  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
959  glEnableVertexAttribArray(5);
960  glVertexAttribPointer(5, 1, GL_FLOAT, false, 0, 0LL);
961 }
962 
963 void GLES2Renderer::bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) {
964  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
965  glEnableVertexAttribArray(6);
966  glVertexAttribPointer(6, 2, GL_FLOAT, false, 0, 0LL);
967 }
968 
969 void GLES2Renderer::drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances)
970 {
971  Console::println(string("GLES2Renderer::drawInstancedIndexedTrianglesFromBufferObjects()::not implemented yet"));
972 }
973 
974 void GLES2Renderer::drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
975 {
976  #define BUFFER_OFFSET(i) ((void*)(i))
977  glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_SHORT, BUFFER_OFFSET(static_cast<int64_t>(trianglesOffset) * 3LL * 2LL));
979  statistics.instances+= 1;
980  statistics.triangles+= triangles;
981 }
982 
983 void GLES2Renderer::drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) {
984  Console::println(string("GL2Renderer::drawInstancedTrianglesFromBufferObjects()::not implemented yet"));
985 }
986 
987 void GLES2Renderer::drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
988 {
989  glDrawArrays(GL_TRIANGLES, trianglesOffset * 3, triangles * 3);
991  statistics.instances+= 1;
992  statistics.triangles+= triangles;
993 }
994 
995 void GLES2Renderer::drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
996 {
997  glDrawArrays(GL_POINTS, pointsOffset, points);
999  statistics.points+= points;
1000 }
1001 
1002 void GLES2Renderer::setLineWidth(float lineWidth)
1003 {
1004  glLineWidth(lineWidth);
1005 }
1006 
1007 void GLES2Renderer::drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
1008 {
1009  glDrawArrays(GL_LINES, pointsOffset, points);
1011  statistics.linePoints+= points;
1012 }
1013 
1015 {
1016  glDisableVertexAttribArray(0);
1017  glDisableVertexAttribArray(1);
1018  glDisableVertexAttribArray(2);
1019  glDisableVertexAttribArray(3);
1020  glDisableVertexAttribArray(4);
1021  glBindBuffer(GL_ARRAY_BUFFER, 0);
1022  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1023 }
1024 
1025 void GLES2Renderer::disposeBufferObjects(vector<int32_t>& bufferObjectIds)
1026 {
1027  for (auto& bufferObjectId: bufferObjectIds) vbosUsage.erase(bufferObjectId);
1028  glDeleteBuffers(bufferObjectIds.size(), (const uint32_t*)bufferObjectIds.data());
1029  statistics.disposedBuffers+= bufferObjectIds.size();
1030 }
1031 
1032 int32_t GLES2Renderer::getTextureUnit(int contextIdx)
1033 {
1034  return activeTextureUnit;
1035 }
1036 
1037 void GLES2Renderer::setTextureUnit(int contextIdx, int32_t textureUnit)
1038 {
1039  this->activeTextureUnit = textureUnit;
1040  glActiveTexture(GL_TEXTURE0 + textureUnit);
1041 }
1042 
1043 float GLES2Renderer::readPixelDepth(int32_t x, int32_t y)
1044 {
1045  return -1.0f;
1046 }
1047 
1048 ByteBuffer* GLES2Renderer::readPixels(int32_t x, int32_t y, int32_t width, int32_t height)
1049 {
1050  return nullptr;
1051 }
1052 
1054 {
1056  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1057  glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
1058  glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1059  glEnable(GL_BLEND);
1060  glDisable(GL_DEPTH_TEST);
1061  glDisable(GL_CULL_FACE);
1062 }
1063 
1065 {
1066  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1067  glDisable(GL_BLEND);
1068  glEnable(GL_DEPTH_TEST);
1069  glEnable(GL_CULL_FACE);
1070 }
1071 
1072 void GLES2Renderer::dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) {
1073  Console::println("GLES2Renderer::dispatchCompute(): Not implemented");
1074 }
1075 
1077  Console::println("GLES2Renderer::memoryBarrier(): Not implemented");
1078 }
1079 
1080 void GLES2Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) {
1081  Console::println("GLES2Renderer::uploadSkinningBufferObject(): Not implemented");
1082 }
1083 
1084 void GLES2Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) {
1085  Console::println("GLES2Renderer::uploadSkinningBufferObject(): Not implemented");
1086 }
1087 
1088 void GLES2Renderer::bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) {
1089  Console::println("GLES2Renderer::bindSkinningVerticesBufferObject(): Not implemented");
1090 }
1091 
1092 void GLES2Renderer::bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) {
1093  Console::println("GLES2Renderer::bindSkinningNormalsBufferObject(): Not implemented");
1094 }
1095 
1096 void GLES2Renderer::bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) {
1097  Console::println("GLES2Renderer::bindSkinningVertexJointsBufferObject(): Not implemented");
1098 }
1099 
1100 void GLES2Renderer::bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) {
1101  Console::println("GLES2Renderer::bindSkinningVertexJointIdxsBufferObject(): Not implemented");
1102 }
1103 
1104 void GLES2Renderer::bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) {
1105  Console::println("GLES2Renderer::bindSkinningVertexJointWeightsBufferObject(): Not implemented");
1106 }
1107 
1108 void GLES2Renderer::bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1109  Console::println("GLES2Renderer::bindSkinningVerticesResultBufferObject(): Not implemented");
1110 }
1111 
1112 void GLES2Renderer::bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1113  Console::println("GLES2Renderer::bindSkinningNormalsResultBufferObject(): Not implemented");
1114 }
1115 
1116 void GLES2Renderer::bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
1117  Console::println("GLES2Renderer::bindSkinningMatricesBufferObject(): Not implemented");
1118 }
1119 
1120 void GLES2Renderer::setVSync(bool vSync) {
1121  // no op
1122 }
1123 
1125  auto stats = statistics;
1126  statistics.time = Time::getCurrentMillis();
1127  statistics.memoryUsageGPU = -1LL;
1129  statistics.clearCalls = 0;
1130  statistics.renderCalls = 0;
1131  statistics.instances = 0;
1133  statistics.triangles = 0;
1134  statistics.points = 0;
1135  statistics.linePoints = 0;
1140  statistics.submits = 0;
1143  return stats;
1144 }
1145 
1147 {
1148  auto error = glGetError();
1149  if (error != GL_NO_ERROR) {
1150  Console::println(string("OpenGL Error: (" + to_string(error) + ") @:"));
1151  }
1152 }
#define BUFFER_OFFSET(i)
Engine main class.
Definition: Engine.h:131
Frame buffer class.
Definition: FrameBuffer.h:22
Texture entity.
Definition: Texture.h:24
TextureFilter getMinFilter() const
Definition: Texture.h:339
bool isRepeat() const
Definition: Texture.h:309
ByteBuffer getRGBTextureData()
Definition: Texture.h:253
bool isUseMipMap() const
Definition: Texture.h:294
uint8_t getRGBDepthBitsPerPixel() const
Definition: Texture.h:186
uint16_t getTextureHeight() const
Definition: Texture.h:211
TextureFilter getMagFilter() const
Definition: Texture.h:354
uint16_t getTextureWidth() const
Definition: Texture.h:218
@ TEXTUREFILTER_LINEAR_MIPMAP_LINEAR
Definition: Texture.h:49
@ TEXTUREFILTER_LINEAR_MIPMAP_NEAREST
Definition: Texture.h:47
@ TEXTUREFILTER_NEAREST_MIPMAP_NEAREST
Definition: Texture.h:46
@ TEXTUREFILTER_NEAREST_MIPMAP_LINEAR
Definition: Texture.h:48
uint16_t getAtlasSize() const
Definition: Texture.h:369
void setClearColor(float red, float green, float blue, float alpha) override
Set up clear color.
void enableDepthBufferWriting() override
Enable depth buffer writing.
void bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind sprite sheet dimension buffer object.
void bindTexture(int contextIdx, int32_t textureId) override
Binds a texture with given id or unbinds when using ID_NONE.
void clear(int32_t mask) override
Clear render buffer with given mask.
void bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind tangents buffer object.
void disposeBufferObjects(vector< int32_t > &bufferObjectIds) override
Disposes a frame buffer object.
int32_t getTextureUnit(int contextIdx) override
Get texture unit.
void setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array< float, 9 > &data) override
Set up a float matrix 3x3 uniform value.
void doneGuiMode() override
Set up renderer for 3d rendering.
void setColorMask(bool red, bool green, bool blue, bool alpha) override
Set up GL rendering colormask.
void bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind texture coordinates buffer object.
void bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joint weights buffer object.
void dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) override
Dispatch compute.
void attachShaderToProgram(int32_t programId, int32_t shaderId) override
Attaches a shader to a program.
void setFrontFace(int contextIdx, int32_t frontFace) override
Set up clock wise or counter clock wise faces as front face.
void setTextureUnit(int contextIdx, int32_t textureUnit) override
Sets up texture unit.
void drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override
Draw lines from buffer objects.
void disableBlending() override
Disables blending.
void setProgramAttributeLocation(int32_t programId, int32_t location, const string &name) override
Bind attribute to a input location.
void setViewPort(int32_t width, int32_t height) override
Set up viewport parameter.
void bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertices result buffer object.
void setProgramUniformFloat(int contextIdx, int32_t uniformId, float value) override
Set up a float uniform value.
const Renderer_Statistics getStatistics() override
void initialize() override
Initialize renderer.
void setVSync(bool vSync) override
Enable/Disable v-sync.
int32_t createGBufferColorTexture(int32_t width, int32_t height) override
Creates a geometry buffer color RGBA texture.
void setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array< float, 3 > &data) override
Set up a float vec3 uniform value.
void bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override
Bind effect color adds buffer object.
void disposeFrameBufferObject(int32_t frameBufferId) override
Disposes a frame buffer object.
void uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data) override
Uploads buffer data to buffer object.
void setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value) override
Set up a integer uniform value.
int32_t getProgramUniformLocation(int32_t programId, const string &name) override
Returns location of given uniform variable.
void disableDepthBufferWriting() override
Disable depth buffer writing.
void bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joint indices buffer object.
void bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind normals buffer object.
void drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset) override
Draw points from buffer objects.
void drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override
Draw instanced triangles from buffer objects.
void disposeTexture(int32_t textureId) override
Dispose a texture.
int32_t createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override
Creates a color buffer texture.
void disableCulling(int contextIdx) override
Disable culling.
void bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) override
Bind effect color muls buffer object.
int32_t createCubeMapTexture(int contextIdx, int32_t width, int32_t height) override
Create cube map texture from frame buffers.
int32_t createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId=0, int32_t cubeMapTextureIndex=0) override
Creates a frame buffer object with depth texture attached.
int32_t createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex) override
Creates a depth buffer texture.
void bindCubeMapTexture(int contextIdx, int32_t textureId) override
Binds a cube map texture with given id or unbinds when using ID_NONE.
void setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array< float, 4 > &data) override
Set up a float vec4 uniform value.
void setDepthFunction(int32_t depthFunction) override
Set up depth function.
void uploadCubeMapTexture(int contextIdx, Texture *textureLeft, Texture *textureRight, Texture *textureTop, Texture *textureBottom, Texture *textureFront, Texture *textureBack) override
Uploads cube map texture data to current bound texture.
void bindFrameBuffer(int32_t frameBufferId) override
Enables a framebuffer to be rendered.
int32_t loadShader(int32_t type, const string &pathName, const string &fileName, const string &definitions=string(), const string &functions=string()) override
Loads a shader.
void resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a depth texture.
void resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a geometry buffer geometry texture.
bool isInstancedRenderingAvailable() override
Checks if instanced rendering is available.
void drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override
Draw triangles from buffer objects.
void initGuiMode() override
Set up renderer for GUI rendering.
void bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertex joints buffer object.
void setCullFace(int32_t cullFace) override
Sets up which face will be culled.
void enableBlending() override
Enables blending.
void uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer *data) override
Uploads buffer data to buffer object.
bool linkProgram(int32_t programId) override
Links attached shaders to a program.
void setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array< float, 16 > &data) override
Set up a float matrix 4x4 uniform value.
void enableCulling(int contextIdx) override
Enable culling.
void bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind origins buffer object.
int32_t createProgram(int type) override
Creates a shader program.
void bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind indices buffer object.
void initializeFrame() override
Pre Frame Initialization.
int32_t createGBufferGeometryTexture(int32_t width, int32_t height) override
Creates a geometry buffer geometry texture.
void uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer *data) override
Upload skinning buffer object.
void enableAdditionBlending() override
Enable blending with c = a + b.
void bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind vertices buffer object.
void drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) override
Draw instanced indexed triangles from buffer objects.
void bindVertices2BufferObject(int contextIdx, int32_t bufferObjectId) override
Bind vertices 2 buffer object.
void useProgram(int contextIdx, int32_t programId) override
Use shader program.
void bindColorsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind colors buffer object.
void bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind point sizes buffer object.
void bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning vertices buffer object.
void bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind bitangents buffer object.
void bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning normals result buffer object.
void setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer *data) override
Set up a float matrices 4x4 uniform values.
void resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) override
Resizes a geometry buffer color RGBA texture.
void bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning matrices result buffer object.
int32_t createGeometryBufferObject(int32_t depthBufferTextureId, int32_t geometryBufferTextureId1, int32_t geometryBufferTextureId2, int32_t geometryBufferTextureId3, int32_t colorBufferTextureId1, int32_t colorBufferTextureId2, int32_t colorBufferTextureId3, int32_t colorBufferTextureId4, int32_t colorBufferTextureId5) override
Creates a geometry frame buffer object.
vector< int32_t > createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared) override
Generate buffer objects for vertex data and such.
void updateViewPort() override
Update viewport.
void bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind model matrices buffer object.
void drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset) override
Draw indexed triangles from buffer objects.
void disableDepthBufferTest() override
Disable depth buffer test.
void bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind skinning normal buffer object.
void unbindBufferObjects(int contextIdx) override
Unbind buffer objects.
int32_t createTexture() override
Creates a texture.
float readPixelDepth(int32_t x, int32_t y) override
Reads a pixel depth.
void uploadTexture(int contextIdx, Texture *texture) override
Uploads texture data to current bound texture.
void checkGLError()
Checks if GL error did occour.
void setLineWidth(float lineWidth) override
Set line width.
ByteBuffer * readPixels(int32_t x, int32_t y, int32_t width, int32_t height) override
Read pixels.
void enableDepthBufferTest() override
Enable depth buffer test.
void resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height) override
Resize color buffer texture.
void bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind texture and sprite indices buffer object.
void setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array< float, 2 > &data) override
Set up a float vec2 uniform value.
void bindSolidColorsBufferObject(int contextIdx, int32_t bufferObjectId) override
Bind solid colors buffer object.
vector< Renderer_Context > rendererContexts
Definition: Renderer.h:192
virtual void onBindTexture(int contextIdx, int32_t textureId)=0
On bind texture event.
Matrix4x4 class representing matrix4x4 mathematical structure and operations for 3d space.
Definition: Matrix4x4.h:23
File system singleton class.
Definition: FileSystem.h:17
Base class of buffers.
Definition: Buffer.h:21
const uint8_t * getBuffer() const
Definition: Buffer.h:150
Byte buffer class.
Definition: ByteBuffer.h:27
Console class.
Definition: Console.h:29
Float buffer class.
Definition: FloatBuffer.h:18
Integer buffer class.
Definition: IntBuffer.h:14
Short buffer class.
Definition: ShortBuffer.h:14
String tools class.
Definition: StringTools.h:22
Time utility class.
Definition: Time.h:20