Loading [MathJax]/jax/input/TeX/config.js
Radium Engine  1.5.0
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Modules Pages
OpenGL.hpp
1 #pragma once
2 
8 #include <glbinding/gl/gl.h>
9 #include <glbinding/gl45core/gl.h>
10 #include <glbinding/gl45ext/gl.h>
11 
12 namespace Ra {
13 namespace Engine {
14 // use glbinding namespace only in Ra::Engine to avoid namespace clash with e.g. Qt.
15 using namespace gl45core;
16 using namespace gl45ext;
17 using namespace gl;
18 } // namespace Engine
19 } // namespace Ra
20 
21 #include <glbinding-aux/types_to_string.h>
22 
23 // use always float on the OpenGL side, since double have some unresolved func with globjects.
24 // maybe fix this to allow GL_DOUBLE ? in this change data conversion in color or mesh attrib gpu
25 // data transfer.
26 #define GL_SCALAR GL_FLOAT
27 #define GL_SCALAR_PLAIN float
28 
30 inline bool checkOpenGLContext() {
31  return gl::glGetString( gl::GL_VERSION ) != nullptr;
32 }
33 
35 inline const char* glErrorString( gl::GLenum err ) {
36  using namespace gl45core;
37  using namespace gl45ext;
38  using namespace gl;
39  switch ( err ) {
40  case GL_INVALID_ENUM:
41  return " Invalid enum : An unacceptable value is specified for an enumerated argument. The "
42  "offending command is ignored and has no other side effect than to set the error "
43  "flag.\n";
44  case GL_INVALID_VALUE:
45  return " Invalid value : A numeric argument is out of range. The offending command is "
46  "ignored and has no other side effect than to set the error flag.\n";
47  case GL_INVALID_OPERATION:
48  return " Invalid operation : The specified operation is not allowed in the current state. "
49  "The offending command is ignored and has no other side effect than to set the "
50  "error flag.\n";
51  case GL_INVALID_FRAMEBUFFER_OPERATION:
52  return " Invalid framebuffer operation : The framebuffer object is not complete. The "
53  "offending command is ignored and has no other side effect than to set the error "
54  "flag.\n";
55  case GL_OUT_OF_MEMORY:
56  return " Out of memory : There is not enough memory left to execute the command. The state "
57  "of the GL is undefined, except for the state of the error flags, after this error "
58  "is recorded.\n";
59  // case GL_STACK_UNDERFLOW:
60  // return " Stack underflow : An attempt has been made to perform an operation that would
61  // cause an internal stack to underflow.\n";
62  // case GL_STACK_OVERFLOW:
63  // return " Stack overflow : An attempt has been made to perform an operation that would
64  // cause an internal stack to overflow.\n";
65  case GL_NO_ERROR:
66  return " No error\n";
67  default:
68  return " Unknown GL error\n";
69  }
70 }
71 
72 #ifdef _DEBUG
73 # include <Core/Utils/Log.hpp>
74 # include <Core/Utils/StackTrace.hpp>
75 # define GL_ASSERT( x ) \
76  x; \
77  { \
78  gl::GLenum err = gl::glGetError(); \
79  if ( err != gl::GL_NO_ERROR ) { \
80  const char* errBuf = glErrorString( err ); \
81  LOG( Ra::Core::Utils::logERROR ) \
82  << "OpenGL error (" << __FILE__ << ":" << __LINE__ << ", " << STRINGIFY( x ) \
83  << ") : " << errBuf << "(" << err << " : 0x" << std::hex << int( err ) \
84  << std::dec << ")."; \
85  BREAKPOINT( 0 ); \
86  } \
87  }
88 
90 # define GL_CHECK_ERROR \
91  { \
92  gl::GLenum err = gl::glGetError(); \
93  if ( err != gl::GL_NO_ERROR ) { \
94  const char* errBuf = glErrorString( err ); \
95  LOG( Ra::Core::Utils::logERROR ) \
96  << "OpenGL error (" << __FILE__ << ":" << __LINE__ \
97  << ", glCheckError()) : " << errBuf << "(" << err << " : 0x" << std::hex \
98  << err << std::dec << ")." << '\n' \
99  << Ra::Core::Utils::StackTrace(); \
100  BREAKPOINT( 0 ); \
101  } \
102  }
103 
105 # define glFlushError() glGetError()
106 
107 #else // Release version ignores the checks and errors.
108 # define GL_ASSERT( x ) x
109 # define GL_CHECK_ERROR \
110  {}
111 # define glFlushError() \
112  {}
113 #endif // _DEBUG
Definition: Cage.cpp:3