一、mGLView.setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);
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 whenrequestRenderis 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 aftersetRenderer(Renderer)
Parameters:
renderModeone of the RENDERMODE_X constants
See Also:
RENDERMODE_CONTINUOUSLY
RENDERMODE_WHEN_DIRTY
设置渲染模式。 当renderMode为RENDERMODE_CONTINUOUSLY时,会重复调用渲染器以重新渲染场景。 当renderMode为RENDERMODE_WHEN_DIRTY时,仅在创建曲面时或在调用requestRender时才渲染渲染器。 默认为RENDERMODE_CONTINUOUSLY。
使用RENDERMODE_WHEN_DIRTY可以通过允许GPU和CPU在视图不需要更新时空闲,从而延长电池寿命和整体系统性能。
此方法只能在setRenderer(Renderer)之后调用
二、mGLView.setRenderer(mOpenGL2Renderer);
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 GLSurfaceView.
The following GLSurfaceView methods can only be called before setRenderer is called:
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int, int, int, int, int, int)
The following GLSurfaceView methods can only be called after setRenderer is called:
getRenderMode()
onPause()
onResume()
queueEvent(Runnable)
requestRender()
setRenderMode(int)
Parameters:
renderer the renderer to use to perform OpenGL drawing.
设置与此视图相关联的渲染器。 还启动将调用渲染器的线程,这又导致渲染开始。
这个方法应该在GLSurfaceView的生命周期中被调用一次而且只被调用一次。
以下GLSurfaceView方法只能在调用setRenderer之前调用:
setEGLConfigChooser(boolean)
setEGLConfigChooser(EGLConfigChooser)
setEGLConfigChooser(int,int,int,int,int,int)
以下GLSurfaceView方法只能在调用setRenderer后调用:
getRenderMode()
onPause()
onResume()
queueEvent(Runnable)
requestRender()
setRenderMode(int)
参数:
renderer使用渲染器来执行OpenGL绘图。
三、mGLView.setEGLConfigChooser(8,8,8,8,16,0);
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.
Parameters:
redSize
greenSize
blueSize
alphaSize
depthSize
stencilSize
安装配置选择器,它将选择至少具有指定depthSize和stencilSize的配置,以及指定的redSize,greenSize,blueSize和alphaSize。
如果调用此方法,则必须在调用setRenderer(Renderer)之前调用此方法。
如果没有调用setEGLConfigChooser方法,则默认情况下视图将选择一个RGB_888曲面,其深度缓存深度至少为16位。
参数:
redSize
greenSize
blueSize
alphaSize
depthSize
stencilSize
四、
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
通知默认EGLContextFactory和默认EGLConfigChooser要选择哪个EGLContext客户端版本。
使用此方法创建一个OpenGL ES 2.0兼容的上下文。例:
public MyView(Context context){
super(context);
setEGLContextClientVersion(2); //选择OpenGL ES 2.0上下文。
setRenderer(new MyRenderer());
}}
注意:需要OpenGL ES 2.0的活动应该在活动的AndroidManifest.xml文件中设置@lt; uses-feature android:glEsVersion =“0x00020000”/>。
如果调用此方法,则必须在调用setRenderer(Renderer)之前调用此方法。
此方法仅影响默认EGLContexFactory和默认EGLConfigChooser的行为。如果setEGLContextFactory(EGLContextFactory)已被调用,则提供的EGLContextFactory负责创建一个OpenGL ES 2.0兼容的上下文。如果setEGLConfigChooser(EGLConfigChooser)已被调用,则所提供的EGLConfigChooser负责选择与OpenGL ES 2.0兼容的配置。
参数:
version要选择的EGLContext客户端版本。对于OpenGL ES 2.0使用2
调用案列: