# GlUtil

Artifact: [androidx.media3:media3-common](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/common/util/GlUtil.java+class:androidx.media3.common.util.GlUtil)

*** ** * ** ***


```
@UnstableApi
public final class GlUtil
```

<br />

*** ** * ** ***

OpenGL ES utilities.

## Summary

| ### Nested types |
|---|
| `public final class https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException extends https://developer.android.com/reference/java/lang/Exception.html` Thrown when an OpenGL error occurs. |

| ### Constants |
|---|---|
| `static final int[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_1010102()` |
| `static final int[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_8888()` |
| `static final long` | `@https://developer.android.com/reference/androidx/media3/common/util/ExperimentalApi https://developer.android.com/reference/androidx/media3/common/util/GlUtil#GL_FENCE_SYNC_UNSET() = -1` Marker value for when no fence sync is set. |
| `static final int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#HOMOGENEOUS_COORDINATE_VECTOR_SIZE() = 4` Number of elements in a 3d homogeneous coordinate vector describing a vertex. |
| `static final float` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#LENGTH_NDC() = 2.0f` Length of the normalized device coordinate (NDC) space, which spans from -1 to 1. |

| ### Public methods |
|---|---|
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#awaitSyncObject(long)(long syncObject)` Ensures that following commands on the current OpenGL context will not be executed until the sync point has been reached. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#bindTexture(int,int,int)(int textureTarget, int texId, int sampleFilter)` Binds the texture of the given type with the specified MIN and MAG sampling filter and GL_CLAMP_TO_EDGE wrapping. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#blitFrameBuffer(int,androidx.media3.common.util.GlRect,int,androidx.media3.common.util.GlRect)( int readFboId, https://developer.android.com/reference/androidx/media3/common/util/GlRect readRect, int drawFboId, https://developer.android.com/reference/androidx/media3/common/util/GlRect drawRect )` Copies the pixels from `readFboId` into `drawFboId`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#checkEglException(java.lang.String)(https://developer.android.com/reference/java/lang/String.html errorMessage)` Collects EGL errors that occurred in the last called EGL function and throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the combined error code. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#checkGlError()()` Collects all OpenGL errors that occurred since this method was last called and throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the combined error message. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#checkGlException(boolean,java.lang.String)(boolean expression, https://developer.android.com/reference/java/lang/String.html errorMessage)` Throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the given message if `expression` evaluates to ` false`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#clearFocusedBuffers()()` Fills the pixels in the current output render target buffers with (r=0, g=0, b=0, a=0). |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#clearFocusedBuffersOpaque()()` Fills the pixels in the current output render target buffers with (r=0, g=0, b=0, a=1). |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#create4x4IdentityMatrix()()` Creates a 4x4 identity matrix. |
| `static https://developer.android.com/reference/java/nio/FloatBuffer.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createBuffer(float[])(float[] data)` Allocates a FloatBuffer with the given data. |
| `static https://developer.android.com/reference/android/opengl/EGLContext.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createEglContext(android.opengl.EGLDisplay)(https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay)` Creates a new `https://developer.android.com/reference/android/opengl/EGLContext.html` for the specified `https://developer.android.com/reference/android/opengl/EGLDisplay.html`. |
| `static https://developer.android.com/reference/android/opengl/EGLContext.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createEglContext(android.opengl.EGLContext,android.opengl.EGLDisplay,int,int[])( https://developer.android.com/reference/android/opengl/EGLContext.html sharedContext, https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, @https://developer.android.com/reference/androidx/annotation/IntRange(from = 2, to = 3) int openGlVersion, int[] configAttributes )` Creates a new `https://developer.android.com/reference/android/opengl/EGLContext.html` for the specified `https://developer.android.com/reference/android/opengl/EGLDisplay.html`. |
| `static https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createEglSurface(android.opengl.EGLDisplay,java.lang.Object,int,boolean)( https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, https://developer.android.com/reference/java/lang/Object.html surface, @https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer int colorTransfer, boolean isEncoderInputSurface )` Creates a new `https://developer.android.com/reference/android/opengl/EGLSurface.html` wrapping the specified `surface`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createExternalTexture()()` Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and GL_CLAMP_TO_EDGE wrapping. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFboForTexture(int)(int texId)` Returns a new framebuffer for the texture. |
| `static https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFocusedPlaceholderEglSurface(android.opengl.EGLContext,android.opengl.EGLDisplay)( https://developer.android.com/reference/android/opengl/EGLContext.html eglContext, https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay )` Creates and focuses a placeholder `https://developer.android.com/reference/android/opengl/EGLSurface.html`. |
| `static long` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createGlSyncFence()()` Returns a newly created sync object and inserts it into the GL command stream. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createPixelBufferObject(int)(int size)` Creates a pixel buffer object with a data store of the given size and usage `https://developer.android.com/reference/android/opengl/GLES30.html#GL_DYNAMIC_READ`. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createRgb10A2Texture(int,int)(int width, int height)` Allocates a new `https://developer.android.com/reference/android/opengl/GLES20.html#GL_RGBA``https://developer.android.com/reference/android/opengl/GLES30.html#GL_RGB10_A2` texture with the specified dimensions. |
| `static https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper>` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createSyncFences(int)(int count)` Creates the requested number of native sync fences from the current OpenGL context. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createTexture(android.graphics.Bitmap)(https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Allocates a new texture, initialized with the `https://developer.android.com/reference/android/graphics/Bitmap.html` data and size. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createTexture(int,int,boolean)( int width, int height, boolean useHighPrecisionColorComponents )` Allocates a new RGBA texture with the specified dimensions and color component precision. |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createVertexBuffer(java.util.List<float[]>)(https://developer.android.com/reference/java/util/List.html<float[]> vertexList)` Flattens the list of 4 element NDC coordinate vectors into a buffer. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteBuffer(int)(int bufferId)` Deletes a buffer object, or silently ignores the method call if `bufferId` is unused. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteFbo(int)(int fboId)` Deletes a framebuffer, or silently ignores the method call if `fboId` is unused. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteRbo(int)(int rboId)` Deletes a renderbuffer, or silently ignores the method call if `rboId` is unused. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteSyncObject(long)(long syncObject)` Deletes the underlying native object. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteSyncObjectQuietly(long)(long syncObject)` Releases the GL sync object if set, suppressing any error. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#deleteTexture(int)(int textureId)` Deletes a GL texture. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#destroyEglContext(android.opengl.EGLDisplay,android.opengl.EGLContext)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/opengl/EGLContext.html eglContext )` Destroys the `https://developer.android.com/reference/android/opengl/EGLContext.html` identified by the provided `https://developer.android.com/reference/android/opengl/EGLDisplay.html` and `https://developer.android.com/reference/android/opengl/EGLContext.html`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#destroyEglSurface(android.opengl.EGLDisplay,android.opengl.EGLSurface)( @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, @https://developer.android.com/reference/androidx/annotation/Nullable https://developer.android.com/reference/android/opengl/EGLSurface.html eglSurface )` Destroys the `https://developer.android.com/reference/android/opengl/EGLSurface.html` identified by the provided `https://developer.android.com/reference/android/opengl/EGLDisplay.html` and `https://developer.android.com/reference/android/opengl/EGLSurface.html`. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusEglSurface(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int)( https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, https://developer.android.com/reference/android/opengl/EGLContext.html eglContext, https://developer.android.com/reference/android/opengl/EGLSurface.html eglSurface, int width, int height )` Makes the specified `eglSurface` the render target, using a viewport of `width` by `height` pixels. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebuffer(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int,int)( https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay, https://developer.android.com/reference/android/opengl/EGLContext.html eglContext, https://developer.android.com/reference/android/opengl/EGLSurface.html eglSurface, int framebuffer, int width, int height )` Makes the specified `framebuffer` the render target, using a viewport of `width` by `height` pixels. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebufferUsingCurrentContext(int,int,int)( int framebuffer, int width, int height )` Makes the specified `framebuffer` the render target, using a viewport of `width` by `height` pixels. |
| `static int` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#generateTexture()()` Returns a new, unbound GL texture identifier. |
| `static long` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#getContextMajorVersion()()` Returns the `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_CONTEXT_CLIENT_VERSION` of the current context. |
| `static https://developer.android.com/reference/android/opengl/EGLContext.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#getCurrentContext()()` Gets the current `https://developer.android.com/reference/android/opengl/EGLContext.html`. |
| `static https://developer.android.com/reference/android/opengl/EGLDisplay.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#getDefaultEglDisplay()()` Returns an initialized default `https://developer.android.com/reference/android/opengl/EGLDisplay.html`. |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#getNormalizedCoordinateBounds()()` Bounds of normalized device coordinates, commonly used for defining viewport boundaries. |
| `static float[]` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#getTextureCoordinateBounds()()` Typical bounds used for sampling from textures. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isBt2020HlgExtensionSupported()()` Returns whether `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_COLORSPACE_BT2020_HLG()` is supported. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isBt2020PqExtensionSupported()()` Returns whether `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_COLORSPACE_BT2020_PQ()` is supported. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isColorTransferSupported(int)(@https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer int colorTransfer)` Returns whether the given `https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer` is supported. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isProtectedContentExtensionSupported(android.content.Context)(https://developer.android.com/reference/android/content/Context.html context)` Returns whether creating a GL context with `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_PROTECTED_CONTENT()` is possible. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isSurfacelessContextExtensionSupported()()` Returns whether the `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_SURFACELESS_CONTEXT()` extension is supported. |
| `static boolean` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#isYuvTargetExtensionSupported()()` Returns whether the `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_YUV_TARGET()` extension is supported. |
| `static https://developer.android.com/reference/java/nio/ByteBuffer.html` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#mapPixelBufferObject(int,int)(int bufferId, int size)` Maps the pixel buffer object's data store of a given size and returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` of OpenGL managed memory. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#schedulePixelBufferRead(int,int,int,int)( int readFboId, int width, int height, int bufferId )` Reads pixel data from the `https://developer.android.com/reference/android/opengl/GLES20.html#GL_COLOR_ATTACHMENT0` attachment of a framebuffer into the data store of a pixel buffer object. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#setTexture(int,android.graphics.Bitmap)(int texId, https://developer.android.com/reference/android/graphics/Bitmap.html bitmap)` Sets the `texId` to contain the `https://developer.android.com/reference/android/graphics/Bitmap.html` data and size. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#setToIdentity(float[])(float[] matrix)` Sets the input `matrix` to an identity matrix. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#terminate(android.opengl.EGLDisplay)(https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay)` Terminates the `https://developer.android.com/reference/android/opengl/EGLDisplay.html` connection. |
| `static void` | `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#unmapPixelBufferObject(int)(int bufferId)` Unmaps the pixel buffer object `bufferId`'s data store. |

