/** * Checks for any GL error codes and logs them (if {@link #checkErrors} is true). * @return true if any errors were reported. */ public boolean checkError (String op) { int reported = 0; if (checkErrors) { int error; while ((error = glGetError()) != GL_NO_ERROR) { reported += 1; System.err.println(op + ": glError " + error); } } return reported > 0; }
/** * Checks for any GL error codes and logs them (if {@link #checkErrors} is true). * @return true if any errors were reported. */ public boolean checkError (String op) { int reported = 0; if (checkErrors) { int error; while ((error = glGetError()) != GL_NO_ERROR) { reported += 1; System.err.println(op + ": glError " + error); } } return reported > 0; }
private static int usableMaxUniformVectors (GL20 gl) { // this returns the maximum number of vec4s; then we subtract one vec2 to account for the // uHScreenSize uniform, and two more because some GPUs seem to need one for our vec3 attr int maxVecs = gl.glGetInteger(GL_MAX_VERTEX_UNIFORM_VECTORS) - 3; // we have to check errors always in this case, because if GL failed to return a value we would // otherwise return the value of uninitialized memory which could be some huge number which we // might turn around and try to compile into a shader causing GL to crash (you might think from // such a careful description that such a thing has in fact come to pass, and you would not be // incorrect) int glErr = gl.glGetError(); if (glErr != GL20.GL_NO_ERROR) throw new RuntimeException( "Unable to query GL_MAX_VERTEX_UNIFORM_VECTORS, error " + glErr); return maxVecs; }
private static int usableMaxUniformVectors (GL20 gl) { // this returns the maximum number of vec4s; then we subtract one vec2 to account for the // uHScreenSize uniform, and two more because some GPUs seem to need one for our vec3 attr int maxVecs = gl.glGetInteger(GL_MAX_VERTEX_UNIFORM_VECTORS) - 3; // we have to check errors always in this case, because if GL failed to return a value we would // otherwise return the value of uninitialized memory which could be some huge number which we // might turn around and try to compile into a shader causing GL to crash (you might think from // such a careful description that such a thing has in fact come to pass, and you would not be // incorrect) int glErr = gl.glGetError(); if (glErr != GL20.GL_NO_ERROR) throw new RuntimeException( "Unable to query GL_MAX_VERTEX_UNIFORM_VECTORS, error " + glErr); return maxVecs; }
/** Creates a render target that renders to {@code texture}. */ public static RenderTarget create (Graphics gfx, final Texture tex) { GL20 gl = gfx.gl; final int fb = gl.glGenFramebuffer(); if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError()); gl.glBindFramebuffer(GL_FRAMEBUFFER, fb); gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0); gl.checkError("RenderTarget.create"); return new RenderTarget (gfx) { public int id () { return fb; } public int width () { return tex.pixelWidth; } public int height () { return tex.pixelHeight; } public float xscale () { return tex.pixelWidth / tex.displayWidth; } public float yscale () { return tex.pixelHeight / tex.displayHeight; } public boolean flip () { return false; } }; }
/** Creates a render target that renders to {@code texture}. */ public static RenderTarget create (Graphics gfx, final Texture tex) { GL20 gl = gfx.gl; final int fb = gl.glGenFramebuffer(); if (fb == 0) throw new RuntimeException("Failed to gen framebuffer: " + gl.glGetError()); gl.glBindFramebuffer(GL_FRAMEBUFFER, fb); gl.glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex.id, 0); gl.checkError("RenderTarget.create"); return new RenderTarget (gfx) { public int id () { return fb; } public int width () { return tex.pixelWidth; } public int height () { return tex.pixelHeight; } public float xscale () { return tex.pixelWidth / tex.displayWidth; } public float yscale () { return tex.pixelHeight / tex.displayHeight; } public boolean flip () { return false; } }; }
private int compileShader(int type, final String shaderSource) { int shader = gl.glCreateShader(type); if (shader == 0) throw new RuntimeException( "Failed to create shader (" + type + "): " + gl.glGetError()); gl.glShaderSource(shader, shaderSource); gl.glCompileShader(shader); int[] compiled = new int[1]; gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == GL20.GL_FALSE) { String log = gl.glGetShaderInfoLog(shader); gl.glDeleteShader(shader); throw new RuntimeException("Failed to compile shader (" + type + "): " + log); } return shader; } }
private int compileShader(int type, final String shaderSource) { int shader = gl.glCreateShader(type); if (shader == 0) throw new RuntimeException( "Failed to create shader (" + type + "): " + gl.glGetError()); gl.glShaderSource(shader, shaderSource); gl.glCompileShader(shader); int[] compiled = new int[1]; gl.glGetShaderiv(shader, GL20.GL_COMPILE_STATUS, compiled, 0); if (compiled[0] == GL20.GL_FALSE) { String log = gl.glGetShaderInfoLog(shader); gl.glDeleteShader(shader); throw new RuntimeException("Failed to compile shader (" + type + "): " + log); } return shader; } }
try { id = gl.glCreateProgram(); if (id == 0) throw new RuntimeException("Failed to create program: " + gl.glGetError()); gl.checkError("glCreateProgram");
try { id = gl.glCreateProgram(); if (id == 0) throw new RuntimeException("Failed to create program: " + gl.glGetError()); gl.checkError("glCreateProgram");