# GLRenderer.RenderTarget

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.RenderTarget) Added in [1.0.0](https://developer.android.com/jetpack/androidx/releases/graphics#1.0.0)

*** ** * ** ***


```
public final class GLRenderer.RenderTarget
```

<br />

*** ** * ** ***

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.

## Summary

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#detach(kotlin.Boolean,kotlin.Function1)( boolean cancelPending, 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 boolean` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#isAttached()()` Determines if the current RenderTarget is attached to GLRenderer. |
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#requestRender(kotlin.Function1)( @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> onRenderComplete )` Request that this `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` should have its contents redrawn. |
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#resize(kotlin.Int,kotlin.Int,kotlin.Function1)( int width, int height, @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> onResizeComplete )` Resize the RenderTarget to the specified width and height. |

## Public methods

### detach

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

```
public final void detach(
    boolean cancelPending,
    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.RenderTarget#detach(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.

This is a convenience method around `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer#detach(androidx.graphics.opengl.GLRenderer.RenderTarget,kotlin.Boolean,kotlin.Function1)`

Note the detach operation will only occur if the RenderTarget is attached, that is `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#isAttached()` returns true. If the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` is detached or the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` that created this RenderTarget is stopped, this is a no-op.

### isAttached

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

```
public final boolean isAttached()
```

Determines if the current RenderTarget is attached to GLRenderer. This is true until `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#detach(kotlin.Boolean,kotlin.Function1)` has been called. If the RenderTarget is no longer in an attached state (i.e. this returns false). Subsequent calls to `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#requestRender(kotlin.Function1)` will be ignored.

### requestRender

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

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

Request that this `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` should have its contents redrawn. This consumes an optional callback that is invoked on the backing thread when the rendering is completed.

Note the render operation will only occur if the RenderTarget is attached, that is `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#isAttached()` returns true. If the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` is detached or the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` that created this RenderTarget is stopped, this is a no-op.

| Parameters |
|---|---|
| `@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> onRenderComplete` | Optional callback called on the backing thread when rendering is finished |

### resize

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

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

Resize the RenderTarget to the specified width and height. 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 RenderTarget is attached, that is `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget#isAttached()` returns true. If the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderTarget` is detached or the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` that created this RenderTarget is stopped, this is a no-op.

| Parameters |
|---|---|
| `int width` | New target width to resize the RenderTarget |
| `int height` | New target height to resize the RenderTarget |
| `@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> onResizeComplete` | Optional callback invoked after the resize is complete |