TDME2  1.9.200
GL3Renderer.cpp
Go to the documentation of this file.
2 
3 #if defined (__APPLE__)
4  #define GL_SILENCE_DEPRECATION
5  #define GL_COMPRESSED_RGBA_BPTC_UNORM 0x8E8C
6  #define GL_INTERNALFORMAT_SUPPORTED 0x826F
7  #include <OpenGL/gl3.h>
8  #include <OpenGL/OpenGL.h>
9  #if !defined(__aarch64__)
10  #include <OpenCL/opencl.h>
11  #include <OpenCL/cl_gl.h>
12  #endif
13 #elif defined(__FreeBSD__) || defined(__NetBSD__) || defined(__OpenBSD__) || defined(__linux__) || defined(_WIN32) || defined(__HAIKU__)
14  #define GLEW_NO_GLU
15  #include <GL/glew.h>
16 #endif
17 
18 #include <string.h>
19 
20 #include <array>
21 #include <map>
22 #include <string>
23 #include <vector>
24 
25 #include <tdme/tdme.h>
27 #include <tdme/engine/Texture.h>
28 #include <tdme/engine/Engine.h>
30 #include <tdme/math/Math.h>
31 #include <tdme/math/Matrix4x4.h>
34 #include <tdme/utilities/Buffer.h>
36 #include <tdme/utilities/Console.h>
42 #include <tdme/utilities/Time.h>
43 
44 using std::array;
45 using std::map;
46 using std::string;
47 using std::to_string;
48 using std::vector;
49 
51 
56 using tdme::math::Math;
68 
69 GL3Renderer::GL3Renderer()
70 {
72  // setup GL3 consts
73  ID_NONE = 0;
74  CLEAR_DEPTH_BUFFER_BIT = GL_DEPTH_BUFFER_BIT;
75  CLEAR_COLOR_BUFFER_BIT = GL_COLOR_BUFFER_BIT;
76  CULLFACE_FRONT = GL_FRONT;
77  CULLFACE_BACK = GL_BACK;
78  FRONTFACE_CW = GL_CW;
79  FRONTFACE_CCW = GL_CCW;
80  SHADER_FRAGMENT_SHADER = GL_FRAGMENT_SHADER;
81  SHADER_VERTEX_SHADER = GL_VERTEX_SHADER;
82  #if defined (__APPLE__)
87  #else
88  SHADER_COMPUTE_SHADER = GL_COMPUTE_SHADER;
89  #endif
90  DEPTHFUNCTION_ALWAYS = GL_ALWAYS;
91  DEPTHFUNCTION_EQUAL = GL_EQUAL;
92  DEPTHFUNCTION_LESSEQUAL = GL_LEQUAL;
93  DEPTHFUNCTION_GREATEREQUAL = GL_GEQUAL;
94  CUBEMAPTEXTUREINDEX_NEGATIVE_X = GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
95  CUBEMAPTEXTUREINDEX_POSITIVE_X = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
96  CUBEMAPTEXTUREINDEX_POSITIVE_Y = GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
97  CUBEMAPTEXTUREINDEX_NEGATIVE_Y = GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
98  CUBEMAPTEXTUREINDEX_POSITIVE_Z = GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
99  CUBEMAPTEXTUREINDEX_NEGATIVE_Z = GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
100  activeTextureUnit = 0;
101  engineVAO = ID_NONE;
102  deferredShadingAvailable = false;
104 }
105 
106 const string GL3Renderer::getVendor() {
107  auto vendor = (char*)glGetString(GL_VENDOR);
108  return string(vendor);
109 }
110 
111 const string GL3Renderer::getRenderer() {
112  auto renderer = (char*)glGetString(GL_RENDERER);
113  return string(renderer) + " [GL3+/CORE]";
114 }
115 
117 {
118  return "gl3";
119 }
120 
122  return false;
123 }
124 
125 #if defined (__APPLE__) && !defined(__aarch64__)
126  void GL3Renderer::clErrorCallback(const char* errorInfo, const void* privateInfo, size_t cb, void* userData) {
127  Console::println(string("GL3Renderer::clErrorCallback(): ") + errorInfo);
128  }
129 #endif
130 
132 {
133  glGetError();
134  // get default framebuffer
135  FRAMEBUFFER_DEFAULT = 0; //getContext()->getDefaultDrawFramebuffer();
136  // setup open gl
137  glClearColor(0.0f, 0.0f, 0.0f, 1.0f);
138  glClearDepth(1.0f);
139  glEnable(GL_DEPTH_TEST);
140  glEnable(GL_CULL_FACE);
141  glDepthFunc(GL_LEQUAL);
142  glBlendEquation(GL_FUNC_ADD);
143  glDisable(GL_BLEND);
144  #if !defined (__APPLE__) && !defined(__HAIKU__)
145  // TODO: can this be removed???
146  glEnable(GL_POINT_SPRITE);
147  #endif
148  glEnable(GL_PROGRAM_POINT_SIZE);
150  // port-macosx requires this
151  glGenVertexArrays(1, &engineVAO);
152  glBindVertexArray(engineVAO);
153  //
154  #if defined (__APPLE__) && !defined(__aarch64__)
155  // TODO: error management
156  // shader source
157  auto skinningKernelProgramSource = FileSystem::getInstance()->getContentAsString("shader/gl3/skinning", "skinning.cl");
158  auto skinningKernelProgramSourceSize = skinningKernelProgramSource.size();
159  array<const char*, 1> skinningKernelProgramSourceArray = { skinningKernelProgramSource.data() };
160 
161  // context, device
162  cl_int clError = 0;
163  cl_device_id clDeviceId = 0;
164  auto clCurrentContext = CGLGetCurrentContext();
165  auto clShareGroup = CGLGetShareGroup(clCurrentContext);
166  gcl_gl_set_sharegroup(clShareGroup);
167  auto clDispatchQueue = gcl_create_dispatch_queue(CL_DEVICE_TYPE_GPU, nullptr);
168  clDeviceId = gcl_get_device_id_with_dispatch_queue(clDispatchQueue);
169 
170  // device vendor + names
171  size_t clSize = 0;
172  cl_char clDeviceVendorName[1024] = {0};
173  cl_char clDeviceDeviceName[1024] = {0};
174  clError = clGetDeviceInfo(clDeviceId, CL_DEVICE_VENDOR, sizeof(clDeviceVendorName) - 1, clDeviceVendorName, &clSize);
175  clError|= clGetDeviceInfo(clDeviceId, CL_DEVICE_NAME, sizeof(clDeviceDeviceName) - 1, clDeviceDeviceName, &clSize);
176  Console::println(string("GL3Renderer::initialize(): Using OpenCL CL device: ") + (char*)clDeviceVendorName + ": " + (char*)clDeviceDeviceName);
177 
178  // CL context, skinning kernel
179  cl_context_properties properties[] = {
180  CL_CONTEXT_PROPERTY_USE_CGL_SHAREGROUP_APPLE,
181  (cl_context_properties)clShareGroup,
182  0
183  };
184  clContext = clCreateContext(properties, 1, &clDeviceId, clErrorCallback, nullptr, &clError);
185  clCommandQueue = clCreateCommandQueue(clContext, clDeviceId, 0, &clError);
186  clSkinningKernelProgram = clCreateProgramWithSource(clContext, 1, skinningKernelProgramSourceArray.data(), &skinningKernelProgramSourceSize, &clError);
187  clError = clBuildProgram(clSkinningKernelProgram, 1, &clDeviceId, nullptr, nullptr, nullptr);
188  auto clBuildInfo = clGetProgramBuildInfo(clSkinningKernelProgram, clDeviceId, CL_PROGRAM_BUILD_STATUS, 0, nullptr, &clSize);
189  clSkinningKernel = clCreateKernel(clSkinningKernelProgram, "computeSkinning", &clError);
190  #endif
191  // check if deferred shading is available
192  int glMaxColorAttachments = 0;
193  glGetIntegerv(GL_MAX_COLOR_ATTACHMENTS, &glMaxColorAttachments);
194  int glMaxDrawBuffers = 0;
195  glGetIntegerv(GL_MAX_DRAW_BUFFERS, &glMaxDrawBuffers);
196  deferredShadingAvailable = glMaxColorAttachments >= 8 && glMaxDrawBuffers >= 8;
197  //
198  #if !defined (__APPLE__) && !defined(__HAIKU__)
199  // texture compression
200  int textureCompressionParam = 0;
201  glGetInternalformativ(
202  GL_TEXTURE_2D,
203  GL_COMPRESSED_RGBA_BPTC_UNORM,
204  GL_INTERNALFORMAT_SUPPORTED,
205  1,
206  &textureCompressionParam
207  );
208  textureCompressionAvailable = textureCompressionParam == GL_TRUE;
209  #endif
210  // renderer contexts
211  rendererContexts.resize(1);
212  for (auto& rendererContext: rendererContexts) {
213  for (auto i = 0; i < rendererContext.lights.size(); i++) {
214  rendererContext.lights[i].spotCosCutoff = static_cast<float>(Math::cos(Math::PI / 180.0f * 180.0f));
215  }
216  rendererContext.textureMatrix.identity();
217  }
218 }
219 
221 {
222 }
223 
225 {
226 }
227 
229 {
231 }
232 
234 {
235  return false;
236 }
237 
239  return true;
240 }
241 
243 {
244  return true;
245 }
246 
248 {
249  return true;
250 }
251 
253  return true;
254 }
255 
257 {
258  return true;
259 }
260 
262  #if defined(__HAIKU__)
263  // does not work for now with Haiku OS
264  return false;
265  #else
266  int glMajorVersion;
267  int glMinorVersion;
268  glGetIntegerv(GL_MAJOR_VERSION, &glMajorVersion);
269  glGetIntegerv(GL_MINOR_VERSION, &glMinorVersion);
270  return (glMajorVersion == 4 && glMinorVersion >= 3) || glMajorVersion > 4;
271  #endif
272 }
273 
275  #if defined (__APPLE__) && !defined(__aarch64__)
276  return true;
277  #else
278  return false;
279  #endif
280 }
281 
283  return false;
284 }
285 
288 }
289 
291 {
292  return activeTextureUnit;
293 }
294 
295 int32_t GL3Renderer::loadShader(int32_t type, const string& pathName, const string& fileName, const string& definitions, const string& functions)
296 {
297  // create shader
298  int32_t shaderId = glCreateShader(type);
299  // exit if no handle returned
300  if (shaderId == 0) return 0;
301 
302  // shader source
303  auto shaderSource = StringTools::replace(
304  StringTools::replace(
305  FileSystem::getInstance()->getContentAsString(pathName, fileName),
306  "{$DEFINITIONS}",
307  definitions + "\n\n"
308  ),
309  "{$FUNCTIONS}",
310  functions + "\n\n"
311  );
312  auto shaderSourceNullTerminated = shaderSource + "\0";
313  // load source
314  array<const char*, 1> shaderSourceNullTerminatedArray = { shaderSourceNullTerminated.data() };
315  glShaderSource(shaderId, 1, shaderSourceNullTerminatedArray.data(), nullptr);
316  // compile
317  glCompileShader(shaderId);
318  // check state
319  int32_t compileStatus;
320  glGetShaderiv(shaderId, GL_COMPILE_STATUS, &compileStatus);
321  if (compileStatus == 0) {
322  // get error
323  int32_t infoLogLength;
324  glGetShaderiv(shaderId, GL_INFO_LOG_LENGTH, &infoLogLength);
325  string infoLog(infoLogLength, static_cast<char>(0));
326  glGetShaderInfoLog(shaderId, infoLogLength, &infoLogLength, infoLog.data());
327  // be verbose
328  Console::println(
329  string(
330  string("GL3Renderer::loadShader") +
331  string("[") +
332  to_string(shaderId) +
333  string("]") +
334  pathName +
335  string("/") +
336  fileName +
337  string(": failed: ") +
338  infoLog
339  )
340  );
341  Console::println(shaderSource);
342  // remove shader
343  glDeleteShader(shaderId);
344  //
345  return 0;
346  }
347  //
348  return shaderId;
349 }
350 
351 void GL3Renderer::useProgram(int contextIdx, int32_t programId)
352 {
353  glUseProgram(programId);
354 }
355 
356 int32_t GL3Renderer::createProgram(int type)
357 {
358  return glCreateProgram();
359 }
360 
361 void GL3Renderer::attachShaderToProgram(int32_t programId, int32_t shaderId)
362 {
363  glAttachShader(programId, shaderId);
364 }
365 
366 bool GL3Renderer::linkProgram(int32_t programId)
367 {
368  glLinkProgram(programId);
369  // check state
370  int32_t linkStatus;
371  glGetProgramiv(programId, GL_LINK_STATUS, &linkStatus);
372  if (linkStatus == 0) {
373  // get error
374  int32_t infoLogLength;
375  glGetProgramiv(programId, GL_INFO_LOG_LENGTH, &infoLogLength);
376  string infoLog(infoLogLength, static_cast<char>(0));
377  glGetProgramInfoLog(programId, infoLogLength, &infoLogLength, infoLog.data());
378  // be verbose
379  Console::println(
380  string(
381  string("GL3Renderer::linkProgram") +
382  "[" +
383  to_string(programId) +
384  "]: failed: " +
385  infoLog
386  )
387  );
388  //
389  return false;
390  }
391  //
392  return true;
393 }
394 
395 int32_t GL3Renderer::getProgramUniformLocation(int32_t programId, const string& name)
396 {
397  return glGetUniformLocation(programId, name.c_str());
398 }
399 
400 void GL3Renderer::setProgramUniformInteger(int contextIdx, int32_t uniformId, int32_t value)
401 {
402  #if defined (__APPLE__) && !defined(__aarch64__)
403  if (uniformId == UNIFORM_CL_SKINNING_VERTEX_COUNT) {
404  clSkinningParameters.vertexCount = value;
405  } else
406  if (uniformId == UNIFORM_CL_SKINNING_MATRIX_COUNT) {
407  clSkinningParameters.matrixCount = value;
408  } else
409  if (uniformId == UNIFORM_CL_SKINNING_INSTANCE_COUNT) {
410  clSkinningParameters.instanceCount = value;
411  } else {
412  glUniform1i(uniformId, value);
413  }
414  #else
415  glUniform1i(uniformId, value);
416  #endif
417 }
418 
419 void GL3Renderer::setProgramUniformFloat(int contextIdx, int32_t uniformId, float value)
420 {
421  glUniform1f(uniformId, value);
422 }
423 
424 void GL3Renderer::setProgramUniformFloatMatrix3x3(int contextIdx, int32_t uniformId, const array<float, 9>& data)
425 {
426  glUniformMatrix3fv(uniformId, 1, false, data.data());
427 }
428 
429 void GL3Renderer::setProgramUniformFloatMatrix4x4(int contextIdx, int32_t uniformId, const array<float, 16>& data)
430 {
431  glUniformMatrix4fv(uniformId, 1, false, data.data());
432 }
433 
434 void GL3Renderer::setProgramUniformFloatMatrices4x4(int contextIdx, int32_t uniformId, int32_t count, FloatBuffer* data)
435 {
436  glUniformMatrix4fv(uniformId, count, false, (float*)data->getBuffer());
437 }
438 
439 void GL3Renderer::setProgramUniformFloatVec4(int contextIdx, int32_t uniformId, const array<float, 4>& data)
440 {
441  glUniform4fv(uniformId, 1, data.data());
442 }
443 
444 void GL3Renderer::setProgramUniformFloatVec3(int contextIdx, int32_t uniformId, const array<float, 3>& data)
445 {
446  glUniform3fv(uniformId, 1, data.data());
447 }
448 
449 void GL3Renderer::setProgramUniformFloatVec2(int contextIdx, int32_t uniformId, const array<float, 2>& data)
450 {
451  glUniform2fv(uniformId, 1, data.data());
452 }
453 
454 void GL3Renderer::setProgramAttributeLocation(int32_t programId, int32_t location, const string& name)
455 {
456  glBindAttribLocation(programId, location, (name).c_str());
457 }
458 
459 void GL3Renderer::setViewPort(int32_t width, int32_t height)
460 {
461  this->viewPortWidth = width;
462  this->viewPortHeight = height;
463 }
464 
466 {
467  glViewport(0, 0, viewPortWidth, viewPortHeight);
468 }
469 
470 void GL3Renderer::setClearColor(float red, float green, float blue, float alpha)
471 {
472  glClearColor(red, green, blue, alpha);
473 }
474 
475 void GL3Renderer::enableCulling(int contextIdx)
476 {
477  glEnable(GL_CULL_FACE);
478 }
479 
480 void GL3Renderer::disableCulling(int contextIdx)
481 {
482  glDisable(GL_CULL_FACE);
483 }
484 
485 void GL3Renderer::setFrontFace(int contextIdx, int32_t frontFace)
486 {
487  glFrontFace(frontFace);
488 }
489 
490 void GL3Renderer::setCullFace(int32_t cullFace)
491 {
492  glCullFace(cullFace);
493 }
494 
496 {
497  glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
498  glEnable(GL_BLEND);
499 }
500 
502  glBlendFunc(GL_ONE, GL_ONE);
503  glEnable(GL_BLEND);
504 }
505 
507 {
508  glDisable(GL_BLEND);
509 }
510 
512 {
513  glDepthMask(true);
514 }
515 
517 {
518  glDepthMask(false);
519 }
520 
522 {
523  glDisable(GL_DEPTH_TEST);
524 }
525 
527 {
528  glEnable(GL_DEPTH_TEST);
529 }
530 
531 void GL3Renderer::setDepthFunction(int32_t depthFunction)
532 {
533  // TODO: remove me
534  glDepthFunc(depthFunction);
535 }
536 
537 void GL3Renderer::setColorMask(bool red, bool green, bool blue, bool alpha)
538 {
539  glColorMask(red, green, blue, alpha);
540 }
541 
542 void GL3Renderer::clear(int32_t mask)
543 {
544  glClear(mask);
546 }
547 
549 {
550  // generate open gl texture
551  uint32_t textureId;
552  glGenTextures(1, &textureId);
553  return textureId;
554 }
555 
556 int32_t GL3Renderer::createDepthBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
557 {
558  uint32_t depthTextureId;
559  // create depth texture
560  glGenTextures(1, &depthTextureId);
561  glBindTexture(GL_TEXTURE_2D, depthTextureId);
562  // create depth texture
563  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
564  // depth texture parameter
565  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
566  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
567  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
568  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
569  // unbind, return
570  glBindTexture(GL_TEXTURE_2D, ID_NONE);
571  return depthTextureId;
572 }
573 
574 int32_t GL3Renderer::createColorBufferTexture(int32_t width, int32_t height, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
575 {
576  uint32_t colorBufferTextureId;
577  // create color texture
578  glGenTextures(1, &colorBufferTextureId);
579  glBindTexture(GL_TEXTURE_2D, colorBufferTextureId);
580  // create color texture
581  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
582  // color texture parameter
583  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
584  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
585  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
586  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
587  // unbind, return
588  glBindTexture(GL_TEXTURE_2D, ID_NONE);
589  return colorBufferTextureId;
590 }
591 
592 int32_t GL3Renderer::createGBufferGeometryTexture(int32_t width, int32_t height) {
593  uint32_t gBufferGeometryTextureId;
594  glGenTextures(1, &gBufferGeometryTextureId);
595  glBindTexture(GL_TEXTURE_2D, gBufferGeometryTextureId);
596  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
597  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
598  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
599  glBindTexture(GL_TEXTURE_2D, ID_NONE);
600  return gBufferGeometryTextureId;
601 }
602 
603 int32_t GL3Renderer::createGBufferColorTexture(int32_t width, int32_t height) {
604  uint32_t gBufferColorTextureId;
605  glGenTextures(1, &gBufferColorTextureId);
606  glBindTexture(GL_TEXTURE_2D, gBufferColorTextureId);
607  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
608  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
609  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
610  glBindTexture(GL_TEXTURE_2D, ID_NONE);
611  return gBufferColorTextureId;
612 }
613 
614 void GL3Renderer::uploadTexture(int contextIdx, Texture* texture)
615 {
616  //
617  if (textureCompressionAvailable == true && texture->isUseCompression() == true) {
618  //
619  auto level = 0;
620  auto mipLevels = texture->getMipLevels();
621  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
622  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, mipLevels - 1);
623  {
624  auto textureTextureData = texture->getBC7TextureData();
625  // base level
626  glCompressedTexImage2D(
627  GL_TEXTURE_2D,
628  level++,
629  GL_COMPRESSED_RGBA_BPTC_UNORM,
630  texture->getTextureWidth(),
631  texture->getTextureHeight(),
632  0,
633  textureTextureData.getCapacity(),
634  textureTextureData.getBuffer()
635  );
636  }
637 
638  //
639  if (texture->isUseMipMap() == true) {
640  // mip levels
641  auto textureMipMaps = texture->getMipMapTextures(true);
642  for (auto& textureMipMap: textureMipMaps) {
643  glCompressedTexImage2D(
644  GL_TEXTURE_2D,
645  level++,
646  GL_COMPRESSED_RGBA_BPTC_UNORM,
647  textureMipMap.width,
648  textureMipMap.height,
649  0,
650  textureMipMap.textureData.getCapacity(),
651  textureMipMap.textureData.getBuffer()
652  );
653  }
654  }
655  } else {
656  //
657  auto textureTextureData = texture->getRGBTextureData();
658  //
659  glTexImage2D(
660  GL_TEXTURE_2D,
661  0,
662  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
663  texture->getTextureWidth(),
664  texture->getTextureHeight(),
665  0,
666  texture->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
667  GL_UNSIGNED_BYTE,
668  textureTextureData.getBuffer()
669  );
670  }
671 
672  //
673  if (texture->getAtlasSize() > 1) {
674  if (texture->isUseMipMap() == true) {
675  float maxLodBias;
676  glGetFloatv(GL_MAX_TEXTURE_LOD_BIAS, &maxLodBias);
677  glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_LOD_BIAS, -Math::clamp(static_cast<float>(texture->getAtlasSize()) * 0.125f, 0.0f, maxLodBias));
678  if (textureCompressionAvailable == false || texture->isUseCompression() == false) {
679  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture->getMipLevels() - 1);
680  glGenerateMipmap(GL_TEXTURE_2D);
681  }
682  }
683  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
684  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
685  } else {
686  if (texture->isUseMipMap() == true && (textureCompressionAvailable == false || texture->isUseCompression() == false)) {
687  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, texture->getMipLevels() - 1);
688  glGenerateMipmap(GL_TEXTURE_2D);
689  }
690  if (texture->isRepeat() == true) {
691  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_REPEAT);
692  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_REPEAT);
693  } else {
694  float color[4] = {0.0f, 0.0f, 0.0f, 0.0f};
695  if (texture->getClampMode() == Texture::CLAMPMODE_TRANSPARENTPIXEL) glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_BORDER_COLOR, color);
696  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
697  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, texture->getClampMode() == Texture::CLAMPMODE_EDGE?GL_CLAMP_TO_EDGE:GL_CLAMP_TO_BORDER);
698  }
699  }
700  switch (texture->getMinFilter()) {
702  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); break;
704  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); break;
706  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
708  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
710  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
712  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
713  }
714  switch (texture->getMagFilter()) {
716  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); break;
718  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); break;
720  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_NEAREST:GL_NEAREST); break;
722  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_NEAREST:GL_NEAREST); break;
724  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_NEAREST_MIPMAP_LINEAR:GL_LINEAR); break;
726  glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, texture->isUseMipMap() == true?GL_LINEAR_MIPMAP_LINEAR:GL_LINEAR); break;
727  }
729 }
730 
731 void GL3Renderer::uploadCubeMapTexture(int contextIdx, Texture* textureLeft, Texture* textureRight, Texture* textureTop, Texture* textureBottom, Texture* textureFront, Texture* textureBack) {
732  if (textureCompressionAvailable == true && textureLeft->isUseCompression() == true) {
733  //
734  auto textureTextureData = textureLeft->getBC7TextureData();
735  //
736  glCompressedTexImage2D(
737  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
738  0,
739  GL_COMPRESSED_RGBA_BPTC_UNORM,
740  textureLeft->getTextureWidth(),
741  textureLeft->getTextureHeight(),
742  0,
743  textureTextureData.getCapacity(),
744  textureTextureData.getBuffer()
745  );
746  } else {
747  //
748  auto textureTextureData = textureLeft->getRGBTextureData();
749  //
750  glTexImage2D(
751  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
752  0,
753  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
754  textureLeft->getTextureWidth(),
755  textureLeft->getTextureHeight(),
756  0,
757  textureLeft->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
758  GL_UNSIGNED_BYTE,
759  textureTextureData.getBuffer()
760  );
761  }
762  if (textureCompressionAvailable == true && textureRight->isUseCompression() == true) {
763  //
764  auto textureTextureData = textureRight->getBC7TextureData();
765  //
766  glCompressedTexImage2D(
767  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
768  0,
769  GL_COMPRESSED_RGBA_BPTC_UNORM,
770  textureRight->getTextureWidth(),
771  textureRight->getTextureHeight(),
772  0,
773  textureTextureData.getCapacity(),
774  textureTextureData.getBuffer()
775  );
776  } else {
777  //
778  auto textureTextureData = textureRight->getRGBTextureData();
779  //
780  glTexImage2D(
781  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
782  0,
783  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
784  textureRight->getTextureWidth(),
785  textureRight->getTextureHeight(),
786  0,
787  textureRight->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
788  GL_UNSIGNED_BYTE,
789  textureTextureData.getBuffer()
790  );
791  }
792  if (textureCompressionAvailable == true && textureTop->isUseCompression() == true) {
793  //
794  auto textureTextureData = textureTop->getBC7TextureData();
795  //
796  glCompressedTexImage2D(
797  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
798  0,
799  GL_COMPRESSED_RGBA_BPTC_UNORM,
800  textureTop->getTextureWidth(),
801  textureTop->getTextureHeight(),
802  0,
803  textureTextureData.getCapacity(),
804  textureTextureData.getBuffer()
805  );
806  } else {
807  //
808  auto textureTextureData = textureTop->getRGBTextureData();
809  //
810  glTexImage2D(
811  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
812  0,
813  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
814  textureTop->getTextureWidth(),
815  textureTop->getTextureHeight(),
816  0,
817  textureTop->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
818  GL_UNSIGNED_BYTE,
819  textureTextureData.getBuffer()
820  );
821  }
822  if (textureCompressionAvailable == true && textureBottom->isUseCompression() == true) {
823  //
824  auto textureTextureData = textureBottom->getBC7TextureData();
825  //
826  glCompressedTexImage2D(
827  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
828  0,
829  GL_COMPRESSED_RGBA_BPTC_UNORM,
830  textureBottom->getTextureWidth(),
831  textureBottom->getTextureHeight(),
832  0,
833  textureTextureData.getCapacity(),
834  textureTextureData.getBuffer()
835  );
836  } else {
837  //
838  auto textureTextureData = textureBottom->getRGBTextureData();
839  //
840  glTexImage2D(
841  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
842  0,
843  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
844  textureBottom->getTextureWidth(),
845  textureBottom->getTextureHeight(),
846  0,
847  textureBottom->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
848  GL_UNSIGNED_BYTE,
849  textureTextureData.getBuffer()
850  );
851  }
852  if (textureCompressionAvailable == true && textureFront->isUseCompression() == true) {
853  //
854  auto textureTextureData = textureFront->getBC7TextureData();
855  //
856  glCompressedTexImage2D(
857  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
858  0,
859  GL_COMPRESSED_RGBA_BPTC_UNORM,
860  textureFront->getTextureWidth(),
861  textureFront->getTextureHeight(),
862  0,
863  textureTextureData.getCapacity(),
864  textureTextureData.getBuffer()
865  );
866  } else {
867  //
868  auto textureTextureData = textureFront->getRGBTextureData();
869  //
870  glTexImage2D(
871  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
872  0,
873  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
874  textureFront->getTextureWidth(),
875  textureFront->getTextureHeight(),
876  0,
877  textureFront->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
878  GL_UNSIGNED_BYTE,
879  textureTextureData.getBuffer()
880  );
881  }
882  if (textureCompressionAvailable == true && textureBack->isUseCompression() == true) {
883  //
884  auto textureTextureData = textureBack->getBC7TextureData();
885  //
886  glCompressedTexImage2D(
887  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
888  0,
889  GL_COMPRESSED_RGBA_BPTC_UNORM,
890  textureBack->getTextureWidth(),
891  textureBack->getTextureHeight(),
892  0,
893  textureTextureData.getCapacity(),
894  textureTextureData.getBuffer()
895  );
896  } else {
897  //
898  auto textureTextureData = textureBack->getRGBTextureData();
899  //
900  glTexImage2D(
901  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
902  0,
903  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
904  textureBack->getTextureWidth(),
905  textureBack->getTextureHeight(),
906  0,
907  textureBack->getRGBDepthBitsPerPixel() == 32?GL_RGBA:GL_RGB,
908  GL_UNSIGNED_BYTE,
909  textureTextureData.getBuffer()
910  );
911  }
912  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
913  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
914  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
915  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
916  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
918 }
919 
920 int32_t GL3Renderer::createCubeMapTexture(int contextIdx, int32_t width, int32_t height) {
921  // generate open gl texture
922  uint32_t textureId;
923  glGenTextures(1, &textureId);
924  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
925  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MIN_FILTER, GL_LINEAR);
926  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_MAG_FILTER, GL_LINEAR);
927  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_R, GL_CLAMP_TO_EDGE);
928  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
929  glTexParameteri(GL_TEXTURE_CUBE_MAP, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
930  glTexImage2D(
931  GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
932  0,
933  GL_RGBA,
934  width,
935  height,
936  0,
937  GL_RGBA,
938  GL_UNSIGNED_BYTE,
939  nullptr
940  );
941  glTexImage2D(
942  GL_TEXTURE_CUBE_MAP_POSITIVE_X,
943  0,
944  GL_RGBA,
945  width,
946  height,
947  0,
948  GL_RGBA,
949  GL_UNSIGNED_BYTE,
950  nullptr
951  );
952  glTexImage2D(
953  GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
954  0,
955  GL_RGBA,
956  width,
957  height,
958  0,
959  GL_RGBA,
960  GL_UNSIGNED_BYTE,
961  nullptr
962  );
963  glTexImage2D(
964  GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
965  0,
966  GL_RGBA,
967  width,
968  height,
969  0,
970  GL_RGBA,
971  GL_UNSIGNED_BYTE,
972  nullptr
973  );
974  glTexImage2D(
975  GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
976  0,
977  GL_RGBA,
978  width,
979  height,
980  0,
981  GL_RGBA,
982  GL_UNSIGNED_BYTE,
983  nullptr
984  );
985  glTexImage2D(
986  GL_TEXTURE_CUBE_MAP_NEGATIVE_Z,
987  0,
988  GL_RGBA,
989  width,
990  height,
991  0,
992  GL_RGBA,
993  GL_UNSIGNED_BYTE,
994  nullptr
995  );
996  glBindTexture(GL_TEXTURE_CUBE_MAP, 0);
997  return textureId;
998 }
999 
1000 void GL3Renderer::resizeDepthBufferTexture(int32_t textureId, int32_t width, int32_t height)
1001 {
1002  glBindTexture(GL_TEXTURE_2D, textureId);
1003  glTexImage2D(GL_TEXTURE_2D, 0, GL_DEPTH_COMPONENT, width, height, 0, GL_DEPTH_COMPONENT, GL_FLOAT, nullptr);
1004  glBindTexture(GL_TEXTURE_2D, 0);
1005 }
1006 
1007 void GL3Renderer::resizeColorBufferTexture(int32_t textureId, int32_t width, int32_t height)
1008 {
1009  glBindTexture(GL_TEXTURE_2D, textureId);
1010  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1011  glBindTexture(GL_TEXTURE_2D, 0);
1012 }
1013 
1014 void GL3Renderer::resizeGBufferGeometryTexture(int32_t textureId, int32_t width, int32_t height) {
1015  glBindTexture(GL_TEXTURE_2D, textureId);
1016  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA16F, width, height, 0, GL_RGBA, GL_FLOAT, nullptr);
1017  glBindTexture(GL_TEXTURE_2D, 0);
1018 }
1019 
1020 void GL3Renderer::resizeGBufferColorTexture(int32_t textureId, int32_t width, int32_t height) {
1021  glBindTexture(GL_TEXTURE_2D, textureId);
1022  glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_UNSIGNED_BYTE, nullptr);
1023  glBindTexture(GL_TEXTURE_2D, 0);
1024 }
1025 
1026 void GL3Renderer::bindTexture(int contextIdx, int32_t textureId)
1027 {
1028  glBindTexture(GL_TEXTURE_2D, textureId);
1029  onBindTexture(contextIdx, textureId);
1030 }
1031 
1032 void GL3Renderer::bindCubeMapTexture(int contextIdx, int32_t textureId) {
1033  glBindTexture(GL_TEXTURE_CUBE_MAP, textureId);
1034  onBindTexture(contextIdx, textureId);
1035 }
1036 
1037 void GL3Renderer::disposeTexture(int32_t textureId)
1038 {
1039  glDeleteTextures(1, (const uint32_t*)&textureId);
1041 }
1042 
1043 int32_t GL3Renderer::createFramebufferObject(int32_t depthBufferTextureId, int32_t colorBufferTextureId, int32_t cubeMapTextureId, int32_t cubeMapTextureIndex)
1044 {
1045  uint32_t frameBufferId;
1046  // create a frame buffer object
1047  glGenFramebuffers(1, &frameBufferId);
1048  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
1049  // attach the depth buffer texture to FBO
1050  if (depthBufferTextureId != ID_NONE) {
1051  glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthBufferTextureId, 0);
1052  }
1053  // attach the depth buffer texture to FBO
1054  if (colorBufferTextureId != ID_NONE) {
1055  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, colorBufferTextureId, 0);
1056  glDrawBuffer(GL_COLOR_ATTACHMENT0);
1057  glReadBuffer(GL_COLOR_ATTACHMENT0);
1058  } else
1059  if (cubeMapTextureId != ID_NONE) {
1060  glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, cubeMapTextureIndex, cubeMapTextureId, 0);
1061  } else {
1062  glDrawBuffer(GL_NONE);
1063  glReadBuffer(GL_NONE);
1064  }
1065  // check FBO status
1066  int32_t fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
1067  if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
1068  Console::println(string("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO: "+ to_string(fboStatus)));
1069  }
1070  // switch back to window-system-provided framebuffer
1071  glBindFramebuffer(GL_FRAMEBUFFER, 0);
1072  return frameBufferId;
1073 }
1074 
1076  int32_t depthBufferTextureId,
1077  int32_t geometryBufferTextureId1,
1078  int32_t geometryBufferTextureId2,
1079  int32_t geometryBufferTextureId3,
1080  int32_t colorBufferTextureId1,
1081  int32_t colorBufferTextureId2,
1082  int32_t colorBufferTextureId3,
1083  int32_t colorBufferTextureId4,
1084  int32_t colorBufferTextureId5
1085 ) {
1086  uint32_t frameBufferId;
1087  // create a frame buffer object
1088  glGenFramebuffers(1, &frameBufferId);
1089  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
1090  // attach the depth buffer texture to FBO
1091  if (depthBufferTextureId != ID_NONE) {
1092  glFramebufferTexture(GL_FRAMEBUFFER, GL_DEPTH_ATTACHMENT, depthBufferTextureId, 0);
1093  }
1094  vector<uint32_t> drawBuffers;
1095  // attach geometry textures
1096  if (geometryBufferTextureId1 != ID_NONE) {
1097  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, geometryBufferTextureId1, 0);
1098  drawBuffers.push_back(GL_COLOR_ATTACHMENT0);
1099  }
1100  if (geometryBufferTextureId2 != ID_NONE) {
1101  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT1, geometryBufferTextureId2, 0);
1102  drawBuffers.push_back(GL_COLOR_ATTACHMENT1);
1103  }
1104  if (geometryBufferTextureId3 != ID_NONE) {
1105  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT2, geometryBufferTextureId3, 0);
1106  drawBuffers.push_back(GL_COLOR_ATTACHMENT2);
1107  }
1108  // attach color textures
1109  if (colorBufferTextureId1 != ID_NONE) {
1110  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT3, colorBufferTextureId1, 0);
1111  drawBuffers.push_back(GL_COLOR_ATTACHMENT3);
1112  }
1113  if (colorBufferTextureId2 != ID_NONE) {
1114  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT4, colorBufferTextureId2, 0);
1115  drawBuffers.push_back(GL_COLOR_ATTACHMENT4);
1116  }
1117  if (colorBufferTextureId3 != ID_NONE) {
1118  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT5, colorBufferTextureId3, 0);
1119  drawBuffers.push_back(GL_COLOR_ATTACHMENT5);
1120  }
1121  if (colorBufferTextureId4 != ID_NONE) {
1122  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT6, colorBufferTextureId4, 0);
1123  drawBuffers.push_back(GL_COLOR_ATTACHMENT6);
1124  }
1125  if (colorBufferTextureId5 != ID_NONE) {
1126  glFramebufferTexture(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT7, colorBufferTextureId5, 0);
1127  drawBuffers.push_back(GL_COLOR_ATTACHMENT7);
1128  }
1129  //
1130  glDrawBuffers(drawBuffers.size(), drawBuffers.data());
1131  // check FBO status
1132  int32_t fboStatus = glCheckFramebufferStatus(GL_FRAMEBUFFER);
1133  if (fboStatus != GL_FRAMEBUFFER_COMPLETE) {
1134  Console::println(string("GL_FRAMEBUFFER_COMPLETE_EXT failed, CANNOT use FBO: "+ to_string(fboStatus)));
1135  }
1136  // switch back to window-system-provided framebuffer
1137  glBindFramebuffer(GL_FRAMEBUFFER, 0);
1138  return frameBufferId;
1139 }
1140 
1141 void GL3Renderer::bindFrameBuffer(int32_t frameBufferId)
1142 {
1143  glBindFramebuffer(GL_FRAMEBUFFER, frameBufferId);
1144 }
1145 
1146 void GL3Renderer::disposeFrameBufferObject(int32_t frameBufferId)
1147 {
1148  glDeleteFramebuffers(1, (uint32_t*)&frameBufferId);
1149 }
1150 
1151 vector<int32_t> GL3Renderer::createBufferObjects(int32_t buffers, bool useGPUMemory, bool shared)
1152 {
1153  vector<int32_t> bufferObjectIds;
1154  bufferObjectIds.resize(buffers);
1155  glGenBuffers(buffers, (uint32_t*)bufferObjectIds.data());
1156  for (auto bufferObjectId: bufferObjectIds) vbosUsage[bufferObjectId] = useGPUMemory == true?GL_STATIC_DRAW:GL_STREAM_DRAW;
1157  return bufferObjectIds;
1158 }
1159 
1160 void GL3Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data)
1161 {
1162  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1163  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1164  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1166 }
1167 
1168 void GL3Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
1169 {
1170  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1171  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1172  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1174 }
1175 
1176 void GL3Renderer::uploadBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
1177 {
1178  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1179  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1180  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1182 }
1183 
1184 void GL3Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, ShortBuffer* data)
1185 {
1186  Console::println(string("GL3Renderer::uploadIndicesBufferObject()::not implemented yet"));
1187 }
1188 
1189 void GL3Renderer::uploadIndicesBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data)
1190 {
1191  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
1192  glBufferData(GL_ELEMENT_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1193  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID_NONE);
1195 }
1196 
1197 void GL3Renderer::bindIndicesBufferObject(int contextIdx, int32_t bufferObjectId)
1198 {
1199  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, bufferObjectId);
1200 }
1201 
1202 void GL3Renderer::bindSolidColorsBufferObject(int contextIdx, int32_t bufferObjectId)
1203 {
1204  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1205  glEnableVertexAttribArray(1);
1206  glVertexAttribPointer(1, 1, GL_FLOAT, false, 0, 0LL);
1207 }
1208 
1209 void GL3Renderer::bindTextureCoordinatesBufferObject(int contextIdx, int32_t bufferObjectId)
1210 {
1211  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1212  glEnableVertexAttribArray(2);
1213  glVertexAttribPointer(2, 2, GL_FLOAT, false, 0, 0LL);
1214 }
1215 
1216 void GL3Renderer::bindVerticesBufferObject(int contextIdx, int32_t bufferObjectId)
1217 {
1218  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1219  glEnableVertexAttribArray(0);
1220  glVertexAttribPointer(0, 3, GL_FLOAT, false, 0, 0LL);
1221 }
1222 
1223 void GL3Renderer::bindVertices2BufferObject(int contextIdx, int32_t bufferObjectId)
1224 {
1225  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1226  glEnableVertexAttribArray(0);
1227  glVertexAttribPointer(0, 2, GL_FLOAT, false, 0, 0LL);
1228 }
1229 
1230 void GL3Renderer::bindNormalsBufferObject(int contextIdx, int32_t bufferObjectId)
1231 {
1232  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1233  glEnableVertexAttribArray(1);
1234  glVertexAttribPointer(1, 3, GL_FLOAT, false, 0, 0LL);
1235 }
1236 
1237 void GL3Renderer::bindColorsBufferObject(int contextIdx, int32_t bufferObjectId)
1238 {
1239  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1240  glEnableVertexAttribArray(3);
1241  glVertexAttribPointer(3, 4, GL_FLOAT, false, 0, 0LL);
1242 }
1243 
1244 void GL3Renderer::bindTangentsBufferObject(int contextIdx, int32_t bufferObjectId)
1245 {
1246  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1247  glEnableVertexAttribArray(4);
1248  glVertexAttribPointer(4, 3, GL_FLOAT, false, 0, 0LL);
1249 }
1250 
1251 void GL3Renderer::bindBitangentsBufferObject(int contextIdx, int32_t bufferObjectId)
1252 {
1253  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1254  glEnableVertexAttribArray(5);
1255  glVertexAttribPointer(5, 3, GL_FLOAT, false, 0, 0LL);
1256 }
1257 
1258 void GL3Renderer::bindModelMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
1259  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1260  glEnableVertexAttribArray(6);
1261  glEnableVertexAttribArray(7);
1262  glEnableVertexAttribArray(8);
1263  glEnableVertexAttribArray(9);
1264  glVertexAttribPointer(6, 4, GL_FLOAT, false, 4 * 4 * sizeof(float), (void*)(0 * 4 * sizeof(float)));
1265  glVertexAttribPointer(7, 4, GL_FLOAT, false, 4 * 4 * sizeof(float), (void*)(1 * 4 * sizeof(float)));
1266  glVertexAttribPointer(8, 4, GL_FLOAT, false, 4 * 4 * sizeof(float), (void*)(2 * 4 * sizeof(float)));
1267  glVertexAttribPointer(9, 4, GL_FLOAT, false, 4 * 4 * sizeof(float), (void*)(3 * 4 * sizeof(float)));
1268  glVertexAttribDivisor(6, 1);
1269  glVertexAttribDivisor(7, 1);
1270  glVertexAttribDivisor(8, 1);
1271  glVertexAttribDivisor(9, 1);
1272 }
1273 
1274 void GL3Renderer::bindEffectColorMulsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
1275  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1276  glEnableVertexAttribArray(10);
1277  glVertexAttribPointer(10, 4, GL_FLOAT, false, 0, 0LL);
1278  glVertexAttribDivisor(10, divisor);
1279 }
1280 
1281 void GL3Renderer::bindEffectColorAddsBufferObject(int contextIdx, int32_t bufferObjectId, int32_t divisor) {
1282  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1283  glEnableVertexAttribArray(11);
1284  glVertexAttribPointer(11, 4, GL_FLOAT, false, 0, 0LL);
1285  glVertexAttribDivisor(11, divisor);
1286 }
1287 
1288 void GL3Renderer::bindOriginsBufferObject(int contextIdx, int32_t bufferObjectId) {
1289  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1290  glEnableVertexAttribArray(12);
1291  glVertexAttribPointer(12, 3, GL_FLOAT, false, 0, 0LL);
1292 }
1293 
1294 void GL3Renderer::bindTextureSpriteIndicesBufferObject(int contextIdx, int32_t bufferObjectId) {
1295  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1296  glEnableVertexAttribArray(1);
1297  glVertexAttribIPointer(1, 2, GL_UNSIGNED_SHORT, 0, 0LL);
1298 }
1299 
1300 void GL3Renderer::bindPointSizesBufferObject(int contextIdx, int32_t bufferObjectId) {
1301  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1302  glEnableVertexAttribArray(5);
1303  glVertexAttribPointer(5, 1, GL_FLOAT, false, 0, 0LL);
1304 }
1305 
1306 void GL3Renderer::bindSpriteSheetDimensionBufferObject(int contextIdx, int32_t bufferObjectId) {
1307  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1308  glEnableVertexAttribArray(6);
1309  glVertexAttribIPointer(6, 2, GL_UNSIGNED_SHORT, 0, 0LL);
1310  glVertexAttribDivisor(6, 0);
1311 }
1312 
1313 void GL3Renderer::drawInstancedIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances)
1314 {
1315  #define BUFFER_OFFSET(i) ((void*)(i))
1316  glDrawElementsInstanced(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_INT, BUFFER_OFFSET(static_cast<int64_t>(trianglesOffset) * 3LL * 4LL), instances);
1318  statistics.instances+= instances;
1319  statistics.triangles+= triangles * instances;
1320 }
1321 
1322 void GL3Renderer::drawIndexedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
1323 {
1324  #define BUFFER_OFFSET(i) ((void*)(i))
1325  glDrawElements(GL_TRIANGLES, triangles * 3, GL_UNSIGNED_INT, BUFFER_OFFSET(static_cast<int64_t>(trianglesOffset) * 3LL * 4LL));
1327  statistics.instances+= 1;
1328  statistics.triangles+= triangles;
1329 }
1330 
1331 void GL3Renderer::drawInstancedTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset, int32_t instances) {
1332  glDrawArraysInstanced(GL_TRIANGLES, trianglesOffset * 3, triangles * 3, instances);
1334  statistics.instances+= instances;
1335  statistics.triangles+= triangles * instances;
1336 }
1337 
1338 void GL3Renderer::drawTrianglesFromBufferObjects(int contextIdx, int32_t triangles, int32_t trianglesOffset)
1339 {
1340  glDrawArrays(GL_TRIANGLES, trianglesOffset * 3, triangles * 3);
1342  statistics.instances+= 1;
1343  statistics.triangles+= triangles;
1344 }
1345 
1346 void GL3Renderer::drawPointsFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
1347 {
1348  glDrawArrays(GL_POINTS, pointsOffset, points);
1350  statistics.points+= points;
1351 }
1352 
1353 void GL3Renderer::setLineWidth(float lineWidth)
1354 {
1355  glLineWidth(lineWidth);
1356 }
1357 
1358 void GL3Renderer::drawLinesFromBufferObjects(int contextIdx, int32_t points, int32_t pointsOffset)
1359 {
1360  glDrawArrays(GL_LINES, pointsOffset, points);
1362  statistics.linePoints+= points;
1363 }
1364 
1366 {
1367  glDisableVertexAttribArray(0);
1368  glDisableVertexAttribArray(1);
1369  glDisableVertexAttribArray(2);
1370  glDisableVertexAttribArray(3);
1371  glDisableVertexAttribArray(4);
1372  glDisableVertexAttribArray(5);
1373  glDisableVertexAttribArray(6);
1374  glDisableVertexAttribArray(7);
1375  glDisableVertexAttribArray(8);
1376  glDisableVertexAttribArray(9);
1377  glDisableVertexAttribArray(10);
1378  glDisableVertexAttribArray(11);
1379  glDisableVertexAttribArray(12);
1380  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1381  glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, ID_NONE);
1382 }
1383 
1384 void GL3Renderer::disposeBufferObjects(vector<int32_t>& bufferObjectIds)
1385 {
1386  for (auto bufferObjectId: bufferObjectIds) vbosUsage.erase(bufferObjectId);
1387  glDeleteBuffers(bufferObjectIds.size(), (const uint32_t*)bufferObjectIds.data());
1388  statistics.disposedBuffers+= bufferObjectIds.size();
1389 }
1390 
1391 int32_t GL3Renderer::getTextureUnit(int contextIdx)
1392 {
1393  return activeTextureUnit;
1394 }
1395 
1396 void GL3Renderer::setTextureUnit(int contextIdx, int32_t textureUnit)
1397 {
1398  this->activeTextureUnit = textureUnit;
1399  glActiveTexture(GL_TEXTURE0 + textureUnit);
1400 }
1401 
1402 float GL3Renderer::readPixelDepth(int32_t x, int32_t y)
1403 {
1404  float depth;
1405  glReadPixels(x, y, 1, 1, GL_DEPTH_COMPONENT, GL_FLOAT, &depth);
1406  return depth;
1407 }
1408 
1409 ByteBuffer* GL3Renderer::readPixels(int32_t x, int32_t y, int32_t width, int32_t height)
1410 {
1411  auto pixelBuffer = ByteBuffer::allocate(width * height * 4);
1412  glPixelStorei(GL_PACK_ALIGNMENT, 1);
1413  glReadPixels(x, y, width, height, GL_RGBA, GL_UNSIGNED_BYTE, pixelBuffer->getBuffer());
1414  return pixelBuffer;
1415 }
1416 
1418 {
1420  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1421  glBlendEquationSeparate(GL_FUNC_ADD, GL_FUNC_ADD);
1422  glBlendFuncSeparate(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
1423  glEnable(GL_BLEND);
1424  glDisable(GL_DEPTH_TEST);
1425  glDisable(GL_CULL_FACE);
1426  glGetError();
1427 }
1428 
1430 {
1431  glGetError();
1432  glBindTexture(GL_TEXTURE_2D, ID_NONE);
1433  glDisable(GL_BLEND);
1434  glEnable(GL_DEPTH_TEST);
1435  glEnable(GL_CULL_FACE);
1436 }
1437 
1439 {
1440  auto error = glGetError();
1441  if (error != GL_NO_ERROR) {
1442  Console::println(string("OpenGL Error: (" + to_string(error) + ") @: " + __FILE__ + ":" + to_string(line)));
1443  }
1444 }
1445 
1446 void GL3Renderer::dispatchCompute(int contextIdx, int32_t numGroupsX, int32_t numGroupsY, int32_t numGroupsZ) {
1447  #if defined (__APPLE__) && !defined(__aarch64__)
1448  clSkinningParameters.numGroupsX = numGroupsX;
1449  clSkinningParameters.numGroupsY = numGroupsY;
1450  glFinish();
1451  auto& _clSkinningParameters = clSkinningParameters;
1452  cl_int clError;
1453  array<cl_mem, 8> boundCLMemObjects;
1454  for (auto i = 0; i < _clSkinningParameters.boundGLBuffers.size(); i++) {
1455  boundCLMemObjects[i] = clCreateFromGLBuffer(clContext, _clSkinningParameters.boundGLBuffersWrite[i] == true?CL_MEM_WRITE_ONLY:CL_MEM_READ_ONLY, _clSkinningParameters.boundGLBuffers[i], &clError);
1456  clError = clSetKernelArg(clSkinningKernel, i, sizeof(cl_mem), &boundCLMemObjects[i]);
1457  }
1458  clSetKernelArg(clSkinningKernel, 8, sizeof(cl_int), &_clSkinningParameters.vertexCount);
1459  clSetKernelArg(clSkinningKernel, 9, sizeof(cl_int), &_clSkinningParameters.matrixCount);
1460  clSetKernelArg(clSkinningKernel, 10, sizeof(cl_int), &_clSkinningParameters.instanceCount);
1461  size_t local_size[] = {(size_t)16, (size_t)16};
1462  size_t global_size[] = {(size_t)_clSkinningParameters.numGroupsX * local_size[0], (size_t)_clSkinningParameters.numGroupsY * local_size[1]};
1463  clEnqueueAcquireGLObjects(clCommandQueue, boundCLMemObjects.size(), boundCLMemObjects.data(), 0, nullptr, nullptr);
1464  clEnqueueNDRangeKernel(clCommandQueue, clSkinningKernel, 2, nullptr, global_size, local_size, 0, nullptr, nullptr);
1465  clEnqueueReleaseGLObjects(clCommandQueue, boundCLMemObjects.size(), boundCLMemObjects.data(), 0, nullptr, nullptr);
1466  clFinish(clCommandQueue);
1467  clSkinningParameters = CLSkinningParameters();
1469  #elif !defined(__APPLE__)
1470  glDispatchCompute(numGroupsX, numGroupsY, numGroupsZ);
1472  #endif
1473 }
1474 
1476  #if defined (__APPLE__)
1477  // no op
1478  #else
1479  // TODO: put barrier bits into paramters
1480  glMemoryBarrier(GL_ALL_BARRIER_BITS);
1481  #endif
1482 }
1483 
1484 void GL3Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, FloatBuffer* data) {
1485  #if defined (__APPLE__) && !defined(__aarch64__)
1486  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1487  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1488  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1490  #elif !defined(__APPLE__)
1491  glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferObjectId);
1492  glBufferData(GL_SHADER_STORAGE_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1493  glBindBuffer(GL_SHADER_STORAGE_BUFFER, ID_NONE);
1495  #endif
1496 }
1497 
1498 void GL3Renderer::uploadSkinningBufferObject(int contextIdx, int32_t bufferObjectId, int32_t size, IntBuffer* data) {
1499  #if defined (__APPLE__) && !defined(__aarch64__)
1500  glBindBuffer(GL_ARRAY_BUFFER, bufferObjectId);
1501  glBufferData(GL_ARRAY_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1502  glBindBuffer(GL_ARRAY_BUFFER, ID_NONE);
1504  #elif !defined(__APPLE__)
1505  glBindBuffer(GL_SHADER_STORAGE_BUFFER, bufferObjectId);
1506  glBufferData(GL_SHADER_STORAGE_BUFFER, size, data->getBuffer(), vbosUsage[bufferObjectId]);
1507  glBindBuffer(GL_SHADER_STORAGE_BUFFER, ID_NONE);
1509  #endif
1510 }
1511 
1512 #if defined (__APPLE__) && !defined(__aarch64__)
1513  inline void GL3Renderer::clBindGLBuffer(int32_t idx, int32_t bufferObjectId, bool write) {
1514  clSkinningParameters.boundGLBuffers[idx] = bufferObjectId;
1515  clSkinningParameters.boundGLBuffersWrite[idx] = write;
1516  }
1517 #endif
1518 
1519 void GL3Renderer::bindSkinningVerticesBufferObject(int contextIdx, int32_t bufferObjectId) {
1520  #if defined (__APPLE__) && !defined(__aarch64__)
1521  clBindGLBuffer(0, bufferObjectId, false);
1522  #elif !defined(__APPLE__)
1523  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 0, bufferObjectId);
1524  #endif
1525 }
1526 
1527 void GL3Renderer::bindSkinningNormalsBufferObject(int contextIdx, int32_t bufferObjectId) {
1528  #if defined (__APPLE__) && !defined(__aarch64__)
1529  clBindGLBuffer(1, bufferObjectId, false);
1530  #elif !defined(__APPLE__)
1531  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 1, bufferObjectId);
1532  #endif
1533 }
1534 
1535 void GL3Renderer::bindSkinningVertexJointsBufferObject(int contextIdx, int32_t bufferObjectId) {
1536  #if defined (__APPLE__) && !defined(__aarch64__)
1537  clBindGLBuffer(2, bufferObjectId, false);
1538  #elif !defined(__APPLE__)
1539  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 2, bufferObjectId);
1540  #endif
1541 }
1542 
1543 void GL3Renderer::bindSkinningVertexJointIdxsBufferObject(int contextIdx, int32_t bufferObjectId) {
1544  #if defined (__APPLE__) && !defined(__aarch64__)
1545  clBindGLBuffer(3, bufferObjectId, false);
1546  #elif !defined(__APPLE__)
1547  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 3, bufferObjectId);
1548  #endif
1549 }
1550 
1551 void GL3Renderer::bindSkinningVertexJointWeightsBufferObject(int contextIdx, int32_t bufferObjectId) {
1552  #if defined (__APPLE__) && !defined(__aarch64__)
1553  clBindGLBuffer(4, bufferObjectId, false);
1554  #elif !defined(__APPLE__)
1555  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 4, bufferObjectId);
1556  #endif
1557 }
1558 
1559 void GL3Renderer::bindSkinningVerticesResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1560  #if defined (__APPLE__) && !defined(__aarch64__)
1561  clBindGLBuffer(5, bufferObjectId, true);
1562  #elif !defined(__APPLE__)
1563  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 5, bufferObjectId);
1564  #endif
1565 }
1566 
1567 void GL3Renderer::bindSkinningNormalsResultBufferObject(int contextIdx, int32_t bufferObjectId) {
1568  #if defined (__APPLE__) && !defined(__aarch64__)
1569  clBindGLBuffer(6, bufferObjectId, true);
1570  #elif !defined(__APPLE__)
1571  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 6, bufferObjectId);
1572  #endif
1573 }
1574 
1575 void GL3Renderer::bindSkinningMatricesBufferObject(int contextIdx, int32_t bufferObjectId) {
1576  #if defined (__APPLE__) && !defined(__aarch64__)
1577  clBindGLBuffer(7, bufferObjectId, false);
1578  #elif !defined(__APPLE__)
1579  glBindBufferBase(GL_SHADER_STORAGE_BUFFER, 7, bufferObjectId);
1580  #endif
1581 }
1582 
1583 void GL3Renderer::setVSync(bool vSync) {
1584  // no op
1585 }
1586 
1588  auto stats = statistics;
1589  statistics.time = Time::getCurrentMillis();
1590  statistics.memoryUsageGPU = -1LL;
1592  statistics.clearCalls = 0;
1593  statistics.renderCalls = 0;
1594  statistics.instances = 0;
1596  statistics.triangles = 0;
1597  statistics.points = 0;
1598  statistics.linePoints = 0;
1603  statistics.submits = 0;
1606  return stats;
1607 }
#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
const vector< MipMapTexture > & getMipMapTextures(bool bc7Encoded)
Get mip map textures.
Definition: Texture.cpp:286
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
ByteBuffer getBC7TextureData()
Definition: Texture.cpp:140
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
bool isUseCompression() const
Definition: Texture.h:279
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: GL3Renderer.h:39
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 checkGLError(int line)
Checks if GL error did occour.
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.
Standard math functions.
Definition: Math.h:19
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