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

The following examples show how to use android.opengl.GLES20#glCreateShader() . 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: Shader.java    From smartGL with Apache License 2.0 6 votes vote down vote up
private int loadShader(int shaderType, String script) {

		int shader = GLES20.glCreateShader(shaderType);
		Assert.assertTrue(shader != 0);

		GLES20.glShaderSource(shader, script);
		GLES20.glCompileShader(shader);
		int[] compiled = new int[1];
		GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
		if (compiled[0] == 0) {
			Log.e(TAG, "Could not compile shader " + shaderType + " : " + GLES20.glGetShaderInfoLog(shader));
			GLES20.glDeleteShader(shader);
			shader = 0;
			Assert.assertTrue(false);
		}
		return shader;
	}
 
Example 2
Source File: GLES20TriangleRenderer.java    From codeexamples-android with Eclipse Public License 1.0 6 votes vote down vote up
private int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        GLES20.glShaderSource(shader, source);
        GLES20.glCompileShader(shader);
        int[] compiled = new int[1];
        GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
        if (compiled[0] == 0) {
            Log.e(TAG, "Could not compile shader " + shaderType + ":");
            Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
            GLES20.glDeleteShader(shader);
            shader = 0;
        }
    }
    return shader;
}
 
Example 3
Source File: RoundedTextureView.java    From android-RoundedTextureView with Apache License 2.0 6 votes vote down vote up
private static int loadShader(int shaderType, String source) {
  int shader = GLES20.glCreateShader(shaderType);
  if (shader != 0) {
    GLES20.glShaderSource(shader, source);
    GLES20.glCompileShader(shader);
    int[] compiled = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
    if (compiled[0] == 0) {
      Log.e(TAG, "Could not compile shader " + shaderType + ":");
      Log.e(TAG, GLES20.glGetShaderInfoLog(shader));
      GLES20.glDeleteShader(shader);
      shader = 0;
    }
  }
  return shader;
}
 
Example 4
Source File: ShaderLoader.java    From unity-ads-android with Apache License 2.0 6 votes vote down vote up
public static int load(String code, int type) {
	int shader = GLES20.glCreateShader(type);
	GLES20.glShaderSource(shader, code);
	GLES20.glCompileShader(shader);

	final int[] status = new int[1];
	GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, status, 0);

	if (status[0] != GLES10.GL_TRUE) {
		DeviceLog.error("Error compiling shader: " + GLES20.glGetShaderInfoLog(shader));
		GLES20.glDeleteShader(shader);
		shader = 0;
	}

	return shader;
}
 
Example 5
Source File: GLToolbox.java    From Rocko-Android-Demos with Apache License 2.0 6 votes vote down vote up
public static int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    if (shader != 0) {
        GLES20.glShaderSource(shader, source);
        GLES20.glCompileShader(shader);
        int[] compiled = new int[1];
        GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
        if (compiled[0] == 0) {
            String info = GLES20.glGetShaderInfoLog(shader);
            GLES20.glDeleteShader(shader);
            shader = 0;
            throw new RuntimeException("Could not compile shader " +
                    shaderType + ":" + info);
        }
    }
    return shader;
}
 
Example 6
Source File: Cube.java    From TraceByAmap with MIT License 6 votes vote down vote up
public void create() {
    int vertexLocation = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    int fragmentLocation = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);

    GLES20.glShaderSource(vertexLocation,vertexShader);
    GLES20.glCompileShader(vertexLocation);

    GLES20.glShaderSource(fragmentLocation,fragmentShader);
    GLES20.glCompileShader(fragmentLocation);

    program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program,vertexLocation);
    GLES20.glAttachShader(program,fragmentLocation);
    GLES20.glLinkProgram(program);


    aVertex  = GLES20.glGetAttribLocation(program, "aVertex");
    aMVPMatrix = GLES20.glGetUniformLocation(program,"aMVPMatrix");
    aColor = GLES20.glGetAttribLocation(program,"aColor");

}
 