## Constants

### EGL_CONFIG_ATTRIBUTES_RGBA_1010102

```
public static final int[] EGL_CONFIG_ATTRIBUTES_RGBA_1010102
```

### EGL_CONFIG_ATTRIBUTES_RGBA_8888

```
public static final int[] EGL_CONFIG_ATTRIBUTES_RGBA_8888
```

### GL_FENCE_SYNC_UNSET

```
@ExperimentalApi
public static final long GL_FENCE_SYNC_UNSET = -1
```

Marker value for when no fence sync is set.

### HOMOGENEOUS_COORDINATE_VECTOR_SIZE

```
public static final int HOMOGENEOUS_COORDINATE_VECTOR_SIZE = 4
```

Number of elements in a 3d homogeneous coordinate vector describing a vertex.

### LENGTH_NDC

```
public static final float LENGTH_NDC = 2.0f
```

Length of the normalized device coordinate (NDC) space, which spans from -1 to 1.

## Public methods

### awaitSyncObject

```
public static void awaitSyncObject(long syncObject)
```

Ensures that following commands on the current OpenGL context will not be executed until the sync point has been reached. If `syncObject` equals `#GL_FENCE_SYNC_UNSET`, this is a no-op. This method does not block the CPU.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### bindTexture

```
public static void bindTexture(int textureTarget, int texId, int sampleFilter)
```

