Java Code Examples for android.opengl.GLES20#glGetError()

The following examples show how to use android.opengl.GLES20#glGetError() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GlShader.java    From VideoCRE with MIT License 6 votes vote down vote up
private static int compileShader(int shaderType, String source) {
  final int shader = GLES20.glCreateShader(shaderType);
  if (shader == 0) {
    throw new RuntimeException("glCreateShader() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compileStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
  if (compileStatus[0] != GLES20.GL_TRUE) {
    Logging.e(
        TAG, "Could not compile shader " + shaderType + ":" + GLES20.glGetShaderInfoLog(shader));
    throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
  }
  GlUtil.checkNoGLES2Error("compileShader");
  return shader;
}
 
Example 2
Source File: GLES20Canvas.java    From LB-Launcher with Apache License 2.0 6 votes vote down vote up
private int assembleProgram(int vertexShader, int fragmentShader, ShaderParameter[] params) {
    int program = GLES20.glCreateProgram();
    checkError();
    if (program == 0) {
        throw new RuntimeException("Cannot create GL program: " + GLES20.glGetError());
    }
    GLES20.glAttachShader(program, vertexShader);
    checkError();
    GLES20.glAttachShader(program, fragmentShader);
    checkError();
    GLES20.glLinkProgram(program);
    checkError();
    int[] mLinkStatus = mTempIntArray;
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, mLinkStatus, 0);
    if (mLinkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    for (int i = 0; i < params.length; i++) {
        params[i].loadHandle(program);
    }
    return program;
}
 
Example 3
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 6 votes vote down vote up
private int assembleProgram(int vertexShader, int fragmentShader, ShaderParameter[] params) {
    int program = GLES20.glCreateProgram();
    checkError();
    if (program == 0) {
        throw new RuntimeException("Cannot create GL program: " + GLES20.glGetError());
    }
    GLES20.glAttachShader(program, vertexShader);
    checkError();
    GLES20.glAttachShader(program, fragmentShader);
    checkError();
    GLES20.glLinkProgram(program);
    checkError();
    int[] mLinkStatus = mTempIntArray;
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, mLinkStatus, 0);
    if (mLinkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: ");
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
    }
    for (int i = 0; i < params.length; i++) {
        params[i].loadHandle(program);
    }
    return program;
}
 
Example 4
Source File: SphericalViewRenderer.java    From DeviceConnect-Android with MIT License 5 votes vote down vote up
/**
 * GL error judgment method for debugging
 * @param glOperation Message output character string
 */
private void checkGlError(final String glOperation) {
    int error;
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        mLogger.warning(glOperation + ": glError " + error);
        throw new RuntimeException(glOperation + ": glError " + error);
    }
}
 
Example 5
Source File: ShaderUtil.java    From justaline-android with Apache License 2.0 5 votes vote down vote up
/**
 * Checks if we've had an error inside of OpenGL ES, and if so what that error is.
 *
 * @param label Label to report in case of error.
 * @throws RuntimeException If an OpenGL error is detected.
 */
static void checkGLError(String tag, String label) {
    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR) {
        Log.e(tag, label + ": glError " + error);
        throw new RuntimeException(label + ": glError " + error);
    }
}
 
Example 6
Source File: DistortionRenderer.java    From Cardboard with Apache License 2.0 5 votes vote down vote up
private void checkGlError(String op) {
	int error;
	if ((error = GLES20.glGetError()) != 0) {
		Log.e("DistortionRenderer", op + ": glError " + error);
		throw new RuntimeException(op + ": glError " + error);
	}
}
 
Example 7
Source File: GlUtil.java    From PLDroidMediaStreaming with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see if a GLES error has been raised.
 */
public static void checkGlError(String op) {
    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR) {
        String msg = op + ": glError 0x" + Integer.toHexString(error);
        Log.e(TAG, msg);
        throw new RuntimeException(msg);
    }
}
 
Example 8
Source File: GlShader.java    From VideoCRE with MIT License 5 votes vote down vote up
public GlShader(String vertexSource, String fragmentSource) {
  final int vertexShader = compileShader(GLES20.GL_VERTEX_SHADER, vertexSource);
  final int fragmentShader = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
  program = GLES20.glCreateProgram();
  if (program == 0) {
    throw new RuntimeException("glCreateProgram() failed. GLES20 error: " + GLES20.glGetError());
  }
  GLES20.glAttachShader(program, vertexShader);
  GLES20.glAttachShader(program, fragmentShader);
  GLES20.glLinkProgram(program);
  int[] linkStatus = new int[] {GLES20.GL_FALSE};
  GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
  if (linkStatus[0] != GLES20.GL_TRUE) {
    Logging.e(TAG, "Could not link program: " + GLES20.glGetProgramInfoLog(program));
    throw new RuntimeException(GLES20.glGetProgramInfoLog(program));
  }
  // According to the documentation of glLinkProgram():
  // "After the link operation, applications are free to modify attached shader objects, compile
  // attached shader objects, detach shader objects, delete shader objects, and attach additional
  // shader objects. None of these operations affects the information log or the program that is
  // part of the program object."
  // But in practice, detaching shaders from the program seems to break some devices. Deleting the
  // shaders are fine however - it will delete them when they are no longer attached to a program.
  GLES20.glDeleteShader(vertexShader);
  GLES20.glDeleteShader(fragmentShader);
  GlUtil.checkNoGLES2Error("Creating GlShader");
}
 