Example 7
Source File: GlShader.java    From sealrtc-android 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) {
        Log.e(
                TAG,
                "Could not compile shader "
                        + shaderType
                        + ":"
                        + GLES20.glGetShaderInfoLog(shader));
        throw new RuntimeException(GLES20.glGetShaderInfoLog(shader));
    }
    GlUtil.checkNoGLES2Error("compileShader");
    return shader;
}
 
Example 8
Source File: ShaderProgram.java    From Spectaculum with Apache License 2.0 6 votes vote down vote up
public static int loadShader(int type, String shaderCode) {
    if(type != GLES20.GL_VERTEX_SHADER && type != GLES20.GL_FRAGMENT_SHADER) {
        throw new InvalidParameterException("invalid shader type");
    }

    int handle = GLES20.glCreateShader(type);
    if(handle != 0) {
        GLES20.glShaderSource(handle, shaderCode);
        GLES20.glCompileShader(handle);

        int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(handle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);
        if (compileStatus[0] != GLES20.GL_TRUE) {
            Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(handle));
            deleteShader(handle);
            handle = 0;
        }
    } else {
        GLUtils.checkError("glCreateShader");
    }

    return handle;
}
 
Example 9
Source File: ExtractMpegFramesTest.java    From Android-MediaCodec-Examples with Apache License 2.0 5 votes vote down vote up
private int loadShader(int shaderType, String source) {
    int shader = GLES20.glCreateShader(shaderType);
    checkGlError("glCreateShader type=" + shaderType);
    GLES20.glShaderSource(shader, source);
    GLES20.glCompileShader(shader);
    int[] compiled = new int[1];
    GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
    if (compiled[0] == 0) {
        Log.e(TAG, "Could not compile shader " + shaderType + ":");
        Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
        GLES20.glDeleteShader(shader);
        shader = 0;
    }
    return shader;
}
 
Example 10
Source File: GLUtil.java    From Beginner-Level-Android-Studio-Apps with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Helper function to compile a shader.
 *
 * @param shaderType   The shader type.
 * @param shaderSource The shader source code.
 * @return An OpenGL handle to the shader.
 */
public static int compileShader(final int shaderType, final String shaderSource) {
    int shaderHandle = GLES20.glCreateShader(shaderType);

    if (shaderHandle != 0) {
        // Pass in the shader source.
        GLES20.glShaderSource(shaderHandle, shaderSource);

        // Compile the shader.
        GLES20.glCompileShader(shaderHandle);

        // Get the compilation status.
        final int[] compileStatus = new int[1];
        GLES20.glGetShaderiv(shaderHandle, GLES20.GL_COMPILE_STATUS, compileStatus, 0);

        // If the compilation failed, delete the shader.
        if (compileStatus[0] == 0) {
            Log.e(TAG, "Error compiling shader: " + GLES20.glGetShaderInfoLog(shaderHandle));
            GLES20.glDeleteShader(shaderHandle);
            shaderHandle = 0;
        }
    }

    if (shaderHandle == 0) {
        throw new RuntimeException("Error creating shader.");
    }

    return shaderHandle;
}
 
Example 11
Source File: GLDrawer.java    From Building-Android-UIs-with-Custom-Views with MIT License 5 votes vote down vote up
public static int loadShader(int type, String shaderCode){

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

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

        return shader;
    }
 
Example 12
Source File: TextureManager.java    From spydroid-ipcamera with GNU General Public License v3.0 5 votes vote down vote up
private int loadShader(int shaderType, String source) {
	int shader = GLES20.glCreateShader(shaderType);
	checkGlError("glCreateShader type=" + shaderType);
	GLES20.glShaderSource(shader, source);
	GLES20.glCompileShader(shader);
	int[] compiled = new int[1];
	GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
	if (compiled[0] == 0) {
		Log.e(TAG, "Could not compile shader " + shaderType + ":");
		Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
		GLES20.glDeleteShader(shader);
		shader = 0;
	}
	return shader;
}
 
