19bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich/* 29bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Copyright (C) 2009 The Android Open Source Project 39bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 49bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Licensed under the Apache License, Version 2.0 (the "License"); 59bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * you may not use this file except in compliance with the License. 69bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * You may obtain a copy of the License at 79bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 89bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * http://www.apache.org/licenses/LICENSE-2.0 99bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 109bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Unless required by applicable law or agreed to in writing, software 119bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * distributed under the License is distributed on an "AS IS" BASIS, 129bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * See the License for the specific language governing permissions and 149bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * limitations under the License. 159bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich */ 169bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 179bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichpackage com.android.gldual; 189bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich/* 199bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Copyright (C) 2008 The Android Open Source Project 209bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 219bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Licensed under the Apache License, Version 2.0 (the "License"); 229bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * you may not use this file except in compliance with the License. 239bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * You may obtain a copy of the License at 249bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 259bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * http://www.apache.org/licenses/LICENSE-2.0 269bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 279bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * Unless required by applicable law or agreed to in writing, software 289bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * distributed under the License is distributed on an "AS IS" BASIS, 299bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 309bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * See the License for the specific language governing permissions and 319bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * limitations under the License. 329bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich */ 339bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 349bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 359bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport javax.microedition.khronos.egl.EGL10; 369bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport javax.microedition.khronos.egl.EGLConfig; 379bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport javax.microedition.khronos.egl.EGLContext; 389bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport javax.microedition.khronos.egl.EGLDisplay; 399bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport javax.microedition.khronos.opengles.GL10; 409bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 419bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport android.content.Context; 429bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport android.opengl.GLSurfaceView; 439bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport android.util.AttributeSet; 449bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichimport android.util.Log; 459bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 469bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich/** 479bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * An implementation of SurfaceView that uses the dedicated surface for 489bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * displaying an OpenGL animation. This allows the animation to run in a 499bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * separate thread, without requiring that it be driven by the update mechanism 509bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * of the view hierarchy. 519bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * 529bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * The application-specific rendering code is delegated to a GLView.Renderer 539bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich * instance. 549bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich */ 559bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevichclass GLDualGL2View extends GLSurfaceView { 569bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static String TAG = "GLDualGL2View"; 579bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 589bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public GLDualGL2View(Context context) { 599bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich super(context); 609bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich init(false, 0, 0); 619bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 629bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 639bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public GLDualGL2View(Context context, AttributeSet set) { 649bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich super(context, set); 659bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich init(false, 0, 0); 669bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 679bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 689bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public GLDualGL2View(Context context, boolean translucent, int depth, int stencil) { 699bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich super(context); 709bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich init(translucent, depth, stencil); 719bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 729bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 739bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private void init(boolean translucent, int depth, int stencil) { 749bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich setEGLContextFactory(new ContextFactory()); 759bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich setEGLConfigChooser( translucent ? 769bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich new ConfigChooser(8,8,8,8, depth, stencil) : 779bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich new ConfigChooser(5,6,5,0, depth, stencil)); 789bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich setRenderer(new Renderer()); 799bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 809bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 819bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static class ContextFactory implements GLSurfaceView.EGLContextFactory { 829bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static int EGL_CONTEXT_CLIENT_VERSION = 0x3098; 839bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig eglConfig) { 849bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich Log.w(TAG, "creating OpenGL ES 2.0 context"); 859bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich checkEglError("Before eglCreateContext", egl); 869bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, 2, EGL10.EGL_NONE }; 879bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLContext context = egl.eglCreateContext(display, eglConfig, EGL10.EGL_NO_CONTEXT, attrib_list); 889bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich checkEglError("After eglCreateContext", egl); 899bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich return context; 909bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 919bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 929bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context) { 939bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich egl.eglDestroyContext(display, context); 949bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 959bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 969bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 979bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static void checkEglError(String prompt, EGL10 egl) { 989bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int error; 999bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich while ((error = egl.eglGetError()) != EGL10.EGL_SUCCESS) { 1009bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich Log.e(TAG, String.format("%s: EGL error: 0x%x", prompt, error)); 1019bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1029bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1039bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1049bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static class ConfigChooser implements GLSurfaceView.EGLConfigChooser { 1059bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static int EGL_OPENGL_ES2_BIT = 4; 1069bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static int[] s_configAttribs2 = 1079bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich { 1089bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_RED_SIZE, 4, 1099bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_GREEN_SIZE, 4, 1109bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_BLUE_SIZE, 4, 1119bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT, 1129bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_NONE 1139bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich }; 1149bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1159bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public ConfigChooser(int r, int g, int b, int a, int depth, int stencil) { 1169bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mRedSize = r; 1179bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mGreenSize = g; 1189bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mBlueSize = b; 1199bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mAlphaSize = a; 1209bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mDepthSize = depth; 1219bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich mStencilSize = stencil; 1229bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1239bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1249bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) { 1259bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1269bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int[] num_config = new int[1]; 1279bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich egl.eglChooseConfig(display, s_configAttribs2, null, 0, num_config); 1289bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1299bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int numConfigs = num_config[0]; 1309bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1319bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich if (numConfigs <= 0) { 1329bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich throw new IllegalArgumentException("No configs match configSpec"); 1339bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1349bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig[] configs = new EGLConfig[numConfigs]; 1359bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich egl.eglChooseConfig(display, s_configAttribs2, configs, numConfigs, num_config); 1369bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich // printConfigs(egl, display, configs); 1379bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich return chooseConfig(egl, display, configs); 1389bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1399bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1409bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display, 1419bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig[] configs) { 1429bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig closestConfig = null; 1439bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int closestDistance = 1000; 1449bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich for(EGLConfig config : configs) { 1459bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int d = findConfigAttrib(egl, display, config, 1469bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_DEPTH_SIZE, 0); 1479bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int s = findConfigAttrib(egl, display, config, 1489bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_STENCIL_SIZE, 0); 1499bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich if (d >= mDepthSize && s>= mStencilSize) { 1509bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int r = findConfigAttrib(egl, display, config, 1519bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_RED_SIZE, 0); 1529bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int g = findConfigAttrib(egl, display, config, 1539bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_GREEN_SIZE, 0); 1549bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int b = findConfigAttrib(egl, display, config, 1559bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_BLUE_SIZE, 0); 1569bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int a = findConfigAttrib(egl, display, config, 1579bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_ALPHA_SIZE, 0); 1589bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int distance = Math.abs(r - mRedSize) 1599bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich + Math.abs(g - mGreenSize) 1609bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich + Math.abs(b - mBlueSize) 1619bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich + Math.abs(a - mAlphaSize); 1629bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich if (distance < closestDistance) { 1639bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich closestDistance = distance; 1649bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich closestConfig = config; 1659bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1669bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1679bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1689bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich return closestConfig; 1699bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1709bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1719bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private int findConfigAttrib(EGL10 egl, EGLDisplay display, 1729bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig config, int attribute, int defaultValue) { 1739bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1749bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich if (egl.eglGetConfigAttrib(display, config, attribute, mValue)) { 1759bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich return mValue[0]; 1769bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1779bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich return defaultValue; 1789bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1799bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1809bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private void printConfigs(EGL10 egl, EGLDisplay display, 1819bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig[] configs) { 1829bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int numConfigs = configs.length; 1839bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich Log.w(TAG, String.format("%d configurations", numConfigs)); 1849bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich for (int i = 0; i < numConfigs; i++) { 1859bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich Log.w(TAG, String.format("Configuration %d:\n", i)); 1869bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich printConfig(egl, display, configs[i]); 1879bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1889bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 1899bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 1909bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private void printConfig(EGL10 egl, EGLDisplay display, 1919bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGLConfig config) { 1929bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int[] attributes = { 1939bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_BUFFER_SIZE, 1949bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_ALPHA_SIZE, 1959bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_BLUE_SIZE, 1969bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_GREEN_SIZE, 1979bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_RED_SIZE, 1989bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_DEPTH_SIZE, 1999bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_STENCIL_SIZE, 2009bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_CONFIG_CAVEAT, 2019bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_CONFIG_ID, 2029bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_LEVEL, 2039bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_MAX_PBUFFER_HEIGHT, 2049bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_MAX_PBUFFER_PIXELS, 2059bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_MAX_PBUFFER_WIDTH, 2069bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_NATIVE_RENDERABLE, 2079bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_NATIVE_VISUAL_ID, 2089bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_NATIVE_VISUAL_TYPE, 2099bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x3030, // EGL10.EGL_PRESERVED_RESOURCES, 2109bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_SAMPLES, 2119bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_SAMPLE_BUFFERS, 2129bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_SURFACE_TYPE, 2139bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_TRANSPARENT_TYPE, 2149bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_TRANSPARENT_RED_VALUE, 2159bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_TRANSPARENT_GREEN_VALUE, 2169bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_TRANSPARENT_BLUE_VALUE, 2179bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x3039, // EGL10.EGL_BIND_TO_TEXTURE_RGB, 2189bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x303A, // EGL10.EGL_BIND_TO_TEXTURE_RGBA, 2199bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x303B, // EGL10.EGL_MIN_SWAP_INTERVAL, 2209bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x303C, // EGL10.EGL_MAX_SWAP_INTERVAL, 2219bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_LUMINANCE_SIZE, 2229bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_ALPHA_MASK_SIZE, 2239bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_COLOR_BUFFER_TYPE, 2249bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich EGL10.EGL_RENDERABLE_TYPE, 2259bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 0x3042 // EGL10.EGL_CONFORMANT 2269bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich }; 2279bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich String[] names = { 2289bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_BUFFER_SIZE", 2299bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_ALPHA_SIZE", 2309bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_BLUE_SIZE", 2319bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_GREEN_SIZE", 2329bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_RED_SIZE", 2339bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_DEPTH_SIZE", 2349bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_STENCIL_SIZE", 2359bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_CONFIG_CAVEAT", 2369bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_CONFIG_ID", 2379bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_LEVEL", 2389bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_MAX_PBUFFER_HEIGHT", 2399bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_MAX_PBUFFER_PIXELS", 2409bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_MAX_PBUFFER_WIDTH", 2419bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_NATIVE_RENDERABLE", 2429bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_NATIVE_VISUAL_ID", 2439bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_NATIVE_VISUAL_TYPE", 2449bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_PRESERVED_RESOURCES", 2459bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_SAMPLES", 2469bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_SAMPLE_BUFFERS", 2479bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_SURFACE_TYPE", 2489bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_TRANSPARENT_TYPE", 2499bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_TRANSPARENT_RED_VALUE", 2509bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_TRANSPARENT_GREEN_VALUE", 2519bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_TRANSPARENT_BLUE_VALUE", 2529bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_BIND_TO_TEXTURE_RGB", 2539bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_BIND_TO_TEXTURE_RGBA", 2549bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_MIN_SWAP_INTERVAL", 2559bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_MAX_SWAP_INTERVAL", 2569bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_LUMINANCE_SIZE", 2579bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_ALPHA_MASK_SIZE", 2589bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_COLOR_BUFFER_TYPE", 2599bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_RENDERABLE_TYPE", 2609bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich "EGL_CONFORMANT" 2619bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich }; 2629bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int[] value = new int[1]; 2639bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich for (int i = 0; i < attributes.length; i++) { 2649bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich int attribute = attributes[i]; 2659bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich String name = names[i]; 2669bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich if ( egl.eglGetConfigAttrib(display, config, attribute, value)) { 2679bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich Log.w(TAG, String.format(" %s: %d\n", name, value[0])); 2689bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } else { 2699bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich // Log.w(TAG, String.format(" %s: failed\n", name)); 2709bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich while (egl.eglGetError() != EGL10.EGL_SUCCESS); 2719bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2729bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2739bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2749bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 2759bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich // Subclasses can adjust these values: 2769bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mRedSize; 2779bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mGreenSize; 2789bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mBlueSize; 2799bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mAlphaSize; 2809bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mDepthSize; 2819bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich protected int mStencilSize; 2829bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private int[] mValue = new int[1]; 2839bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2849bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 2859bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich private static class Renderer implements GLSurfaceView.Renderer { 2869bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public void onDrawFrame(GL10 gl) { 2879bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich GLDualLib.step(); 2889bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2899bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 2909bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public void onSurfaceChanged(GL10 gl, int width, int height) { 2919bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich GLDualLib.init(width, height); 2929bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2939bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 2949bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich public void onSurfaceCreated(GL10 gl, EGLConfig config) { 2959bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich // Do nothing. 2969bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2979bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich } 2989bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich} 2999bd30f05e890b213e97b838e04024d8cd232dbc0Jack Palevich 300