Binds the texture of the given type with the specified MIN and MAG sampling filter and GL_CLAMP_TO_EDGE wrapping.

| Parameters |
|---|---|
| `int textureTarget` | The target to which the texture is bound, e.g. `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_2D` for a two-dimensional texture or `https://developer.android.com/reference/android/opengl/GLES11Ext.html#GL_TEXTURE_EXTERNAL_OES` for an external texture. |
| `int texId` | The texture identifier. |
| `int sampleFilter` | The texture sample filter for both `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_MAG_FILTER` and `https://developer.android.com/reference/android/opengl/GLES20.html#GL_TEXTURE_MIN_FILTER`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### blitFrameBuffer

```
public static void blitFrameBuffer(
    int readFboId,
    GlRect readRect,
    int drawFboId,
    GlRect drawRect
)
```

Copies the pixels from `readFboId` into `drawFboId`. Requires OpenGL ES 3.0.

When the input pixel region (given by `readRect`) doesn't have the same size as the output region (given by `drawRect`), this method uses `https://developer.android.com/reference/android/opengl/GLES20.html#GL_LINEAR` filtering to scale the image contents.

| Parameters |
|---|---|
| `int readFboId` | The framebuffer object to read from. |
| `https://developer.android.com/reference/androidx/media3/common/util/GlRect readRect` | The rectangular region of `readFboId` to read from. |
| `int drawFboId` | The framebuffer object to draw into. |
| `https://developer.android.com/reference/androidx/media3/common/util/GlRect drawRect` | The rectangular region of `drawFboId` to draw into. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### checkEglException