Example 13
Source File: GlUtil.java    From MediaSDK with Apache License 2.0 5 votes vote down vote up
private static void addShader(int type, String source, int program) {
  int shader = GLES20.glCreateShader(type);
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);

  int[] result = new int[] {GLES20.GL_FALSE};
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, result, 0);
  if (result[0] != GLES20.GL_TRUE) {
    throwGlError(GLES20.glGetShaderInfoLog(shader) + ", source: " + source);
  }

  GLES20.glAttachShader(program, shader);
  GLES20.glDeleteShader(shader);
  checkGlError();
}
 
Example 14
Source File: GlUtil.java    From rtmp-rtsp-stream-client-java with Apache License 2.0 5 votes vote down vote up
public static int loadShader(int shaderType, String source) {
  int shader = GLES20.glCreateShader(shaderType);
  checkGlError("glCreateShader type=" + shaderType);
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  int[] compiled = new int[1];
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, compiled, 0);
  if (compiled[0] == 0) {
    Log.e(TAG, "Could not compile shader " + shaderType + ":");
    Log.e(TAG, " " + GLES20.glGetShaderInfoLog(shader));
    GLES20.glDeleteShader(shader);
    shader = 0;
  }
  return shader;
}
 
Example 15
Source File: PointsMatrix.java    From MegviiFacepp-Android-SDK with Apache License 2.0 5 votes vote down vote up
public int loadShader(int type, String shaderCode) {
	// create a vertex shader type (GLES20.GL_VERTEX_SHADER)
	// or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
	int shader = GLES20.glCreateShader(type);

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

	return shader;
}
 
Example 16
Source File: FrameRenderer.java    From DanDanPlayForAndroid with MIT License 5 votes vote down vote up
private void addShader(int type, String source, int program) {
  int[] result = new int[]{
          GLES20.GL_FALSE
  };
  int shader = GLES20.glCreateShader(type);
  GLES20.glShaderSource(shader, source);
  GLES20.glCompileShader(shader);
  GLES20.glGetShaderiv(shader, GLES20.GL_COMPILE_STATUS, result, 0);
  abortUnless(result[0] == GLES20.GL_TRUE,
          GLES20.glGetShaderInfoLog(shader) + ", source: " + source);
  GLES20.glAttachShader(program, shader);
  GLES20.glDeleteShader(shader);

  checkNoGLES2Error();
}
 
Example 17
Source File: GLES20Canvas.java    From Trebuchet with GNU General Public License v3.0 5 votes vote down vote up
private static int loadShader(int type, String shaderCode) {
    // create a vertex shader type (GLES20.GL_VERTEX_SHADER)
    // or a fragment shader type (GLES20.GL_FRAGMENT_SHADER)
    int shader = GLES20.glCreateShader(type);

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

    return shader;
}
 
Example 18
Source File: GLDrawer2D.java    From AudioVideoRecordingSample with Apache License 2.0 5 votes vote down vote up
/**
 * load, compile and link shader
 * @param vss source of vertex shader
 * @param fss source of fragment shader
 * @return
 */
