Skip to content

Commit 5af9cf8

Browse files
committed
some work to eventually enable multisampling on android, not working yet
1 parent d027233 commit 5af9cf8

File tree

2 files changed

+111
-22
lines changed

2 files changed

+111
-22
lines changed

core/src/processing/core/PApplet.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,10 @@ public SketchSurfaceViewGL(Context context, int wide, int high, boolean is3D) {
818818
// Tells the default EGLContextFactory and EGLConfigChooser to create an GLES2 context.
819819
setEGLContextClientVersion(2);
820820

821+
if (PGLES.ENABLE_MULTISAMPLING) {
822+
setEGLConfigChooser(((PGLES)g3.pgl).getConfigChooser());
823+
}
824+
821825
// The renderer can be set only once.
822826
setRenderer(((PGLES)g3.pgl).getRenderer());
823827
setRenderMode(GLSurfaceView.RENDERMODE_WHEN_DIRTY);

core/src/processing/opengl/PGLES.java

Lines changed: 107 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class PGLES extends PGL {
4545
/** The renderer object driving the rendering loop, analogous to the
4646
* GLEventListener in JOGL */
4747
protected static AndroidRenderer renderer;
48+
protected static AndroidConfigChooser configChooser;
4849

4950
// ........................................................
5051

@@ -70,10 +71,15 @@ public class PGLES extends PGL {
7071
MAX_CAPS_JOINS_LENGTH = 1000;
7172
}
7273

74+
public static final boolean ENABLE_MULTISAMPLING = false;
75+
7376
// Some EGL constants needed to initialize a GLES2 context.
7477
protected static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
7578
protected static final int EGL_OPENGL_ES2_BIT = 0x0004;
7679

80+
// Coverage multisampling identifiers for nVidia Tegra2
81+
protected static final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;
82+
protected static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;
7783

7884
///////////////////////////////////////////////////////////
7985

@@ -168,9 +174,16 @@ public AndroidContextFactory getContextFactory() {
168174
}
169175

170176

177+
public AndroidConfigChooser getConfigChooser() {
178+
configChooser = new AndroidConfigChooser(5, 6, 5, 4, 16, 1);
179+
return configChooser;
180+
}
181+
182+
171183
public AndroidConfigChooser getConfigChooser(int r, int g, int b, int a,
172184
int d, int s) {
173-
return new AndroidConfigChooser(r, g, b, a, d, s);
185+
configChooser = new AndroidConfigChooser(r, g, b, a, d, s);
186+
return configChooser;
174187
}
175188

176189

@@ -249,12 +262,51 @@ protected class AndroidConfigChooser implements EGLConfigChooser {
249262
// The attributes we want in the frame buffer configuration for Processing.
250263
// For more details on other attributes, see:
251264
// http://www.khronos.org/opengles/documentation/opengles1_0/html/eglChooseConfig.html
252-
protected int[] configAttribsGL = { EGL10.EGL_RED_SIZE, 4,
253-
EGL10.EGL_GREEN_SIZE, 4,
254-
EGL10.EGL_BLUE_SIZE, 4,
255-
EGL10.EGL_RENDERABLE_TYPE,
256-
EGL_OPENGL_ES2_BIT,
257-
EGL10.EGL_NONE };
265+
protected int[] configAttribsGL_MSAA = {
266+
EGL10.EGL_RED_SIZE, 5,
267+
EGL10.EGL_GREEN_SIZE, 6,
268+
EGL10.EGL_BLUE_SIZE, 5,
269+
EGL10.EGL_ALPHA_SIZE, 4,
270+
EGL10.EGL_DEPTH_SIZE, 16,
271+
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
272+
EGL10.EGL_SAMPLE_BUFFERS, 1,
273+
EGL10.EGL_SAMPLES, 2,
274+
EGL10.EGL_NONE };
275+
276+
protected int[] configAttribsGL_CovMSAA = {
277+
EGL10.EGL_RED_SIZE, 5,
278+
EGL10.EGL_GREEN_SIZE, 6,
279+
EGL10.EGL_BLUE_SIZE, 5,
280+
EGL10.EGL_ALPHA_SIZE, 4,
281+
EGL10.EGL_DEPTH_SIZE, 16,
282+
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
283+
EGL_COVERAGE_BUFFERS_NV, 1,
284+
EGL_COVERAGE_SAMPLES_NV, 2,
285+
EGL10.EGL_NONE };
286+
287+
protected int[] configAttribsGL_NoMSAA = {
288+
EGL10.EGL_RED_SIZE, 5,
289+
EGL10.EGL_GREEN_SIZE, 6,
290+
EGL10.EGL_BLUE_SIZE, 5,
291+
EGL10.EGL_ALPHA_SIZE, 4,
292+
EGL10.EGL_DEPTH_SIZE, 16,
293+
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
294+
EGL10.EGL_NONE };
295+
296+
protected int[] configAttribsGL_Good = {
297+
EGL10.EGL_RED_SIZE, 8,
298+
EGL10.EGL_GREEN_SIZE, 8,
299+
EGL10.EGL_BLUE_SIZE, 8,
300+
EGL10.EGL_ALPHA_SIZE, 8,
301+
EGL10.EGL_DEPTH_SIZE, 16,
302+
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
303+
EGL10.EGL_NONE };
304+
305+
protected int[] configAttribsGL_TestMSAA = {
306+
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
307+
EGL10.EGL_SAMPLE_BUFFERS, 1,
308+
EGL10.EGL_SAMPLES, 2,
309+
EGL10.EGL_NONE };
258310

259311
public AndroidConfigChooser(int r, int g, int b, int a, int d, int s) {
260312
redTarget = r;
@@ -266,22 +318,18 @@ public AndroidConfigChooser(int r, int g, int b, int a, int d, int s) {
266318
}
267319

268320
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
321+
EGLConfig[] configs = chooseConfigWithAttribs(egl, display, configAttribsGL_MSAA);
322+
if (configs == null) {
323+
chooseConfigWithAttribs(egl, display, configAttribsGL_CovMSAA);
324+
if (configs == null) {
325+
chooseConfigWithAttribs(egl, display, configAttribsGL_NoMSAA);
326+
}
327+
}
269328

270-
// Get the number of minimally matching EGL configurations
271-
int[] num_config = new int[1];
272-
egl.eglChooseConfig(display, configAttribsGL, null, 0, num_config);
273-
274-
int numConfigs = num_config[0];
275-
276-
if (numConfigs <= 0) {
329+
if (configs == null) {
277330
throw new IllegalArgumentException("No EGL configs match configSpec");
278331
}
279332

280-
// Allocate then read the array of minimally matching EGL configs
281-
EGLConfig[] configs = new EGLConfig[numConfigs];
282-
egl.eglChooseConfig(display, configAttribsGL, configs, numConfigs,
283-
num_config);
284-
285333
if (PApplet.DEBUG) {
286334
for (EGLConfig config : configs) {
287335
String configStr = "P3D - selected EGL config : "
@@ -297,12 +345,13 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
297345
public EGLConfig chooseBestConfig(EGL10 egl, EGLDisplay display,
298346
EGLConfig[] configs) {
299347
EGLConfig bestConfig = null;
300-
float bestScore = 1000;
348+
float bestScore = Float.MAX_VALUE;
301349

302350
for (EGLConfig config : configs) {
303351
int gl = findConfigAttrib(egl, display, config,
304352
EGL10.EGL_RENDERABLE_TYPE, 0);
305-
if (gl == EGL_OPENGL_ES2_BIT) {
353+
boolean isGLES2 = (gl & EGL_OPENGL_ES2_BIT) != 0;
354+
if (isGLES2) {
306355
int d = findConfigAttrib(egl, display, config,
307356
EGL10.EGL_DEPTH_SIZE, 0);
308357
int s = findConfigAttrib(egl, display, config,
@@ -320,7 +369,7 @@ public EGLConfig chooseBestConfig(EGL10 egl, EGLDisplay display,
320369
float score = 0.20f * PApplet.abs(r - redTarget) +
321370
0.20f * PApplet.abs(g - greenTarget) +
322371
0.20f * PApplet.abs(b - blueTarget) +
323-
0.15f * PApplet.abs(a - blueTarget) +
372+
0.15f * PApplet.abs(a - alphaTarget) +
324373
0.15f * PApplet.abs(d - depthTarget) +
325374
0.10f * PApplet.abs(s - stencilTarget);
326375

@@ -391,6 +440,42 @@ protected int findConfigAttrib(EGL10 egl, EGLDisplay display,
391440
}
392441
return defaultValue;
393442
}
443+
444+
protected EGLConfig[] chooseConfigWithAttribs(EGL10 egl,
445+
EGLDisplay display,
446+
int[] configAttribs) {
447+
// Get the number of minimally matching EGL configurations
448+
int[] configCounts = new int[1];
449+
egl.eglChooseConfig(display, configAttribs, null, 0, configCounts);
450+
451+
int count = configCounts[0];
452+
453+
if (count <= 0) {
454+
//throw new IllegalArgumentException("No EGL configs match configSpec");
455+
return null;
456+
}
457+
458+
// Allocate then read the array of minimally matching EGL configs
459+
EGLConfig[] configs = new EGLConfig[count];
460+
egl.eglChooseConfig(display, configAttribs, configs, count, configCounts);
461+
return configs;
462+
463+
// Get the number of minimally matching EGL configurations
464+
// int[] num_config = new int[1];
465+
// egl.eglChooseConfig(display, configAttribsGL, null, 0, num_config);
466+
//
467+
// int numConfigs = num_config[0];
468+
//
469+
// if (numConfigs <= 0) {
470+
// throw new IllegalArgumentException("No EGL configs match configSpec");
471+
// }
472+
//
473+
// // Allocate then read the array of minimally matching EGL configs
474+
// EGLConfig[] configs = new EGLConfig[numConfigs];
475+
// egl.eglChooseConfig(display, configAttribsGL, configs, numConfigs,
476+
// num_config);
477+
478+
}
394479
}
395480

396481

0 commit comments

Comments
 (0)