1 /** 2 Copyright: Copyright (c) 2013-2017 Andrey Penechko. 3 License: $(WEB boost.org/LICENSE_1_0.txt, Boost License 1.0). 4 Authors: Andrey Penechko. 5 */ 6 7 module anchovy.glerrors; 8 9 import std.conv: to; 10 import derelict.opengl3.gl3; 11 12 /// Errors checking template; should work in debug build. 13 /// Using: checkgl!glFunction(funcParams); 14 template checkgl(alias func) 15 { 16 import std.traits : Parameters; 17 debug auto checkgl(string file = __FILE__, int line = __LINE__)(Parameters!func args) 18 { 19 scope(success) checkGlError(file, line, func.stringof); 20 return func(args); 21 } else 22 alias checkgl = func; 23 } 24 25 void checkGlError(string file = __FILE__, size_t line = __LINE__, string funcName = "") 26 { 27 uint error = glGetError(); 28 if (error != GL_NO_ERROR) 29 { 30 throw new OpenglException(error, file, line, funcName); 31 } 32 } 33 34 class OpenglException : Exception 35 { 36 this(uint errorCode, string file = __FILE__, size_t line = __LINE__, string funcName = "") 37 { 38 super("OpenGL error [" ~ to!string(errorCode) ~ "] " ~ glErrorStringTable[errorCode] ~ " " ~ funcName, file, line); 39 } 40 } 41 42 static const string[uint] glErrorStringTable; 43 44 static this() 45 { 46 glErrorStringTable = [ 47 //GL_NO_ERROR : "no error", 48 GL_INVALID_ENUM : "invalid enum", 49 GL_INVALID_VALUE : "invalid value", 50 GL_INVALID_OPERATION : "invalid operation", 51 GL_INVALID_FRAMEBUFFER_OPERATION : "invalid framebuffer operation", 52 GL_OUT_OF_MEMORY : "out of memory", 53 //GL_STACK_UNDERFLOW : "stack underflow", 54 //GL_STACK_OVERFLOW : "stack overflow", 55 ]; 56 }