SLProject  4.2.000
A platform independent 3D computer graphics framework for desktop OS, Android, iOS and online in web browsers
SLGLState.cpp
Go to the documentation of this file.
1 /**
2  * \file SLGLState.cpp
3  * \brief Singleton class implementation for global OpenGL replacement
4  * \date July 2014
5  * \authors Marcus Hudritsch
6  * \copyright http://opensource.org/licenses/GPL-3.0
7  * \remarks Please use clangformat to format the code. See more code style on
8  * https://github.com/cpvrlab/SLProject4/wiki/SLProject-Coding-Style
9  */
10 
11 #include <SL.h>
12 #include <Utils.h>
13 #include <SLGLState.h>
14 #include <SLMaterial.h>
15 #include <CVImage.h>
16 #include <AppCommon.h>
17 #include <string>
18 
19 #ifdef SL_OS_ANDROID
20 # include <android/log.h>
21 #endif
22 //-----------------------------------------------------------------------------
24 //-----------------------------------------------------------------------------
25 /*! Public static destruction.
26  */
28 {
29  delete _instance;
30  _instance = nullptr;
31 }
32 //-----------------------------------------------------------------------------
33 /*! Private constructor should be called only once for a singleton class.
34  */
36 {
37  initAll();
38 }
39 //-----------------------------------------------------------------------------
40 /*! Initializes all states.
41  */
43 {
48 
49  _glVersion = SLstring((const char*)glGetString(GL_VERSION));
51  _glVersionNOf = (SLfloat)atof(_glVersionNO.c_str());
52  _glVendor = SLstring((const char*)glGetString(GL_VENDOR));
53  _glRenderer = SLstring((const char*)glGetString(GL_RENDERER));
54  _glSLVersion = SLstring((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
56  _glIsES2 = (_glVersion.find("OpenGL ES 2") != string::npos);
57  _glIsES3 = (_glVersion.find("OpenGL ES 3") != string::npos);
58  glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits);
59  glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize);
60 
61 // Get extensions
62 #ifndef APP_USES_GLES
63  if (_glVersionNOf > 3.0f)
64  {
65  GLint n;
66  glGetIntegerv(GL_NUM_EXTENSIONS, &n);
67  for (SLuint i = 0; i < (SLuint)n; i++)
68  _glExtensions += SLstring((const char*)glGetStringi(GL_EXTENSIONS, i)) + ", ";
69  }
70  else
71 #endif
72  {
73  const GLubyte* ext = glGetString(GL_EXTENSIONS);
74  if (ext) _glExtensions = SLstring((const char*)ext);
75  }
76 
77  // initialize states a unset
78  _blend = false;
79  _blendFuncSfactor = GL_SRC_ALPHA;
80  _blendFuncDfactor = GL_ONE_MINUS_SRC_ALPHA;
81  _cullFace = false;
82  _depthTest = false;
83  _depthMask = false;
84  _depthFunc = GL_LESS;
85  _multisample = false;
86  _polygonLine = false;
90  _viewport.set(-1, -1, -1, -1);
91  _clearColor.set(-1, -1, -1, -1);
92 
93  // Reset all cached states to an invalid state
94  _programID = 0;
95  _colorMaskR = -1;
96  _colorMaskG = -1;
97  _colorMaskB = -1;
98  _colorMaskA = -1;
99 
100  _isInitialized = true;
101 
102  glGetIntegerv(GL_SAMPLES, &_multiSampleSamples);
103 
104  /* After over 10 years of OpenGL experience I used once a texture that is
105  not divisible by 4 and this caused distorted texture displays. By default
106  OpenGL has a pixel alignment of 4 which means that all images must be
107  divisible by 4! If you want to use textures of any size you have to set
108  a pixel alignment of 1:*/
109  glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
110  glPixelStorei(GL_PACK_ALIGNMENT, 1);
111 
112 #ifndef SL_GLES
113  glEnable(GL_PROGRAM_POINT_SIZE);
114 #endif
115 
116  GET_GL_ERROR;
117 
118  _currentMaterial = nullptr;
119 }
120 //-----------------------------------------------------------------------------
121 /*! The destructor only empties the stacks
122  */
124 {
125 #if _DEBUG
126  SL_LOG("--------------------- Collected OpenGL Error: --------------------");
127  SL_LOG("Destructor : ~SLGLState");
128  for (size_t i = 0; i < errorTexts.size(); ++i)
129  SL_LOG("(%04d) %s", errorCounts[i], errorTexts[i].c_str());
130  if (errorTexts.size() == 0) SL_LOG("None");
131  SL_LOG("------------------------------------------------------------------");
132 #endif
133 }
134 //-----------------------------------------------------------------------------
135 /*! One time initialization
136  */
137 void SLGLState::onInitialize(const SLCol4f& clearColor)
138 {
139  // Reset all internal states
140  if (!_isInitialized) initAll();
141 
142  // enable depth_test
143  glDepthFunc(GL_LESS);
144  glEnable(GL_DEPTH_TEST);
145 
146  // set blend function for classic transparency
147  glBlendFunc(_blendFuncSfactor, _blendFuncDfactor);
148 
149  // set background color
150  glClearColor(clearColor.r,
151  clearColor.g,
152  clearColor.b,
153  clearColor.a);
154  GET_GL_ERROR;
155 }
156 //-----------------------------------------------------------------------------
157 void SLGLState::clearColor(const SLCol4f& newColor)
158 {
159  if (_clearColor != newColor)
160  {
161  glClearColor(newColor.r, newColor.g, newColor.b, newColor.a);
162  _clearColor = newColor;
163 
164  GET_GL_ERROR;
165  }
166 }
167 //-----------------------------------------------------------------------------
168 /*! SLGLState::depthTest enables or disables depth testing but only if the
169  state really changes. The depth test decides for each pixel in the depth buffer
170  which polygon is the closest to the eye.
171  */
173 {
174  if (_depthTest != stateNew)
175  {
176  if (stateNew)
177  glEnable(GL_DEPTH_TEST);
178  else
179  glDisable(GL_DEPTH_TEST);
180  _depthTest = stateNew;
181 
182  GET_GL_ERROR;
183  }
184 }
185 //-----------------------------------------------------------------------------
186 /*! SLGLState::depthTest enables or disables depth buffer writing but only if
187  the state really changes. Turning on depth masking freezes the depth test but
188  keeps all values in the depth buffer.
189  */
191 {
192  if (_depthMask != stateNew)
193  {
194  glDepthMask(stateNew ? GL_TRUE : GL_FALSE);
195  _depthMask = stateNew;
196 
197  GET_GL_ERROR;
198  }
199 }
200 //-----------------------------------------------------------------------------
201 /*! SLGLState::depthFunc specifies the depth comparison function.
202 Symbolic constants GL_NEVER, GL_LESS, GL_EQUAL, GL_LEQUAL, GL_GREATER,
203 GL_NOTEQUAL, GL_GEQUAL, and GL_ALWAYS are accepted. The initial value is GL_LESS.
204 */
206 {
207  if (_depthFunc != func)
208  {
209  glDepthFunc(func);
210  _depthFunc = func;
211 
212  GET_GL_ERROR;
213  }
214 }
215 //-----------------------------------------------------------------------------
216 /*! SLGLState::cullFace sets the GL_CULL_FACE state but only if the state
217  really changes. If face culling is turned on no back faces are processed.
218  */
220 {
221  if (_cullFace != stateNew)
222  {
223  if (stateNew)
224  glEnable(GL_CULL_FACE);
225  else
226  glDisable(GL_CULL_FACE);
227  _cullFace = stateNew;
228 
229  GET_GL_ERROR;
230  }
231 }
232 //-----------------------------------------------------------------------------
233 /*! SLGLState::blend enables or disables alpha blending but only if the state
234  really changes.
235  */
236 void SLGLState::blend(SLbool stateNew)
237 {
238  if (_blend != stateNew)
239  {
240  if (stateNew)
241  glEnable(GL_BLEND);
242  else
243  glDisable(GL_BLEND);
244  _blend = stateNew;
245  GET_GL_ERROR;
246  }
247 }
248 //-----------------------------------------------------------------------------
249 //! Sets new blend function source and destination factors
250 void SLGLState::blendFunc(SLenum newBlendFuncSFactor,
251  SLenum newBlendFuncDFactor)
252 {
253  if (_blendFuncSfactor != newBlendFuncSFactor ||
254  _blendFuncDfactor != newBlendFuncDFactor)
255  {
256  glBlendFunc(newBlendFuncSFactor, newBlendFuncDFactor);
257  _blendFuncSfactor = newBlendFuncSFactor;
258  _blendFuncDfactor = newBlendFuncDFactor;
259  GET_GL_ERROR;
260  }
261 }
262 //-----------------------------------------------------------------------------
263 /*! SLGLState::multiSample enables or disables multisampling but only if the
264  state really changes. Multisampling turns on fullscreen anti aliasing on the GPU
265  witch produces smooth polygon edges, lines and points.
266  */
268 {
269 #ifndef SL_GLES3
270  if (_multisample != stateNew)
271  {
272  if (_multiSampleSamples > 0)
273  {
274  if (stateNew)
275  glEnable(GL_MULTISAMPLE);
276  else
277  glDisable(GL_MULTISAMPLE);
278  _multisample = stateNew;
279  }
280 
281  GET_GL_ERROR;
282  }
283 #endif
284 }
285 //-----------------------------------------------------------------------------
286 /*! SLGLState::polygonMode sets the polygonMode to GL_LINE but only if the
287  state really changes. OpenGL ES doesn't support glPolygonMode. It has to be
288  mimicked with GL_LINE_LOOP drawing.
289  */
291 {
292 #ifndef SL_GLES3
293  if (_polygonLine != stateNew)
294  {
295  if (stateNew)
296  glPolygonMode(GL_FRONT_AND_BACK, GL_LINE);
297  else
298  glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
299  _polygonLine = stateNew;
300 
301  GET_GL_ERROR;
302  }
303 #endif
304 }
305 //-----------------------------------------------------------------------------
306 /*! SLGLState::polygonOffsetPoint turns on/off polygon offset for points
307  and sets the factor and unit for glPolygonOffset but only if the state really
308  changes. Polygon offset is used to reduce z-fighting due to parallel planes or
309  lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
310  */
312 {
313 #ifndef SL_GLES3
314  if (_polygonOffsetPointEnabled != enabled)
315  {
316  if (enabled)
317  {
318  glEnable(GL_POLYGON_OFFSET_POINT);
319  glPolygonOffset(factor, units);
320  }
321  else
322  glDisable(GL_POLYGON_OFFSET_POINT);
323  _polygonOffsetPointEnabled = enabled;
324 
325  GET_GL_ERROR;
326  }
327 #endif
328 }
329 //-----------------------------------------------------------------------------
330 /*! SLGLState::polygonOffsetLine turns on/off polygon offset for lines
331  and sets the factor and unit for glPolygonOffset but only if the state really
332  changes. Polygon offset is used to reduce z-fighting due to parallel planes or
333  lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
334  */
336 {
337 #ifndef SL_GLES3
338  if (_polygonOffsetLineEnabled != enabled)
339  {
340  if (enabled)
341  {
342  glEnable(GL_POLYGON_OFFSET_LINE);
343  glPolygonOffset(factor, units);
344  }
345  else
346  glDisable(GL_POLYGON_OFFSET_LINE);
347  _polygonOffsetLineEnabled = enabled;
348 
349  GET_GL_ERROR;
350  }
351 #endif
352 }
353 //-----------------------------------------------------------------------------
354 /*! SLGLState::polygonOffsetFill turns on/off polygon offset for filled polygons
355  and sets the factor and unit for glPolygonOffset but only if the state really
356  changes. Polygon offset is used to reduce z-fighting due to parallel planes or
357  lines. See: http://www.zeuscmd.com/tutorials/opengl/15-PolygonOffset.php
358  */
360 {
361  if (_polygonOffsetFillEnabled != enabled)
362  {
363  if (enabled)
364  {
365  glEnable(GL_POLYGON_OFFSET_FILL);
366  glPolygonOffset(factor, units);
367  }
368  else
369  glDisable(GL_POLYGON_OFFSET_FILL);
370  _polygonOffsetFillEnabled = enabled;
371 
372  GET_GL_ERROR;
373  }
374 }
375 //-----------------------------------------------------------------------------
376 /*! SLGLState::viewport sets the OpenGL viewport position and size
377  */
378 void SLGLState::viewport(SLint x, SLint y, SLsizei width, SLsizei height)
379 {
380  if (_viewport.x != x ||
381  _viewport.y != y ||
382  _viewport.z != width ||
383  _viewport.w != height)
384  {
385  glViewport(x, y, width, height);
386  _viewport.set(x, y, width, height);
387 
388  GET_GL_ERROR;
389  }
390 }
391 //-----------------------------------------------------------------------------
392 /*! SLGLState::colorMask sets the OpenGL colorMask for framebuffer masking
393  */
394 void SLGLState::colorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
395 {
396  if (r != _colorMaskR || g != _colorMaskG || b != _colorMaskB || a != _colorMaskA)
397  {
398  glColorMask(r, g, b, a);
399  _colorMaskR = r;
400  _colorMaskG = g;
401  _colorMaskB = b;
402  _colorMaskA = a;
403 
404  GET_GL_ERROR;
405  }
406 }
407 //-----------------------------------------------------------------------------
408 /*! SLGLState::useProgram sets the _rent active shader program
409  */
411 {
412  if (_programID != progID)
413  {
414  glUseProgram(progID);
415  _programID = progID;
416 
417  GET_GL_ERROR;
418  }
419 }
420 //-----------------------------------------------------------------------------
421 /*! SLGLState::bindTexture sets the current active texture.
422  */
423 void SLGLState::bindTexture(SLenum target, SLuint textureID)
424 {
425  // (luc) If we call glActiveTexture and glBindTexture from outside,
426  // This will lead to problems as the global state in SLGLState will not be
427  // equivalent to the OpenGL state.
428  // We should solve this by querying opengl for the last bound texture.
429  // glGetIntegeriv(GL_ACTIVE_TEXTURE, active_texture)
430  // glGetIntegeriv(GL_TEXTURE_BINDING_2D, textureID)
431 
432  // if (target != _textureTarget || textureID != _textureID)
433  {
434  glBindTexture(target, textureID);
435 
436  _textureTarget = target;
437  _textureID = textureID;
438 
439  GET_GL_ERROR;
440  }
441 }
442 //-----------------------------------------------------------------------------
443 /*! SLGLState::activeTexture sets the current active texture unit
444  */
446 {
447  if (((SLint)textureUnit - GL_TEXTURE0) > _glMaxTexUnits)
448  SL_LOG("******* To many texture units: %i used of %i",
449  (SLint)textureUnit - GL_TEXTURE0,
451 
452  assert((textureUnit - GL_TEXTURE0) <= _glMaxTexUnits &&
453  "To many texture units!");
454 
455  glActiveTexture(textureUnit);
456  _textureUnit = textureUnit;
457 
458  GET_GL_ERROR;
459 }
460 //-----------------------------------------------------------------------------
461 /*! SLGLState::unbindAnythingAndFlush unbinds all shaderprograms and buffers in
462  use and calls glFinish. This should be the last call to GL before buffer
463  swapping.
464  */
466 {
467  useProgram(0);
468 
469  // reset the bound texture unit
470  // This is needed since leaving one texture unit bound over multiple windows
471  // sometimes (most of the time) causes bugs
472  // glBindTexture(GL_TEXTURE_2D, 0);
473  // glBindVertexArray(0);
474  // glBindBuffer(GL_ARRAY_BUFFER, 0);
475  // glBindBuffer(GL_ELEMENT_ARRAY_BUFFER, 0);
476 
477  // The iOS OpenGL ES Analyzer suggests not to use flush or finish
478  // glFlush();
479  // glFinish();
480 
481  GET_GL_ERROR;
482 }
483 //-----------------------------------------------------------------------------
484 void SLGLState::getGLError(const char* file,
485  int line,
486  bool quit)
487 {
488  GLenum err = glGetError();
489  if (err != GL_NO_ERROR)
490  {
491  string errStr;
492  switch (err)
493  {
494  case GL_INVALID_ENUM:
495  errStr = "GL_INVALID_ENUM";
496  break;
497  case GL_INVALID_VALUE:
498  errStr = "GL_INVALID_VALUE";
499  break;
500  case GL_INVALID_OPERATION:
501  errStr = "GL_INVALID_OPERATION";
502  break;
503  case GL_INVALID_FRAMEBUFFER_OPERATION:
504  errStr = "GL_INVALID_FRAMEBUFFER_OPERATION";
505  break;
506  case GL_OUT_OF_MEMORY:
507  errStr = "GL_OUT_OF_MEMORY";
508  break;
509  default:
510  errStr = "Unknown error";
511  }
512 
513  // Build error string as a concatenation of file, line & error
514  string newErr("OpenGL Error in scene: ");
515  newErr += std::to_string(AppCommon::sceneID);
516  newErr += ": file: ";
517  newErr += Utils::getFileName(file);
518  newErr += ": line:";
519  newErr += std::to_string(line);
520  newErr += ": ";
521  newErr += errStr;
522 
523  // Check if error exists already
524  SLGLState* state = SLGLState::instance();
525  auto foundErr = std::find(state->errorTexts.begin(),
526  state->errorTexts.end(),
527  newErr);
528 
529  // Add error if not found in errorTexts
530  if (foundErr == state->errorTexts.end())
531  {
532  state->errorTexts.push_back(newErr);
533  state->errorCounts.push_back(1);
534  SL_LOG("**** %s ****", newErr.c_str());
535  }
536  else // error occurred already
537  {
538  long errorIndex = foundErr - state->errorTexts.begin();
539  state->errorCounts[errorIndex]++;
540  }
541 
542  if (quit)
543  exit(1);
544  }
545 }
546 //-----------------------------------------------------------------------------
547 /// Returns the OpenGL version number as a string
548 /*! The string returned by glGetString can contain additional vendor
549  information such as the build number and the brand name.
550  For the OpenGL version string "4.5.0 NVIDIA 347.68" the function returns "4.5"
551  */
553 {
554  SLstring versionStr = SLstring((const char*)glGetString(GL_VERSION));
555  size_t dotPos = versionStr.find('.');
556  SLchar NO[4];
557  NO[0] = versionStr[dotPos - 1];
558  NO[1] = '.';
559  NO[2] = versionStr[dotPos + 1];
560  NO[3] = 0;
561 
562  if (versionStr.find("OpenGL ES") != string::npos)
563  {
564  return SLstring(NO) + "ES";
565  }
566  else
567  return SLstring(NO);
568 }
569 //-----------------------------------------------------------------------------
570 //! Returns the OpenGL Shading Language version number as a string.
571 /*! The string returned by glGetString can contain additional vendor
572  information such as the build number and the brand name.
573  For the shading language string "Nvidia GLSL 4.5" the function returns "450"
574  */
576 {
577  SLstring versionStr = SLstring((const char*)glGetString(GL_SHADING_LANGUAGE_VERSION));
578  size_t dotPos = versionStr.find('.');
579  SLchar NO[4];
580  NO[0] = versionStr[dotPos - 1];
581  NO[1] = versionStr[dotPos + 1];
582  NO[2] = '0';
583  NO[3] = 0;
584  return SLstring(NO);
585 }
586 //-----------------------------------------------------------------------------
587 //! Returns true if the according GL pixel format is valid in the GL context
589 { /*
590  #define SL_ALPHA 0x1906 // ES2 ES3 GL2
591  #define SL_LUMINANCE 0x1909 // ES2 ES3 GL2
592  #define SL_LUMINANCE_ALPHA 0x190A // ES2 ES3 GL2
593  #define SL_INTENSITY 0x8049 // GL2
594  #define SL_GREEN 0x1904 // GL2
595  #define SL_BLUE 0x1905 // GL2
596 
597  #define SL_RED 0x1903 // ES3 GL2 GL3 GL4
598  #define SL_RG 0x8227 // ES3 GL3 GL4
599  #define SL_RGB 0x1907 // ES2 ES3 GL2 GL3 GL4
600  #define SL_RGBA 0x1908 // ES2 ES3 GL2 GL3 GL4
601  #define SL_BGR 0x80E0 // GL2 GL3 GL4
602  #define SL_BGRA 0x80E1 // GL2 GL3 GL4 (iOS defines it but it doesn't work)
603 
604  #define SL_RG_INTEGER 0x8228 // ES3 GL4
605  #define SL_RED_INTEGER 0x8D94 // ES3 GL4
606  #define SL_RGB_INTEGER 0x8D98 // ES3 GL4
607  #define SL_RGBA_INTEGER 0x8D99 // ES3 GL4
608  #define SL_BGR_INTEGER 0x8D9A // GL4
609  #define SL_BGRA_INTEGER 0x8D9B // GL4
610  */
611  switch (pixelFormat)
612  {
613  case PF_rgb:
614  case PF_rgba: return true;
615  case PF_red: return (!_glIsES2);
616  case PF_bgr:
617  case PF_bgra: return (!_glIsES2 && !_glIsES3);
618  case PF_luminance:
619  case PF_luminance_alpha:
620  case PF_alpha: return (_glIsES2 || _glIsES3 || (((SLint)_glVersionNOf) == 2));
621  case PF_intensity:
622  case PF_green:
623  case PF_blue: return (!_glIsES2 && !_glIsES3 && (((SLint)_glVersionNOf) == 2));
624  case PF_rg: return (!_glIsES2 && _glVersionNOf >= 3);
625  case PF_rg_integer:
626  case PF_red_integer:
627  case PF_rgb_integer:
628  case PF_rgba_integer: return (!_glIsES2 && _glVersionNOf >= 4);
629  case PF_bgr_integer:
630  case PF_bgra_integer: return (_glVersionNOf >= 4);
631  default: return false;
632  }
633 }
634 //-----------------------------------------------------------------------------
635 //! Reads the front framebuffer pixels into the passed buffer
636 /*!
637  * \param buffer Pointer to a 4 byte aligned buffer with the correct size.
638  */
639 void SLGLState::readPixels(void* buffer)
640 {
641  glPixelStorei(GL_PACK_ALIGNMENT, 4);
642 
643 #ifndef SL_EMSCRIPTEN
644  glReadBuffer(GL_FRONT);
645 #endif
646 
647  // Get viewport size
648  GLint vp[4];
649  glGetIntegerv(GL_VIEWPORT, vp);
650 
651  glReadPixels(vp[0],
652  vp[1],
653  vp[2],
654  vp[3],
656  GL_UNSIGNED_BYTE,
657  buffer);
658 }
659 //-----------------------------------------------------------------------------
The AppCommon class holds the top-level instances of the app-demo.
@ PF_rgb_integer
Definition: CVImage.h:42
@ PF_luminance
Definition: CVImage.h:28
@ PF_bgr_integer
Definition: CVImage.h:44
@ PF_alpha
Definition: CVImage.h:27
@ PF_rgba_integer
Definition: CVImage.h:43
@ PF_green
Definition: CVImage.h:31
@ PF_rg_integer
Definition: CVImage.h:40
@ PF_red
Definition: CVImage.h:34
@ PF_luminance_alpha
Definition: CVImage.h:29
@ PF_rgb
Definition: CVImage.h:36
@ PF_bgra_integer
Definition: CVImage.h:45
@ PF_rg
Definition: CVImage.h:35
@ PF_bgra
Definition: CVImage.h:39
@ PF_rgba
Definition: CVImage.h:37
@ PF_bgr
Definition: CVImage.h:38
@ PF_red_integer
Definition: CVImage.h:41
@ PF_blue
Definition: CVImage.h:32
@ PF_intensity
Definition: CVImage.h:30
float SLfloat
Definition: SL.h:173
unsigned int SLenum
Definition: SL.h:176
#define SL_LOG(...)
Definition: SL.h:233
unsigned int SLuint
Definition: SL.h:171
char SLchar
Definition: SL.h:162
bool SLbool
Definition: SL.h:175
int SLsizei
Definition: SL.h:172
string SLstring
Definition: SL.h:158
int SLint
Definition: SL.h:170
Singleton class for global render state.
#define GET_GL_ERROR
Definition: SLGLState.h:56
#define SL_READ_PIXELS_GL_FORMAT
Definition: SLGLTexture.h:59
static SLSceneID sceneID
ID of currently loaded scene.
Definition: AppCommon.h:89
Singleton class holding all OpenGL states.
Definition: SLGLState.h:71
void clearColor(const SLCol4f &c)
Definition: SLGLState.cpp:157
static void deleteInstance()
global destruction
Definition: SLGLState.cpp:27
static SLGLState * _instance
global singleton object
Definition: SLGLState.h:164
SLbool _depthMask
glDepthMask state
Definition: SLGLState.h:186
SLMat4f textureMatrix
matrix for the texture transform
Definition: SLGLState.h:92
SLVec4i _viewport
viewport size (x,y,w,h) of the framebuffer
Definition: SLGLState.h:195
void activeTexture(SLenum textureUnit)
Definition: SLGLState.cpp:445
SLVec4i viewport()
Definition: SLGLState.h:142
SLuint _textureID
current texture id
Definition: SLGLState.h:202
SLMat4f modelMatrix
Init all states.
Definition: SLGLState.h:89
void polygonOffsetPoint(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
Definition: SLGLState.cpp:311
void depthMask(SLbool state)
Definition: SLGLState.cpp:190
SLCol4f _clearColor
clear color
Definition: SLGLState.h:196
SLbool _depthTest
GL_DEPTH_TEST state.
Definition: SLGLState.h:185
void multiSample(SLbool state)
Definition: SLGLState.cpp:267
static SLGLState * instance()
Public static instance getter for singleton pattern.
Definition: SLGLState.h:74
void polygonOffsetLine(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
Definition: SLGLState.cpp:335
~SLGLState()
destruction in ~SLScene
Definition: SLGLState.cpp:123
SLGLState()
private onetime constructor
Definition: SLGLState.cpp:35
SLbool _multisample
Multisampling state.
Definition: SLGLState.h:189
SLbool _isInitialized
flag for first init
Definition: SLGLState.h:166
SLbool _glIsES2
Flag if OpenGL ES2.
Definition: SLGLState.h:176
SLMat4f viewMatrix
matrix for the active cameras view transform
Definition: SLGLState.h:91
SLstring _glSLVersion
GLSL Version string.
Definition: SLGLState.h:173
void unbindAnythingAndFlush()
finishes all GL commands
Definition: SLGLState.cpp:465
SLVstring errorTexts
vector for error texts collected in getGLError
Definition: SLGLState.h:208
SLenum _textureTarget
current texture target
Definition: SLGLState.h:201
GLboolean _colorMaskA
current color mask for A
Definition: SLGLState.h:206
SLenum _blendFuncSfactor
blend function source factor enum
Definition: SLGLState.h:183
void initAll()
Definition: SLGLState.cpp:42
void blendFunc(SLenum blendFuncSFactor, SLenum blendFuncDFactor)
Sets new blend function source and destination factors.
Definition: SLGLState.cpp:250
void colorMask(GLboolean r, GLboolean g, GLboolean b, GLboolean a)
Definition: SLGLState.cpp:394
SLenum _blendFuncDfactor
blend function destination factor enum
Definition: SLGLState.h:184
SLstring getSLVersionNO()
Returns the OpenGL Shading Language version number as a string.
Definition: SLGLState.cpp:575
SLstring _glVendor
OpenGL Vendor string.
Definition: SLGLState.h:171
GLboolean _colorMaskR
current color mask for R
Definition: SLGLState.h:203
SLstring _glVersionNO
OpenGL Version number string.
Definition: SLGLState.h:169
SLstring _glSLVersionNO
GLSL Version number string.
Definition: SLGLState.h:174
SLstring _glExtensions
OpenGL extensions string.
Definition: SLGLState.h:175
SLbool _polygonOffsetFillEnabled
GL_POLYGON_OFFSET_FILL state enabled.
Definition: SLGLState.h:194
SLstring _glRenderer
OpenGL Renderer string.
Definition: SLGLState.h:172
SLbool blend() const
Definition: SLGLState.h:126
SLbool _blend
blending default false;
Definition: SLGLState.h:182
SLbool _polygonOffsetLineEnabled
GL_POLYGON_OFFSET_LINE state enabled.
Definition: SLGLState.h:193
SLstring getGLVersionNO()
Returns the OpenGL version number as a string.
Definition: SLGLState.cpp:552
SLenum _textureUnit
current texture unit
Definition: SLGLState.h:200
SLint _glMaxTexUnits
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_glMaxTexUnits);
Definition: SLGLState.h:178
SLbool pixelFormatIsSupported(SLint pixelFormat)
Returns true if the according GL pixel format is valid in the GL context.
Definition: SLGLState.cpp:588
void depthFunc(SLenum func)
Definition: SLGLState.cpp:205
SLbool _polygonOffsetPointEnabled
GL_POLYGON_OFFSET_POINT state enabled.
Definition: SLGLState.h:192
SLenum _depthFunc
depth buffer comparison function
Definition: SLGLState.h:187
void bindTexture(SLenum target, SLuint textureID)
Definition: SLGLState.cpp:423
SLfloat _glVersionNOf
OpenGL Version number as float.
Definition: SLGLState.h:170
static void getGLError(const char *file, int line, bool quit)
Checks if an OpenGL error occurred.
Definition: SLGLState.cpp:484
void polygonOffsetFill(SLbool enabled, SLfloat factor=-1.0f, SLfloat units=-1.0f)
Definition: SLGLState.cpp:359
SLbool _glIsES3
Flag if OpenGL ES3.
Definition: SLGLState.h:177
void onInitialize(const SLCol4f &clearColor)
On init GL.
Definition: SLGLState.cpp:137
SLbool _polygonLine
Line polygon state.
Definition: SLGLState.h:191
SLMat4f projectionMatrix
matrix for projection transform
Definition: SLGLState.h:90
SLVlong errorCounts
vector for counts for the corresponding errorTexts
Definition: SLGLState.h:209
SLstring _glVersion
OpenGL Version string.
Definition: SLGLState.h:168
void useProgram(SLuint progID)
Definition: SLGLState.cpp:410
SLMaterial * _currentMaterial
Definition: SLGLState.h:211
void polygonLine(SLbool state)
Definition: SLGLState.cpp:290
SLint _glMaxTexSize
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_glMaxTexSize);
Definition: SLGLState.h:179
SLbool _cullFace
Face culling state.
Definition: SLGLState.h:188
SLint _multiSampleSamples
NO. of multisampling samples.
Definition: SLGLState.h:190
void readPixels(void *buffer)
Reads the front framebuffer pixels into the passed buffer.
Definition: SLGLState.cpp:639
GLboolean _colorMaskB
current color mask for B
Definition: SLGLState.h:205
GLboolean _colorMaskG
current color mask for G
Definition: SLGLState.h:204
void cullFace(SLbool state)
Definition: SLGLState.cpp:219
void depthTest(SLbool state)
Definition: SLGLState.cpp:172
SLuint _programID
current shader program id
Definition: SLGLState.h:199
void identity()
Sets the identity matrix.
Definition: SLMat4.h:1333
T w
Definition: SLVec4.h:32
T z
Definition: SLVec4.h:32
T g
Definition: SLVec4.h:33
void set(const T X, const T Y, const T Z, const T W=1)
Definition: SLVec4.h:49
T b
Definition: SLVec4.h:33
T y
Definition: SLVec4.h:32
T a
Definition: SLVec4.h:33
T r
Definition: SLVec4.h:33
T x
Definition: SLVec4.h:32
string getFileName(const string &pathFilename)
Returns the filename of path-filename string.
Definition: Utils.cpp:580