# 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)

*** ** * ** ***


```
public final 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 |
|---|
| `public interface https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.EGLContextCallback` Callbacks invoked when the GL dependencies are created and destroyed. |
| `public interface https://developer.android.com/reference/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 |
| `public final class https://developer.android.com/reference/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/androidx/graphics/opengl/GLRenderer` to handle rendering. |

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

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

## Public constructors

### GLRenderer

```
public GLRenderer(
    @NonNull Function0<@NonNull EGLSpec> eglSpecFactory,
    @NonNull Function1<@NonNull EGLManager, @NonNull EGLConfig> eglConfigFactory
)
```

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function0<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLSpec> eglSpecFactory` | Callback invoked to determine the EGL spec version to use for EGL management. This is invoked on the GL Thread |
| `@https://developer.android.com/reference/androidx/annotation/NonNull Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLManager, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/opengl/EGLConfig.html> eglConfigFactory` | Callback invoked to determine the appropriate EGLConfig used to create the EGL context. This is invoked on the GL Thread |

## Public methods

### attach

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

```
public final @NonNull GLRenderer.RenderTarget attach(
    @NonNull SurfaceView surfaceView,
    @NonNull GLRenderer.RenderCallback renderer
)
```

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/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/SurfaceView.html surfaceView` | SurfaceView that provides the surface to be rendered by the backing thread |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback renderer` | 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/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/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)

```
public final @NonNull GLRenderer.RenderTarget attach(
    @NonNull TextureView textureView,
    @NonNull GLRenderer.RenderCallback renderer
)
```

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/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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/TextureView.html textureView` | TextureView that provides the surface to be rendered into on the GLThread |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback renderer` | 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/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/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)

```
public final @NonNull GLRenderer.RenderTarget attach(
    @NonNull Surface surface,
    int width,
    int height,
    @NonNull GLRenderer.RenderCallback renderer
)
```

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/androidx/graphics/opengl/GLRenderer.RenderCallback`. Unlike the other `https://developer.android.com/reference/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/Surface.html surface` | Target surface to be managed by the backing thread |
| `int width` | Desired width of the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` |
| `int height` | Desired height of the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#attach(android.view.Surface,kotlin.Int,kotlin.Int,androidx.graphics.opengl.GLRenderer.RenderCallback)` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback renderer` | 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/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to communicate with the provided Surface (ex. `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)` or `https://developer.android.com/reference/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)

```
public final @NonNull GLRenderer.RenderTarget createRenderTarget(
    int width,
    int height,
    @NonNull GLRenderer.RenderCallback renderer
)
```

Creates a new `https://developer.android.com/reference/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 |
|---|---|
| `int width` | Desired width of the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` |
| `int height` | Desired height of the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback renderer` | Callbacks used to issue OpenGL commands to the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` |

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` used for subsequent requests to render through `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#requestRender(kotlin.Function1)` or to remove itself from the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` through `https://developer.android.com/reference/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)

```
public final void detach(
    @NonNull GLRenderer.RenderTarget target,
    boolean cancelPending,
    @WorkerThread Function1<@NonNull GLRenderer.RenderTarget, Unit> onDetachComplete
)
```

Removes the corresponding `https://developer.android.com/reference/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/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/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/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op. GLRenderer will automatically detach all `https://developer.android.com/reference/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)

```
public final void execute(@NonNull Runnable runnable)
```

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/androidx/graphics/opengl/GLRenderer#start(kotlin.String)` is invoked and before the runnable is executed.

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

### isRunning

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

```
public final boolean isRunning()
```

Determines if the GLThread has been started. That is `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#start(kotlin.String)` has been invoked on this GLRenderer instance without a corresponding call to `https://developer.android.com/reference/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)

```
public final void registerEGLContextCallback(
    @NonNull GLRenderer.EGLContextCallback callback
)
```

Add an `https://developer.android.com/reference/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)

```
public final void requestRender(
    @NonNull GLRenderer.RenderTarget target,
    Function1<@NonNull GLRenderer.RenderTarget, Unit> onRenderComplete
)
```

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/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 |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget target` | RenderTarget to be re-rendered |
| `Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onRenderComplete` | 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)

```
public final void resize(
    @NonNull GLRenderer.RenderTarget target,
    int width,
    int height,
    Function1<@NonNull GLRenderer.RenderTarget, Unit> onResizeComplete
)
```

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/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/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget target` | RenderTarget to be resized |
| `int width` | Updated width of the corresponding surface |
| `int height` | Updated height of the corresponding surface |
| `Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onResizeComplete` | 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)

```
public final void start(@NonNull String name)
```

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/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/androidx/graphics/opengl/GLRenderer#requestRender(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Function1)`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/java/lang/String.html name` | 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)

```
public final void stop(boolean cancelPending, Function1<@NonNull GLRenderer, Unit> onStop)
```

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/androidx/graphics/opengl/GLRenderer#isRunning()` returns true. Otherwise this is a no-op.

| Parameters |
|---|---|
| `boolean cancelPending` | 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. |
| `Function1<@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer, https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onStop` | 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)

```
public final void unregisterEGLContextCallback(
    @NonNull GLRenderer.EGLContextCallback callback
)
```

Remove `https://developer.android.com/reference/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