TDME2  1.9.200
GL2Renderer.cpp
Go to the documentation of this file.
2 
3 #if defined(__APPLE__)
4  #include <OpenGL/gl.h>
5 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32) || defined(__HAIKU__)
6  #define GLEW_NO_GLU
7  #include <GL/glew.h>
8 #endif
9 
10 #include <string.h>
11 
12 #include <array>
13 #include <map>
14 #include <string>
15 #include <vector>
16 
17 #include <tdme/tdme.h>
18 #include <tdme/engine/Texture.h>
19 #include <tdme/engine/Engine.h>
21 #include <tdme/math/Matrix4x4.h>
24 #include <tdme/utilities/Buffer.h>
26 #include <tdme/utilities/Console.h>
32 #include <tdme/utilities/Time.h>
33 
34 using std::array;
35 using std::map;
36 using std::string;
37 using std::to_string;
38 using std::vector;
39 
41 
57 
58 GL2Renderer::GL2Renderer()
59 {
60  // setup GL2 consts
62  ID_NONE = 0;
63  CLEAR_DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT;
64  CLEAR_COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT;
65  CULLFACE_FRONT = GL_FRONT;
66  CULLFACE_BACK = GL_BACK;
67  FRONTFACE_CW = GL_CW;
68  FRONTFACE_CCW = GL_CCW;
69  SHADER_FRAGMENT_SHADER = GL_FRAGMENT_SHADER;
70  SHADER_VERTEX_SHADER = GL_VERTEX_SHADER;
72  DEPTHFUNCTION_ALWAYS = GL_ALWAYS;
73  DEPTHFUNCTION_EQUAL = GL_EQUAL;
74  DEPTHFUNCTION_LESSEQUAL = GL_LEQUAL;
75  DEPTHFUNCTION_GREATEREQUAL = GL_GEQUAL;
76  CUBEMAPTEXTUREINDEX_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
77  CUBEMAPTEXTUREINDEX_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
78  CUBEMAPTEXTUREINDEX_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
79  CUBEMAPTEXTUREINDEX_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
80  CUBEMAPTEXTUREINDEX_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
81  CUBEMAPTEXTUREINDEX_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
82  // TODO: buffer objects available
84 }
85 
86 const string GL2Renderer::getVendor() {
87  auto vendor = glGetString(GL_VENDOR);
88  return string((char*)vendor);
89 }
90 
91 const string GL2Renderer::getRenderer() {
92  auto renderer = glGetString(GL_RENDERER);
93  return string((char*)renderer) + " [GL2/3]";
94 }
95 
97 {
98  return "gl2";
99 }
100 
102  return false;
103 }
104 
106 {
107  return false;
108 }
109 
111 {
112  glGetError();
113  // get default framebuffer
114  FRAMEBUFFER_DEFAULT = 0; // getContext()->getDefaultDrawFramebuffer();
115  // setup open gl
116  glShadeModel(GL_SMOOTH);
117  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
118  glClearDepth(1.0f);
119  glEnable(GL_DEPTH_TEST);
120  glEnable(GL_CULL_FACE);
121  glDepthFunc(GL_LEQUAL);
122  glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_NICEST);
123  glBlendEquation(GL_FUNC_ADD);
124  glDisable(GL_BLEND);
125  glEnable(GL_POINT_SPRITE);
126  glEnable(GL_PROGRAM_POINT_SIZE_EXT);
128  // renderer contexts
129  rendererContexts.resize(1);
130  for (auto& rendererContext: rendererContexts) {
131  for (auto i = 0; i < rendererContext.lights.size(); i++) {
132  rendererContext.lights[i].spotCosCutoff = static_cast<float>(Math::cos(Math::PI / 180.0f * 180.0f));
133  }
134  rendererContext.textureMatrix.identity();
135  }
136 }
137 
139 {
140 }
141 
143 {
144 }
145 
147 {
148  return true;
149 }
150 
152  return false;
153 }
154 
156 {
157  return false;
158 }
159 
161 {
162  return false;
163 }
164 
166  return false;
167 }
168 
170 {
171  return false;
172 }
173 
175  return false;
176 }
177 
179  return false;
180 }
181 
183  return false;
184 }
185 
187  return false;
188 }
189 
191 {
192  return -1;
193 }
194 
195 int32_t GL2Renderer::loadShader(int32_t type, const string& pathName, const string& fileName, const string& definitions, const string& functions)
196 {
197  // create shader
198  int32_t shaderId = glCreateShader(type);
199  // exit if no handle returned
200  if (shaderId == 0) return 0;
201  // shader source
202  auto shaderSource = StringTools::replace(
203  StringTools::replace(
204  FileSystem::getInstance()->getContentAsString(pathName, fileName),
205  "{$DEFINITIONS}",
206  definitions + "\n\n"
207  ),
208  "{$FUNCTIONS}",
209  functions + "\n\n"
210  );
211  // some adjustments to have GLES2 shader working with GL2
212  shaderSource = StringTools::replace(shaderSource, "#version 100", "#version 120");
213  shaderSource = StringTools::replace(shaderSource, "\r", "");
214  {
215  StringTokenizer t;
216  t.tokenize(shaderSource, "\n");
217  shaderSource.clear();
218  while (t.hasMoreTokens() == true) {
219  auto line = t.nextToken();
220  if (StringTools::startsWith(line, "precision") == true) continue;
221  shaderSource+= line + "\n";
222  }
223  }
224  auto shaderSourceNullTerminated = shaderSource + "\0";
225  // load source
226  array<const char*, 1> shaderSourceNullTerminatedArray = { shaderSourceNullTerminated.data() };
227  glShaderSource(shaderId, 1, shaderSourceNullTerminatedArray.data(), nullptr);
228  // compile
229  glCompileShader(shaderId);
230  // check state
231  int32_t compileStatus;
232  glGetShaderiv(shaderId, GL_COMPILE_STATUS, &compileStatus);
233  if (compileStatus == 0) {
234  // get error
235  int32_t infoLogLength;
236  glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
237  string infoLog(infoLogLength, static_cast<char>(0));
238  glGetShaderInfoLog(shaderId, infoLogLength, &infoLogLength, infoLog.data());
239  // be verbose
240  Console::println(
241  string(
242  string("GL2Renderer::loadShader") +
243  string("[") +
244  to_string(shaderId) +
245  string("]") +
246  pathName +
247  string("/") +
248  fileName +
249  string(": failed: ") +
250  infoLog
251  )
252  );
253  Console::println(shaderSource);
254  // remove shader
255  glDeleteShader(shaderId);
256  //
257  return 0;
258  }
259  //
260  return shaderId;
261 }
262 
263 void GL2Renderer::useProgram(int contextIdx, int32_t programId)
264 {
265  glUseProgram(programId);
266 }
267 
268 int32_t GL2Renderer::createProgram(int type)
269 {
270  return glCreateProgram();
271 }
272 
273 void GL2Renderer::attachShaderToProgram(int32_t programId, int32_t shaderId)
274 {
275  glAttachShader(programId, shaderId);
276 }
277 
278 bool GL2Renderer::linkProgram(int32_t programId)
279 {
280  glLinkProgram(programId);
281  // check state
282  int32_t linkStatus;
283  glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus);
284  if (linkStatus == 0) {
285  // get error
286  int32_t infoLogLength;
287  glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &infoLogLength);
288  string infoLog(infoLogLength, static_cast<char>(0));
289  glGetProgramInfoLog(programId, infoLogLength, &infoLogLength, infoLog.data());
290  // be verbose
291  Console::println(
292  string(
293  string("GL2Renderer::linkProgram") +
294  "[" +
295  to_string(programId) +
296  "]: failed: " +
297  infoLog
298  )
299  );
300  //
301  return false;
302  }
303  //
304  return true;
305 }
306 
307 int32_t GL2Renderer::getProgramUniformLocation(int32_t programId, const string& name)
308 {
309  auto uniformLocation = glGetUniformLocation(programId, (name).c_str());
310  return uniformLocation;
311 }
312 
313 void GL2Renderer::setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)
314 {
315  glUniform1i(uniformId, value);
316 }
317 
318 void GL2Renderer::setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)
319 {
320  glUniform1f(uniformId, value);
321 }
322 
323 void GL2Renderer::setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer* data)
324 {
325  glUniformMatrix4fv(uniformId, count, false, (float*)data->getBuffer());
326 }
327 
328 void GL2Renderer::setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array<float, 9>& data)
329 {
330  glUniformMatrix3fv(uniformId, 1, false, data.data());
331 }
332 
333 void GL2Renderer::setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array<float, 16>& data)
334 {
335  glUniformMatrix4fv(uniformId, 1, false, data.data());
336 }
337 
338 void GL2Renderer::setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array<float, 4>& data)
339 {
340  glUniform4fv(uniformId, 1, data.data());
341 }
342 
343 void GL2Renderer::setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array<float, 3>& data)
344 {
345  glUniform3fv(uniformId, 1, data.data());
346 }
347 
348 void GL2Renderer::setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array<float, 2>& data)
349 {
350  glUniform2fv(uniformId, 1, data.data());
351 }
352 
353 void GL2Renderer::setProgramAttributeLocation(int32_t programId, int32_t location, const string& name)
354 {
355  glBindAttribLocation(programId, location, (name).c_str());
356 }
357 
358 void GL2Renderer::setViewPort(int32_t width, int32_t height)
359 {
360  this->viewPortWidth = width;
361  this->viewPortHeight = height;
362 }
363 
365 {
366  glViewport(0, 0, viewPortWidth, viewPortHeight);
367 }
368 
369 void GL2Renderer::setClearColor(float red, float green, float blue, float alpha)
370 {
371  glClearColor(red, green, blue, alpha);
372 }
373 
374 void GL2Renderer::enableCulling(int contextIdx)
375 {
376  glEnable(GL_CULL_FACE);
377 }
378 
379 void GL2Renderer::disableCulling(int contextIdx)
380 {
381  glDisable(GL_CULL_FACE);
382 }
383 
384 void GL2Renderer::setFrontFace(int contextIdx, int32_t frontFace)
385 {
386  glFrontFace(frontFace);
387 }
388 
389 void GL2Renderer::setCullFace(int32_t cullFace)
390 {
391  glCullFace(cullFace);
392 }
393 
395 {
396  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
397  glEnable(GL_BLEND);
398 }
399 
401  glBlendFunc(GL_ONE, GL_ONE);
402  glEnable(GL_BLEND);
403 }
404 
406 {
407  glDisable(GL_BLEND);
408 }
409 
411 {
412  glDepthMask(true);
413 }
414 
416 {
417  glDepthMask(false);
418 }
419 
421 {
422  glDisable(GL_DEPTH_TEST);
423 }
424 
426 {
427  glEnable(GL_DEPTH_TEST);
428 }
429 
430 void GL2Renderer::setDepthFunction(int32_t depthFunction)
431 {
432  glDepthFunc(depthFunction);
433 }
434 
435 void GL2Renderer::setColorMask(bool red, bool green, bool blue, bool alpha)
436 {
437  glColorMask(red, green, blue, alpha);
438 }
439 
440 void GL2Renderer::clear(int32_t mask)
441 {
442  glClear(mask);
444 }
445 
447 {
448  uint32_t textureId;
449  glGenTextures(1, &textureId);
450  return textureId;
451 }
452 
453 int32_t GL2Renderer::createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
454 {
455  uint32_t depthTextureId;
456  // create depth texture
457  glGenTextures(1, &depthTextureId);
458  glBindTexture(GL_TEXTURE_2D, depthTextureId);
459  // create depth texture
460  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
461  // depth texture parameter
462  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
463  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
464  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
465  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
466  // unbind, return
467  glBindTexture(GL_TEXTURE_2D, ID_NONE);
468  return depthTextureId;
469 }
470 
471 int32_t GL2Renderer::createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
472 {
473  uint32_t colorBufferTextureId;
474  // create color texture
475  glGenTextures(1, &colorBufferTextureId);
476  glBindTexture(GL_TEXTURE_2D, colorBufferTextureId);
477  // create color texture
478  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, static_cast<Buffer*>(nullptr));
479  // color texture parameter
480  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
481  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
482  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
483  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
484  // unbind, return
485  glBindTexture(GL_TEXTURE_2D, ID_NONE);
486  return colorBufferTextureId;
487 }
488 
489 int32_t GL2Renderer::createGBufferGeometryTexture(int32_t width, int32_t height) {
490  Console::println("GL2Renderer::createGBufferGeometryTexture(): Not implemented");
491  return ID_NONE;
492 }
493 
494 int32_t GL2Renderer::createGBufferColorTexture(int32_t width, int32_t height) {
495  Console::println("GL2Renderer::createGBufferColorTexture(): Not implemented");
496  return ID_NONE;
497 }
498 
499 void GL2Renderer::uploadTexture(int contextIdx, Texture* texture)
500 {
501  //
502  auto textureTextureData = texture->getRGBTextureData();
503  //
504  glTexImage2D(
505  GL_TEXTURE_2D,
506  0,
507  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
508  texture->getTextureWidth(),
509  texture->getTextureHeight(),
510  0,
511  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
512  GL_UNSIGNED_BYTE,
513  textureTextureData.getBuffer()
514  );
515  if (texture->getAtlasSize() > 1) {
516  if (texture->isUseMipMap() == true) {
517  float maxLodBias;
518  glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &maxLodBias);
519  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -Math::clamp(static_cast<float>(texture->getAtlasSize()) * 0.125f, 0.0f, maxLodBias));
520  auto borderSize = 32;
521  auto maxLevel = 0;
522  while (borderSize > 4) {
523  maxLevel++;
524  borderSize/= 2;
525  }
526  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
527  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, maxLevel - 1);
528  glGenerateMipmap(GL_TEXTURE_2D);
529  }
530  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
531  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
532  } else {
533  if (texture->isUseMipMap() == true) glGenerateMipmap(GL_TEXTURE_2D);
534  if (texture->isRepeat() == true) {
535  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
536  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
537  } else {
538  float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
539  if (texture->getClampMode() == Texture::CLAMPMODE_TRANSPARENTPIXEL) glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
540  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
541  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
542  }
543  }
544  switch (texture->getMinFilter()) {
546  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); break;
548  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); break;
550  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
552  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
554  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
556  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
557  }
558  switch (texture->getMagFilter()) {
560  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); break;
562  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break;
564  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
566  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
568  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
570  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
571  }
573 }
574 
575 void GL2Renderer::uploadCubeMapTexture(int contextIdx, Texture* textureLeft, Texture* textureRight, Texture* textureTop, Texture* textureBottom, Texture* textureFront, Texture* textureBack) {
576  {
577  //
578  auto textureTextureData = textureLeft->getRGBTextureData();
579  //
580  glTexImage2D(
581  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
582  0,
583  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
584  textureLeft->getTextureWidth(),
585  textureLeft->getTextureHeight(),
586  0,
587  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
588  GL_UNSIGNED_BYTE,
589  textureTextureData.getBuffer()
590  );
591  }
592  {
593  //
594  auto textureTextureData = textureRight->getRGBTextureData();
595  //
596  glTexImage2D(
597  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
598  0,
599  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
600  textureRight->getTextureWidth(),
601  textureRight->getTextureHeight(),
602  0,
603  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
604  GL_UNSIGNED_BYTE,
605  textureTextureData.getBuffer()
606  );
607  }
608  {
609  //
610  auto textureTextureData = textureTop->getRGBTextureData();
611  //
612  glTexImage2D(
613  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
614  0,
615  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
616  textureTop->getTextureWidth(),
617  textureTop->getTextureHeight(),
618  0,
619  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
620  GL_UNSIGNED_BYTE,
621  textureTextureData.getBuffer()
622  );
623  }
624  {
625  //
626  auto textureTextureData = textureBottom->getRGBTextureData();
627  //
628  glTexImage2D(
629  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
630  0,
631  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
632  textureBottom->getTextureWidth(),
633  textureBottom->getTextureHeight(),
634  0,
635  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
636  GL_UNSIGNED_BYTE,
637  textureTextureData.getBuffer()
638  );
639  }
640  {
641  //
642  auto textureTextureData = textureFront->getRGBTextureData();
643  //
644  glTexImage2D(
645  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
646  0,
647  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
648  textureFront->getTextureWidth(),
649  textureFront->getTextureHeight(),
650  0,
651  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
652  GL_UNSIGNED_BYTE,
653  textureTextureData.getBuffer()
654  );
655  }
656  {
657  //
658  auto textureTextureData = textureBack->getRGBTextureData();
659  //
660  glTexImage2D(
661  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
662  0,
663  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
664  textureBack->getTextureWidth(),
665  textureBack->getTextureHeight(),
666  0,
667  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
668  GL_UNSIGNED_BYTE,
669  textureTextureData.getBuffer()
670  );
671  }
672  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
673  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
674  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
675  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
676  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
678 }
679 
680 int32_t GL2Renderer::createCubeMapTexture(int contextIdx, int32_t width, int32_t height) {
681  // generate open gl texture
682  uint32_t textureId;
683  glGenTextures(1, &textureId);
684  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
685  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
686  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
687  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
688  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
689  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
690  glTexImage2D(
691  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
692  0,
693  GL_RGBA,
694  width,
695  height,
696  0,
697  GL_RGBA,
698  GL_UNSIGNED_BYTE,
699  nullptr
700  );
701  glTexImage2D(
702  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
703  0,
704  GL_RGBA,
705  width,
706  height,
707  0,
708  GL_RGBA,
709  GL_UNSIGNED_BYTE,
710  nullptr
711  );
712  glTexImage2D(
713  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
714  0,
715  GL_RGBA,
716  width,
717  height,
718  0,
719  GL_RGBA,
720  GL_UNSIGNED_BYTE,
721  nullptr
722  );
723  glTexImage2D(
724  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
725  0,
726  GL_RGBA,
727  width,
728  height,
729  0,
730  GL_RGBA,
731  GL_UNSIGNED_BYTE,
732  nullptr
733  );
734  glTexImage2D(
735  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
736  0,
737  GL_RGBA,
738  width,
739  height,
740  0,
741  GL_RGBA,
742  GL_UNSIGNED_BYTE,
743  nullptr
744  );
745  glTexImage2D(
746  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
747  0,
748  GL_RGBA,
749  width,
750  height,
751  0,
752  GL_RGBA,
753  GL_UNSIGNED_BYTE,
754  nullptr
755  );
756  glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
757  return textureId;
758 }
759 
760 void GL2Renderer::resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height)
761 {
762  glBindTexture(GL_TEXTURE_2D, textureId);
763  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
764  glBindTexture(GL_TEXTURE_2D, 0);
765 }
766 
767 void GL2Renderer::resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height)
768 {
769  glBindTexture(GL_TEXTURE_2D, textureId);
770  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
771  glBindTexture(GL_TEXTURE_2D, 0);
772 }
773 
774 void GL2Renderer::resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) {
775  Console::println("GL2Renderer::resizeGBufferGeometryTexture(): Not implemented");
776 }
777 
778 void GL2Renderer::resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) {
779  Console::println("GL2Renderer::resizeGBufferColorTexture(): Not implemented");
780 }
781 
782 void GL2Renderer::bindTexture(int contextIdx, int32_t textureId)
783 {
784  glBindTexture(GL_TEXTURE_2D, textureId);
785  onBindTexture(contextIdx, textureId);
786 }
787 
788 void GL2Renderer::bindCubeMapTexture(int contextIdx, int32_t textureId) {
789  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
790  onBindTexture(contextIdx, textureId);
791 }
792 
793 void GL2Renderer::disposeTexture(int32_t textureId)
794 {
795  glDeleteTextures(1, (const uint32_t*)&textureId);
797 }
798 
799 int32_t GL2Renderer::createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
800 {
801  // create a frame buffer object
802  uint32_t frameBufferId;
803  glGenFramebuffers(1, &frameBufferId);
804  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
805  // attach the depth buffer texture to FBO
806  if (depthBufferTextureId != ID_NONE) {
807  #ifdef __APPLE__
808  glFramebufferTextureEXT(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthBufferTextureId, 0);
809  #else
810  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, GL_TEXTURE_2D, depthBufferTextureId, 0);
811  #endif
812  }
813  // attach the color buffer texture to FBO
814  if (colorBufferTextureId != ID_NONE) {
815  #ifdef __APPLE__
816  glFramebufferTextureEXT(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBufferTextureId, 0);
817  #else
818  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, colorBufferTextureId, 0);
819  #endif
820  glDrawBuffer(GL_COLOR_ATTACHMENT0);
821  glReadBuffer(GL_COLOR_ATTACHMENT0);
822  } else
823  if (cubeMapTextureId != ID_NONE) {
824  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cubeMapTextureIndex, cubeMapTextureId, 0);
825  } else {
826  glDrawBuffer(GL_NONE);
827  glReadBuffer(GL_NONE);
828  }
829  // check FBO status
830  int32_t fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
831  if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
832  Console::println(string("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO: ") + to_string(fboStatus));
833  }
834  // switch back to window-system-provided framebuffer
835  glBindFramebuffer(GL_FRAMEBUFFER, 0);
836  return frameBufferId;
837 }
838 
840  int32_t depthBufferTextureId,
841  int32_t geometryBufferTextureId1,
842  int32_t geometryBufferTextureId2,
843  int32_t geometryBufferTextureId3,
844  int32_t colorBufferTextureId1,
845  int32_t colorBufferTextureId2,
846  int32_t colorBufferTextureId3,
847  int32_t colorBufferTextureId4,
848  int32_t colorBufferTextureId5
849 ) {
850  Console::println(string("GL2Renderer::createGeometryBufferObject()::not implemented yet"));
851  return ID_NONE;
852 }
853 
854 void GL2Renderer::bindFrameBuffer(int32_t frameBufferId)
855 {
856  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
857 }
858 
859 void GL2Renderer::disposeFrameBufferObject(int32_t frameBufferId)
860 {
861  glDeleteFramebuffers(1, (uint32_t*)&frameBufferId);
862 }
863 
864 vector<int32_t> GL2Renderer::createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared)
865 {
866  vector<int32_t> bufferObjectIds;
867  bufferObjectIds.resize(buffers);
868  glGenBuffers(buffers, (uint32_t*)bufferObjectIds.data());
869  for (auto bufferObjectId: bufferObjectIds) vbosUsage[bufferObjectId] = useGPUMemory == true?GL_STATIC_DRAW:GL_STREAM_DRAW;
870  return bufferObjectIds;
871 }
872 
873 void GL2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data)
874 {
875  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
876  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
877  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
879 }
880 
881 void GL2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
882 {
883  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
884  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
885  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
887 }
888 
889 void GL2Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
890 {
891  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
892  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
893  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
895 }
896 
897 void GL2Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
898 {
899  Console::println(string("GL2Renderer::uploadIndicesBufferObject()::not implemented yet"));
900 }
901 
902 void GL2Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
903 {
904  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
905  glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
906  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID_NONE);
908 }
909 
910 void GL2Renderer::bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId)
911 {
912  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
913 }
914 
915 void GL2Renderer::bindSolidColorsBufferObject(int contextIdx, int32_t bufferObjectId)
916 {
917  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
918  glEnableVertexAttribArray(1);
919  glVertexAttribPointer(1, 1, GL_FLOAT, false, 0, 0LL);
920 }
921 
922 void GL2Renderer::bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId)
923 {
924  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
925  glEnableVertexAttribArray(2);
926  glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0LL);
927 }
928 
929 void GL2Renderer::bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId)
930 {
931  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
932  glEnableVertexAttribArray(0);
933  glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0LL);
934 }
935 
936 void GL2Renderer::bindVertices2BufferObject(int contextIdx, int32_t bufferObjectId)
937 {
938  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
939  glEnableVertexAttribArray(0);
940  glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0LL);
941 }
942 
943 void GL2Renderer::bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId)
944 {
945  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
946  glEnableVertexAttribArray(1);
947  glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0LL);
948 }
949 
950 void GL2Renderer::bindColorsBufferObject(int contextIdx, int32_t bufferObjectId)
951 {
952  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
953  glEnableVertexAttribArray(3);
954  glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0LL);
955 }
956 
957 void GL2Renderer::bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId)
958 {
959  Console::println(string("GL2Renderer::bindTangentsBufferObject()::not implemented yet"));
960 }
961 
962 void GL2Renderer::bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId)
963 {
964  Console::println(string("GL2Renderer::bindBitangentsBufferObject()::not implemented yet"));
965 }
966 
967 void GL2Renderer::bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
968  Console::println(string("GL2Renderer::bindModelViewMatricesBufferObject()::not implemented yet"));
969 }
970 
971 void GL2Renderer::bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
972  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
973  glEnableVertexAttribArray(10);
974  glVertexAttribPointer(10, 4, GL_FLOAT, false, 0, 0LL);
975 }
976 
977 void GL2Renderer::bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
978  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
979  glEnableVertexAttribArray(11);
980  glVertexAttribPointer(11, 4, GL_FLOAT, false, 0, 0LL);
981 }
982 
983 void GL2Renderer::bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) {
984  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
985  glEnableVertexAttribArray(4);
986  glVertexAttribPointer(4, 3, GL_FLOAT, false, 0, 0LL);
987 }
988 
989 void GL2Renderer::bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) {
990  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
991  glEnableVertexAttribArray(1);
992  glVertexAttribPointer(1, 2, GL_FLOAT, false, 0, 0LL);
993 }
994 
995 void GL2Renderer::bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) {
996  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
997  glEnableVertexAttribArray(5);
998  glVertexAttribPointer(5, 1, GL_FLOAT, false, 0, 0LL);
999 }
1000 
1001 void GL2Renderer::bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) {
1002  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1003  glEnableVertexAttribArray(6);
1004  glVertexAttribPointer(6, 2, GL_FLOAT, false, 0, 0LL);
1005 }
1006 
1007 void GL2Renderer::drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances)
1008 {
1009  Console::println(string("GL2Renderer::drawInstancedIndexedTrianglesFromBufferObjects()::not implemented yet"));
1010 }
1011 
1012 void GL2Renderer::drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
1013 {
1014  #define BUFFER_OFFSET(i) ((void*)(i))
1015  glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_INT, BUFFER_OFFSET(static_cast<int64_t>(trianglesOffset) * 3LL * 4LL));
1017  statistics.instances+= 1;
1018  statistics.triangles+= triangles;
1019 }
1020 
1021 void GL2Renderer::drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) {
1022  Console::println(string("GL2Renderer::drawInstancedTrianglesFromBufferObjects()::not implemented yet"));
1023 }
1024 
1025 void GL2Renderer::drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
1026 {
1027  glDrawArrays(GL_TRIANGLES, trianglesOffset * 3, triangles * 3);
1029  statistics.instances+= 1;
1030  statistics.triangles+= triangles;
1031 }
1032 
1033 void GL2Renderer::drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
1034 {
1035  glDrawArrays(GL_POINTS, pointsOffset, points);
1037  statistics.points+= points;
1038 }
1039 
1040 void GL2Renderer::setLineWidth(float lineWidth)
1041 {
1042  glLineWidth(lineWidth);
1043 }
1044 
1045 void GL2Renderer::drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
1046 {
1047  glDrawArrays(GL_LINES, pointsOffset, points);
1049  statistics.linePoints+= points;
1050 }
1051 
1053 {
1054  glDisableVertexAttribArray(0);
1055  glDisableVertexAttribArray(1);
1056  glDisableVertexAttribArray(2);
1057  glDisableVertexAttribArray(3);
1058  glBindBuffer(GL_ARRAY_BUFFER, 0);
1059  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
1060 }
1061 
1062 void GL2Renderer::disposeBufferObjects(vector<int32_t>& bufferObjectIds)
1063 {
1064  for (auto bufferObjectId: bufferObjectIds) vbosUsage.erase(bufferObjectId);
1065  glDeleteBuffers(bufferObjectIds.size(), (const uint32_t*)bufferObjectIds.data());
1066  statistics.disposedBuffers+= bufferObjectIds.size();
1067 }
1068 
1069 int32_t GL2Renderer::getTextureUnit(int contextIdx)
1070 {
1071  return activeTextureUnit;
1072 }
1073 
1074 void GL2Renderer::setTextureUnit(int contextIdx, int32_t textureUnit)
1075 {
1076  this->activeTextureUnit = textureUnit;
1077  glActiveTexture(GL_TEXTURE0 + textureUnit);
1078 }
1079 
1080 float GL2Renderer::readPixelDepth(int32_t x, int32_t y)
1081 {
1082  float depth;
1083  glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
1084  return depth;
1085 }
1086 
1087 ByteBuffer* GL2Renderer::readPixels(int32_t x, int32_t y, int32_t width, int32_t height)
1088 {
1089  auto pixelBuffer = ByteBuffer::allocate(width * height * 4);
1090  glPixelStorei(GL_PACK_ALIGNMENT, 1);
1091  glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->getBuffer());
1092  return pixelBuffer;
1093 }
1094 
1096 {
1098  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1099  glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
1100  glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1101  glEnable(GL_BLEND);
1102  glDisable(GL_DEPTH_TEST);
1103  glDisable(GL_CULL_FACE);
1104  glGetError();
1105 }
1106 
1108 {
1109  glGetError();
1110  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1111  glDisable(GL_BLEND);
1112  glEnable(GL_DEPTH_TEST);
1113  glEnable(GL_CULL_FACE);
1114 }
1115 
1116 void GL2Renderer::dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) {
1117  Console::println("GL2Renderer::dispatchCompute(): Not implemented");
1118 }
1119 
1121  Console::println("GL2Renderer::memoryBarrier(): Not implemented");
1122 }
1123 
1124 void GL2Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) {
1125  Console::println("GL2Renderer::uploadSkinningBufferObject(): Not implemented");
1126 }
1127 
1128 void GL2Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) {
1129  Console::println("GL2Renderer::uploadSkinningBufferObject(): Not implemented");
1130 }
1131 
1132 void GL2Renderer::bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) {
1133  Console::println("GL2Renderer::bindSkinningVerticesBufferObject(): Not implemented");
1134 }
1135 
1136 void GL2Renderer::bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) {
1137  Console::println("GL2Renderer::bindSkinningNormalsBufferObject(): Not implemented");
1138 }
1139 
1140 void GL2Renderer::bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) {
1141  Console::println("GL2Renderer::bindSkinningVertexJointsBufferObject(): Not implemented");
1142 }
1143 
1144 void GL2Renderer::bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) {
1145  Console::println("GL2Renderer::bindSkinningVertexJointIdxsBufferObject(): Not implemented");
1146 }
1147 
1148 void GL2Renderer::bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) {
1149  Console::println("GL2Renderer::bindSkinningVertexJointWeightsBufferObject(): Not implemented");
1150 }
1151 
1152 void GL2Renderer::bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1153  Console::println("GL2Renderer::bindSkinningVerticesResultBufferObject(): Not implemented");
1154 }
1155 
1156 void GL2Renderer::bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1157  Console::println("GL2Renderer::bindSkinningNormalsResultBufferObject(): Not implemented");
1158 }
1159 
1160 void GL2Renderer::bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
1161  Console::println("GL2Renderer::bindSkinningMatricesBufferObject(): Not implemented");
1162 }
1163 
1164 void GL2Renderer::setVSync(bool vSync) {
1165  // no op
1166 }
1167 
1169  auto stats = statistics;
1170  statistics.time = Time::getCurrentMillis();
1171  statistics.memoryUsageGPU = -1LL;
1173  statistics.clearCalls = 0;
1174  statistics.renderCalls = 0;
1175  statistics.instances = 0;
1177  statistics.triangles = 0;
1178  statistics.points = 0;
1179  statistics.linePoints = 0;
1184  statistics.submits = 0;
1187  return stats;
1188 }
#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
ClampMode getClampMode() const
Definition: Texture.h:324
@ 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 memoryBarrier() override
Memory barrier.
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.
unordered_map< uint32_t, int32_t > vbosUsage
Definition: GL2Renderer.h:35
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 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 tokenizer class.
void tokenize(const string &str, const string &delimiters, bool emptyTokens=false)
Tokenize.
String tools class.
Definition: StringTools.h:22
Time utility class.
Definition: Time.h:20