# GLRenderer

Artifact: [androidx.graphics:graphics-core](https://developer.android.com/jetpack/androidx/releases/graphics) [View Source](https://cs.android.com/search?q=file:androidx/graphics/opengl/GLRenderer.kt+class:androidx.graphics.opengl.GLRenderer) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

*** ** * ** ***


```
class GLRenderer
```

<br />

*** ** * ** ***

Class responsible for coordination of requests to render into surfaces using OpenGL. This creates a backing thread to handle EGL dependencies and draw leveraging OpenGL across multiple `https://developer.android.com/reference/android/view/Surface.html` instances that can be attached and detached throughout the lifecycle of an application. Usage of this class is recommended to be done on the UI thread.

## Summary

| ### Nested types |
|---|
| `interface https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback` Callbacks invoked when the GL dependencies are created and destroyed. |
| `interface https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback` Interface used for creating an `https://developer.android.com/reference/android/opengl/EGLSurface.html` with a user defined configuration from the provided surface as well as a callback used to render content into the surface for a given frame |
| `class https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` Handle to a `https://developer.android.com/reference/android/view/Surface.html` that is given to `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` to handle rendering. |

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#GLRenderer(kotlin.Function0,kotlin.Function1)( eglSpecFactory: () -> https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLSpec, eglConfigFactory: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager.() -> https://developer.android.com/reference/android/opengl/EGLConfig.html )` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.SurfaceView,androidx.graphics.opengl.GLRenderer.RenderCallback)(surfaceView: https://developer.android.com/reference/android/view/SurfaceView.html, renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback)` Adds the `https://developer.android.com/reference/android/view/Surface.html` provided by the given `https://developer.android.com/reference/android/view/SurfaceView.html` to be managed by the backing thread. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.TextureView,androidx.graphics.opengl.GLRenderer.RenderCallback)(textureView: https://developer.android.com/reference/android/view/TextureView.html, renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback)` Adds the `https://developer.android.com/reference/android/view/Surface.html` provided by the given `https://developer.android.com/reference/android/view/TextureView.html` to be managed by the backing thread. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)( surface: https://developer.android.com/reference/android/view/Surface.html, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback )` Adds the `https://developer.android.com/reference/android/view/Surface.html` to be managed by the GLThread. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#createRenderTarget(kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)( width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback )` Creates a new `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` without a corresponding `https://developer.android.com/reference/android/view/Surface.html`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)( target: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget, cancelPending: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, @https://developer.android.com/reference/kotlin/androidx/annotation/WorkerThread onDetachComplete: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` Removes the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` from management of the GLThread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#execute(java.lang.Runnable)(runnable: https://developer.android.com/reference/java/lang/Runnable.html)` Queue a `https://developer.android.com/reference/java/lang/Runnable.html` to be executed on the GL rendering thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#isRunning()()` Determines if the GLThread has been started. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#registerEGLContextCallback(androidx.graphics.opengl.GLRenderer.EGLContextCallback)(callback: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback)` Add an `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback` to receive callbacks for construction and destruction of EGL dependencies. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)( target: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget, onRenderComplete: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` Mark the corresponding surface session with the given token as dirty to schedule a call to RenderCallback#onDrawFrame. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#resize(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Int,kotlin.Int,kotlin.Function1)( target: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget, width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html, onResizeComplete: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? )` Resize the corresponding surface associated with the RenderTarget to the specified width and height and re-render. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#start(kotlin.String)(name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Starts the GLThread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#stop(kotlin.Boolean,kotlin.Function1)(cancelPending: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html, onStop: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)?)` Stop the corresponding GL thread. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#unregisterEGLContextCallback(androidx.graphics.opengl.GLRenderer.EGLContextCallback)(callback: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback)` Remove `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback` to no longer receive callbacks for construction and destruction of EGL dependencies. |

## Public constructors

### GLRenderer

```
GLRenderer(
    eglSpecFactory: () -> EGLSpec = { EGLSpec.V14 },
    eglConfigFactory: EGLManager.() -> EGLConfig = {
        // 8 bit channels should always be supported
        loadConfig(EGLConfigAttributes.RGBA_8888)
            ?: throw IllegalStateException(
                "Unable to obtain config for 8 bit EGL " + "configuration"
            )
    }
)
```

| Parameters |
|---|---|
| `eglSpecFactory: () -> https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLSpec = { EGLSpec.V14 }` | Callback invoked to determine the EGL spec version to use for EGL management. This is invoked on the GL Thread |
| `eglConfigFactory: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager.() -> https://developer.android.com/reference/android/opengl/EGLConfig.html = { // 8 bit channels should always be supported loadConfig(EGLConfigAttributes.RGBA_8888) ?: throw IllegalStateException( "Unable to obtain config for 8 bit EGL " + "configuration" ) }` | Callback invoked to determine the appropriate EGLConfig used to create the EGL context. This is invoked on the GL Thread |

## Public functions

### attach

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun attach(surfaceView: SurfaceView, renderer: GLRenderer.RenderCallback): GLRenderer.RenderTarget
```

Adds the `https://developer.android.com/reference/android/view/Surface.html` provided by the given `https://developer.android.com/reference/android/view/SurfaceView.html` to be managed by the backing thread.

A corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` is created on the GLThread as well as a callback for rendering into the surface through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback`.

This method automatically configures a `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html` used to attach the `https://developer.android.com/reference/android/view/Surface.html` when the underlying `https://developer.android.com/reference/android/view/SurfaceHolder.html` that contains the surface is available. Similarly this surface will be detached from `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` when the surface provided by the `https://developer.android.com/reference/android/view/SurfaceView.html` is destroyed (i.e. `https://developer.android.com/reference/android/view/SurfaceHolder.Callback.html#surfaceDestroyed(android.view.SurfaceHolder)` is called.

If the `https://developer.android.com/reference/android/view/Surface.html` is already available by the time this method is invoked, it is attached synchronously.

| Parameters |
|---|---|
| `surfaceView: https://developer.android.com/reference/android/view/SurfaceView.html` | SurfaceView that provides the surface to be rendered by the backing thread |
| `renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback` | callbacks used to create a corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` from the given surface as well as render content into the created `https://developer.android.com/reference/android/opengl/EGLSurface.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)`). |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If this method was called when the GLThread has not started (i.e. start has not been called) |

### attach

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun attach(textureView: TextureView, renderer: GLRenderer.RenderCallback): GLRenderer.RenderTarget
```

Adds the `https://developer.android.com/reference/android/view/Surface.html` provided by the given `https://developer.android.com/reference/android/view/TextureView.html` to be managed by the backing thread.

A corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` is created on the GLThread as well as a callback for rendering into the surface through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback`.

This method automatically configures a `https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener.html` used to create a `https://developer.android.com/reference/android/view/Surface.html` when the underlying `https://developer.android.com/reference/android/graphics/SurfaceTexture.html` is available. Similarly this surface will be detached from `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` if the underlying `https://developer.android.com/reference/android/graphics/SurfaceTexture.html` is destroyed (i.e. `https://developer.android.com/reference/android/view/TextureView.SurfaceTextureListener.html#onSurfaceTextureDestroyed(android.graphics.SurfaceTexture)` is called.

If the `https://developer.android.com/reference/android/graphics/SurfaceTexture.html` is already available by the time this method is called, then it is attached synchronously.

| Parameters |
|---|---|
| `textureView: https://developer.android.com/reference/android/view/TextureView.html` | TextureView that provides the surface to be rendered into on the GLThread |
| `renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback` | callbacks used to create a corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` from the given surface as well as render content into the created `https://developer.android.com/reference/android/opengl/EGLSurface.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)`). |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If this method was called when the GLThread has not started (i.e. start has not been called) |

### attach

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun attach(
    surface: Surface,
    width: Int,
    height: Int,
    renderer: GLRenderer.RenderCallback
): GLRenderer.RenderTarget
```

Adds the `https://developer.android.com/reference/android/view/Surface.html` to be managed by the GLThread. A corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` is created on the GLThread as well as a callback for rendering into the surface through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback`. Unlike the other `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` methods that consume a `https://developer.android.com/reference/android/view/SurfaceView.html` or `https://developer.android.com/reference/android/view/TextureView.html`, this method does not handle any lifecycle callbacks associated with the target surface. Therefore it is up to the consumer to properly setup/teardown resources associated with this surface.

| Parameters |
|---|---|
| `surface: https://developer.android.com/reference/android/view/Surface.html` | Target surface to be managed by the backing thread |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired width of the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired height of the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` |
| `renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback` | Callbacks used to create a corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` from the given surface as well as render content into the created `https://developer.android.com/reference/android/opengl/EGLSurface.html` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)`). |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If this method was called when the GLThread has not started (i.e. start has not been called) |

### createRenderTarget

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun createRenderTarget(
    width: Int,
    height: Int,
    renderer: GLRenderer.RenderCallback
): GLRenderer.RenderTarget
```

Creates a new `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` without a corresponding `https://developer.android.com/reference/android/view/Surface.html`. This avoids creation of an `https://developer.android.com/reference/android/opengl/EGLSurface.html` which is useful in scenarios where only rendering to a frame buffer object is required.

| Parameters |
|---|---|
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired width of the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Desired height of the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` |
| `renderer: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback` | Callbacks used to issue OpenGL commands to the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` |

| Returns |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to render through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget#requestRender(kotlin.Function1)` or to remove itself from the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer` through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget#detach(kotlin.Boolean,kotlin.Function1)` |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | If this method was called when the GLThread has not started (i.e. start has not been called) |

### detach

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun detach(
    target: GLRenderer.RenderTarget,
    cancelPending: Boolean,
    @WorkerThread onDetachComplete: ((GLRenderer.RenderTarget) -> Unit)? = null
): Unit
```

Removes the corresponding `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` from management of the GLThread. This destroys the EGLSurface associated with this surface and subsequent requests to render into the surface with the provided token are ignored.

If the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)` flag is set to true, any queued request to render that has not started yet is cancelled. However, if this is invoked in the middle of the frame being rendered, it will continue to process the current frame.

Additionally if this flag is false, all pending requests to render will be processed before the `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` is detached.

Note the detach operation will only occur if the GLRenderer is started, that is if `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op. GLRenderer will automatically detach all `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` instances as part of its teardown process.

### execute

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun execute(runnable: Runnable): Unit
```

Queue a `https://developer.android.com/reference/java/lang/Runnable.html` to be executed on the GL rendering thread. Note it is important that this `https://developer.android.com/reference/java/lang/Runnable.html` does not block otherwise it can stall the GL thread. The EGLContext will be created after `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#start(kotlin.String)` is invoked and before the runnable is executed.

| Parameters |
|---|---|
| `runnable: https://developer.android.com/reference/java/lang/Runnable.html` | Runnable to be executed |

### isRunning

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun isRunning(): Boolean
```

Determines if the GLThread has been started. That is `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#start(kotlin.String)` has been invoked on this GLRenderer instance without a corresponding call to `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#stop(kotlin.Boolean,kotlin.Function1)`.

### registerEGLContextCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun registerEGLContextCallback(callback: GLRenderer.EGLContextCallback): Unit
```

Add an `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback` to receive callbacks for construction and destruction of EGL dependencies.

These callbacks are invoked on the backing thread.

### requestRender

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun requestRender(
    target: GLRenderer.RenderTarget,
    onRenderComplete: ((GLRenderer.RenderTarget) -> Unit)? = null
): Unit
```

Mark the corresponding surface session with the given token as dirty to schedule a call to RenderCallback#onDrawFrame. If there is already a queued request to render into the provided surface with the specified token, this request is ignored.

Note the render operation will only occur if the GLRenderer is started, that is if `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op.

When rendering continuously callers should typically use `https://developer.android.com/reference/android/view/Choreographer.html` to render no more than the refresh rate of the display.

| Parameters |
|---|---|
| `target: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | RenderTarget to be re-rendered |
| `onRenderComplete: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Optional callback invoked on the backing thread after the frame has been rendered. |

### resize

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun resize(
    target: GLRenderer.RenderTarget,
    width: Int,
    height: Int,
    onResizeComplete: ((GLRenderer.RenderTarget) -> Unit)? = null
): Unit
```

Resize the corresponding surface associated with the RenderTarget to the specified width and height and re-render. This will destroy the EGLSurface created by `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderCallback#onSurfaceCreated(androidx.graphics.opengl.egl.EGLSpec,android.opengl.EGLConfig,android.view.Surface,kotlin.Int,kotlin.Int)` and invoke it again with the updated dimensions. An optional callback is invoked on the backing thread after the resize operation is complete.

Note the resize operation will only occur if the GLRenderer is started, that is if `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op.

| Parameters |
|---|---|
| `target: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget` | RenderTarget to be resized |
| `width: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Updated width of the corresponding surface |
| `height: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | Updated height of the corresponding surface |
| `onResizeComplete: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.RenderTarget) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Optional callback invoked on the backing thread when the resize operation is complete |

### start

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun start(name: String = "GLThread"): Unit
```

Starts the GLThread. After this method is called, consumers can attempt to attach `https://developer.android.com/reference/android/view/Surface.html` instances through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` as well as schedule content to be drawn through `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)`

| Parameters |
|---|---|
| `name: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html = "GLThread"` | Optional name to provide to the GLThread |

| Throws |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-illegal-state-exception/index.html` | if EGLConfig with desired attributes cannot be created |

### stop

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun stop(cancelPending: Boolean, onStop: ((GLRenderer) -> Unit)? = null): Unit
```

Stop the corresponding GL thread. This destroys all EGLSurfaces as well as any other EGL dependencies. All queued requests that have not been processed yet are cancelled.

Note the stop operation will only occur if the GLRenderer was previously started, that is `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op.

| Parameters |
|---|---|
| `cancelPending: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | If true, all pending requests are cancelled and the backing thread is torn down immediately. If false, all pending requests are processed first before tearing down the backing thread. Subsequent requests made after this call are ignored. |
| `onStop: ((https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer) -> https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html)? = null` | Optional callback invoked on the backing thread after it is torn down. |

### unregisterEGLContextCallback

Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

```
fun unregisterEGLContextCallback(callback: GLRenderer.EGLContextCallback): Unit
```

Remove `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/GLRenderer.EGLContextCallback` to no longer receive callbacks for construction and destruction of EGL dependencies.

These callbacks are invoked on the backing thread