# GLFrameBufferRenderer

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

*** ** * ** ***


```
@RequiresApi(value = 29)
public final class GLFrameBufferRenderer
```

<br />

*** ** * ** ***

Class responsible for supporting rendering to frame buffer objects that are backed by `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` instances. This provides for more flexibility in OpenGL rendering as it supports configuration of the number of buffers within the underlying swap chain, pixel format of the buffers as well as fine grained control over synchronization of buffer content.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer.Builder` Builder used to create a `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` with various configurations |
| `public interface https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer.Callback` `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` callbacks that are invoked to render OpenGL content within the underlying buffers. |

| ### Public methods |
|---|---|
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#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 int` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#getBufferFormat()()` Returns the `https://developer.android.com/reference/androidx/hardware/HardwareBufferFormat` of the buffers that are being rendered into by this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#getGLRenderer()()` Returns the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` used for issuing requests to render into the underlying buffers with OpenGL. |
| `final int` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#getMaxBuffers()()` Returns the number of buffers within the swap chain used for rendering with this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` |
| `final @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/SyncStrategy` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#getSyncStrategy()()` Returns the `https://developer.android.com/reference/androidx/graphics/opengl/SyncStrategy` used for determining when to create `https://developer.android.com/reference/androidx/hardware/SyncFenceCompat` objects in order to handle synchronization. |
| `final long` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#getUsageFlags()()` Returns the current usage flag hints of the buffers that are being rendered into by this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` |
| `final boolean` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#isValid()()` Determines whether or not the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` is in a valid state. |
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#release(kotlin.Boolean,kotlin.Function0)(boolean cancelPending, Function0<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onReleaseCallback)` Release resources associated with the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer`. |
| `final void` | `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#render()()` Render content to a buffer and present the result to the display. |

## Public methods

### 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 this `https://developer.android.com/reference/java/lang/Runnable.html` does not block otherwise it can stall the GL thread.

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

### getBufferFormat

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

```
public final int getBufferFormat()
```

Returns the `https://developer.android.com/reference/androidx/hardware/HardwareBufferFormat` of the buffers that are being rendered into by this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer`

### getGLRenderer

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

```
public final @NonNull GLRenderer getGLRenderer()
```

Returns the `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer` used for issuing requests to render into the underlying buffers with OpenGL.

### getMaxBuffers

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

```
public final int getMaxBuffers()
```

Returns the number of buffers within the swap chain used for rendering with this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer`

### getSyncStrategy

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

```
public final @NonNull SyncStrategy getSyncStrategy()
```

Returns the `https://developer.android.com/reference/androidx/graphics/opengl/SyncStrategy` used for determining when to create `https://developer.android.com/reference/androidx/hardware/SyncFenceCompat` objects in order to handle synchronization. The `https://developer.android.com/reference/androidx/hardware/SyncFenceCompat` instance created according to the algorithm specified in the provided `https://developer.android.com/reference/androidx/graphics/opengl/SyncStrategy` will be passed to the corresponding `https://developer.android.com/reference/androidx/graphics/surface/SurfaceControlCompat.Transaction#setBuffer(androidx.graphics.surface.SurfaceControlCompat,android.hardware.HardwareBuffer,androidx.hardware.SyncFenceCompat,kotlin.Function1)` call in order to ensure the underlying buffer is not presented by the display until the fence signals.

### getUsageFlags

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

```
public final long getUsageFlags()
```

Returns the current usage flag hints of the buffers that are being rendered into by this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer`

### isValid

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

```
public final boolean isValid()
```

Determines whether or not the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` is in a valid state. That is the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#release(kotlin.Boolean,kotlin.Function0)` method has not been called. If this returns false, then subsequent calls to `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#render()`, and `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#release(kotlin.Boolean,kotlin.Function0)` are ignored

| Returns |
|---|---|
| `boolean` | `true` if this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` has been released, `false` otherwise |

### release

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

```
public final void release(boolean cancelPending, Function0<Unit> onReleaseCallback)
```

Release resources associated with the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer`. After this method is invoked, the `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` is in an invalid state and can no longer handle rendering content.

| Parameters |
|---|---|
| `boolean cancelPending` | If true, pending render requests are cancelled immediately. If false, pending render requests are completed before releasing the renderer. |
| `Function0<https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html> onReleaseCallback` | Optional callback to be invoked on the underlying OpenGL thread when releasing resources has been completed |

### render

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

```
public final void render()
```

Render content to a buffer and present the result to the display.

If this `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer` has been released, that is `https://developer.android.com/reference/androidx/graphics/opengl/GLFrameBufferRenderer#isValid()` returns `false`, this call is ignored.