public class

GLTextureView

extends TextureView
java.lang.Object
   ↳ TextureView
     ↳ com.carto.ui.GLTextureView
Known Direct Subclasses

Class Overview

GLTextureView is a wrapper for TextureView class that emulates GLSurfaceView API.

Summary

Constants
int DEBUG_CHECK_GL_ERROR Check glError() after every GL call and throw an exception if glError indicates that an error has occurred.
int DEBUG_LOG_GL_CALLS Log GL calls to the system log at "verbose" level with tag "GLTextureView".
int RENDERMODE_CONTINUOUSLY The renderer is called continuously to re-render the scene.
int RENDERMODE_WHEN_DIRTY The renderer only renders when the surface is created, or when requestRender() is called.
Public Constructors
GLTextureView(Context context)
Standard View constructor.
GLTextureView(Context context, AttributeSet attrs)
Standard View constructor.
Public Methods
void addSurfaceTextureListener(SurfaceTextureListener listener)
int getDebugFlags()
Get the current value of the debug flags.
boolean getPreserveEGLContextOnPause()
int getRenderMode()
Get the current rendering mode.
void onLayoutChange(View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)
void onPause()
Inform the view that the activity is paused.
void onResume()
Inform the view that the activity is resumed.
void onSurfaceTextureAvailable(SurfaceTexture surface, int width, int height)
boolean onSurfaceTextureDestroyed(SurfaceTexture surface)
void onSurfaceTextureSizeChanged(SurfaceTexture surface, int width, int height)
void onSurfaceTextureUpdated(SurfaceTexture surface)
void queueEvent(Runnable r)
Queue a runnable to be run on the GL rendering thread.
void requestRender()
Request that the renderer render a frame.
void setDebugFlags(int debugFlags)
Set the debug flags to a new value.
void setEGLConfigChooser(boolean needDepth)
Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth buffer as close to 16-bits as possible.
void setEGLConfigChooser(GLSurfaceView.EGLConfigChooser configChooser)
Install a custom EGLConfigChooser.
void setEGLConfigChooser(int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)
Install a config chooser which will choose a config with at least the specified depthSize and stencilSize, and exactly the specified redSize, greenSize, blueSize and alphaSize.
void setEGLContextClientVersion(int version)
Inform the default EGLContextFactory and default EGLConfigChooser which EGLContext client version to pick.
void setEGLContextFactory(GLSurfaceView.EGLContextFactory factory)
Install a custom EGLContextFactory.
void setEGLWindowSurfaceFactory(GLSurfaceView.EGLWindowSurfaceFactory factory)
Install a custom EGLWindowSurfaceFactory.
void setGLWrapper(GLSurfaceView.GLWrapper glWrapper)
Set the glWrapper.
void setPreserveEGLContextOnPause(boolean preserveOnPause)
Control whether the EGL context is preserved when the GLTextureView is paused and resumed.
void setRenderMode(int renderMode)
Set the rendering mode.
void setRenderer(GLSurfaceView.Renderer renderer)
Set the renderer associated with this view.
void surfaceChanged(SurfaceTexture texture, int format, int w, int h)
This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.
void surfaceCreated(SurfaceTexture texture)
This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.
void surfaceDestroyed(SurfaceTexture texture)
This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.
[Expand]
Inherited Methods
From class java.lang.Object

Constants

public static final int DEBUG_CHECK_GL_ERROR

Check glError() after every GL call and throw an exception if glError indicates that an error has occurred. This can be used to help track down which OpenGL ES call is causing an error.

Constant Value: 1 (0x00000001)

public static final int DEBUG_LOG_GL_CALLS

Log GL calls to the system log at "verbose" level with tag "GLTextureView".

Constant Value: 2 (0x00000002)

public static final int RENDERMODE_CONTINUOUSLY

The renderer is called continuously to re-render the scene.

Constant Value: 1 (0x00000001)

