@@ -71,15 +71,18 @@ public class PGLES extends PGL {
7171 MAX_CAPS_JOINS_LENGTH = 1000 ;
7272 }
7373
74- public static final boolean ENABLE_MULTISAMPLING = false ;
75-
7674 // Some EGL constants needed to initialize a GLES2 context.
7775 protected static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098 ;
7876 protected static final int EGL_OPENGL_ES2_BIT = 0x0004 ;
7977
8078 // Coverage multisampling identifiers for nVidia Tegra2
8179 protected static final int EGL_COVERAGE_BUFFERS_NV = 0x30E0 ;
8280 protected static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1 ;
81+ protected static final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000 ;
82+
83+ protected static boolean usingMultisampling = false ;
84+ protected static boolean usingCoverageMultisampling = false ;
85+ protected static int multisampleCount = 1 ;
8386
8487 ///////////////////////////////////////////////////////////
8588
@@ -174,15 +177,15 @@ public AndroidContextFactory getContextFactory() {
174177 }
175178
176179
177- public AndroidConfigChooser getConfigChooser () {
178- configChooser = new AndroidConfigChooser (5 , 6 , 5 , 4 , 16 , 1 );
180+ public AndroidConfigChooser getConfigChooser (int samples ) {
181+ configChooser = new AndroidConfigChooser (5 , 6 , 5 , 4 , 16 , 1 , samples );
179182 return configChooser ;
180183 }
181184
182185
183186 public AndroidConfigChooser getConfigChooser (int r , int g , int b , int a ,
184- int d , int s ) {
185- configChooser = new AndroidConfigChooser (r , g , b , a , d , s );
187+ int d , int s , int samples ) {
188+ configChooser = new AndroidConfigChooser (r , g , b , a , d , s , samples );
186189 return configChooser ;
187190 }
188191
@@ -259,6 +262,26 @@ protected class AndroidConfigChooser implements EGLConfigChooser {
259262 public int stencilBits ;
260263 public int [] tempValue = new int [1 ];
261264
265+ public int numSamples ;
266+
267+ /*
268+ The GLES2 extensions supported are:
269+ GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_vertex_half_float
270+ GL_OES_texture_float GL_OES_texture_half_float
271+ GL_OES_element_index_uint GL_OES_mapbuffer
272+ GL_OES_fragment_precision_high GL_OES_compressed_ETC1_RGB8_texture
273+ GL_OES_EGL_image GL_OES_required_internalformat GL_OES_depth_texture
274+ GL_OES_get_program_binary GL_OES_packed_depth_stencil
275+ GL_OES_standard_derivatives GL_OES_vertex_array_object GL_OES_egl_sync
276+ GL_EXT_multi_draw_arrays GL_EXT_texture_format_BGRA8888
277+ GL_EXT_discard_framebuffer GL_EXT_shader_texture_lod
278+ GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc
279+ GL_IMG_texture_stream2 GL_IMG_texture_npot
280+ GL_IMG_texture_format_BGRA8888 GL_IMG_read_format
281+ GL_IMG_program_binary GL_IMG_multisampled_render_to_texture
282+ */
283+
284+ /*
262285 // The attributes we want in the frame buffer configuration for Processing.
263286 // For more details on other attributes, see:
264287 // http://www.khronos.org/opengles/documentation/opengles1_0/html/eglChooseConfig.html
@@ -307,23 +330,57 @@ protected class AndroidConfigChooser implements EGLConfigChooser {
307330 EGL10.EGL_SAMPLE_BUFFERS, 1,
308331 EGL10.EGL_SAMPLES, 2,
309332 EGL10.EGL_NONE };
333+ */
334+
335+ protected int [] attribsNoMSAA = {
336+ EGL10 .EGL_RENDERABLE_TYPE , EGL_OPENGL_ES2_BIT ,
337+ EGL10 .EGL_SAMPLE_BUFFERS , 0 ,
338+ EGL10 .EGL_NONE };
310339
311- public AndroidConfigChooser (int r , int g , int b , int a , int d , int s ) {
312- redTarget = r ;
313- greenTarget = g ;
314- blueTarget = b ;
315- alphaTarget = a ;
316- depthTarget = d ;
317- stencilTarget = s ;
340+ public AndroidConfigChooser (int rbits , int gbits , int bbits , int abits ,
341+ int dbits , int sbits , int samples ) {
342+ redTarget = rbits ;
343+ greenTarget = gbits ;
344+ blueTarget = bbits ;
345+ alphaTarget = abits ;
346+ depthTarget = dbits ;
347+ stencilTarget = sbits ;
348+ numSamples = samples ;
318349 }
319350
320351 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 );
352+ EGLConfig [] configs = null ;
353+ if (1 < numSamples ) {
354+ int [] attribs = new int [] {
355+ EGL10 .EGL_RENDERABLE_TYPE , EGL_OPENGL_ES2_BIT ,
356+ EGL10 .EGL_SAMPLE_BUFFERS , 1 ,
357+ EGL10 .EGL_SAMPLES , numSamples ,
358+ EGL10 .EGL_NONE };
359+ configs = chooseConfigWithAttribs (egl , display , attribs );
324360 if (configs == null ) {
325- chooseConfigWithAttribs (egl , display , configAttribsGL_NoMSAA );
361+ // No normal multisampling config was found. Try to create a
362+ // coverage multisampling configuration, for the nVidia Tegra2.
363+ // See the EGL_NV_coverage_sample documentation.
364+ int [] attribsCov = {
365+ EGL10 .EGL_RENDERABLE_TYPE , EGL_OPENGL_ES2_BIT ,
366+ EGL_COVERAGE_BUFFERS_NV , 1 ,
367+ EGL_COVERAGE_SAMPLES_NV , numSamples ,
368+ EGL10 .EGL_NONE };
369+ configs = chooseConfigWithAttribs (egl , display , attribsCov );
370+ if (configs == null ) {
371+ configs = chooseConfigWithAttribs (egl , display , attribsNoMSAA );
372+ } else {
373+ usingMultisampling = true ;
374+ usingCoverageMultisampling = true ;
375+ multisampleCount = numSamples ;
376+ }
377+ } else {
378+ usingMultisampling = true ;
379+ usingCoverageMultisampling = false ;
380+ multisampleCount = numSamples ;
326381 }
382+ } else {
383+ configs = chooseConfigWithAttribs (egl , display , attribsNoMSAA );
327384 }
328385
329386 if (configs == null ) {
@@ -1619,6 +1676,9 @@ public void stencilMaskSeparate(int face, int mask) {
16191676
16201677 @ Override
16211678 public void clear (int buf ) {
1679+ if (usingMultisampling && usingCoverageMultisampling ) {
1680+ buf |= GL_COVERAGE_BUFFER_BIT_NV ;
1681+ }
16221682 GLES20 .glClear (buf );
16231683 }
16241684
0 commit comments