Java Code Examples for android.opengl.GLES30#glCompileShader()

The following examples show how to use android.opengl.GLES30#glCompileShader() . 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: GLHelper.java    From libcommon with Apache License 2.0 6 votes vote down vote up
/**
  * Compiles the provided shader source.
  *
  * @return A handle to the shader, or 0 on failure.
  */
public static int loadShader(final int shaderType, final String source) {
	int shader = GLES30.glCreateShader(shaderType);
	checkGlError("glCreateShader type=" + shaderType);
	GLES30.glShaderSource(shader, source);
	GLES30.glCompileShader(shader);
	final int[] compiled = new int[1];
	GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);
	if (compiled[0] == 0) {
		Log.e(TAG, "Could not compile shader " + shaderType + ":");
		Log.e(TAG, " " + GLES30.glGetShaderInfoLog(shader));
		GLES30.glDeleteShader(shader);
		shader = 0;
	}
	return shader;
 }
 
Example 2
Source File: Utils.java    From alynx-live-wallpaper with Apache License 2.0 5 votes vote down vote up
static int compileShaderResourceGLES30(
    @NonNull Context context,
    final int shaderType,
    final int shaderRes
) throws RuntimeException {
    final InputStream inputStream = context.getResources().openRawResource(shaderRes);
    final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
    String line;
    final StringBuilder stringBuilder = new StringBuilder();
    try {
        while ((line = bufferedReader.readLine()) != null) {
            stringBuilder.append(line);
            stringBuilder.append('\n');
        }
    } catch (IOException e) {
        e.printStackTrace();
        return 0;
    }
    final String shaderSource = stringBuilder.toString();
    int shader = GLES30.glCreateShader(shaderType);
    if (shader == 0) {
        throw new RuntimeException("Failed to create shader");
    }
    GLES30.glShaderSource(shader, shaderSource);
    GLES30.glCompileShader(shader);
    final int[] status = new int[1];
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        final String log = GLES30.glGetShaderInfoLog(shader);
        GLES30.glDeleteShader(shader);
        throw new RuntimeException(log);
    }
    return shader;
}
 
Example 3
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public static int LoadShader(int type, String shaderSrc) {
    int shader;
    int[] compiled = new int[1];

    // Create the shader object
    shader = GLES30.glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    // Load the shader source
    GLES30.glShaderSource(shader, shaderSrc);

    // Compile the shader
    GLES30.glCompileShader(shader);

    // Check the compile status
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);

    if (compiled[0] == 0) {
        Log.e(TAG, "Erorr!!!!");
        Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
        GLES30.glDeleteShader(shader);
        return 0;
    }

    return shader;
}
 
Example 4
Source File: HelloTriangleRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
private int LoadShader(int type, String shaderSrc) {
    int shader;
    int[] compiled = new int[1];

    // Create the shader object
    shader = GLES30.glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    // Load the shader source
    GLES30.glShaderSource(shader, shaderSrc);

    // Compile the shader
    GLES30.glCompileShader(shader);

    // Check the compile status
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);

    if (compiled[0] == 0) {
        Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
        GLES30.glDeleteShader(shader);
        return 0;
    }

    return shader;
}
 
Example 5
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public static int LoadShader(int type, String shaderSrc) {
    int shader;
    int[] compiled = new int[1];

    // Create the shader object
    shader = GLES30.glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    // Load the shader source
    GLES30.glShaderSource(shader, shaderSrc);

    // Compile the shader
    GLES30.glCompileShader(shader);

    // Check the compile status
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);

    if (compiled[0] == 0) {
        Log.e(TAG, "Erorr!!!!");
        Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
        GLES30.glDeleteShader(shader);
        return 0;
    }

    return shader;
}
 
Example 6
Source File: MyGLRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
/**
 * Utility method for compiling a OpenGL shader.
 *
 * <p><strong>Note:</strong> When developing shaders, use the checkGlError()
 * method to debug shader coding errors.</p>
 *
 * @param type - Vertex or fragment shader type.
 * @param shaderCode - String containing the shader code.
 * @return - Returns an id for the shader.
 */
public static int loadShader(int type, String shaderCode){

    // create a vertex shader type (GLES30.GL_VERTEX_SHADER)
    // or a fragment shader type (GLES30.GL_FRAGMENT_SHADER)
    int shader = GLES30.glCreateShader(type);

    // add the source code to the shader and compile it
    GLES30.glShaderSource(shader, shaderCode);
    GLES30.glCompileShader(shader);

    return shader;
}
 
Example 7
Source File: myRenderer.java    From opengl with Apache License 2.0 5 votes vote down vote up
public static int LoadShader(int type, String shaderSrc) {
    int shader;
    int[] compiled = new int[1];

    // Create the shader object
    shader = GLES30.glCreateShader(type);

    if (shader == 0) {
        return 0;
    }

    // Load the shader source
    GLES30.glShaderSource(shader, shaderSrc);

    // Compile the shader
    GLES30.glCompileShader(shader);

    // Check the compile status
    GLES30.glGetShaderiv(shader, GLES30.GL_COMPILE_STATUS, compiled, 0);

    if (compiled[0] == 0) {
        Log.e(TAG, "Erorr!!!!");
        Log.e(TAG, GLES30.glGetShaderInfoLog(shader));
        GLES30.glDeleteShader(shader);
        return 0;
    }

    return shader;
}