check And Halt On OpenGL Error - Android android.opengl

Android examples for android.opengl:OpenGL Error

Description

check And Halt On OpenGL Error

Demo Code


import android.util.Log;
import static android.opengl.GLES20.GL_INVALID_ENUM;
import static android.opengl.GLES20.GL_INVALID_FRAMEBUFFER_OPERATION;
import static android.opengl.GLES20.GL_INVALID_OPERATION;
import static android.opengl.GLES20.GL_INVALID_VALUE;
import static android.opengl.GLES20.GL_NO_ERROR;
import static android.opengl.GLES20.GL_OUT_OF_MEMORY;
import static android.opengl.GLES20.glGetError;

public class Main{
    private static final String LOGTAG = GLESUtil.class.getSimpleName();
    public static void checkAndHaltOnGlError(String op) {
        int error;
        if ((error = glGetError()) != GL_NO_ERROR) {
            String msg = op + ": glError " + error + ":"
                    + getShortDescription(error);
            Log.e(LOGTAG, msg);//from w w w  .  j  a v a  2  s . c o  m
            throw new RuntimeException("GLES Error: " + msg);
        }
    }
    /**
     * Translates a gl error into a short readable format. Based upon the official documentation.
     *
     * @param glError The OpenGL error.
     * @return The readable string of the error.
     */
    public static String getShortDescription(int glError) {
        switch (glError) {
        case GL_INVALID_ENUM:
            return "GL_INVALID_ENUM";
        case GL_INVALID_VALUE:
            return "GL_INVALID_VALUE";
        case GL_INVALID_OPERATION:
            return "GL_INVALID_OPERATION";
        case GL_OUT_OF_MEMORY:
            return "GL_OUT_OF_MEMORY";
        case GL_INVALID_FRAMEBUFFER_OPERATION:
            return "GL_INVALID_FRAMEBUFFER_OPERATION";
        }
        return "";
    }
}

Related Tutorials