public static final int RENDERMODE_WHEN_DIRTY

The renderer only renders when the surface is created, or when requestRender() is called.

Constant Value: 0 (0x00000000)

Public Constructors

public GLTextureView (Context context)

Standard View constructor. In order to render something, you must call setRenderer(GLSurfaceView.Renderer) to register a renderer.

public GLTextureView (Context context, AttributeSet attrs)

Standard View constructor. In order to render something, you must call setRenderer(GLSurfaceView.Renderer) to register a renderer.

Public Methods

public void addSurfaceTextureListener (SurfaceTextureListener listener)

public int getDebugFlags ()

Get the current value of the debug flags.

Returns
  • the current value of the debug flags.

public boolean getPreserveEGLContextOnPause ()

Returns
  • true if the EGL context will be preserved when paused

public int getRenderMode ()

Get the current rendering mode. May be called from any thread. Must not be called before a renderer has been set.

Returns
  • the current rendering mode.

public void onLayoutChange (View v, int left, int top, int right, int bottom, int oldLeft, int oldTop, int oldRight, int oldBottom)

public void onPause ()

Inform the view that the activity is paused. The owner of this view must call this method when the activity is paused. Calling this method will pause the rendering thread. Must not be called before a renderer has been set.

public void onResume ()

Inform the view that the activity is resumed. The owner of this view must call this method when the activity is resumed. Calling this method will recreate the OpenGL display and resume the rendering thread. Must not be called before a renderer has been set.

public void onSurfaceTextureAvailable (SurfaceTexture surface, int width, int height)

public boolean onSurfaceTextureDestroyed (SurfaceTexture surface)

public void onSurfaceTextureSizeChanged (SurfaceTexture surface, int width, int height)

public void onSurfaceTextureUpdated (SurfaceTexture surface)

public void queueEvent (Runnable r)

Queue a runnable to be run on the GL rendering thread. This can be used to communicate with the Renderer on the rendering thread. Must not be called before a renderer has been set.

Parameters
r the runnable to be run on the GL rendering thread.

public void requestRender ()

Request that the renderer render a frame. This method is typically used when the render mode has been set to RENDERMODE_WHEN_DIRTY, so that frames are only rendered on demand. May be called from any thread. Must not be called before a renderer has been set.

public void setDebugFlags (int debugFlags)

Set the debug flags to a new value. The value is constructed by OR-together zero or more of the DEBUG_CHECK_* constants. The debug flags take effect whenever a surface is created. The default value is zero.

Parameters
debugFlags the new debug flags

public void setEGLConfigChooser (boolean needDepth)

Install a config chooser which will choose a config as close to 16-bit RGB as possible, with or without an optional depth buffer as close to 16-bits as possible.

If this method is called, it must be called before setRenderer(Renderer) is called.

If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.

public void setEGLConfigChooser (GLSurfaceView.EGLConfigChooser configChooser)

Install a custom EGLConfigChooser.

If this method is called, it must be called before setRenderer(Renderer) is called.

If no setEGLConfigChooser method is called, then by default the view will choose an EGLConfig that is compatible with the current android.view.Surface, with a depth buffer depth of at least 16 bits.

public void setEGLConfigChooser (int redSize, int greenSize, int blueSize, int alphaSize, int depthSize, int stencilSize)

Install a config chooser which will choose a config with at least the specified depthSize and stencilSize, and exactly the specified redSize, greenSize, blueSize and alphaSize.

If this method is called, it must be called before setRenderer(Renderer) is called.

If no setEGLConfigChooser method is called, then by default the view will choose an RGB_888 surface with a depth buffer depth of at least 16 bits.

public void setEGLContextClientVersion (int version)

Inform the default EGLContextFactory and default EGLConfigChooser which EGLContext client version to pick.

