# BaseGlShaderProgram

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

*** ** * ** ***


```
@UnstableApi
abstract class BaseGlShaderProgram : GlShaderProgram
```

<br />

*** ** * ** ***

A base implementation of `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram`.

`BaseGlShaderProgram` manages an output texture pool, whose size is configurable on construction. An implementation should manage a GLSL shader program for processing frames. Override `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)` to customize drawing. Implementations generally copy input pixels into an output frame, with changes to pixels specific to the implementation.

`BaseShaderProgram` implementations can produce any number of output frames per input frame with the same presentation timestamp.

All methods in this class must be called on the thread that owns the OpenGL context.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#BaseGlShaderProgram(boolean,int)( useHighPrecisionColorComponents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, texturePoolCapacity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Creates a `BaseGlShaderProgram` instance. |

| ### Public functions |
|---|---|
| `abstract https://developer.android.com/reference/kotlin/androidx/media3/common/util/Size!` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#configure(int,int)(inputWidth: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, inputHeight: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html)` Configures the instance based on the input dimensions. |
| `abstract https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)(inputTexId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html)` Draws one frame. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#flush()()` Flushes the `GlShaderProgram`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#queueInputFrame(androidx.media3.common.GlObjectsProvider,androidx.media3.common.GlTextureInfo,long)( glObjectsProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider!, inputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!, presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html )` Processes an input frame if possible. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `@https://developer.android.com/reference/kotlin/androidx/annotation/CallSuper https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#release()()` Releases all resources. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#releaseOutputFrame(androidx.media3.common.GlTextureInfo)(outputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!)` Notifies the `GlShaderProgram` that the frame on the given output texture is no longer used and can be overwritten. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#setErrorListener(java.util.concurrent.Executor,androidx.media3.effect.GlShaderProgram.ErrorListener)( errorListenerExecutor: https://developer.android.com/reference/java/util/concurrent/Executor.html!, errorListener: https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener! )` Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#shouldClearTextureBuffer()()` Returns `true` if the texture buffer should be cleared before calling `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)` or `false` if it should retain the content of the last drawn frame. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#signalEndOfCurrentInputStream()()` Notifies the `GlShaderProgram` that no further input frames belonging to the current input stream will be queued. |

| ### Protected functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#onError(java.lang.Exception)(e: https://developer.android.com/reference/java/lang/Exception.html!)` |

| ### Protected properties |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener!` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#inputListener()` |
| `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener!` | `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#outputListener()` |

## Public constructors

### BaseGlShaderProgram

```
BaseGlShaderProgram(
    useHighPrecisionColorComponents: Boolean,
    texturePoolCapacity: Int
)
```

Creates a `BaseGlShaderProgram` instance.

| Parameters |
|---|---|
| `useHighPrecisionColorComponents: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | If `false`, uses colors with 8-bit unsigned bytes. If `true`, use 16-bit (half-precision) floating-point. |
| `texturePoolCapacity: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The capacity of the texture pool. For example, if implementing a texture cache, the size should be the number of textures to cache. |

## Public functions

### configure

```
abstract fun configure(inputWidth: Int, inputHeight: Int): Size!
```

Configures the instance based on the input dimensions.

This method must be called before `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)` the first frame and before drawing subsequent frames with different input dimensions.

| Parameters |
|---|---|
| `inputWidth: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The input width, in pixels. |
| `inputHeight: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | The input height, in pixels. |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/util/Size!` | The output width and height of frames processed through `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while configuring. |

### drawFrame

```
abstract fun drawFrame(inputTexId: Int, presentationTimeUs: Long): Unit
```

Draws one frame.

This method may only be called after the shader program has been `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#configure(int,int)`. The caller is responsible for focussing the correct render target before calling this method.

A minimal implementation should tell OpenGL to use its shader program, bind the shader program's vertex attributes and uniforms, and issue a drawing command.

| Parameters |
|---|---|
| `inputTexId: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Identifier of a 2D OpenGL texture containing the input frame. |
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp of the current frame, in microseconds. |

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while processing or drawing the frame. |

### flush

```
@CallSuper
fun flush(): Unit
```

Flushes the `GlShaderProgram`.

The `GlShaderProgram` should reclaim the ownership of its allocated textures, `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onFlush()` its `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener` about the flush event, and `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onReadyToAcceptInputFrame()` if necessary.

The implementation must not `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.OutputListener#onOutputFrameAvailable(androidx.media3.common.GlTextureInfo,long)` until after this method returns.

### queueInputFrame

```
fun queueInputFrame(
    glObjectsProvider: GlObjectsProvider!,
    inputTexture: GlTextureInfo!,
    presentationTimeUs: Long
): Unit
```

Processes an input frame if possible.

The `GlShaderProgram` owns the accepted frame until it calls `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onInputFrameProcessed(androidx.media3.common.GlTextureInfo)`. The caller should not overwrite or release the texture before the `GlShaderProgram` has finished processing it.

This method must only be called when the `GlShaderProgram` can `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.InputListener#onReadyToAcceptInputFrame()`.

| Parameters |
|---|---|
| `glObjectsProvider: https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider!` | The `https://developer.android.com/reference/kotlin/androidx/media3/common/GlObjectsProvider` for using EGL and GLES. |
| `inputTexture: https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo!` | A `https://developer.android.com/reference/kotlin/androidx/media3/common/GlTextureInfo` describing the texture containing the input frame. |
| `presentationTimeUs: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-long/index.html` | The presentation timestamp of the input frame, in microseconds. |

### release

```
@CallSuper
fun release(): Unit
```

Releases all resources.

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/media3/common/VideoFrameProcessingException` | If an error occurs while releasing resources. |

### releaseOutputFrame

```
fun releaseOutputFrame(outputTexture: GlTextureInfo!): Unit
```

Notifies the `GlShaderProgram` that the frame on the given output texture is no longer used and can be overwritten.

### setErrorListener

```
fun setErrorListener(
    errorListenerExecutor: Executor!,
    errorListener: GlShaderProgram.ErrorListener!
): Unit
```

Sets the `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener`.

The `https://developer.android.com/reference/kotlin/androidx/media3/effect/GlShaderProgram.ErrorListener` is invoked on the provided `https://developer.android.com/reference/java/util/concurrent/Executor.html`.

### shouldClearTextureBuffer

```
fun shouldClearTextureBuffer(): Boolean
```

Returns `true` if the texture buffer should be cleared before calling `https://developer.android.com/reference/kotlin/androidx/media3/effect/BaseGlShaderProgram#drawFrame(int,long)` or `false` if it should retain the content of the last drawn frame.

When returning `false`, the shader program must clear the texture before first drawing to it, because textures are not zero-initialized when created. This can be done by calling `https://developer.android.com/reference/kotlin/androidx/media3/common/util/GlUtil#clearFocusedBuffers()`.

### signalEndOfCurrentInputStream

```
fun signalEndOfCurrentInputStream(): Unit
```

Notifies the `GlShaderProgram` that no further input frames belonging to the current input stream will be queued.

Input frames that are queued after this method is called belong to a different input stream.

## Protected functions

### onError

```
protected fun onError(e: Exception!): Unit
```

## Protected properties

### inputListener

```
protected var inputListener: GlShaderProgram.InputListener!
```

### outputListener

```
protected var outputListener: GlShaderProgram.OutputListener!
```