1 /** 2 * Retrograde Engine 3 * 4 * Authors: 5 * Mike Bierlee, m.bierlee@lostmoment.com 6 * Copyright: 2014-2021 Mike Bierlee 7 * License: 8 * This software is licensed under the terms of the MIT license. 9 * The full terms of the license can be found in the LICENSE.txt file. 10 */ 11 12 module retrograde.graphics.threedee.opengl.error; 13 14 version(Have_derelict_gl3) { 15 16 import std.experimental.logger; 17 import std.string; 18 import std.exception; 19 20 import poodinis; 21 22 import derelict.opengl3.gl3; 23 24 class ErrorService { 25 26 @Autowire 27 private Logger logger; 28 29 public GLenum[] getAllErrors() { 30 GLenum[] errors; 31 while(true) { 32 GLenum error = glGetError(); 33 if (error == GL_NO_ERROR) { 34 break; 35 } 36 37 errors ~= error; 38 } 39 return errors; 40 } 41 42 public void throwOnErrors(ExceptionType : Exception)(string action = "") { 43 auto errors = getAllErrors(); 44 auto actionSpecifier = !action.empty ? " while " ~ action : ""; 45 if (errors.length > 0) { 46 throw new ExceptionType(format("OpenGL errors were flagged%s: %s", actionSpecifier, errors)); 47 } 48 } 49 50 public void logErrorsIfAny() { 51 auto errors = getAllErrors(); 52 if (errors.length > 0) { 53 logger.error(format("OpenGL errors were flagged: %s", errors)); 54 } 55 56 } 57 } 58 59 }