Example 9
Source File: EGLSurfaceTexture.java    From TelePlus-Android with GNU General Public License v2.0 5 votes vote down vote up
private static void generateTextureIds(int[] textureIdHolder) {
  GLES20.glGenTextures(/* n= */ 1, textureIdHolder, /* offset= */ 0);
  int errorCode = GLES20.glGetError();
  if (errorCode != GLES20.GL_NO_ERROR) {
    throw new GlException("glGenTextures failed. Error: " + Integer.toHexString(errorCode));
  }
}
 
Example 10
Source File: GLUtils.java    From Spectaculum with Apache License 2.0 5 votes vote down vote up
private static void checkError(String operation, boolean throwException) {
    int errorCount = 0;
    int error;
    String msg = null;

    while((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        msg = "GL ERROR " + String.format("0x%X", error) + " @ " + operation;
        Log.e(TAG, msg);
        errorCount++;
    }

    if(throwException && errorCount > 0) {
        throw new RuntimeException(msg);
    }
}
 
Example 11
Source File: ShaderUtils.java    From Pano360 with MIT License 5 votes vote down vote up
public static void checkGlError(String label) {
    int error;
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        Log.e(TAG, label + ": glError " + error);
        throw new RuntimeException(label + ": glError " + error);
    }
}
 
Example 12
Source File: GLUtil.java    From VideoRecorder with Apache License 2.0 5 votes vote down vote up
public static void checkGlError(String op) {
    int error = GLES20.glGetError();
    if (error != GLES20.GL_NO_ERROR) {
        String msg = op + ": glError 0x" + Integer.toHexString(error);
        LogUtil.logd(msg);
        throw new RuntimeException(msg);
    }
}
 
Example 13
Source File: JPGFileEndpoint.java    From UltimateAndroid with Apache License 2.0 5 votes vote down vote up
private void initFBO() {
	if(frameBuffer != null) {
		GLES20.glDeleteFramebuffers(1, frameBuffer, 0);
		frameBuffer = null;
	}
	if(texture_out != null) {
		GLES20.glDeleteTextures(1, texture_out, 0);
		texture_out = null;
	}
	if(depthRenderBuffer != null) {
		GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0);
		depthRenderBuffer = null;
	}
	frameBuffer = new int[1];
	texture_out = new int[1];
	depthRenderBuffer = new int[1];
	GLES20.glGenFramebuffers(1, frameBuffer, 0);
	GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
	GLES20.glGenTextures(1, texture_out, 0);
	
	GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
	
	GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
	GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
	GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
	GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
	GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
	
	GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
	GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
	
	int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
	if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
		throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
	}
}
 
Example 14
Source File: AtkinsonShader.java    From retroboy with MIT License 5 votes vote down vote up
private void checkGlError(String op) {
    int error;
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        Log.e(TAG, op + ": glError " + error);
        throw new RuntimeException(op + ": glError " + error);
    }
}
 
Example 15
Source File: GlShader.java    From sealrtc-android with MIT License 5 votes vote down vote up
public GlShader(String vertexSource, String fragmentSource) {
    final int vertexShader = compileShader(GLES20.GL_VERTEX_SHADER, vertexSource);
    final int fragmentShader = compileShader(GLES20.GL_FRAGMENT_SHADER, fragmentSource);
    program = GLES20.glCreateProgram();
    if (program == 0) {
        throw new RuntimeException(
                "glCreateProgram() failed. GLES20 error: " + GLES20.glGetError());
    }
    GLES20.glAttachShader(program, vertexShader);
    GLES20.glAttachShader(program, fragmentShader);
    GLES20.glLinkProgram(program);
    int[] linkStatus = new int[] {GLES20.GL_FALSE};
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, linkStatus, 0);
    if (linkStatus[0] != GLES20.GL_TRUE) {
        Log.e(TAG, "Could not link program: " + GLES20.glGetProgramInfoLog(program));
        throw new RuntimeException(GLES20.glGetProgramInfoLog(program));
    }
    // According to the documentation of glLinkProgram():
    // "After the link operation, applications are free to modify attached shader objects,
    // compile
    // attached shader objects, detach shader objects, delete shader objects, and attach
    // additional
    // shader objects. None of these operations affects the information log or the program that
    // is
    // part of the program object."
    // But in practice, detaching shaders from the program seems to break some devices. Deleting
    // the
    // shaders are fine however - it will delete them when they are no longer attached to a
    // program.
    GLES20.glDeleteShader(vertexShader);
    GLES20.glDeleteShader(fragmentShader);
    GlUtil.checkNoGLES2Error("Creating GlShader");
}
 
