Class GlUtil
- java.lang.Object
-
- com.google.android.exoplayer2.util.GlUtil
-
public final class GlUtil extends Object
GL utilities.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
GlUtil.Attribute
GL attribute, which can be attached to a buffer withGlUtil.Attribute.setBuffer(float[], int)
.static class
GlUtil.GlException
Thrown when an OpenGL error occurs andglAssertionsEnabled
istrue
.static class
GlUtil.Program
GL program.static class
GlUtil.Uniform
GL uniform, which can be attached to a sampler usingGlUtil.Uniform.setSamplerTexId(int, int)
.static class
GlUtil.UnsupportedEglVersionException
Thrown when the required EGL version is not supported by the device.
-
Field Summary
Fields Modifier and Type Field Description static boolean
glAssertionsEnabled
Whether to throw aGlUtil.GlException
in case of an OpenGL error.static int
TEXTURE_ID_UNSET
Represents an unset texture ID.
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static void
checkGlError()
If there is an OpenGl error, logs the error and ifglAssertionsEnabled
is true throws aGlUtil.GlException
.static FloatBuffer
createBuffer(float[] data)
Allocates a FloatBuffer with the given data.static FloatBuffer
createBuffer(int capacity)
Allocates a FloatBuffer.static EGLContext
createEglContext(EGLDisplay eglDisplay)
Returns a newEGLContext
for the specifiedEGLDisplay
.static EGLDisplay
createEglDisplay()
Returns an initialized defaultEGLDisplay
.static int
createExternalTexture()
Creates a GL_TEXTURE_EXTERNAL_OES with default configuration of GL_LINEAR filtering and GL_CLAMP_TO_EDGE wrapping.static void
deleteTexture(int textureId)
Deletes a GL texture.static void
destroyEglContext(EGLDisplay eglDisplay, EGLContext eglContext)
static void
focusSurface(EGLDisplay eglDisplay, EGLContext eglContext, EGLSurface surface, int width, int height)
Makes the specifiedsurface
the render target, using a viewport ofwidth
byheight
pixels.static EGLSurface
getEglSurface(EGLDisplay eglDisplay, Object surface)
Returns a newEGLSurface
wrapping the specifiedsurface
.static boolean
isProtectedContentExtensionSupported(Context context)
Returns whether creating a GL context with "EGL_EXT_protected_content" is possible.static boolean
isSurfacelessContextExtensionSupported()
Returns whether creating a GL context with "EGL_KHR_surfaceless_context" is possible.static String
loadAsset(Context context, String assetPath)
Loads a file from the assets folder.
-
-
-
Field Detail
-
TEXTURE_ID_UNSET
public static final int TEXTURE_ID_UNSET
Represents an unset texture ID.- See Also:
- Constant Field Values
-
glAssertionsEnabled
public static boolean glAssertionsEnabled
Whether to throw aGlUtil.GlException
in case of an OpenGL error.
-
-
Method Detail
-
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) throws GlUtil.UnsupportedEglVersionException
Returns a newEGLContext
for the specifiedEGLDisplay
.- Throws:
GlUtil.UnsupportedEglVersionException
- If the device does not support EGL version 2.eglDisplay
is terminated before the exception is thrown in this case.
-
getEglSurface
@RequiresApi(17) public static EGLSurface getEglSurface(EGLDisplay eglDisplay, Object surface)
Returns a newEGLSurface
wrapping the specifiedsurface
.- Parameters:
eglDisplay
- TheEGLDisplay
to 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 ifglAssertionsEnabled
is true throws aGlUtil.GlException
.
-
focusSurface
@RequiresApi(17) public static void focusSurface(EGLDisplay eglDisplay, EGLContext eglContext, EGLSurface surface, int width, int height)
Makes the specifiedsurface
the render target, using a viewport ofwidth
byheight
pixels.
-
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.
-
-