GLSurfaceView.Renderer
android.opengl.GLSurfaceView.Renderer |
Class Overview
A generic renderer interface.
是一个一般的渲染类接口
The renderer is responsible for making OpenGL calls to render a frame.
这个renderer类负责 让OpenGL调用去渲染一个框架。
GLSurfaceView clients typically create their own classes that implement this interface, and then callsetRenderer(GLSurfaceView.Renderer)
to register the renderer with the GLSurfaceView.
通常使用GLSurfaceView的客户都会通过调用这个“renderer”类接口去创建他们自己的对象。同时也会通过调用GLSurfaceView类的GLSurfaceView类的setRenderer(GLSurfaceView.Renderer)方法去注册这个“renderer”。
Threading 线程
queueEvent(Runnable)
convenience method.
queueEvent(Runnable)
这个便利的方法。
EGL Context Lost
onSurfaceCreated(GL10, EGLConfig)
method is a convenient place to do this.
See Also
Summary
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
abstract void | onDrawFrame(GL10 gl)
Called to draw the current frame.
绘制当前的框架时调用
| ||||||||||
abstract void | onSurfaceChanged(GL10 gl, int width, int height)
Called when the surface changed size.
表层界面(主视图)发生改变时调用
| ||||||||||
abstract void | onSurfaceCreated(GL10 gl, EGLConfig config)
Called when the surface is created or recreated.
框架被创建或者被重建的时候调用
|
Public Methods
public abstract void onDrawFrame (GL10 gl)
Called to draw the current frame.
This method is responsible for drawing the current frame.
The implementation of this method typically looks like this:
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 | the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces. |
---|
public abstract void onSurfaceChanged (GL10 gl, int width, int height)
Called when the surface changed size.
Called after the surface is created and whenever the OpenGL ES surface size changes.
Typically you will set your viewport here. If your camera is fixed then you could also set your projection matrix here:
void onSurfaceChanged(GL10 gl, int width, int height) { gl.glViewport(0, 0, width, height); //这是OpenGL场景的大小 // 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 | the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces. |
---|
public abstract void onSurfaceCreated (GL10 gl, EGLConfig config)
Called when the surface is created or recreated.
Called when the rendering thread starts and whenever the EGL context is lost. The EGL context will typically be lost when the Android device awakes after going to sleep.
Since this method is called at the beginning of rendering, as well as every time the EGL context is lost, this method is a convenient place to put code to create resources that need to be created when the rendering starts, and that need to be recreated when the EGL context is lost. Textures are an example of a resource that you might want to create here.
Note that when the EGL context is lost, all OpenGL resources associated with that context will be automatically deleted. You do not need to call the corresponding "glDelete" methods such as glDeleteTextures to manually delete these lost resources.
Parameters
gl | the GL interface. Use instanceof to test if the interface supports GL11 or higher interfaces. |
---|---|
config | the EGLConfig of the created surface. Can be used to create matching pbuffers. |