# GlProgram

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/GlProgram.java+class:androidx.media3.common.util.GlProgram)

*** ** * ** ***


```
@UnstableApi
class GlProgram
```

<br />

*** ** * ** ***

Represents a GLSL shader program.

After constructing a program, keep a reference for its lifetime and call `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#delete()` (or release the current GL context) when it's no longer needed.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#GlProgram(java.lang.String,java.lang.String)(vertexShaderGlsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, fragmentShaderGlsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Creates a GL shader program from vertex and fragment shader GLSL GLES20 code. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#GlProgram(android.content.Context,java.lang.String,java.lang.String)( context: https://developer.android.com/reference/android/content/Context.html!, vertexShaderFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, fragmentShaderFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html! )` Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#GlProgram(android.content.Context,int,int)( context: https://developer.android.com/reference/android/content/Context.html!, vertexShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, fragmentShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Compiles a GL shader program from vertex and fragment shader GLSL GLES20 code. |
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#GlProgram(android.content.Context,int,int,int...)( context: https://developer.android.com/reference/android/content/Context.html!, vertexShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, firstFragmentShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, additionalFragmentShaderResIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>! )` Compiles a GL shader program from a vertex shader resource and one or more fragment shader resource IDs. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#bindAttributesAndUniforms()()` Binds all attributes and uniforms in the program. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#delete()()` Deletes the program. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#getAttributeArrayLocationAndEnable(java.lang.String)(attributeName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns the location of an `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram.Attribute`, which has been enabled as a vertex attribute array. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#getUniformLocation(java.lang.String)(uniformName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!)` Returns the location of a `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram.Uniform`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setBufferAttribute(java.lang.String,float[],int)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, values: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>!, size: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets a float buffer type attribute. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setExternalTexturesRequireNearestSampling(boolean)( externalTexturesRequireNearestSampling: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html )` Sets whether to sample external textures with GL_NEAREST. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setFloatUniform(java.lang.String,float)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html)` Sets a `float` type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setFloatsUniform(java.lang.String,float[])(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>!)` Sets a `float[]` type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setFloatsUniformIfPresent(java.lang.String,float[])(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-float/index.html>!)` Sets a `float[]` type uniform if `name` is present, no-op otherwise. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setIntUniform(java.lang.String,int)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets an `int` type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setIntsUniform(java.lang.String,int[])(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, value: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!)` Sets a `int[]` type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setSamplerTexIdUniform(java.lang.String,int,int)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, texId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, texUnitIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Sets a texture sampler type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#setSamplerTexIdUniform(java.lang.String,int,int,int)( name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!, texId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, texUnitIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, @https://developer.android.com/reference/kotlin/androidx/media3/common/C.TextureMinFilter texMinFilter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Sets a texture sampler type uniform. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram#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: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The vertex shader program. |
| `fragmentShaderGlsl: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | 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: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `vertexShaderFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The path to a vertex shader program. |
| `fragmentShaderFilePath: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The path to a fragment shader program. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | When failing to read shader files. |

### GlProgram

```
GlProgram(
    context: Context!,
    vertexShaderResId: Int,
    fragmentShaderResId: Int
)
```

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

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `vertexShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The resource ID of a vertex shader program. |
| `fragmentShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The resource ID of a fragment shader program. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | When failing to read shader files. |

### GlProgram

```
GlProgram(
    context: Context!,
    vertexShaderResId: Int,
    firstFragmentShaderResId: Int,
    additionalFragmentShaderResIds: IntArray<Int>!
)
```

Compiles a GL shader program from a vertex shader resource and one or more fragment shader resource IDs.

When multiple fragment shader resource IDs are passed, their sources are concatenated in order.

| Parameters |
|---|---|
| `context: https://developer.android.com/reference/android/content/Context.html!` | The `https://developer.android.com/reference/android/content/Context.html`. |
| `vertexShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The resource ID of a vertex shader program. |
| `firstFragmentShaderResId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The resource ID of the primary fragment shader program. |
| `additionalFragmentShaderResIds: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int-array/index.html<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html>!` | Optional additional resource IDs of fragment shader programs. |

| Throws |
|---|---|
| `https://developer.android.com/reference/java/io/IOException.html` | When failing to read shader files. |

## Public functions

### bindAttributesAndUniforms

```
fun bindAttributesAndUniforms(): Unit
```

Binds all attributes and uniforms in the program.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### delete

```
fun delete(): Unit
```

Deletes the program. Deleted programs cannot be used again.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### getAttributeArrayLocationAndEnable

```
fun getAttributeArrayLocationAndEnable(attributeName: String!): Int
```

Returns the location of an `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram.Attribute`, which has been enabled as a vertex attribute array.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |

### getUniformLocation

```
fun getUniformLocation(uniformName: String!): Int
```

Returns the location of a `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlProgram.Uniform`.

### setBufferAttribute

```
fun setBufferAttribute(name: String!, values: FloatArray<Float>!, 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<Float>!): Unit
```

Sets a `float[]` type uniform.

### setFloatsUniformIfPresent

```
fun setFloatsUniformIfPresent(name: String!, value: FloatArray<Float>!): 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<Int>!): Unit
```

Sets a `int[]` type uniform.

### setSamplerTexIdUniform

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

Sets a texture sampler type uniform.

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The uniform's name. |
| `texId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The texture identifier. |
| `texUnitIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program. |

### setSamplerTexIdUniform

```
fun setSamplerTexIdUniform(
    name: String!,
    texId: Int,
    texUnitIndex: Int,
    @C.TextureMinFilter texMinFilter: Int
): Unit
```

Sets a texture sampler type uniform.

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html!` | The uniform's name. |
| `texId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The texture identifier. |
| `texUnitIndex: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The texture unit index. Use a different index (0, 1, 2, ...) for each texture sampler in the program. |
| `@https://developer.android.com/reference/kotlin/androidx/media3/common/C.TextureMinFilter texMinFilter: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/C.TextureMinFilter`. |

### use

```
fun use(): Unit
```

Uses the program.

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

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil.GlException` |   |