# EGLManager

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

*** ** * ** ***


```
class EGLManager
```

<br />

*** ** * ** ***

Class responsible for configuration of EGL related resources. This includes initialization of the corresponding EGL Display as well as EGL Context, among other EGL related facilities.

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#EGLManager(androidx.graphics.opengl.egl.EGLSpec)(eglSpec: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLSpec)` |

| ### Public functions |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLContext.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#createContext(android.opengl.EGLConfig)(config: https://developer.android.com/reference/android/opengl/EGLConfig.html)` Creates an `https://developer.android.com/reference/android/opengl/EGLContext.html` from the given `https://developer.android.com/reference/android/opengl/EGLConfig.html` returning null if the context could not be created |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#initialize()()` Initialize the EGLManager. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#isExtensionSupported(kotlin.String)(extensionName: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-string/index.html)` Determines whether the extension with the provided name is supported. |
| `https://developer.android.com/reference/android/opengl/EGLConfig.html?` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#loadConfig(androidx.graphics.opengl.egl.EGLConfigAttributes)(configAttributes: https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLConfigAttributes)` Attempt to load an `https://developer.android.com/reference/android/opengl/EGLConfig.html` instance from the given `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLConfigAttributes`. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-boolean/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#makeCurrent(android.opengl.EGLSurface,android.opengl.EGLSurface)(drawSurface: https://developer.android.com/reference/android/opengl/EGLSurface.html, readSurface: https://developer.android.com/reference/android/opengl/EGLSurface.html)` Binds the current context to the given draw and read surfaces. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#release()()` Release the resources allocated by EGLManager. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#swapAndFlushBuffers()()` Post EGL surface color buffer to a native window. |

| ### Public properties |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#currentDrawSurface()` Returns the current surface used for drawing pixel content |
| `https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#currentReadSurface()` Returns the current surface used for reading back or copying pixels |
| `https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#defaultSurface()` Returns the default surface. |
| `https://developer.android.com/reference/android/opengl/EGLConfig.html?` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#eglConfig()` Returns the `https://developer.android.com/reference/android/opengl/EGLConfig.html` used to load the current `https://developer.android.com/reference/android/opengl/EGLContext.html`. |
| `https://developer.android.com/reference/android/opengl/EGLContext.html?` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#eglContext()` Returns the current EGLContext. |
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLSpec` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#eglSpec()` |
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLVersion` | `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#eglVersion()` Returns the EGL version that is supported. |

## Public constructors

### EGLManager

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

```
EGLManager(eglSpec: EGLSpec = EGLSpec.V14)
```

## Public functions

### createContext

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

```
fun createContext(config: EGLConfig): EGLContext
```

Creates an `https://developer.android.com/reference/android/opengl/EGLContext.html` from the given `https://developer.android.com/reference/android/opengl/EGLConfig.html` returning null if the context could not be created

| Throws |
|---|---|
| `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLException` | if the default surface could not be made current after context creation |

### initialize

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

```
fun initialize(): Unit
```

Initialize the EGLManager. This initializes the default display as well as queries the supported extensions

### isExtensionSupported

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

```
fun isExtensionSupported(extensionName: String): Boolean
```

Determines whether the extension with the provided name is supported. The string provided is expected to be one of the named extensions defined within the OpenGL extension documentation.

See `https://developer.android.com/reference/kotlin/androidx/opengl/EGLExt` for additional documentation for given extension name constants and descriptions.

The set of supported extensions is configured after `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#initialize()` is invoked. Attempts to query support for any extension beforehand will return false.

### loadConfig

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

```
fun loadConfig(configAttributes: EGLConfigAttributes): EGLConfig?
```

Attempt to load an `https://developer.android.com/reference/android/opengl/EGLConfig.html` instance from the given `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLConfigAttributes`. If the `https://developer.android.com/reference/android/opengl/EGLConfig.html` could not be loaded this returns null

### makeCurrent

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

```
fun makeCurrent(drawSurface: EGLSurface, readSurface: EGLSurface = drawSurface): Boolean
```

Binds the current context to the given draw and read surfaces. The draw surface is used for all operations except for any pixel data read back or copy operations which are taken from the read surface.

The same EGLSurface may be specified for both draw and read surfaces.

If the context is not previously configured, the only valid parameters for the draw and read surfaces is `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_NO_SURFACE`. This is useful to make sure there is always a surface specified and to release the current context without assigning a new one.

See https://www.khronos.org/registry/EGL/sdk/docs/man/html/eglMakeCurrent.xhtml

| Parameters |
|---|---|
| `drawSurface: https://developer.android.com/reference/android/opengl/EGLSurface.html` | Surface used for all operations that involve writing pixel information |
| `readSurface: https://developer.android.com/reference/android/opengl/EGLSurface.html = drawSurface` | Surface used for pixel data read back or copy operations. By default this is the same as `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#makeCurrent(android.opengl.EGLSurface,android.opengl.EGLSurface)` |

### release

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

```
fun release(): Unit
```

Release the resources allocated by EGLManager. This will destroy the corresponding EGLContext instance if it was previously initialized. The configured EGLVersion as well as EGLExtensions

### swapAndFlushBuffers

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

```
fun swapAndFlushBuffers(): Unit
```

Post EGL surface color buffer to a native window. If the current drawing surface is single buffered this will flush the buffer

## Public properties

### currentDrawSurface

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

```
val currentDrawSurface: EGLSurface
```

Returns the current surface used for drawing pixel content

### currentReadSurface

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

```
val currentReadSurface: EGLSurface
```

Returns the current surface used for reading back or copying pixels

### defaultSurface

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

```
val defaultSurface: EGLSurface
```

Returns the default surface. This can be an offscreen pixel buffer surface or `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_NO_SURFACE` if the surfaceless context extension is supported.

### eglConfig

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

```
val eglConfig: EGLConfig?
```

Returns the `https://developer.android.com/reference/android/opengl/EGLConfig.html` used to load the current `https://developer.android.com/reference/android/opengl/EGLContext.html`. This is configured after `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#createContext(android.opengl.EGLConfig)` is invoked.

### eglContext

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

```
val eglContext: EGLContext?
```

Returns the current EGLContext. This parameter is configured after `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#initialize()` is invoked

### eglSpec

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

```
val eglSpec: EGLSpec
```

### eglVersion

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

```
val eglVersion: EGLVersion
```

Returns the EGL version that is supported. This parameter is configured after `https://developer.android.com/reference/kotlin/androidx/graphics/opengl/egl/EGLManager#initialize()` is invoked.