@UnstableApi
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

GlProgram(vertexShaderGlsl: String!, fragmentShaderGlsl: String!)

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

GlProgram(
    context: Context!,
    vertexShaderFilePath: String!,
    fragmentShaderFilePath: String!
)

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

Public functions

Unit

Binds all attributes and uniforms in the program.

Unit

Deletes the program.

Int

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

Int
getUniformLocation(uniformName: String!)

Returns the location of a Uniform.

Unit
setBufferAttribute(name: String!, values: FloatArray!, size: Int)

Sets a float buffer type attribute.

Unit
setExternalTexturesRequireNearestSampling(
    externalTexturesRequireNearestSampling: Boolean
)

Sets whether to sample external textures with GL_NEAREST.

Unit
setFloatUniform(name: String!, value: Float)

Sets a float type uniform.

Unit
setFloatsUniform(name: String!, value: FloatArray!)

Sets a float[] type uniform.

Unit

Sets a float[] type uniform if name is present, no-op otherwise.

Unit
setIntUniform(name: String!, value: Int)

Sets an int type uniform.

Unit
setIntsUniform(name: String!, value: IntArray!)

Sets a int[] type uniform.

Unit
setSamplerTexIdUniform(name: String!, texId: Int, texUnitIndex: Int)

Sets a texture sampler type uniform.

Unit
use()

Uses the program.

Public constructors

GlProgram

GlProgram(vertexShaderGlsl: String!, fragmentShaderGlsl: String!)

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: String!

The vertex shader program.

fragmentShaderGlsl: String!

The fragment shader program.

GlProgram

GlProgram(
    context: Context!,
    vertexShaderFilePath: String!,
    fragmentShaderFilePath: String!
)

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

Parameters
context: Context!

The Context.

vertexShaderFilePath: String!

The path to a vertex shader program.

fragmentShaderFilePath: String!

The path to a fragment shader program.

Throws
java.io.IOException

When failing to read shader files.

Public functions

bindAttributesAndUniforms

fun bindAttributesAndUniforms(): Unit

Binds all attributes and uniforms in the program.

delete

fun delete(): Unit

Deletes the program. Deleted programs cannot be used again.

getAttributeArrayLocationAndEnable

fun getAttributeArrayLocationAndEnable(attributeName: String!): Int

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

getUniformLocation

fun getUniformLocation(uniformName: String!): Int

Returns the location of a Uniform.

setBufferAttribute

fun setBufferAttribute(name: String!, values: FloatArray!, size: Int): Unit

Sets a float buffer type attribute.

setExternalTexturesRequireNearestSampling

fun setExternalTexturesRequireNearestSampling(
    externalTexturesRequireNearestSampling: Boolean
): Unit

Sets whether to sample external textures with GL_NEAREST.

The default value is false.

setFloatUniform

fun setFloatUniform(name: String!, value: Float): Unit

Sets a float type uniform.

setFloatsUniform

fun setFloatsUniform(name: String!, value: FloatArray!): Unit

Sets a float[] type uniform.

setFloatsUniformIfPresent

fun setFloatsUniformIfPresent(name: String!, value: FloatArray!): Unit

Sets a float[] type uniform if name is present, no-op otherwise.

setIntUniform

fun setIntUniform(name: String!, value: Int): Unit

Sets an int type uniform.

setIntsUniform

fun setIntsUniform(name: String!, value: IntArray!): Unit

Sets a int[] type uniform.

setSamplerTexIdUniform

fun setSamplerTexIdUniform(name: String!, texId: Int, texUnitIndex: Int): Unit

Sets a texture sampler type uniform.

Parameters
name: String!

The uniform's name.

texId: Int

The texture identifier.

texUnitIndex: Int

The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program.

use

fun use(): Unit

Uses the program.

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