1 module des.gl.error; 2 3 import des.gl.general; 4 5 /// 6 enum GLError 7 { 8 NO = GL_NO_ERROR, /// `GL_NO_ERROR` 9 INVALID_ENUM = GL_INVALID_ENUM, /// `GL_INVALID_ENUM` 10 INVALID_VALUE = GL_INVALID_VALUE, /// `GL_INVALID_VALUE` 11 INVALID_OPERATION = GL_INVALID_OPERATION, /// `GL_INVALID_OPERATION` 12 STACK_OVERFLOW = 0x0503, /// `0x0503` 13 STACK_UNDERFLOW = 0x0504, /// `0x0504` 14 OUT_OF_MEMORY = GL_OUT_OF_MEMORY, /// `GL_OUT_OF_MEMORY` 15 INVALID_FRAMEBUFFER_OPERATION = 0x0506 /// `0x0506` 16 } 17 18 /// `glGetError`, if has error throw exception 19 void checkGL( string file=__FILE__, size_t line=__LINE__ ) 20 { 21 debug 22 { 23 GLError err = cast(GLError)glGetError(); 24 if( err != GLError.NO ) 25 throw new DesGLException( format("%s", err), file, line ); 26 } 27 else pragma(msg,"warning: no check GL errors"); 28 } 29 30 /// `glGetError`, no throw exception, output to logger error 31 void ntCheckGL( string file=__FILE__, size_t line=__LINE__ ) nothrow 32 { 33 debug 34 { 35 try checkGL(file,line); 36 catch( DesGLException e ) 37 logger.error( ntFormat( "GL ERROR at [%s:%d] %s", e.file, e.line, e.msg ) ); 38 catch( Exception e ) 39 logger.error( ntFormat( "[%s:%d] %s", e.file, e.line, e.msg ) ); 40 } else return; 41 } 42 43 /// call `checkGL` after function call 44 template checkGLCall(alias fnc, string file=__FILE__, size_t line=__LINE__, Args...) 45 { 46 auto checkGLCall(Args...)( Args args ) 47 { 48 debug scope(exit) checkGL(file,line); 49 static if( is( typeof(fnc(args)) == void ) ) fnc( args ); 50 else return fnc( args ); 51 } 52 } 53 54 /// call `ntCheckGL` after function call 55 template ntCheckGLCall(alias fnc, string file=__FILE__, size_t line=__LINE__, Args...) 56 { 57 auto ntCheckGLCall(Args...)( Args args ) nothrow 58 { 59 debug scope(exit) ntCheckGL(file,line); 60 static if( is( typeof(fnc(args)) == void ) ) fnc( args ); 61 else return fnc( args ); 62 } 63 }