Class GlProgram
- java.lang.Object
-
- com.google.android.exoplayer2.util.GlProgram
-
-
Constructor Summary
Constructors Constructor Description GlProgram(Context context, String vertexShaderFilePath, String fragmentShaderFilePath)Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.GlProgram(String vertexShaderGlsl, String fragmentShaderGlsl)Creates a GL shader program from vertex and fragment shader GLSL GLES20 code.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidbindAttributesAndUniforms()Binds all attributes and uniforms in the program.voiddelete()Deletes the program.intgetAttributeArrayLocationAndEnable(String attributeName)Returns the location of anGlProgram.Attribute, which has been enabled as a vertex attribute array.intgetUniformLocation(String uniformName)Returns the location of aGlProgram.Uniform.static StringloadAsset(Context context, String assetPath)Loads a file from the assets folder.voidsetBufferAttribute(String name, float[] values, int size)Sets a float buffer type attribute.voidsetFloatsUniform(String name, float[] value)Sets afloat[]type uniform.voidsetFloatUniform(String name, float value)Sets afloattype uniform.voidsetIntUniform(String name, int value)Sets aninttype uniform.voidsetSamplerTexIdUniform(String name, int texId, int texUnitIndex)Sets a texture sampler type uniform.voiduse()Uses the program.
-
-
-
Constructor Detail
-
GlProgram
public GlProgram(Context context, String vertexShaderFilePath, String fragmentShaderFilePath) throws IOException, GlUtil.GlException
Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.- Parameters:
context- TheContext.vertexShaderFilePath- The path to a vertex shader program.fragmentShaderFilePath- The path to a fragment shader program.- Throws:
IOException- When failing to read shader files.GlUtil.GlException
-
GlProgram
public GlProgram(String vertexShaderGlsl, String fragmentShaderGlsl) throws GlUtil.GlException
Creates a GL shader program from vertex and fragment shader GLSL GLES20 code.This involves slow steps, like compiling, linking, and switching the GL program, so do not call this in fast rendering loops.
- Parameters:
vertexShaderGlsl- The vertex shader program.fragmentShaderGlsl- The fragment shader program.- Throws:
GlUtil.GlException
-
-
Method Detail
-
loadAsset
public static String loadAsset(Context context, String assetPath) throws IOException
Loads a file from the assets folder.- Parameters:
context- TheContext.assetPath- The path to the file to load, from the assets folder.- Returns:
- The content of the file to load.
- Throws:
IOException- If the file couldn't be read.
-
getUniformLocation
public int getUniformLocation(String uniformName)
Returns the location of aGlProgram.Uniform.
-
use
public void use() throws GlUtil.GlExceptionUses the program.Call this in the rendering loop to switch between different programs.
- Throws:
GlUtil.GlException
-
delete
public void delete() throws GlUtil.GlExceptionDeletes the program. Deleted programs cannot be used again.- Throws:
GlUtil.GlException
-
getAttributeArrayLocationAndEnable
public int getAttributeArrayLocationAndEnable(String attributeName) throws GlUtil.GlException
Returns the location of anGlProgram.Attribute, which has been enabled as a vertex attribute array.- Throws:
GlUtil.GlException
-
setBufferAttribute
public void setBufferAttribute(String name, float[] values, int size)
Sets a float buffer type attribute.
-
setSamplerTexIdUniform
public void setSamplerTexIdUniform(String name, int texId, int texUnitIndex)
Sets a texture sampler type uniform.- Parameters:
name- The uniform's name.texId- The texture identifier.texUnitIndex- The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program.
-
setIntUniform
public void setIntUniform(String name, int value)
Sets aninttype uniform.
-
setFloatUniform
public void setFloatUniform(String name, float value)
Sets afloattype uniform.
-
setFloatsUniform
public void setFloatsUniform(String name, float[] value)
Sets afloat[]type uniform.
-
bindAttributesAndUniforms
public void bindAttributesAndUniforms() throws GlUtil.GlExceptionBinds all attributes and uniforms in the program.- Throws:
GlUtil.GlException
-
-