public final class

GlUtil.Program

extends java.lang.Object

 java.lang.Object

↳androidx.media3.common.util.GlUtil.Program

Overview

Represents a GLSL shader program.

After constructing a program, keep a reference for its lifetime and call GlUtil.Program.delete() (or release the current GL context) when it's no longer needed.

Summary

Constructors
publicProgram(Context context, java.lang.String vertexShaderFilePath, java.lang.String fragmentShaderFilePath)

Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.

publicProgram(java.lang.String vertexShaderGlsl, java.lang.String fragmentShaderGlsl)

Creates a GL shader program from vertex and fragment shader GLSL GLES20 code.

Methods
public voidbindAttributesAndUniforms()

Binds all attributes and uniforms in the program.

public voiddelete()

Deletes the program.

public intgetAttributeArrayLocationAndEnable(java.lang.String attributeName)

Returns the location of an , which has been enabled as a vertex attribute array.

public intgetUniformLocation(java.lang.String uniformName)

Returns the location of a .

public voidsetBufferAttribute(java.lang.String name, float[] values[], int size)

Sets a float buffer type attribute.

public voidsetFloatsUniform(java.lang.String name, float[] value[])

Sets a float array type uniform.

public voidsetFloatUniform(java.lang.String name, float value)

Sets a float type uniform.

public voidsetSamplerTexIdUniform(java.lang.String name, int texId, int unit)

Sets a texture sampler type uniform.

public voiduse()

Uses the program.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Program(Context context, java.lang.String vertexShaderFilePath, java.lang.String fragmentShaderFilePath)

Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.

Parameters:

context: The .
vertexShaderFilePath: The path to a vertex shader program.
fragmentShaderFilePath: The path to a fragment shader program.

public Program(java.lang.String vertexShaderGlsl, java.lang.String fragmentShaderGlsl)

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.

Methods

public void use()

Uses the program.

Call this in the rendering loop to switch between different programs.

public void delete()

Deletes the program. Deleted programs cannot be used again.

public int getAttributeArrayLocationAndEnable(java.lang.String attributeName)

Returns the location of an , which has been enabled as a vertex attribute array.

public int getUniformLocation(java.lang.String uniformName)

Returns the location of a .

public void setBufferAttribute(java.lang.String name, float[] values[], int size)

Sets a float buffer type attribute.

public void setSamplerTexIdUniform(java.lang.String name, int texId, int unit)

Sets a texture sampler type uniform.

public void setFloatUniform(java.lang.String name, float value)

Sets a float type uniform.

public void setFloatsUniform(java.lang.String name, float[] value[])

Sets a float array type uniform.

public void bindAttributesAndUniforms()

Binds all attributes and uniforms in the program.