SimpleGL  1.1.0
A framework for platform independent rendering
gl_general.cpp
Go to the documentation of this file.
1 
9 
10 #include <string>
11 
12 #include <SimpleGL/logging.hpp>
13 
15 
16 using namespace std;
17 using namespace glm;
18 
19 namespace sgl {
20 
21  GL::GL(void) {
22  /* Nothing to do here */
23  }
24 
25  void GL::checkError() {
26  GLenum error;
27  while ((error = glGetError()) != GL_NO_ERROR) {
28  Logger::logError("OpenGL error " + to_string(error) + ":");
29  switch (error) {
30  case GL_INVALID_ENUM:
31  Logger::logError("GL_INVALID_ENUM: An unacceptable value is specified for an enumerated argument.");
32  break;
33 
34  case GL_INVALID_VALUE:
35  Logger::logError("GL_INVALID_VALUE: A numeric argument is out of range.");
36  break;
37 
38  case GL_INVALID_OPERATION:
39  Logger::logError("GL_INVALID_OPERATION: The specified operation is not allowed in the current state.");
40  break;
41 
42  case GL_INVALID_FRAMEBUFFER_OPERATION:
43  Logger::logError("GL_INVALID_FRAMEBUFFER_OPERATION: The framebuffer object is not complete.");
44  break;
45 
46  case GL_OUT_OF_MEMORY:
47  Logger::logError("GL_OUT_OF_MEMORY: There is not enough memory left to execute the command.");
48  break;
49  }
50  }
51  }
52 
53  void GL::enable(Capability cap) {
54  glEnable(to_GLenum(cap));
55  }
56 
57  void GL::disable(Capability cap) {
58  glDisable(to_GLenum(cap));
59  }
60 
61  void GL::clearColor(float r, float g, float b, float a) {
62  clearColor(vec4(r, g, b, a));
63  }
64 
65  void GL::clearColor(glm::vec4 color) {
66  /* Values need to be normalized */
67  vec4 normal = normalize(color);
68  glClearColor(normal.r, normal.g, normal.b, normal.a);
69  }
70 
71  void GL::clear(ClearBit mask) {
72  glClear(to_GLbitfield(mask));
73  }
74 
75  void GL::drawArrays(Primitive mode, int first, int count) {
76  glDrawArrays(to_GLenum(mode), first, count);
77  }
78 
79  void GL::blendFunc(BlendFactor source, BlendFactor destination) {
80  glBlendFunc(to_GLenum(source), to_GLenum(destination));
81  }
82 
83  void GL::cullFace(CullFaceMode mode) {
84  glCullFace(to_GLenum(mode));
85  }
86 
87  void GL::depthFunc(DepthFunction func) {
88  glDepthFunc(to_GLenum(func));
89  }
90 }
ClearBit
This enum wraps the clear buffer bits.
Definition: gl_general.hpp:43
Primitive
This enum wraps Primitive types of OpenGL.
Definition: gl_general.hpp:60
GLenum to_GLenum(E e)
Gets the GLenum value from an enum class.
Definition: backend_gl.tcc:22
Generic namespace for the SimpleGL framework.
Definition: application.hpp:18
DepthFunction
This enum wraps the depth functions.
Definition: gl_general.hpp:171
CullFaceMode
This enum wraps the face culling modes.
Definition: gl_general.hpp:154
BlendFactor
This enum wraps the blend factos.
Definition: gl_general.hpp:89
GLbitfield to_GLbitfield(E e)
Gets the GLbitfield value from an enum class.
Definition: backend_gl.tcc:27
Capability
This enum wraps OpenGL capabilities.
Definition: gl_general.hpp:26