22 package com.arm.malideveloper.openglessdk.graphicssetup;
24 import android.content.Context;
25 import android.opengl.GLSurfaceView;
26 import javax.microedition.khronos.egl.EGL10;
27 import javax.microedition.khronos.egl.EGLConfig;
28 import javax.microedition.khronos.egl.EGLContext;
29 import javax.microedition.khronos.egl.EGLDisplay;
30 import javax.microedition.khronos.opengles.GL10;
34 class TutorialView
extends GLSurfaceView
36 protected int redSize = 8;
37 protected int greenSize = 8;
38 protected int blueSize = 8 ;
39 protected int alphaSize = 8;
40 protected int depthSize = 16;
41 protected int sampleSize = 4;
42 protected int stencilSize = 0;
43 protected int[]
value =
new int [1];
46 public TutorialView(Context context)
50 setEGLContextFactory(
new ContextFactory());
52 setEGLConfigChooser(
new ConfigChooser());
54 setRenderer(
new Renderer());
59 private static class ContextFactory implements GLSurfaceView.EGLContextFactory
61 public EGLContext
createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
63 final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
65 int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
67 EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
72 public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)
74 egl.eglDestroyContext(display, context);
83 final int EGL_OPENGL_ES2_BIT = 4;
86 EGL10.EGL_RED_SIZE, redSize,
87 EGL10.EGL_GREEN_SIZE, greenSize,
88 EGL10.EGL_BLUE_SIZE, blueSize,
89 EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
90 EGL10.EGL_SAMPLES, sampleSize,
91 EGL10.EGL_DEPTH_SIZE, depthSize,
92 EGL10.EGL_STENCIL_SIZE, stencilSize,
96 int[] num_config =
new int[1];
99 int numConfigs = num_config[0];
101 EGLConfig[] configs =
new EGLConfig[numConfigs];
102 egl.eglChooseConfig(display,
configAttributes, configs, numConfigs, num_config);
108 public EGLConfig
selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs)
110 for(EGLConfig config : configs)
112 int d =
getConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
113 int s =
getConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
119 if (r == redSize && g == greenSize && b == blueSize && a == alphaSize && d >= depthSize && s >= stencilSize)
129 int attribute,
int defaultValue)
131 if (egl.eglGetConfigAttrib(display, config, attribute,
value))
144 NativeLibrary.step();
EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
void onSurfaceCreated(GL10 gl, EGLConfig config)
GLboolean GLboolean GLboolean GLboolean a
GLint GLsizei GLsizei height
EGLConfig selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs)
int getConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue)
void onSurfaceChanged(GL10 gl, int width, int height)
EGLint configAttributes[]
void onDrawFrame(GL10 gl)
GLboolean GLboolean GLboolean b
EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)