Example 16
Source File: GLState.java    From tilt-game-android with MIT License 4 votes vote down vote up
public void checkError() throws GLException {
	final int error = GLES20.glGetError();
	if (error != GLES20.GL_NO_ERROR) {
		throw new GLException(error);
	}
}
 
Example 17
Source File: GLUtil.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 4 votes vote down vote up
public static void glCheck(String op) {
    int error;
    while ((error = GLES20.glGetError()) != GLES20.GL_NO_ERROR) {
        Log.e(TAG, op + ": glError " + android.opengl.GLUtils.getEGLErrorString(error));
    }
}
 
Example 18
Source File: Utils.java    From Telegram with GNU General Public License v2.0 4 votes vote down vote up
public static void HasGLError() {
    int error = GLES20.glGetError();
    if (error != 0) {
        Log.d("Paint", GLUtils.getEGLErrorString(error));
    }
}
 
Example 19
Source File: BitmapOutput.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
private void initFBO() {
		if(frameBuffer != null) {
			GLES20.glDeleteFramebuffers(1, frameBuffer, 0);
			frameBuffer = null;
		}
		if(texture_out != null) {
			GLES20.glDeleteTextures(1, texture_out, 0);
			texture_out = null;
		}
		if(depthRenderBuffer != null) {
			GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0);
			depthRenderBuffer = null;
		}
		frameBuffer = new int[1];
		texture_out = new int[1];
		depthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, frameBuffer, 0);
		GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
		GLES20.glGenTextures(1, texture_out, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	} 
Example 20
Source File: GLTextureOutputRenderer.java    From UltimateAndroid with Apache License 2.0 votes vote down vote up
private void initFBO() {
		if(frameBuffer != null) {
			GLES20.glDeleteFramebuffers(1, frameBuffer, 0);
			frameBuffer = null;
		}
		if(texture_out != null) {
			GLES20.glDeleteTextures(1, texture_out, 0);
			texture_out = null;
		}
		if(depthRenderBuffer != null) {
			GLES20.glDeleteRenderbuffers(1, depthRenderBuffer, 0);
			depthRenderBuffer = null;
		}
		frameBuffer = new int[1];
		texture_out = new int[1];
		depthRenderBuffer = new int[1];
		GLES20.glGenFramebuffers(1, frameBuffer, 0);
		GLES20.glGenRenderbuffers(1, depthRenderBuffer, 0);
		GLES20.glGenTextures(1, texture_out, 0);
		
		GLES20.glBindFramebuffer(GLES20.GL_FRAMEBUFFER, frameBuffer[0]);
		
		GLES20.glActiveTexture(GLES20.GL_TEXTURE0);
		GLES20.glBindTexture(GLES20.GL_TEXTURE_2D, texture_out[0]);
		GLES20.glTexImage2D(GLES20.GL_TEXTURE_2D, 0, GLES20.GL_RGBA, getWidth(), getHeight(), 0, GLES20.GL_RGBA, GLES20.GL_UNSIGNED_BYTE, null);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_S, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_WRAP_T, GLES20.GL_CLAMP_TO_EDGE);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MAG_FILTER, GLES20.GL_LINEAR);
		GLES20.glTexParameteri(GLES20.GL_TEXTURE_2D, GLES20.GL_TEXTURE_MIN_FILTER, GLES20.GL_LINEAR);
		GLES20.glFramebufferTexture2D(GLES20.GL_FRAMEBUFFER, GLES20.GL_COLOR_ATTACHMENT0, GLES20.GL_TEXTURE_2D, texture_out[0], 0);
		
		GLES20.glBindRenderbuffer(GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		GLES20.glRenderbufferStorage(GLES20.GL_RENDERBUFFER, GLES20.GL_DEPTH_COMPONENT16, getWidth(), getHeight());
		GLES20.glFramebufferRenderbuffer(GLES20.GL_FRAMEBUFFER, GLES20.GL_DEPTH_ATTACHMENT, GLES20.GL_RENDERBUFFER, depthRenderBuffer[0]);
		
		int status = GLES20.glCheckFramebufferStatus(GLES20.GL_FRAMEBUFFER);
		if (status != GLES20.GL_FRAMEBUFFER_COMPLETE) {
			throw new RuntimeException(this+": Failed to set up render buffer with status "+status+" and error "+GLES20.glGetError());
		}
	}