Skip to content

Commit b7e3891

Browse files
committed
use custom EGL config for 3D watch faces so depth buffer is enabled
1 parent f55a014 commit b7e3891

File tree

2 files changed

+29
-2
lines changed

2 files changed

+29
-2
lines changed

core/src/processing/android/PWatchFaceCanvas.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424

2525
import java.lang.reflect.Method;
2626

27+
import android.annotation.TargetApi;
2728
import android.graphics.Canvas;
2829
import android.graphics.Point;
2930
import android.os.Bundle;
@@ -40,6 +41,7 @@
4041
import processing.a2d.PGraphicsAndroid2D;
4142
import processing.core.PApplet;
4243

44+
@TargetApi(21)
4345
public class PWatchFaceCanvas extends CanvasWatchFaceService implements AppComponent {
4446
private Point size;
4547
private DisplayMetrics metrics;

core/src/processing/android/PWatchFaceGLES.java

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,11 @@
2222

2323
package processing.android;
2424

25+
import android.annotation.TargetApi;
2526
import android.graphics.Point;
27+
import android.opengl.EGL14;
28+
import android.opengl.EGLConfig;
29+
import android.opengl.EGLDisplay;
2630
import android.os.Bundle;
2731
import android.view.Display;
2832
import android.view.WindowInsets;
@@ -38,7 +42,17 @@
3842

3943
import android.graphics.Rect;
4044

45+
@TargetApi(21)
4146
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+
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

Comments
 (0)