```
public static void checkEglException(String errorMessage)
```

Collects EGL errors that occurred in the last called EGL function and throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the combined error code.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### checkGlError

```
public static void checkGlError()
```

Collects all OpenGL errors that occurred since this method was last called and throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the combined error message.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### checkGlException

```
public static void checkGlException(boolean expression, String errorMessage)
```

Throws a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` with the given message if `expression` evaluates to `
false`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### clearFocusedBuffers

```
public static void clearFocusedBuffers()
```

Fills the pixels in the current output render target buffers with (r=0, g=0, b=0, a=0).

Buffers can be focused using `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusEglSurface(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int)` and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebufferUsingCurrentContext(int,int,int)`, `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebuffer(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int,int)`, and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFocusedPlaceholderEglSurface(android.opengl.EGLContext,android.opengl.EGLDisplay)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### clearFocusedBuffersOpaque

```
public static void clearFocusedBuffersOpaque()
```

Fills the pixels in the current output render target buffers with (r=0, g=0, b=0, a=1).

Buffers can be focused using `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusEglSurface(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int)` and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebufferUsingCurrentContext(int,int,int)`, `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebuffer(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int,int)`, and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFocusedPlaceholderEglSurface(android.opengl.EGLContext,android.opengl.EGLDisplay)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### create4x4IdentityMatrix

```
public static float[] create4x4IdentityMatrix()
```

Creates a 4x4 identity matrix.

### createBuffer

```
public static FloatBuffer createBuffer(float[] data)
```

Allocates a FloatBuffer with the given data.

| Parameters |
|---|---|
| `float[] data` | Used to initialize the new buffer. |

### createEglContext

```
public static EGLContext createEglContext(EGLDisplay eglDisplay)
```

Creates a new `https://developer.android.com/reference/android/opengl/EGLContext.html` for the specified `https://developer.android.com/reference/android/opengl/EGLDisplay.html`.

Configures the `https://developer.android.com/reference/android/opengl/EGLContext.html` with `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_8888()` and OpenGL ES 2.0.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay` | The `https://developer.android.com/reference/android/opengl/EGLDisplay.html` to create an `https://developer.android.com/reference/android/opengl/EGLContext.html` for. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createEglContext

```
public static EGLContext createEglContext(
    EGLContext sharedContext,
    EGLDisplay eglDisplay,
    @IntRange(from = 2, to = 3) int openGlVersion,
    int[] configAttributes
)
```

Creates a new `https://developer.android.com/reference/android/opengl/EGLContext.html` for the specified `https://developer.android.com/reference/android/opengl/EGLDisplay.html`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLContext.html sharedContext` | The `https://developer.android.com/reference/android/opengl/EGLContext.html` with which to share data. |
| `https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay` | The `https://developer.android.com/reference/android/opengl/EGLDisplay.html` to create an `https://developer.android.com/reference/android/opengl/EGLContext.html` for. |
| `@https://developer.android.com/reference/androidx/annotation/IntRange(from = 2, to = 3) int openGlVersion` | The version of OpenGL ES to configure. Accepts either `2`, for OpenGL ES 2.0, or `3`, for OpenGL ES 3.0. |
| `int[] configAttributes` | The attributes to configure EGL with. Accepts either `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_1010102()`, or `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_8888()`. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createEglSurface

