eduEngine 1.0
Course framework for DA376B
Loading...
Searching...
No Matches
glcommon.h
1// Created by Carl Johan Gribel.
2// Licensed under the MIT License. See LICENSE file for details.
3
4#ifndef GLCOMMON_H
5#define GLCOMMON_H
6
7#include <iostream>
8#include <GL/glew.h>
9#ifdef __APPLE__
10#include <OpenGL/gl.h>
11#else
12#define NOMINMAX
13#include <windows.h>
14#include <GL/gl.h>
15#endif
16
17static inline const char *GetGLErrorString(GLenum error)
18{
19 switch (error)
20 {
21 case GL_NO_ERROR:
22 return "GL_NO_ERROR";
23 case GL_INVALID_ENUM:
24 return "GL_INVALID_ENUM";
25 case GL_INVALID_VALUE:
26 return "GL_INVALID_VALUE";
27 case GL_INVALID_OPERATION:
28 return "GL_INVALID_OPERATION";
29 case GL_INVALID_FRAMEBUFFER_OPERATION:
30 return "GL_INVALID_FRAMEBUFFER_OPERATION";
31 case GL_OUT_OF_MEMORY:
32 return "GL_OUT_OF_MEMORY";
33 case GL_STACK_UNDERFLOW:
34 return "GL_STACK_UNDERFLOW";
35 case GL_STACK_OVERFLOW:
36 return "GL_STACK_OVERFLOW";
37 default:
38 return "Unknown GL error";
39 }
40}
41
42static inline void CheckAndThrowGLErrors()
43{
44 GLenum err = glGetError();
45 bool hasError = (err != GL_NO_ERROR);
46
47 while (err != GL_NO_ERROR)
48 {
49 std::cerr << "GLError " << GetGLErrorString(err)
50 << " set in File: " << __FILE__
51 << " Line: " << __LINE__ << std::endl;
52 err = glGetError();
53 }
54
55 if (hasError)
56 {
57 throw std::runtime_error("GL error(s) caught");
58 }
59}
60
61static inline void FlushGLErrors()
62{
63 GLenum err;
64 while ((err = glGetError()) != GL_NO_ERROR)
65 {
66 // Discard the error
67 }
68}
69
70#endif