Use this method to create an OpenGL ES 2.0-compatible context. Example:

 public MyView(Context context) {
 super(context);
 setEGLContextClientVersion(2); // Pick an OpenGL ES 2.0 context.
 setRenderer(new MyRenderer());
 }
 

Note: Activities which require OpenGL ES 2.0 should indicate this by setting @lt;uses-feature android:glEsVersion="0x00020000" /> in the activity's AndroidManifest.xml file.

If this method is called, it must be called before setRenderer(Renderer) is called.

This method only affects the behavior of the default EGLContexFactory and the default EGLConfigChooser. If setEGLContextFactory(EGLContextFactory) has been called, then the supplied EGLContextFactory is responsible for creating an OpenGL ES 2.0-compatible context. If setEGLConfigChooser(EGLConfigChooser) has been called, then the supplied EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config.

Parameters
version The EGLContext client version to choose. Use 2 for OpenGL ES 2.0

public void setEGLContextFactory (GLSurfaceView.EGLContextFactory factory)

Install a custom EGLContextFactory.

If this method is called, it must be called before setRenderer(Renderer) is called.

If this method is not called, then by default a context will be created with no shared context and with a null attribute list.

public void setEGLWindowSurfaceFactory (GLSurfaceView.EGLWindowSurfaceFactory factory)

Install a custom EGLWindowSurfaceFactory.

If this method is called, it must be called before setRenderer(Renderer) is called.

If this method is not called, then by default a window surface will be created with a null attribute list.

public void setGLWrapper (GLSurfaceView.GLWrapper glWrapper)

Set the glWrapper. If the glWrapper is not null, its wrap(javax.microedition.khronos.opengles.GL) method is called whenever a surface is created. A GLWrapper can be used to wrap the GL object that's passed to the renderer. Wrapping a GL object enables examining and modifying the behavior of the GL calls made by the renderer.

Wrapping is typically used for debugging purposes.

The default value is null.

Parameters
glWrapper the new GLWrapper

public void setPreserveEGLContextOnPause (boolean preserveOnPause)

Control whether the EGL context is preserved when the GLTextureView is paused and resumed.

If set to true, then the EGL context may be preserved when the GLTextureView is paused. Whether the EGL context is actually preserved or not depends upon whether the Android device that the program is running on can support an arbitrary number of EGL contexts or not. Devices that can only support a limited number of EGL contexts must release the EGL context in order to allow multiple applications to share the GPU.

If set to false, the EGL context will be released when the GLTextureView is paused, and recreated when the GLTextureView is resumed.

The default is false.

Parameters
preserveOnPause preserve the EGL context when paused

public void setRenderMode (int renderMode)

Set the rendering mode. When renderMode is RENDERMODE_CONTINUOUSLY, the renderer is called repeatedly to re-render the scene. When renderMode is RENDERMODE_WHEN_DIRTY, the renderer only rendered when the surface is created, or when requestRender() is called. Defaults to RENDERMODE_CONTINUOUSLY.

Using RENDERMODE_WHEN_DIRTY can improve battery life and overall system performance by allowing the GPU and CPU to idle when the view does not need to be updated.

This method can only be called after setRenderer(Renderer)

Parameters
renderMode one of the RENDERMODE_X constants

public void setRenderer (GLSurfaceView.Renderer renderer)

Set the renderer associated with this view. Also starts the thread that will call the renderer, which in turn causes the rendering to start.

This method should be called once and only once in the life-cycle of a GLTextureView.

The following GLTextureView methods can only be called before setRenderer is called:

The following GLTextureView methods can only be called after setRenderer is called:

Parameters
renderer the renderer to use to perform OpenGL drawing.

public void surfaceChanged (SurfaceTexture texture, int format, int w, int h)

This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.

public void surfaceCreated (SurfaceTexture texture)

This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.

public void surfaceDestroyed (SurfaceTexture texture)

This method is part of the SurfaceHolder.Callback interface, and is not normally called or subclassed by clients of GLTextureView.