```
public static EGLSurface createEglSurface(
    EGLDisplay eglDisplay,
    Object surface,
    @C.ColorTransfer int colorTransfer,
    boolean isEncoderInputSurface
)
```

Creates a new `https://developer.android.com/reference/android/opengl/EGLSurface.html` wrapping the specified `surface`.

The `https://developer.android.com/reference/android/opengl/EGLSurface.html` will configure with OpenGL ES 2.0.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay` | The `https://developer.android.com/reference/android/opengl/EGLDisplay.html` to attach the surface to. |
| `https://developer.android.com/reference/java/lang/Object.html surface` | The surface to wrap; must be a surface, surface texture or surface holder. |
| `@https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer int colorTransfer` | The `https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer` to which the `surface` is configured. The only accepted values are `https://developer.android.com/reference/androidx/media3/common/C#COLOR_TRANSFER_SDR()`, `https://developer.android.com/reference/androidx/media3/common/C#COLOR_TRANSFER_GAMMA_2_2()`, `https://developer.android.com/reference/androidx/media3/common/C#COLOR_TRANSFER_SRGB()`, `https://developer.android.com/reference/androidx/media3/common/C#COLOR_TRANSFER_HLG()`, and `https://developer.android.com/reference/androidx/media3/common/C#COLOR_TRANSFER_ST2084()`. Value is one of the following: - `Format.NO_VALUE` <br /> |
| `boolean isEncoderInputSurface` | Whether the `surface` is the input surface of an encoder. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createExternalTexture

```
public static int createExternalTexture()
```

Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and GL_CLAMP_TO_EDGE wrapping.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createFboForTexture

```
public static int createFboForTexture(int texId)
```

Returns a new framebuffer for the texture.

| Parameters |
|---|---|
| `int texId` | The identifier of the texture to attach to the framebuffer. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createFocusedPlaceholderEglSurface

```
public static EGLSurface createFocusedPlaceholderEglSurface(
    EGLContext eglContext,
    EGLDisplay eglDisplay
)
```

Creates and focuses a placeholder `https://developer.android.com/reference/android/opengl/EGLSurface.html`.

This makes a `https://developer.android.com/reference/android/opengl/EGLContext.html` current when reading and writing to a surface is not required, configured with `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EGL_CONFIG_ATTRIBUTES_RGBA_8888()`.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLContext.html eglContext` | The `https://developer.android.com/reference/android/opengl/EGLContext.html` to make current. |
| `https://developer.android.com/reference/android/opengl/EGLDisplay.html eglDisplay` | The `https://developer.android.com/reference/android/opengl/EGLDisplay.html` to attach the surface to. |

| Returns |
|---|---|
| `https://developer.android.com/reference/android/opengl/EGLSurface.html` | `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_NO_SURFACE` if supported and a 1x1 pixel buffer surface otherwise. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createGlSyncFence

```
public static long createGlSyncFence()
```

Returns a newly created sync object and inserts it into the GL command stream.

Returns `0` if the operation failed, no `https://developer.android.com/reference/android/opengl/EGLContext.html``https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFocusedPlaceholderEglSurface(android.opengl.EGLContext,android.opengl.EGLDisplay)`, or the focused `https://developer.android.com/reference/android/opengl/EGLContext.html` version is less than 3.0.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createPixelBufferObject

```
public static int createPixelBufferObject(int size)
```

Creates a pixel buffer object with a data store of the given size and usage `https://developer.android.com/reference/android/opengl/GLES30.html#GL_DYNAMIC_READ`.

The buffer is suitable for repeated modification by OpenGL and reads by the application.

| Parameters |
|---|---|
| `int size` | The size of the buffer object's data store. |

| Returns |
|---|---|
| `int` | The pixel buffer object. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### createRgb10A2Texture

```
public static int createRgb10A2Texture(int width, int height)
```

Allocates a new `https://developer.android.com/reference/android/opengl/GLES20.html#GL_RGBA``https://developer.android.com/reference/android/opengl/GLES30.html#GL_RGB10_A2` texture with the specified dimensions.

Normalized integers in textures are automatically converted for floating point numbers https://www.khronos.org/opengl/wiki/Normalized_Integer

The only supported pixel data type for the `https://developer.android.com/reference/android/opengl/GLES30.html#GL_RGB10_A2` sized internal format is `https://developer.android.com/reference/android/opengl/GLES30.html#GL_UNSIGNED_INT_2_10_10_10_REV`. See https://registry.khronos.org/OpenGL-Refpages/es3.0/html/glTexImage2D.xhtml

The created texture is not zero-initialized. To clear the texture, `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebuffer(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int,int)` on the texture and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#clearFocusedBuffers()` its content.

| Parameters |
|---|---|
| `int width` | The width of the new texture in pixels. |
| `int height` | The height of the new texture in pixels. |

| Returns |
|---|---|
| `int` | The texture identifier for the newly-allocated texture. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` | If the texture allocation fails. |

### createSyncFences

```
public static ImmutableList<SyncFenceWrapper> createSyncFences(int count)
```

Creates the requested number of native sync fences from the current OpenGL context.

Inserts a sync fence command into the GL command stream. The returned sync fences will signal when the GPU reaches the fence command in the stream - meaning all OpenGL operations enqueued on the current context before this call have completed execution on the GPU.

Must be called on the thread that owns the current OpenGL context.

| Parameters |
|---|---|
| `int count` | The number of fences to generate. |

| Returns |
|---|---|
| `https://guava.dev/releases/snapshot-android/api/docs/com/google/common/collect/ImmutableList.html<https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper>` | A list of `https://developer.android.com/reference/androidx/media3/common/video/SyncFenceWrapper` instances, or an empty list if native sync fences are unsupported on this device or the API level is less than 33. If an empty list is returned, `glFinish()` is called to ensure synchronization. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` | If creating or duplicating the sync fence fails. |

### createTexture

```
public static int createTexture(Bitmap bitmap)
```

Allocates a new texture, initialized with the `https://developer.android.com/reference/android/graphics/Bitmap.html` data and size.

| Parameters |
|---|---|
| `https://developer.android.com/reference/android/graphics/Bitmap.html bitmap` | The `https://developer.android.com/reference/android/graphics/Bitmap.html` for which the texture is created. |

| Returns |
|---|---|
| `int` | The texture identifier for the newly-allocated texture. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` | If the texture allocation fails. |

### createTexture

```
public static int createTexture(
    int width,
    int height,
    boolean useHighPrecisionColorComponents
)
```

Allocates a new RGBA texture with the specified dimensions and color component precision.

The created texture is not zero-initialized. To clear the texture, `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#focusFramebuffer(android.opengl.EGLDisplay,android.opengl.EGLContext,android.opengl.EGLSurface,int,int,int)` on the texture and `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#clearFocusedBuffers()` its content.

| Parameters |
|---|---|
| `int width` | The width of the new texture in pixels. |
| `int height` | The height of the new texture in pixels. |
| `boolean useHighPrecisionColorComponents` | If `false`, uses colors with 8-bit unsigned bytes. If `true`, use 16-bit (half-precision) floating-point. |

| Returns |
|---|---|
| `int` | The texture identifier for the newly-allocated texture. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` | If the texture allocation fails. |

### createVertexBuffer

```
public static float[] createVertexBuffer(List<float[]> vertexList)
```

Flattens the list of 4 element NDC coordinate vectors into a buffer.

### deleteBuffer

```
public static void deleteBuffer(int bufferId)
```

Deletes a buffer object, or silently ignores the method call if `bufferId` is unused.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### deleteFbo

```
public static void deleteFbo(int fboId)
```

Deletes a framebuffer, or silently ignores the method call if `fboId` is unused.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### deleteRbo

```
public static void deleteRbo(int rboId)
```

Deletes a renderbuffer, or silently ignores the method call if `rboId` is unused.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### deleteSyncObject

```
public static void deleteSyncObject(long syncObject)
```

Deletes the underlying native object.

The `syncObject` must not be used after deletion.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### deleteSyncObjectQuietly

```
public static void deleteSyncObjectQuietly(long syncObject)
```

Releases the GL sync object if set, suppressing any error.

### deleteTexture

```
public static void deleteTexture(int textureId)
```

Deletes a GL texture.

| Parameters |
|---|---|
| `int textureId` | The ID of the texture to delete. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### destroyEglContext

```
public static void destroyEglContext(
    @Nullable EGLDisplay eglDisplay,
    @Nullable EGLContext eglContext
)
```

Destroys the `https://developer.android.com/reference/android/opengl/EGLContext.html` identified by the provided `https://developer.android.com/reference/android/opengl/EGLDisplay.html` and `https://developer.android.com/reference/android/opengl/EGLContext.html`.

This is a no-op if called on already-destroyed `https://developer.android.com/reference/android/opengl/EGLDisplay.html` and `https://developer.android.com/reference/android/opengl/EGLContext.html` instances.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### destroyEglSurface

```
public static void destroyEglSurface(
    @Nullable EGLDisplay eglDisplay,
    @Nullable EGLSurface eglSurface
)
```

Destroys the `https://developer.android.com/reference/android/opengl/EGLSurface.html` identified by the provided `https://developer.android.com/reference/android/opengl/EGLDisplay.html` and `https://developer.android.com/reference/android/opengl/EGLSurface.html`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### focusEglSurface

```
public static void focusEglSurface(
    EGLDisplay eglDisplay,
    EGLContext eglContext,
    EGLSurface eglSurface,
    int width,
    int height
)
```

Makes the specified `eglSurface` the render target, using a viewport of `width` by `height` pixels.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### focusFramebuffer

```
public static void focusFramebuffer(
    EGLDisplay eglDisplay,
    EGLContext eglContext,
    EGLSurface eglSurface,
    int framebuffer,
    int width,
    int height
)
```

Makes the specified `framebuffer` the render target, using a viewport of `width` by `height` pixels.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### focusFramebufferUsingCurrentContext

```
public static void focusFramebufferUsingCurrentContext(
    int framebuffer,
    int width,
    int height
)
```

Makes the specified `framebuffer` the render target, using a viewport of `width` by `height` pixels.

The caller must ensure that there is a current OpenGL context before calling this method.

| Parameters |
|---|---|
| `int framebuffer` | The identifier of the framebuffer object to bind as the output render target. |
| `int width` | The viewport width, in pixels. |
| `int height` | The viewport height, in pixels. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### generateTexture

```
public static int generateTexture()
```

Returns a new, unbound GL texture identifier.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### getContextMajorVersion

```
public static long getContextMajorVersion()
```

Returns the `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_CONTEXT_CLIENT_VERSION` of the current context.

Returns `0` if no `https://developer.android.com/reference/android/opengl/EGLContext.html``https://developer.android.com/reference/androidx/media3/common/util/GlUtil#createFocusedPlaceholderEglSurface(android.opengl.EGLContext,android.opengl.EGLDisplay)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### getCurrentContext

```
public static EGLContext getCurrentContext()
```

Gets the current `https://developer.android.com/reference/android/opengl/EGLContext.html`.

### getDefaultEglDisplay

```
public static EGLDisplay getDefaultEglDisplay()
```

Returns an initialized default `https://developer.android.com/reference/android/opengl/EGLDisplay.html`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### getNormalizedCoordinateBounds

```
public static float[] getNormalizedCoordinateBounds()
```

Bounds of normalized device coordinates, commonly used for defining viewport boundaries.

### getTextureCoordinateBounds

```
public static float[] getTextureCoordinateBounds()
```

Typical bounds used for sampling from textures.

### isBt2020HlgExtensionSupported

```
public static boolean isBt2020HlgExtensionSupported()
```

Returns whether `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_COLORSPACE_BT2020_HLG()` is supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### isBt2020PqExtensionSupported

```
public static boolean isBt2020PqExtensionSupported()
```

Returns whether `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_COLORSPACE_BT2020_PQ()` is supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### isColorTransferSupported

```
public static boolean isColorTransferSupported(@C.ColorTransfer int colorTransfer)
```

Returns whether the given `https://developer.android.com/reference/androidx/media3/common/C.ColorTransfer` is supported.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### isProtectedContentExtensionSupported

```
public static boolean isProtectedContentExtensionSupported(Context context)
```