public static int loadShader(final String vss, final String fss) {
	if (DEBUG) Log.v(TAG, "loadShader:");
	int vs = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
	GLES20.glShaderSource(vs, vss);
	GLES20.glCompileShader(vs);
	final int[] compiled = new int[1];
	GLES20.glGetShaderiv(vs, GLES20.GL_COMPILE_STATUS, compiled, 0);
	if (compiled[0] == 0) {
		if (DEBUG) Log.e(TAG, "Failed to compile vertex shader:"
				+ GLES20.glGetShaderInfoLog(vs));
		GLES20.glDeleteShader(vs);
		vs = 0;
	}

	int fs = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
	GLES20.glShaderSource(fs, fss);
	GLES20.glCompileShader(fs);
	GLES20.glGetShaderiv(fs, GLES20.GL_COMPILE_STATUS, compiled, 0);
	if (compiled[0] == 0) {
		if (DEBUG) Log.w(TAG, "Failed to compile fragment shader:"
			+ GLES20.glGetShaderInfoLog(fs));
		GLES20.glDeleteShader(fs);
		fs = 0;
	}

	final int program = GLES20.glCreateProgram();
	GLES20.glAttachShader(program, vs);
	GLES20.glAttachShader(program, fs);
	GLES20.glLinkProgram(program);

	return program;
}
 
Example 19
Source File: CameraGLRendererBase.java    From real_time_circle_detection_android with MIT License 4 votes vote down vote up
private static int loadShader(String vss, String fss) {
    Log.d("CameraGLRendererBase", "loadShader");
    int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vshader, vss);
    GLES20.glCompileShader(vshader);
    int[] status = new int[1];
    GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile vertex shader: "+GLES20.glGetShaderInfoLog(vshader));
        GLES20.glDeleteShader(vshader);
        vshader = 0;
        return 0;
    }

    int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fshader, fss);
    GLES20.glCompileShader(fshader);
    GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not compile fragment shader:"+GLES20.glGetShaderInfoLog(fshader));
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);
        fshader = 0;
        return 0;
    }

    int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vshader);
    GLES20.glAttachShader(program, fshader);
    GLES20.glLinkProgram(program);
    GLES20.glDeleteShader(vshader);
    GLES20.glDeleteShader(fshader);
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e("CameraGLRendererBase", "Could not link shader program: "+GLES20.glGetProgramInfoLog(program));
        program = 0;
        return 0;
    }
    GLES20.glValidateProgram(program);
    GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0);
    if (status[0] == 0)
    {
        Log.e("CameraGLRendererBase", "Shader program validation error: "+GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
        return 0;
    }

    Log.d("CameraGLRendererBase", "Shader program is built OK");

    return program;
}
 
Example 20
Source File: Utils.java    From Paddle-Lite-Demo with Apache License 2.0 4 votes vote down vote up
public static int createShaderProgram(String vss, String fss) {
    int vshader = GLES20.glCreateShader(GLES20.GL_VERTEX_SHADER);
    GLES20.glShaderSource(vshader, vss);
    GLES20.glCompileShader(vshader);
    int[] status = new int[1];
    GLES20.glGetShaderiv(vshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetShaderInfoLog(vshader));
        GLES20.glDeleteShader(vshader);
        vshader = 0;
        return 0;
    }

    int fshader = GLES20.glCreateShader(GLES20.GL_FRAGMENT_SHADER);
    GLES20.glShaderSource(fshader, fss);
    GLES20.glCompileShader(fshader);
    GLES20.glGetShaderiv(fshader, GLES20.GL_COMPILE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetShaderInfoLog(fshader));
        GLES20.glDeleteShader(vshader);
        GLES20.glDeleteShader(fshader);
        fshader = 0;
        return 0;
    }

    int program = GLES20.glCreateProgram();
    GLES20.glAttachShader(program, vshader);
    GLES20.glAttachShader(program, fshader);
    GLES20.glLinkProgram(program);
    GLES20.glDeleteShader(vshader);
    GLES20.glDeleteShader(fshader);
    GLES20.glGetProgramiv(program, GLES20.GL_LINK_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        program = 0;
        return 0;
    }
    GLES20.glValidateProgram(program);
    GLES20.glGetProgramiv(program, GLES20.GL_VALIDATE_STATUS, status, 0);
    if (status[0] == 0) {
        Log.e(TAG, GLES20.glGetProgramInfoLog(program));
        GLES20.glDeleteProgram(program);
        program = 0;
        return 0;
    }

    return program;
}