22
22
23
23
package processing .android ;
24
24
25
+ import android .annotation .TargetApi ;
25
26
import android .graphics .Point ;
27
+ import android .opengl .EGL14 ;
28
+ import android .opengl .EGLConfig ;
29
+ import android .opengl .EGLDisplay ;
26
30
import android .os .Bundle ;
27
31
import android .view .Display ;
28
32
import android .view .WindowInsets ;
38
42
39
43
import android .graphics .Rect ;
40
44
45
+ @ TargetApi (21 )
41
46
public 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
+
42
56
private Point size ;
43
57
private DisplayMetrics metrics ;
44
58
private GLES2Engine engine ;
@@ -132,8 +146,7 @@ public void onDestroy() {
132
146
}
133
147
134
148
135
- private class GLES2Engine extends Gles2WatchFaceService .Engine implements
136
- ServiceEngine {
149
+ private class GLES2Engine extends Gles2WatchFaceService .Engine implements ServiceEngine {
137
150
private PApplet sketch ;
138
151
private Method compUpdatedMethod ;
139
152
private Method tapCommandMethod ;
@@ -156,6 +169,18 @@ public void onCreate(SurfaceHolder surfaceHolder) {
156
169
}
157
170
158
171
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
+
159
184
@ Override
160
185
public void onGlContextCreated () {
161
186
super .onGlContextCreated ();
0 commit comments