21 package com.arm.malideveloper.openglessdk.simpletriangle;
23 import android.content.Context;
24 import android.opengl.GLSurfaceView;
25 import javax.microedition.khronos.egl.EGL10;
26 import javax.microedition.khronos.egl.EGLConfig;
27 import javax.microedition.khronos.egl.EGLContext;
28 import javax.microedition.khronos.egl.EGLDisplay;
29 import javax.microedition.khronos.opengles.GL10;
31 class TutorialView
extends GLSurfaceView
33 protected int redSize = 8;
34 protected int greenSize = 8;
35 protected int blueSize = 8 ;
36 protected int alphaSize = 8;
37 protected int depthSize = 16;
38 protected int sampleSize = 4;
39 protected int stencilSize = 0;
40 protected int[]
value =
new int [1];
42 public TutorialView(Context context)
46 setEGLContextFactory(
new ContextFactory());
48 setEGLConfigChooser(
new ConfigChooser());
50 setRenderer(
new Renderer());
53 private static class ContextFactory implements GLSurfaceView.EGLContextFactory
55 public EGLContext
createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
57 final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
59 int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE };
61 EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list);
66 public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)
68 egl.eglDestroyContext(display, context);
76 final int EGL_OPENGL_ES2_BIT = 4;
79 EGL10.EGL_RED_SIZE, redSize,
80 EGL10.EGL_GREEN_SIZE, greenSize,
81 EGL10.EGL_BLUE_SIZE, blueSize,
82 EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
83 EGL10.EGL_SAMPLES, sampleSize,
84 EGL10.EGL_DEPTH_SIZE, depthSize,
85 EGL10.EGL_STENCIL_SIZE, stencilSize,
89 int[] num_config =
new int[1];
92 int numConfigs = num_config[0];
94 EGLConfig[] configs =
new EGLConfig[numConfigs];
95 egl.eglChooseConfig(display,
configAttributes, configs, numConfigs, num_config);
100 public EGLConfig
selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs)
102 for(EGLConfig config : configs)
104 int d =
getConfigAttrib(egl, display, config, EGL10.EGL_DEPTH_SIZE, 0);
105 int s =
getConfigAttrib(egl, display, config, EGL10.EGL_GREEN_SIZE, 0);
111 if (r == redSize && g == greenSize && b == blueSize && a == alphaSize && d >= depthSize && s >= stencilSize)
119 int attribute,
int defaultValue)
121 if (egl.eglGetConfigAttrib(display, config, attribute,
value))
132 NativeLibrary.step();
void onSurfaceChanged(GL10 gl, int width, int height)
GLboolean GLboolean GLboolean GLboolean a
GLint GLsizei GLsizei height
void onSurfaceCreated(GL10 gl, EGLConfig config)
EGLint configAttributes[]
EGLConfig selectConfig(EGL10 egl, EGLDisplay display, EGLConfig[] configs)
void onDrawFrame(GL10 gl)
int getConfigAttrib(EGL10 egl, EGLDisplay display, EGLConfig config, int attribute, int defaultValue)
EGLConfig chooseConfig(EGL10 egl, EGLDisplay display)
EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig)
GLboolean GLboolean GLboolean b
void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context)