FileDocCategorySizeDatePackage
GLDepthTestActivity.javaAPI DocAndroid 5.1 API15283Thu Mar 12 22:22:44 GMT 2015com.android.test.hwui

GLDepthTestActivity

public class GLDepthTestActivity extends android.app.Activity
This sample shows how to check for OpenGL ES 2.0 support at runtime, and then use either OpenGL ES 1.0 or OpenGL ES 2.0, as appropriate.

Fields Summary
private android.opengl.GLSurfaceView
mGLSurfaceView
private GLES20TriangleRenderer
mRenderer
Constructors Summary
Methods Summary
private booleandetectOpenGLES20()

        ActivityManager am =
                (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
        ConfigurationInfo info = am.getDeviceConfigurationInfo();
        return (info.reqGlEsVersion >= 0x20000);
    
protected voidonCreate(android.os.Bundle savedInstanceState)

        super.onCreate(savedInstanceState);
        mGLSurfaceView = new GLSurfaceView(this);
        if (detectOpenGLES20()) {
            // Tell the surface view we want to create an OpenGL ES
            // 2.0-compatible
            // context, and set an OpenGL ES 2.0-compatible renderer.
            mGLSurfaceView.setEGLContextClientVersion(2);
            mRenderer = new GLES20TriangleRenderer(this);
            mGLSurfaceView.setRenderer(mRenderer);
        } else {
            throw new IllegalStateException("Can't find OGL ES2.0 context");
        }
        setContentView(mGLSurfaceView);
    
protected voidonPause()

        // Ideally a game should implement onResume() and onPause()
        // to take appropriate action when the activity looses focus
        super.onPause();
        mGLSurfaceView.onPause();
    
protected voidonResume()

        // Ideally a game should implement onResume() and onPause()
        // to take appropriate action when the activity looses focus
        super.onResume();
        mGLSurfaceView.onResume();
    
public booleanonTouchEvent(android.view.MotionEvent event)

        Log.i("motion", event.toString());
        if (event.getActionMasked() ==  MotionEvent.ACTION_DOWN) {
            mRenderer.toggleDepthTest();
        }
        return true;