Class GlUtil
- java.lang.Object
-
- com.google.android.exoplayer2.util.GlUtil
-
public final class GlUtil extends Object
OpenGL ES utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classGlUtil.GlExceptionThrown when an OpenGL error occurs andglAssertionsEnabledistrue.static classGlUtil.ProgramRepresents a GLSL shader program.
-
Field Summary
Fields Modifier and Type Field Description static booleanglAssertionsEnabledWhether to throw aGlUtil.GlExceptionin case of an OpenGL error.static intRECTANGLE_VERTICES_COUNTNumber of vertices in a rectangle.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidcheckGlError()If there is an OpenGl error, logs the error and ifglAssertionsEnabledis true throws aGlUtil.GlException.static FloatBuffercreateBuffer(float[] data)Allocates a FloatBuffer with the given data.static FloatBuffercreateBuffer(int capacity)Allocates a FloatBuffer.static EGLContextcreateEglContext(EGLDisplay eglDisplay)Returns a newEGLContextfor the specifiedEGLDisplay.static EGLContextcreateEglContextEs3Rgba1010102(EGLDisplay eglDisplay)Returns a newEGLContextfor the specifiedEGLDisplay, requesting ES 3 and an RGBA 1010102 config.static EGLDisplaycreateEglDisplay()Returns an initialized defaultEGLDisplay.static intcreateExternalTexture()Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and GL_CLAMP_TO_EDGE wrapping.static voiddeleteTexture(int textureId)Deletes a GL texture.static voiddestroyEglContext(EGLDisplay eglDisplay, EGLContext eglContext)static voidfocusSurface(EGLDisplay eglDisplay, EGLContext eglContext, EGLSurface surface, int width, int height)Makes the specifiedsurfacethe render target, using a viewport ofwidthbyheightpixels.static EGLSurfacegetEglSurface(EGLDisplay eglDisplay, Object surface)Returns a newEGLSurfacewrapping the specifiedsurface.static EGLSurfacegetEglSurfaceBt2020Pq(EGLDisplay eglDisplay, Object surface)Returns a newEGLSurfacewrapping the specifiedsurface, for HDR rendering with Rec.static float[]getNormalizedCoordinateBounds()Bounds of normalized device coordinates, commonly used for defining viewport boundaries.static float[]getTextureCoordinateBounds()Typical bounds used for sampling from textures.static booleanisProtectedContentExtensionSupported(Context context)Returns whether creating a GL context with "EGL_EXT_protected_content" is possible.static booleanisSurfacelessContextExtensionSupported()Returns whether creating a GL context with "EGL_KHR_surfaceless_context" is possible.static StringloadAsset(Context context, String assetPath)Loads a file from the assets folder.
-
-
-
Field Detail
-
glAssertionsEnabled
public static boolean glAssertionsEnabled
Whether to throw aGlUtil.GlExceptionin case of an OpenGL error.
-
RECTANGLE_VERTICES_COUNT
public static final int RECTANGLE_VERTICES_COUNT
Number of vertices in a rectangle.- See Also:
- Constant Field Values
-
-
Method Detail
-
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.
-
isProtectedContentExtensionSupported
public static boolean isProtectedContentExtensionSupported(Context context)
Returns whether creating a GL context with "EGL_EXT_protected_content" is possible. Iftrue, the device supports a protected output path for DRM content when using GL.
-
isSurfacelessContextExtensionSupported
public static boolean isSurfacelessContextExtensionSupported()
Returns whether creating a GL context with "EGL_KHR_surfaceless_context" is possible.
-
createEglDisplay
@RequiresApi(17) public static EGLDisplay createEglDisplay()
Returns an initialized defaultEGLDisplay.
-
createEglContext
@RequiresApi(17) public static EGLContext createEglContext(EGLDisplay eglDisplay)
Returns a newEGLContextfor the specifiedEGLDisplay.
-
createEglContextEs3Rgba1010102
@RequiresApi(17) public static EGLContext createEglContextEs3Rgba1010102(EGLDisplay eglDisplay)
Returns a newEGLContextfor the specifiedEGLDisplay, requesting ES 3 and an RGBA 1010102 config.
-
getEglSurface
@RequiresApi(17) public static EGLSurface getEglSurface(EGLDisplay eglDisplay, Object surface)
Returns a newEGLSurfacewrapping the specifiedsurface.- Parameters:
eglDisplay- TheEGLDisplayto attach the surface to.surface- The surface to wrap; must be a surface, surface texture or surface holder.
-
getEglSurfaceBt2020Pq
@RequiresApi(17) public static EGLSurface getEglSurfaceBt2020Pq(EGLDisplay eglDisplay, Object surface)
Returns a newEGLSurfacewrapping the specifiedsurface, for HDR rendering with Rec. 2020 color primaries and using the PQ transfer function.- Parameters:
eglDisplay- TheEGLDisplayto attach the surface to.surface- The surface to wrap; must be a surface, surface texture or surface holder.
-
checkGlError
public static void checkGlError()
If there is an OpenGl error, logs the error and ifglAssertionsEnabledis true throws aGlUtil.GlException.
-
focusSurface
@RequiresApi(17) public static void focusSurface(EGLDisplay eglDisplay, EGLContext eglContext, EGLSurface surface, int width, int height)
Makes the specifiedsurfacethe render target, using a viewport ofwidthbyheightpixels.
-
deleteTexture
public static void deleteTexture(int textureId)
Deletes a GL texture.- Parameters:
textureId- The ID of the texture to delete.
-
destroyEglContext
@RequiresApi(17) public static void destroyEglContext(@Nullable EGLDisplay eglDisplay, @Nullable EGLContext eglContext)
-
createBuffer
public static FloatBuffer createBuffer(float[] data)
Allocates a FloatBuffer with the given data.- Parameters:
data- Used to initialize the new buffer.
-
createBuffer
public static FloatBuffer createBuffer(int capacity)
Allocates a FloatBuffer.- Parameters:
capacity- The new buffer's capacity, in floats.
-
loadAsset
public static String loadAsset(Context context, String assetPath) throws IOException
Loads a file from the assets folder.- Parameters:
context- TheContext.assetPath- The path to the file to load, from the assets folder.- Returns:
- The content of the file to load.
- Throws:
IOException- If the file couldn't be read.
-
createExternalTexture
public static int createExternalTexture()
Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and GL_CLAMP_TO_EDGE wrapping.
-
-