GlProgram
@UnstableApi
public final class GlProgram
Represents a GLSL shader program.
After constructing a program, keep a reference for its lifetime and call delete (or release the current GL context) when it's no longer needed.
Summary
Public constructors |
|---|
|
Creates a GL shader program from vertex and fragment shader GLSL GLES20 code. |
|
Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code. |
|
Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code. |
Public methods |
|
|---|---|
void |
Binds all attributes and uniforms in the program. |
void |
delete()Deletes the program. |
int |
getAttributeArrayLocationAndEnable(String attributeName)Returns the location of an |
int |
getUniformLocation(String uniformName)Returns the location of a |
void |
setBufferAttribute(String name, float[] values, int size)Sets a float buffer type attribute. |
void |
setExternalTexturesRequireNearestSampling(Sets whether to sample external textures with GL_NEAREST. |
void |
setFloatUniform(String name, float value)Sets a |
void |
setFloatsUniform(String name, float[] value)Sets a |
void |
setFloatsUniformIfPresent(String name, float[] value)Sets a |
void |
setIntUniform(String name, int value)Sets an |
void |
setIntsUniform(String name, int[] value)Sets a |
void |
setSamplerTexIdUniform(String name, int texId, int texUnitIndex)Sets a texture sampler type uniform. |
void |
setSamplerTexIdUniform(Sets a texture sampler type uniform. |
void |
use()Uses the program. |
Public constructors
GlProgram
public GlProgram(String vertexShaderGlsl, 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.
GlProgram
public GlProgram(
Context context,
String vertexShaderFilePath,
String fragmentShaderFilePath
)
Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.
| Parameters | |
|---|---|
Context context |
The |
String vertexShaderFilePath |
The path to a vertex shader program. |
String fragmentShaderFilePath |
The path to a fragment shader program. |
| Throws | |
|---|---|
java.io.IOException |
When failing to read shader files. |
GlProgram
public GlProgram(
Context context,
int vertexShaderResId,
int fragmentShaderResId
)
Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code.
| Parameters | |
|---|---|
Context context |
The |
int vertexShaderResId |
The resource ID of a vertex shader program. |
int fragmentShaderResId |
The resource ID of a fragment shader program. |
| Throws | |
|---|---|
java.io.IOException |
When failing to read shader files. |
Public methods
bindAttributesAndUniforms
public void bindAttributesAndUniforms()
Binds all attributes and uniforms in the program.
getAttributeArrayLocationAndEnable
public int getAttributeArrayLocationAndEnable(String attributeName)
Returns the location of an Attribute, which has been enabled as a vertex attribute array.
getUniformLocation
public int getUniformLocation(String uniformName)
Returns the location of a Uniform.
setBufferAttribute
public void setBufferAttribute(String name, float[] values, int size)
Sets a float buffer type attribute.
setExternalTexturesRequireNearestSampling
public void setExternalTexturesRequireNearestSampling(
boolean externalTexturesRequireNearestSampling
)
Sets whether to sample external textures with GL_NEAREST.
The default value is false.
setFloatsUniform
public void setFloatsUniform(String name, float[] value)
Sets a float[] type uniform.
setFloatsUniformIfPresent
public void setFloatsUniformIfPresent(String name, float[] value)
Sets a float[] type uniform if name is present, no-op otherwise.
setSamplerTexIdUniform
public void setSamplerTexIdUniform(String name, int texId, int texUnitIndex)
Sets a texture sampler type uniform.
| Parameters | |
|---|---|
String name |
The uniform's name. |
int texId |
The texture identifier. |
int texUnitIndex |
The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program. |
setSamplerTexIdUniform
public void setSamplerTexIdUniform(
String name,
int texId,
int texUnitIndex,
@C.TextureMinFilter int texMinFilter
)
Sets a texture sampler type uniform.
| Parameters | |
|---|---|
String name |
The uniform's name. |
int texId |
The texture identifier. |
int texUnitIndex |
The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program. |
@C.TextureMinFilter int texMinFilter |
The |
use
public void use()
Uses the program.
Call this in the rendering loop to switch between different programs.