2222
2323package processing .android ;
2424
25+ import android .annotation .TargetApi ;
2526import android .graphics .Point ;
27+ import android .opengl .EGL14 ;
28+ import android .opengl .EGLConfig ;
29+ import android .opengl .EGLDisplay ;
2630import android .os .Bundle ;
2731import android .view .Display ;
2832import android .view .WindowInsets ;
3842
3943import android .graphics .Rect ;
4044
45+ @ TargetApi (21 )
4146public class PWatchFaceGLES extends Gles2WatchFaceService implements AppComponent {
47+ private static final int [] CONFIG_ATTRIB_LIST = new int []{
48+ EGL14 .EGL_RENDERABLE_TYPE , 4 ,
49+ EGL14 .EGL_RED_SIZE , 8 ,
50+ EGL14 .EGL_GREEN_SIZE , 8 ,
51+ EGL14 .EGL_BLUE_SIZE , 8 ,
52+ EGL14 .EGL_ALPHA_SIZE , 8 ,
53+ EGL14 .EGL_DEPTH_SIZE , 16 , // this was missing
54+ EGL14 .EGL_NONE };
55+
4256 private Point size ;
4357 private DisplayMetrics metrics ;
4458 private GLES2Engine engine ;
@@ -132,8 +146,7 @@ public void onDestroy() {
132146 }
133147
134148
135- private class GLES2Engine extends Gles2WatchFaceService .Engine implements
136- ServiceEngine {
149+ private class GLES2Engine extends Gles2WatchFaceService .Engine implements ServiceEngine {
137150 private PApplet sketch ;
138151 private Method compUpdatedMethod ;
139152 private Method tapCommandMethod ;
@@ -156,6 +169,18 @@ public void onCreate(SurfaceHolder surfaceHolder) {
156169 }
157170
158171
172+ public EGLConfig chooseEglConfig (EGLDisplay eglDisplay ) {
173+ int [] numEglConfigs = new int [1 ];
174+ EGLConfig [] eglConfigs = new EGLConfig [1 ];
175+ if (!EGL14 .eglChooseConfig (eglDisplay , CONFIG_ATTRIB_LIST , 0 , eglConfigs , 0 , eglConfigs .length , numEglConfigs , 0 )) {
176+ throw new RuntimeException ("eglChooseConfig failed" );
177+ } else if (numEglConfigs [0 ] == 0 ) {
178+ throw new RuntimeException ("no matching EGL configs" );
179+ } else {
180+ return eglConfigs [0 ];
181+ }
182+ }
183+
159184 @ Override
160185 public void onGlContextCreated () {
161186 super .onGlContextCreated ();
0 commit comments