summaryrefslogtreecommitdiffstats
path: root/opengl/java/android
diff options
context:
space:
mode:
authorJack Palevich <jackpal@google.com>2009-11-19 19:08:52 +0800
committerJack Palevich <jackpal@google.com>2009-12-09 16:34:34 +0800
commit0dce2dd26699e4dbfba8b8c5ea01f7fd03369e02 (patch)
tree248e09a9cd55f92b9b97110850320af9ed6566aa /opengl/java/android
parent3608891b83af9fbd1af9b9a411f2a90e52353ff8 (diff)
downloadframeworks_base-0dce2dd26699e4dbfba8b8c5ea01f7fd03369e02.zip
frameworks_base-0dce2dd26699e4dbfba8b8c5ea01f7fd03369e02.tar.gz
frameworks_base-0dce2dd26699e4dbfba8b8c5ea01f7fd03369e02.tar.bz2
Extend GLSurfaceView to make it easy to create an OpenGL ES 2.0 context
Provide a new method, GLSurfaceView.setEGLContextClientVersion. Clients call this method to define which level of OpenGL ES support they want. This method only affects the default behavior of GLSurfaceView. If clients have supplied their own EGLContextFactory or EGLConfigChooser then they are on their own if they want to create an OpenGL ES 2.0 context. This API is currently hidden. Update the gl2_java test to use this new API. Update the gl2_java test's AndroidManifest.xml file to indicate that it requires OpenGL ES 2.0.
Diffstat (limited to 'opengl/java/android')
-rw-r--r--opengl/java/android/opengl/GLSurfaceView.java68
1 files changed, 62 insertions, 6 deletions
diff --git a/opengl/java/android/opengl/GLSurfaceView.java b/opengl/java/android/opengl/GLSurfaceView.java
index 1e3bd72..c458a7a 100644
--- a/opengl/java/android/opengl/GLSurfaceView.java
+++ b/opengl/java/android/opengl/GLSurfaceView.java
@@ -372,6 +372,39 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
setEGLConfigChooser(new ComponentSizeChooser(redSize, greenSize,
blueSize, alphaSize, depthSize, stencilSize));
}
+
+ /**
+ * Inform the default EGLContextFactory and default EGLConfigChooser
+ * which EGLContext client version to pick.
+ * <p>Use this method to create an OpenGL ES 2.0-compatible context.
+ * Example:
+ * <pre class="prettyprint">
+ * public MyView(Context context) {
+ * super(context);
+ * setEGLContextClientVersion(2); // Pick an OpenGL ES 2.0 context.
+ * setRenderer(new MyRenderer());
+ * }
+ * </pre>
+ * <p>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.
+ * <p>If this method is called, it must be called before {@link #setRenderer(Renderer)}
+ * is called.
+ * <p>This method only affects the behavior of the default EGLContexFactory and the
+ * default EGLConfigChooser. If
+ * {@link #setEGLContextFactory(EGLContextFactory)} has been called, then the supplied
+ * EGLContextFactory is responsible for creating an OpenGL ES 2.0-compatible context.
+ * If
+ * {@link #setEGLConfigChooser(EGLConfigChooser)} has been called, then the supplied
+ * EGLConfigChooser is responsible for choosing an OpenGL ES 2.0-compatible config.
+ * @param version The EGLContext client version to choose. Use 2 for OpenGL ES 2.0
+ * @hide
+ */
+ public void setEGLContextClientVersion(int version) {
+ checkRenderThreadState();
+ mEGLContextClientVersion = version;
+ }
+
/**
* Set the rendering mode. When renderMode is
* RENDERMODE_CONTINUOUSLY, the renderer is called
@@ -623,10 +656,15 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
void destroyContext(EGL10 egl, EGLDisplay display, EGLContext context);
}
- private static class DefaultContextFactory implements EGLContextFactory {
+ private class DefaultContextFactory implements EGLContextFactory {
+ private int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public EGLContext createContext(EGL10 egl, EGLDisplay display, EGLConfig config) {
- return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT, null);
+ int[] attrib_list = {EGL_CONTEXT_CLIENT_VERSION, mEGLContextClientVersion,
+ EGL10.EGL_NONE };
+
+ return egl.eglCreateContext(display, config, EGL10.EGL_NO_CONTEXT,
+ mEGLContextClientVersion != 0 ? attrib_list : null);
}
public void destroyContext(EGL10 egl, EGLDisplay display,
@@ -680,11 +718,12 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
EGLConfig chooseConfig(EGL10 egl, EGLDisplay display);
}
- private static abstract class BaseConfigChooser
+ private abstract class BaseConfigChooser
implements EGLConfigChooser {
public BaseConfigChooser(int[] configSpec) {
- mConfigSpec = configSpec;
+ mConfigSpec = filterConfigSpec(configSpec);
}
+
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
int[] num_config = new int[1];
if (!egl.eglChooseConfig(display, mConfigSpec, null, 0,
@@ -715,9 +754,25 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
EGLConfig[] configs);
protected int[] mConfigSpec;
+
+ private int[] filterConfigSpec(int[] configSpec) {
+ if (mEGLContextClientVersion != 2) {
+ return configSpec;
+ }
+ /* We know none of the subclasses define EGL_RENDERABLE_TYPE.
+ * And we know the configSpec is well formed.
+ */
+ int len = configSpec.length;
+ int[] newConfigSpec = new int[len + 2];
+ System.arraycopy(configSpec, 0, newConfigSpec, 0, len-1);
+ newConfigSpec[len-1] = EGL10.EGL_RENDERABLE_TYPE;
+ newConfigSpec[len] = 4; /* EGL_OPENGL_ES2_BIT */
+ newConfigSpec[len+1] = EGL10.EGL_NONE;
+ return newConfigSpec;
+ }
}
- private static class ComponentSizeChooser extends BaseConfigChooser {
+ private class ComponentSizeChooser extends BaseConfigChooser {
public ComponentSizeChooser(int redSize, int greenSize, int blueSize,
int alphaSize, int depthSize, int stencilSize) {
super(new int[] {
@@ -793,7 +848,7 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
* RGB565 as possible, with or without a depth buffer.
*
*/
- private static class SimpleEGLConfigChooser extends ComponentSizeChooser {
+ private class SimpleEGLConfigChooser extends ComponentSizeChooser {
public SimpleEGLConfigChooser(boolean withDepthBuffer) {
super(4, 4, 4, 0, withDepthBuffer ? 16 : 0, 0);
// Adjust target values. This way we'll accept a 4444 or
@@ -1401,4 +1456,5 @@ public class GLSurfaceView extends SurfaceView implements SurfaceHolder.Callback
private EGLWindowSurfaceFactory mEGLWindowSurfaceFactory;
private GLWrapper mGLWrapper;
private int mDebugFlags;
+ private int mEGLContextClientVersion;
}