Most visited

Recently visited

Added in API level 3

GLSurfaceView.Renderer

public static interface GLSurfaceView.Renderer

android.opengl.GLSurfaceView.Renderer


一个通用的渲染器接口。

渲染器负责使OpenGL调用渲染帧。

GLSurfaceView客户端通常创建自己的实现此接口的类,然后调用 setRenderer(GLSurfaceView.Renderer)setRenderer(GLSurfaceView.Renderer)注册渲染器。

Developer Guides

有关如何使用OpenGL的更多信息,请阅读 OpenGL开发人员指南。

Threading

The renderer will be called on a separate thread, so that rendering performance is decoupled from the UI thread. Clients typically need to communicate with the renderer from the UI thread, because that's where input events are received. Clients can communicate using any of the standard Java techniques for cross-thread communication, or they can use the queueEvent(Runnable) convenience method.

EGL Context Lost

There are situations where the EGL rendering context will be lost. This typically happens when device wakes up after going to sleep. When the EGL context is lost, all OpenGL resources (such as textures) that are associated with that context will be automatically deleted. In order to keep rendering correctly, a renderer must recreate any lost resources that it still needs. The onSurfaceCreated(GL10, EGLConfig) method is a convenient place to do this.

也可以看看:

Summary

Public methods

abstract void onDrawFrame(GL10 gl)

调用绘制当前帧。

abstract void onSurfaceChanged(GL10 gl, int width, int height)

当表面改变大小时调用。

abstract void onSurfaceCreated(GL10 gl, EGLConfig config)

在表面创建或重新创建时调用。

Public methods

onDrawFrame

Added in API level 3
void onDrawFrame (GL10 gl)

调用绘制当前帧。

此方法负责绘制当前帧。

此方法的实现通常如下所示:

 void onDrawFrame(GL10 gl) {
     gl.glClear(GL10.GL_COLOR_BUFFER_BIT | GL10.GL_DEPTH_BUFFER_BIT);
     //... other gl calls to render the scene ...
 }
 

Parameters
gl GL10: the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

onSurfaceChanged

Added in API level 3
void onSurfaceChanged (GL10 gl, 
                int width, 
                int height)

当表面改变大小时调用。

在创建曲面后以及每当OpenGL ES曲面大小发生变化时调用。

通常你会在这里设置你的视口。 如果你的相机是固定的,那么你也可以在这里设置你的投影矩阵:

 void onSurfaceChanged(GL10 gl, int width, int height) {
     gl.glViewport(0, 0, width, height);
     // for a fixed camera, set the projection too
     float ratio = (float) width / height;
     gl.glMatrixMode(GL10.GL_PROJECTION);
     gl.glLoadIdentity();
     gl.glFrustumf(-ratio, ratio, -1, 1, 1, 10);
 }
 

Parameters
gl GL10: the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.

onSurfaceCreated

Added in API level 3
void onSurfaceCreated (GL10 gl, 
                EGLConfig config)

在表面创建或重新创建时调用。

当渲染线程启动并且每当EGL上下文丢失时调用。 当Android设备在睡觉后醒来时,EGL上下文通常会丢失。

由于在渲染开始时以及每次EGL上下文丢失时调用此方法,因此此方法是放置代码以创建在渲染开始时需要创建且需要重新创建的资源的便利场所当EGL上下文丢失时。 纹理是您可能想要在此创建的资源的示例。

请注意,当EGL上下文丢失时,与该上下文关联的所有OpenGL资源将自动删除。 您无需调用相应的“glDelete”方法(如glDeleteTextures)手动删除这些丢失的资源。

Parameters
gl GL10: the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces.
config EGLConfig: the EGLConfig of the created surface. Can be used to create matching pbuffers.

Hooray!