CGVIS Utils
Loading...
Searching...
No Matches
GLDebug.h
Go to the documentation of this file.
1#pragma once
2
3#include <iostream>
4#include <exception>
5
22
30class GLException : public std::exception {
31public:
33 GLException(const std::string& whatStr) : whatStr(whatStr) {}
35 virtual const char* what() const throw() {
36 return whatStr.c_str();
37 }
38private:
39 std::string whatStr;
40};
41
45struct Dimensions {
46 uint32_t width;
47 uint32_t height;
48
53 float aspect() const {return float(width)/float(height);}
54};
55
61std::string errorString(GLenum glerr);
62
63#ifndef NDEBUG
64
69
76#define MAX_GL_ERROR_COUNT 10
77
86void errorOut(const std::string& statement, const std::string& location,
87 uint32_t line, const std::string& file, uint32_t errnum);
88
101# define GL(stmt) \
102do { \
103GLenum glerr; \
104uint32_t counter = 0; \
105while((glerr = glGetError()) != GL_NO_ERROR) { \
106errorOut(#stmt, "before", __LINE__, __FILE__, \
107static_cast<uint32_t>(glerr)); \
108counter++; \
109if (counter > MAX_GL_ERROR_COUNT) break; \
110} \
111stmt; \
112counter = 0; \
113while((glerr = glGetError()) != GL_NO_ERROR) { \
114errorOut(#stmt, "in", __LINE__, __FILE__, \
115static_cast<uint32_t>(glerr)); \
116counter++; \
117if (counter > MAX_GL_ERROR_COUNT) break; \
118} \
119} while(0)
120
121#else
123# define GL(stmt) do { stmt; } while(0)
124#endif
125
129void checkAndThrow();
130
135void checkAndThrowShader(GLuint shader);
136
141void checkAndThrowProgram(GLuint program);
std::string errorString(GLenum glerr)
Convert a GL error enum to a short string (e.g., "GL_INVALID_VALUE").
Definition GLDebug.cpp:7
void errorOut(const std::string &statement, const std::string &location, uint32_t line, const std::string &file, uint32_t errnum)
Internal printer used by the GL() macro to emit formatted errors.
Definition GLDebug.cpp:19
void checkAndThrow()
Throw a GLException if glGetError() reports an error.
Definition GLDebug.cpp:25
void checkAndThrowShader(GLuint shader)
Check a shader object's compile status and throw with its log on error.
Definition GLDebug.cpp:34
void checkAndThrowProgram(GLuint program)
Check a program object's link status and throw with its log on error.
Definition GLDebug.cpp:48
virtual const char * what() const
Retrieve the explanatory C-string.
Definition GLDebug.h:35
GLException(const std::string &whatStr)
Construct with an explanatory message.
Definition GLDebug.h:33
Simple pixel/viewport dimensions with an aspect ratio helper.
Definition GLDebug.h:45
uint32_t height
Height in pixels/texels.
Definition GLDebug.h:47
float aspect() const
Aspect ratio as width/height.
Definition GLDebug.h:53
uint32_t width
Width in pixels/texels.
Definition GLDebug.h:46