@@ -45,6 +45,7 @@ public class PGLES extends PGL {
45
45
/** The renderer object driving the rendering loop, analogous to the
46
46
* GLEventListener in JOGL */
47
47
protected static AndroidRenderer renderer ;
48
+ protected static AndroidConfigChooser configChooser ;
48
49
49
50
// ........................................................
50
51
@@ -70,10 +71,15 @@ public class PGLES extends PGL {
70
71
MAX_CAPS_JOINS_LENGTH = 1000 ;
71
72
}
72
73
74
+ public static final boolean ENABLE_MULTISAMPLING = false ;
75
+
73
76
// Some EGL constants needed to initialize a GLES2 context.
74
77
protected static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098 ;
75
78
protected static final int EGL_OPENGL_ES2_BIT = 0x0004 ;
76
79
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 ;
77
83
78
84
///////////////////////////////////////////////////////////
79
85
@@ -168,9 +174,16 @@ public AndroidContextFactory getContextFactory() {
168
174
}
169
175
170
176
177
+ public AndroidConfigChooser getConfigChooser () {
178
+ configChooser = new AndroidConfigChooser (5 , 6 , 5 , 4 , 16 , 1 );
179
+ return configChooser ;
180
+ }
181
+
182
+
171
183
public AndroidConfigChooser getConfigChooser (int r , int g , int b , int a ,
172
184
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 ;
174
187
}
175
188
176
189
@@ -249,12 +262,51 @@ protected class AndroidConfigChooser implements EGLConfigChooser {
249
262
// The attributes we want in the frame buffer configuration for Processing.
250
263
// For more details on other attributes, see:
251
264
// 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 };
258
310
259
311
public AndroidConfigChooser (int r , int g , int b , int a , int d , int s ) {
260
312
redTarget = r ;
@@ -266,22 +318,18 @@ public AndroidConfigChooser(int r, int g, int b, int a, int d, int s) {
266
318
}
267
319
268
320
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
+ }
269
328
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 ) {
277
330
throw new IllegalArgumentException ("No EGL configs match configSpec" );
278
331
}
279
332
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
-
285
333
if (PApplet .DEBUG ) {
286
334
for (EGLConfig config : configs ) {
287
335
String configStr = "P3D - selected EGL config : "
@@ -297,12 +345,13 @@ public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
297
345
public EGLConfig chooseBestConfig (EGL10 egl , EGLDisplay display ,
298
346
EGLConfig [] configs ) {
299
347
EGLConfig bestConfig = null ;
300
- float bestScore = 1000 ;
348
+ float bestScore = Float . MAX_VALUE ;
301
349
302
350
for (EGLConfig config : configs ) {
303
351
int gl = findConfigAttrib (egl , display , config ,
304
352
EGL10 .EGL_RENDERABLE_TYPE , 0 );
305
- if (gl == EGL_OPENGL_ES2_BIT ) {
353
+ boolean isGLES2 = (gl & EGL_OPENGL_ES2_BIT ) != 0 ;
354
+ if (isGLES2 ) {
306
355
int d = findConfigAttrib (egl , display , config ,
307
356
EGL10 .EGL_DEPTH_SIZE , 0 );
308
357
int s = findConfigAttrib (egl , display , config ,
@@ -320,7 +369,7 @@ public EGLConfig chooseBestConfig(EGL10 egl, EGLDisplay display,
320
369
float score = 0.20f * PApplet .abs (r - redTarget ) +
321
370
0.20f * PApplet .abs (g - greenTarget ) +
322
371
0.20f * PApplet .abs (b - blueTarget ) +
323
- 0.15f * PApplet .abs (a - blueTarget ) +
372
+ 0.15f * PApplet .abs (a - alphaTarget ) +
324
373
0.15f * PApplet .abs (d - depthTarget ) +
325
374
0.10f * PApplet .abs (s - stencilTarget );
326
375
@@ -391,6 +440,42 @@ protected int findConfigAttrib(EGL10 egl, EGLDisplay display,
391
440
}
392
441
return defaultValue ;
393
442
}
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
+ }
394
479
}
395
480
396
481
0 commit comments