1 /* 2 * Copyright (c) 2002-2011 LWJGL Project 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions are 7 * met: 8 * 9 * * Redistributions of source code must retain the above copyright 10 * notice, this list of conditions and the following disclaimer. 11 * 12 * * Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * * Neither the name of 'LWJGL' nor the names of 17 * its contributors may be used to endorse or promote products derived 18 * from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 21 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 22 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 23 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 24 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 25 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 26 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 27 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 28 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 29 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 30 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 31 */ 32 package org.lwjgl.opengles; 33 34 import org.lwjgl.LWJGLException; 35 import org.lwjgl.opengl.OpenGLException; 36 37 import static org.lwjgl.opengles.EGL.*; 38 import static org.lwjgl.opengles.GLES20.*; 39 40 /** 41 * Simple utility class. 42 * 43 * @author Spasi 44 */ 45 public final class Util { 46 Util()47 private Util() { 48 } 49 50 /** 51 * Checks for OpenGL ES errors. 52 * 53 * @throws org.lwjgl.opengl.OpenGLException 54 * if GLES20.glGetError() returns anything else than GLES20.GL_NO_ERROR 55 */ checkGLError()56 public static void checkGLError() throws OpenGLException { 57 int err = glGetError(); 58 if ( err != GL_NO_ERROR ) 59 throw new OpenGLException(err); 60 } 61 62 /** 63 * Translates a GL error code to a String describing the error. 64 * 65 * @param error_code the OpenGL ES error code 66 * 67 * @return the error description 68 */ translateGLErrorString(int error_code)69 public static String translateGLErrorString(int error_code) { 70 switch ( error_code ) { 71 case GL_NO_ERROR: 72 return "No error"; 73 case GL_INVALID_ENUM: 74 return "Invalid enum"; 75 case GL_INVALID_VALUE: 76 return "Invalid value"; 77 case GL_INVALID_OPERATION: 78 return "Invalid operation"; 79 case GL_OUT_OF_MEMORY: 80 return "Out of memory"; 81 default: 82 return null; 83 } 84 } 85 86 /** 87 * Checks for EGL errors. 88 * 89 * @throws org.lwjgl.LWJGLException if EGL.eglGetError() returns anything else than EGL.EGL_SUCCESS 90 */ checkEGLError()91 static void checkEGLError() throws LWJGLException { 92 int err = eglGetError(); 93 if ( err != EGL_SUCCESS ) 94 throw new LWJGLException(translateEGLErrorString(err)); 95 } 96 97 /** 98 * Translates an EGL error code to a String describing the error. 99 * 100 * @param error_code the EGL error code 101 * 102 * @return the error description 103 */ translateEGLErrorString(int error_code)104 static String translateEGLErrorString(int error_code) { 105 switch ( error_code ) { 106 case EGL_NOT_INITIALIZED: 107 return "EGL not initialized"; 108 case EGL_BAD_ACCESS: 109 return "Bad access"; 110 case EGL_BAD_ALLOC: 111 return "Bad allocation"; 112 case EGL_BAD_ATTRIBUTE: 113 return "Bad attribute"; 114 case EGL_BAD_CONFIG: 115 return "Bad config"; 116 case EGL_BAD_CONTEXT: 117 return "Bad EGL context"; 118 case EGL_BAD_CURRENT_SURFACE: 119 return "Bad current EGL surface"; 120 case EGL_BAD_DISPLAY: 121 return "Bad EGL display"; 122 case EGL_BAD_MATCH: 123 return "Bad match"; 124 case EGL_BAD_NATIVE_PIXMAP: 125 return "Bad native pixmap"; 126 case EGL_BAD_NATIVE_WINDOW: 127 return "Bad native window"; 128 case EGL_BAD_PARAMETER: 129 return "Bad parameter"; 130 case EGL_BAD_SURFACE: 131 return "Bad EGL surface"; 132 case EGL_CONTEXT_LOST: 133 return "EGL context lost"; 134 default: 135 return null; 136 } 137 } 138 139 }