Skip to content

Instantly share code, notes, and snippets.

@player-03
Last active October 8, 2015 20:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save player-03/01cd027edc49c31521f6 to your computer and use it in GitHub Desktop.
Save player-03/01cd027edc49c31521f6 to your computer and use it in GitHub Desktop.
A function to help pin down the location of an OpenGL error.
#if !flash
import openfl.errors.Error;
import openfl.gl.GL;
import haxe.PosInfos;
import haxe.Log;
/**
* Usage: Put "GLCheck.check()" before and after anything that you suspect is causing a
* GL error. If the second call displays the error, you've found the problem. If the
* first one displays it, it actually happened earlier in the program.
*/
class GLCheck {
/**
* Determines how GL errors are handled. Set this to false if you want errors to be
* logged without stopping the program. (In that case, remember to scroll up to the
* top of the list of errors.)
*/
public static var throwErrors:Bool = true;
/**
* @param posInfos For best results, do NOT supply this parameter.
*/
public static inline function check(?posInfos:PosInfos):Void {
var error:Int = GL.getError();
if(error != GL.NO_ERROR) {
if(throwErrors) {
throw new Error(posInfos.fileName + ":" + posInfos.lineNumber + ": " + getErrorDescription(error));
} else {
Log.trace(getErrorDescription(error), posInfos);
}
}
}
public static function getErrorDescription(error:Int):String {
switch(error) {
case GL.NO_ERROR:
return "GL_NO_ERROR";
case GL.INVALID_ENUM:
return "GL_INVALID_ENUM";
case GL.INVALID_OPERATION:
return "GL_INVALID_OPERATION";
case GL.INVALID_FRAMEBUFFER_OPERATION:
return "GL_INVALID_FRAMEBUFFER_OPERATION";
case GL.INVALID_VALUE:
return "GL_INVALID_VALUE";
case GL.OUT_OF_MEMORY:
return "GL_OUT_OF_MEMORY";
default:
return "Unknown GL error: " + error;
}
}
}
#end
@player-03
Copy link
Author

The MIT License (MIT)

Copyright (c) 2015 Joseph Cloutier

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment