Skip to content

Commit

Permalink
checkgl uncleared error support, all aliased away in non-debug
Browse files Browse the repository at this point in the history
  • Loading branch information
John-Colvin committed Feb 26, 2015
1 parent 8562aa5 commit 2f18bc2
Showing 1 changed file with 24 additions and 10 deletions.
34 changes: 24 additions & 10 deletions glamour/util.d
Original file line number Diff line number Diff line change
Expand Up @@ -39,21 +39,35 @@ debug {

/// checkgl checks in a debug build after every opengl call glGetError
/// and calls an error-callback which can be set with set_error_callback
/// a default is provided
ReturnType!func checkgl(alias func, Args...)(Args args) {
debug scope(success) {
/// a default is provided.
/// Example:
/// checkgl!glDrawArrays(GL_POINTS, 0, 10);
template checkgl(alias func)
{
debug ReturnType!func checkgl(Args...)(Args args) {
//get and clear previous error, if any.
GLenum error_code = glGetError();

if(error_code != GL_NO_ERROR) {
_error_callback(error_code, func.stringof, format("%s".repeat(Args.length).join(", "), args));
_error_callback(error_code, "<unknown>", "<unknown>");
}
}

scope(success) {
error_code = glGetError();

debug if(func is null) {
throw new Error("%s is null! OpenGL loaded? Required OpenGL version not supported?".format(func.stringof));
}
if(error_code != GL_NO_ERROR) {
_error_callback(error_code, func.stringof, format("%s".repeat(Args.length).join(", "), args));
}
}

return func(args);
if(func is null) {
throw new Error("%s is null! OpenGL loaded? Required OpenGL version not supported?".format(func.stringof));
}

return func(args);
} else {
alias checkgl = func;
}
}

/// Converts an OpenGL errorenum to a string
Expand Down Expand Up @@ -174,4 +188,4 @@ int glenum2size(GLenum t) {
case GL_DOUBLE: return glenum2sizect!GL_DOUBLE;
default: throw new Exception("Unknown GLenum");
}
}
}

0 comments on commit 2f18bc2

Please sign in to comment.