Returns whether creating a GL context with `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_PROTECTED_CONTENT()` is possible.

If `true`, the device supports a protected output path for DRM content when using GL.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### isSurfacelessContextExtensionSupported

```
public static boolean isSurfacelessContextExtensionSupported()
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_SURFACELESS_CONTEXT()` extension is supported.

This extension allows passing `https://developer.android.com/reference/android/opengl/EGL14.html#EGL_NO_SURFACE` for both the write and read surfaces in a call to `https://developer.android.com/reference/android/opengl/EGL14.html#eglMakeCurrent(android.opengl.EGLDisplay, android.opengl.EGLSurface, android.opengl.EGLSurface, android.opengl.EGLContext)`.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### isYuvTargetExtensionSupported

```
public static boolean isYuvTargetExtensionSupported()
```

Returns whether the `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#EXTENSION_YUV_TARGET()` extension is supported.

This extension allows sampling raw YUV values from an external texture, which is required for HDR input.

### mapPixelBufferObject

```
public static ByteBuffer mapPixelBufferObject(int bufferId, int size)
```

Maps the pixel buffer object's data store of a given size and returns a `https://developer.android.com/reference/java/nio/ByteBuffer.html` of OpenGL managed memory.

The application must not write into the returned `https://developer.android.com/reference/java/nio/ByteBuffer.html`.

The pixel buffer object should have a `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#schedulePixelBufferRead(int,int,int,int)`.

When the application no longer needs to access the returned buffer, call `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#unmapPixelBufferObject(int)`.

This call blocks until the pixel buffer data from the last `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#schedulePixelBufferRead(int,int,int,int)` call is available.

| Parameters |
|---|---|
| `int bufferId` | The pixel buffer object. |
| `int size` | The size of the pixel buffer object's data store to be mapped. |

| Returns |
|---|---|
| `https://developer.android.com/reference/java/nio/ByteBuffer.html` | The `https://developer.android.com/reference/java/nio/ByteBuffer.html` that holds pixel data. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### schedulePixelBufferRead

```
public static void schedulePixelBufferRead(
    int readFboId,
    int width,
    int height,
    int bufferId
)
```

Reads pixel data from the `https://developer.android.com/reference/android/opengl/GLES20.html#GL_COLOR_ATTACHMENT0` attachment of a framebuffer into the data store of a pixel buffer object.

The texture backing the color attachment of `readFboId` and the buffer store of `
bufferId` must hold an image of the given `width` and `height` with format `https://developer.android.com/reference/android/opengl/GLES20.html#GL_RGBA` and type `https://developer.android.com/reference/android/opengl/GLES20.html#GL_UNSIGNED_BYTE`.

This a non-blocking call which reads the data asynchronously.

HDR support is not yet implemented.

| Parameters |
|---|---|
| `int readFboId` | The framebuffer that holds pixel data. |
| `int width` | The image width. |
| `int height` | The image height. |
| `int bufferId` | The pixel buffer object to read into. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### setTexture

```
public static void setTexture(int texId, Bitmap bitmap)
```

Sets the `texId` to contain the `https://developer.android.com/reference/android/graphics/Bitmap.html` data and size.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### setToIdentity

```
public static void setToIdentity(float[] matrix)
```

Sets the input `matrix` to an identity matrix.

### terminate

```
public static void terminate(EGLDisplay eglDisplay)
```

Terminates the `https://developer.android.com/reference/android/opengl/EGLDisplay.html` connection.

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |

### unmapPixelBufferObject

```
public static void unmapPixelBufferObject(int bufferId)
```

Unmaps the pixel buffer object `bufferId`'s data store.

The pixel buffer object should be previously `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#mapPixelBufferObject(int,int)`.

After this method returns, accessing data inside a previously `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#mapPixelBufferObject(int,int)``https://developer.android.com/reference/java/nio/ByteBuffer.html` results in undefined behaviour.

When this method returns, the pixel buffer object `bufferId` can be reused by `https://developer.android.com/reference/androidx/media3/common/util/GlUtil#schedulePixelBufferRead(int,int,int,int)`.

| Parameters |
|---|---|
| `int bufferId` | The pixel buffer object. |

| Throws |
|---|---|
| `https://developer.android.com/reference/androidx/media3/common/util/GlUtil.GlException` |   |