# GLRenderer.RenderCallback

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

*** ** * ** ***


```
public interface GLRenderer.RenderCallback
```

<br />

Known direct subclasses [FrameBufferRenderer](https://developer.android.com/reference/androidx/graphics/opengl/FrameBufferRenderer)

|---|---|
| `https://developer.android.com/reference/androidx/graphics/opengl/FrameBufferRenderer` | `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback` implementation that renders content into a frame buffer object backed by a `https://developer.android.com/reference/android/hardware/HardwareBuffer.html` object |

*** ** * ** ***

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

## Summary

| ### Public methods |
|---|---|
| `abstract void` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback#onDrawFrame(androidx.graphics.opengl.egl.EGLManager)(@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLManager eglManager)` Callback used to issue OpenGL drawing commands into the `https://developer.android.com/reference/android/opengl/EGLSurface.html` created in `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)`. |
| `default https://developer.android.com/reference/android/opengl/EGLSurface.html` | `@https://developer.android.com/reference/androidx/annotation/WorkerThread 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)( @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLSpec spec, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/opengl/EGLConfig.html config, @https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/Surface.html surface, int width, int height )` Used to create a corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` from the provided `https://developer.android.com/reference/android/view/Surface.html` instance. |

## Public methods

### onDrawFrame

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

```
@WorkerThread
abstract void onDrawFrame(@NonNull EGLManager eglManager)
```

Callback used to issue OpenGL drawing commands into the `https://developer.android.com/reference/android/opengl/EGLSurface.html` created in `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)`. This `https://developer.android.com/reference/android/opengl/EGLSurface.html` is guaranteed to be current before this callback is invoked and `https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLManager#swapAndFlushBuffers()` will be invoked afterwards. If additional scratch `https://developer.android.com/reference/android/opengl/EGLSurface.html`s are used here it is up to the implementation of this method to ensure that the proper surfaces are made current and the appropriate swap buffers call is made

This method is invoked on the backing thread

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLManager eglManager` | Handle to EGL dependencies |

### onSurfaceCreated

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

```
@WorkerThread
default EGLSurface onSurfaceCreated(
    @NonNull EGLSpec spec,
    @NonNull EGLConfig config,
    @NonNull Surface surface,
    int width,
    int height
)
```

Used to create a corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` from the provided `https://developer.android.com/reference/android/view/Surface.html` instance. This enables consumers to configure the corresponding `https://developer.android.com/reference/android/opengl/EGLSurface.html` they wish to render into. The `https://developer.android.com/reference/android/opengl/EGLSurface.html` created here is guaranteed to be the current surface before `https://developer.android.com/reference/androidx/graphics/opengl/GLRenderer.RenderCallback#onDrawFrame(androidx.graphics.opengl.egl.EGLManager)` is called. That is, implementations of onDrawFrame do not need to call eglMakeCurrent on this `https://developer.android.com/reference/android/opengl/EGLSurface.html`.

This method is invoked on the GL thread.

The default implementation will create a window surface with EGL_WIDTH and EGL_HEIGHT set to `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 `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)` respectively. Implementations can override this method to provide additional `https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLConfigAttributes` for this surface (ex. `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_SINGLE_BUFFER`.

Implementations can return null to indicate the default surface should be used. This is helpful in situations where content is to be rendered within a frame buffer object instead of to an `https://developer.android.com/reference/android/opengl/EGLSurface.html`

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/androidx/graphics/opengl/egl/EGLSpec spec` | EGLSpec used to create the corresponding EGLSurface |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/opengl/EGLConfig.html config` | EGLConfig used to create the corresponding EGLSurface |
| `@https://developer.android.com/reference/androidx/annotation/NonNull https://developer.android.com/reference/android/view/Surface.html surface` | `https://developer.android.com/reference/android/view/Surface.html` used to create an EGLSurface from |
| `int width` | Desired width of the surface to create |
| `int height` | Desired height of the surface to create |