1 /** 2 Copyright: Copyright (c) 2013-2016 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 debug auto checkgl(string file = __FILE__, int line = __LINE__, Args...)(auto ref Args args) 17 { 18 scope(success) checkGlError(file, line, func.stringof); 19 return func(args); 20 } else 21 alias checkgl = func; 22 } 23 24 void checkGlError(string file = __FILE__, size_t line = __LINE__, string funcName = "") 25 { 26 uint error = glGetError(); 27 if (error != GL_NO_ERROR) 28 { 29 throw new OpenglException(error, file, line, funcName); 30 } 31 } 32 33 class OpenglException : Exception 34 { 35 this(uint errorCode, string file = __FILE__, size_t line = __LINE__, string funcName = "") 36 { 37 super("OpenGL error [" ~ to!string(errorCode) ~ "] " ~ glErrorStringTable[errorCode] ~ " " ~ funcName, file, line); 38 } 39 } 40 41 static const string[uint] glErrorStringTable; 42 43 static this() 44 { 45 glErrorStringTable = 46 [ 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 }