forked from processing/processing-android
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPGLES.java
More file actions
1933 lines (1522 loc) · 56.5 KB
/
Copy pathPGLES.java
File metadata and controls
1933 lines (1522 loc) · 56.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation, version 2.1.
This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General
Public License along with this library; if not, write to the
Free Software Foundation, Inc., 59 Temple Place, Suite 330,
Boston, MA 02111-1307 USA
*/
package processing.opengl;
import java.nio.Buffer;
import java.nio.ByteBuffer;
import java.nio.FloatBuffer;
import java.nio.IntBuffer;
import javax.microedition.khronos.egl.EGL10;
import javax.microedition.khronos.egl.EGLConfig;
import javax.microedition.khronos.egl.EGLContext;
import javax.microedition.khronos.egl.EGLDisplay;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.GLSurfaceView.EGLConfigChooser;
import android.opengl.GLSurfaceView.Renderer;
import android.opengl.GLU;
import processing.core.PApplet;
import processing.opengl.tess.PGLU;
import processing.opengl.tess.PGLUtessellator;
import processing.opengl.tess.PGLUtessellatorCallbackAdapter;
public class PGLES extends PGL {
// ........................................................
// Public members to access the underlying GL objects and glview
/** Basic GLES 1.0 interface */
public GL10 gl;
/** GLU interface **/
public PGLU glu;
/** The current opengl context */
public static EGLContext context;
/** The current surface view */
public static GLSurfaceView glview;
// ........................................................
// Internal objects
/** The renderer object driving the rendering loop, analogous to the
* GLEventListener in JOGL */
protected static AndroidRenderer renderer;
protected static AndroidConfigChooser configChooser;
// ........................................................
// Static initialization for some parameters that need to be different for
// GLES
static {
SINGLE_BUFFERED = true;
MIN_DIRECT_BUFFER_SIZE = 1;
INDEX_TYPE = GLES20.GL_UNSIGNED_SHORT;
MIPMAPS_ENABLED = false;
DEFAULT_IN_VERTICES = 16;
DEFAULT_IN_EDGES = 32;
DEFAULT_IN_TEXTURES = 16;
DEFAULT_TESS_VERTICES = 16;
DEFAULT_TESS_INDICES = 32;
MIN_FONT_TEX_SIZE = 128;
MAX_FONT_TEX_SIZE = 512;
MAX_CAPS_JOINS_LENGTH = 1000;
}
// Some EGL constants needed to initialize a GLES2 context.
protected static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
protected static final int EGL_OPENGL_ES2_BIT = 0x0004;
// Coverage multisampling identifiers for nVidia Tegra2
protected static final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;
protected static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;
protected static final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000;
protected static boolean usingMultisampling = false;
protected static boolean usingCoverageMultisampling = false;
protected static int multisampleCount = 1;
///////////////////////////////////////////////////////////
// Initialization, finalization
public PGLES(PGraphicsOpenGL pg) {
super(pg);
glu = new PGLU();
}
@Override
public GLSurfaceView getNative() {
return glview;
}
@Override
protected void setFrameRate(float fps) { }
@Override
protected void initSurface(int antialias) {
glview = (GLSurfaceView)sketch.getSurfaceView();
reqNumSamples = qualityToSamples(antialias);
registerListeners();
}
@Override
protected void reinitSurface() { }
@Override
protected void registerListeners() { }
@Override
protected int getDepthBits() {
intBuffer.rewind();
getIntegerv(DEPTH_BITS, intBuffer);
return intBuffer.get(0);
}
@Override
protected int getStencilBits() {
intBuffer.rewind();
getIntegerv(STENCIL_BITS, intBuffer);
return intBuffer.get(0);
}
@Override
protected int getDefaultDrawBuffer() {
return fboLayerEnabled ? COLOR_ATTACHMENT0 : FRONT;
}
@Override
protected int getDefaultReadBuffer() {
return fboLayerEnabled ? COLOR_ATTACHMENT0 : FRONT;
}
///////////////////////////////////////////////////////////
// Frame rendering
@Override
protected float getPixelScale() {
return 1;
}
@Override
protected void getGL(PGL pgl) {
PGLES pgles = (PGLES)pgl;
this.gl = pgles.gl;
setThread(pgles.glThread);
}
@Override
protected boolean canDraw() {
return true;
}
@Override
protected void requestFocus() { }
@Override
protected void requestDraw() {
if (graphics.initialized && sketch.canDraw()) {
glview.requestRender();
}
}
@Override
protected void swapBuffers() { }
@Override
protected int getGLSLVersion() {
return 100;
}
@Override
protected void initFBOLayer() {
if (0 < sketch.frameCount) {
IntBuffer buf = allocateDirectIntBuffer(fboWidth * fboHeight);
if (hasReadBuffer()) readBuffer(BACK);
readPixelsImpl(0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
bindTexture(TEXTURE_2D, glColorTex.get(frontTex));
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
bindTexture(TEXTURE_2D, glColorTex.get(backTex));
texSubImage2D(TEXTURE_2D, 0, 0, 0, fboWidth, fboHeight, RGBA, UNSIGNED_BYTE, buf);
bindTexture(TEXTURE_2D, 0);
bindFramebufferImpl(FRAMEBUFFER, 0);
}
}
///////////////////////////////////////////////////////////
// Android specific classes (Renderer, ConfigChooser)
public AndroidRenderer getRenderer() {
renderer = new AndroidRenderer();
return renderer;
}
public AndroidContextFactory getContextFactory() {
return new AndroidContextFactory();
}
public AndroidConfigChooser getConfigChooser(int samples) {
configChooser = new AndroidConfigChooser(5, 6, 5, 4, 16, 1, samples);
return configChooser;
}
public AndroidConfigChooser getConfigChooser(int r, int g, int b, int a,
int d, int s, int samples) {
configChooser = new AndroidConfigChooser(r, g, b, a, d, s, samples);
return configChooser;
}
protected class AndroidRenderer implements Renderer {
public AndroidRenderer() {
}
public void onDrawFrame(GL10 igl) {
gl = igl;
glThread = Thread.currentThread();
sketch.handleDraw();
}
public void onSurfaceChanged(GL10 igl, int iwidth, int iheight) {
gl = igl;
// Here is where we should initialize native libs...
// lib.init(iwidth, iheight);
graphics.setSize(iwidth, iheight);
}
public void onSurfaceCreated(GL10 igl, EGLConfig config) {
gl = igl;
context = ((EGL10)EGLContext.getEGL()).eglGetCurrentContext();
glContext = context.hashCode();
glThread = Thread.currentThread();
if (!hasFBOs()) {
throw new RuntimeException(MISSING_FBO_ERROR);
}
if (!hasShaders()) {
throw new RuntimeException(MISSING_GLSL_ERROR);
}
}
}
protected class AndroidContextFactory implements
GLSurfaceView.EGLContextFactory {
public EGLContext createContext(EGL10 egl, EGLDisplay display,
EGLConfig eglConfig) {
int[] attrib_list = { EGL_CONTEXT_CLIENT_VERSION, 2,
EGL10.EGL_NONE };
EGLContext context = egl.eglCreateContext(display, eglConfig,
EGL10.EGL_NO_CONTEXT,
attrib_list);
return context;
}
public void destroyContext(EGL10 egl, EGLDisplay display,
EGLContext context) {
egl.eglDestroyContext(display, context);
}
}
protected class AndroidConfigChooser implements EGLConfigChooser {
// Desired size (in bits) for the rgba color, depth and stencil buffers.
public int redTarget;
public int greenTarget;
public int blueTarget;
public int alphaTarget;
public int depthTarget;
public int stencilTarget;
// Actual rgba color, depth and stencil sizes (in bits) supported by the
// device.
public int redBits;
public int greenBits;
public int blueBits;
public int alphaBits;
public int depthBits;
public int stencilBits;
public int[] tempValue = new int[1];
public int numSamples;
/*
The GLES2 extensions supported are:
GL_OES_rgb8_rgba8 GL_OES_depth24 GL_OES_vertex_half_float
GL_OES_texture_float GL_OES_texture_half_float
GL_OES_element_index_uint GL_OES_mapbuffer
GL_OES_fragment_precision_high GL_OES_compressed_ETC1_RGB8_texture
GL_OES_EGL_image GL_OES_required_internalformat GL_OES_depth_texture
GL_OES_get_program_binary GL_OES_packed_depth_stencil
GL_OES_standard_derivatives GL_OES_vertex_array_object GL_OES_egl_sync
GL_EXT_multi_draw_arrays GL_EXT_texture_format_BGRA8888
GL_EXT_discard_framebuffer GL_EXT_shader_texture_lod
GL_IMG_shader_binary GL_IMG_texture_compression_pvrtc
GL_IMG_texture_stream2 GL_IMG_texture_npot
GL_IMG_texture_format_BGRA8888 GL_IMG_read_format
GL_IMG_program_binary GL_IMG_multisampled_render_to_texture
*/
/*
// The attributes we want in the frame buffer configuration for Processing.
// For more details on other attributes, see:
// http://www.khronos.org/opengles/documentation/opengles1_0/html/eglChooseConfig.html
protected int[] configAttribsGL_MSAA = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 4,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_SAMPLE_BUFFERS, 1,
EGL10.EGL_SAMPLES, 2,
EGL10.EGL_NONE };
protected int[] configAttribsGL_CovMSAA = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 4,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_COVERAGE_BUFFERS_NV, 1,
EGL_COVERAGE_SAMPLES_NV, 2,
EGL10.EGL_NONE };
protected int[] configAttribsGL_NoMSAA = {
EGL10.EGL_RED_SIZE, 5,
EGL10.EGL_GREEN_SIZE, 6,
EGL10.EGL_BLUE_SIZE, 5,
EGL10.EGL_ALPHA_SIZE, 4,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE };
protected int[] configAttribsGL_Good = {
EGL10.EGL_RED_SIZE, 8,
EGL10.EGL_GREEN_SIZE, 8,
EGL10.EGL_BLUE_SIZE, 8,
EGL10.EGL_ALPHA_SIZE, 8,
EGL10.EGL_DEPTH_SIZE, 16,
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_NONE };
protected int[] configAttribsGL_TestMSAA = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_SAMPLE_BUFFERS, 1,
EGL10.EGL_SAMPLES, 2,
EGL10.EGL_NONE };
*/
protected int[] attribsNoMSAA = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_SAMPLE_BUFFERS, 0,
EGL10.EGL_NONE };
public AndroidConfigChooser(int rbits, int gbits, int bbits, int abits,
int dbits, int sbits, int samples) {
redTarget = rbits;
greenTarget = gbits;
blueTarget = bbits;
alphaTarget = abits;
depthTarget = dbits;
stencilTarget = sbits;
numSamples = samples;
}
public EGLConfig chooseConfig(EGL10 egl, EGLDisplay display) {
EGLConfig[] configs = null;
if (1 < numSamples) {
int[] attribs = new int[] {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL10.EGL_SAMPLE_BUFFERS, 1,
EGL10.EGL_SAMPLES, numSamples,
EGL10.EGL_NONE };
configs = chooseConfigWithAttribs(egl, display, attribs);
if (configs == null) {
// No normal multisampling config was found. Try to create a
// coverage multisampling configuration, for the nVidia Tegra2.
// See the EGL_NV_coverage_sample documentation.
int[] attribsCov = {
EGL10.EGL_RENDERABLE_TYPE, EGL_OPENGL_ES2_BIT,
EGL_COVERAGE_BUFFERS_NV, 1,
EGL_COVERAGE_SAMPLES_NV, numSamples,
EGL10.EGL_NONE };
configs = chooseConfigWithAttribs(egl, display, attribsCov);
if (configs == null) {
configs = chooseConfigWithAttribs(egl, display, attribsNoMSAA);
} else {
usingMultisampling = true;
usingCoverageMultisampling = true;
multisampleCount = numSamples;
}
} else {
usingMultisampling = true;
usingCoverageMultisampling = false;
multisampleCount = numSamples;
}
} else {
configs = chooseConfigWithAttribs(egl, display, attribsNoMSAA);
}
if (configs == null) {
throw new IllegalArgumentException("No EGL configs match configSpec");
}
if (PApplet.DEBUG) {
for (EGLConfig config : configs) {
String configStr = "P3D - selected EGL config : "
+ printConfig(egl, display, config);
System.out.println(configStr);
}
}
// Now return the configuration that best matches the target one.
return chooseBestConfig(egl, display, configs);
}
public EGLConfig chooseBestConfig(EGL10 egl, EGLDisplay display,
EGLConfig[] configs) {
EGLConfig bestConfig = null;
float bestScore = Float.MAX_VALUE;
for (EGLConfig config : configs) {
int gl = findConfigAttrib(egl, display, config,
EGL10.EGL_RENDERABLE_TYPE, 0);
boolean isGLES2 = (gl & EGL_OPENGL_ES2_BIT) != 0;
if (isGLES2) {
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
float score = 0.20f * PApplet.abs(r - redTarget) +
0.20f * PApplet.abs(g - greenTarget) +
0.20f * PApplet.abs(b - blueTarget) +
0.15f * PApplet.abs(a - alphaTarget) +
0.15f * PApplet.abs(d - depthTarget) +
0.10f * PApplet.abs(s - stencilTarget);
if (score < bestScore) {
// We look for the config closest to the target config.
// Closeness is measured by the score function defined above:
// we give more weight to the RGB components, followed by the
// alpha, depth and finally stencil bits.
bestConfig = config;
bestScore = score;
redBits = r;
greenBits = g;
blueBits = b;
alphaBits = a;
depthBits = d;
stencilBits = s;
}
}
}
if (PApplet.DEBUG) {
String configStr = "P3D - selected EGL config : "
+ printConfig(egl, display, bestConfig);
System.out.println(configStr);
}
return bestConfig;
}
protected String printConfig(EGL10 egl, EGLDisplay display,
EGLConfig config) {
int r = findConfigAttrib(egl, display, config,
EGL10.EGL_RED_SIZE, 0);
int g = findConfigAttrib(egl, display, config,
EGL10.EGL_GREEN_SIZE, 0);
int b = findConfigAttrib(egl, display, config,
EGL10.EGL_BLUE_SIZE, 0);
int a = findConfigAttrib(egl, display, config,
EGL10.EGL_ALPHA_SIZE, 0);
int d = findConfigAttrib(egl, display, config,
EGL10.EGL_DEPTH_SIZE, 0);
int s = findConfigAttrib(egl, display, config,
EGL10.EGL_STENCIL_SIZE, 0);
int type = findConfigAttrib(egl, display, config,
EGL10.EGL_RENDERABLE_TYPE, 0);
int nat = findConfigAttrib(egl, display, config,
EGL10.EGL_NATIVE_RENDERABLE, 0);
int bufSize = findConfigAttrib(egl, display, config,
EGL10.EGL_BUFFER_SIZE, 0);
int bufSurf = findConfigAttrib(egl, display, config,
EGL10.EGL_RENDER_BUFFER, 0);
return String.format("EGLConfig rgba=%d%d%d%d depth=%d stencil=%d",
r,g,b,a,d,s)
+ " type=" + type
+ " native=" + nat
+ " buffer size=" + bufSize
+ " buffer surface=" + bufSurf +
String.format(" caveat=0x%04x",
findConfigAttrib(egl, display, config,
EGL10.EGL_CONFIG_CAVEAT, 0));
}
protected int findConfigAttrib(EGL10 egl, EGLDisplay display,
EGLConfig config, int attribute, int defaultValue) {
if (egl.eglGetConfigAttrib(display, config, attribute, tempValue)) {
return tempValue[0];
}
return defaultValue;
}
protected EGLConfig[] chooseConfigWithAttribs(EGL10 egl,
EGLDisplay display,
int[] configAttribs) {
// Get the number of minimally matching EGL configurations
int[] configCounts = new int[1];
egl.eglChooseConfig(display, configAttribs, null, 0, configCounts);
int count = configCounts[0];
if (count <= 0) {
//throw new IllegalArgumentException("No EGL configs match configSpec");
return null;
}
// Allocate then read the array of minimally matching EGL configs
EGLConfig[] configs = new EGLConfig[count];
egl.eglChooseConfig(display, configAttribs, configs, count, configCounts);
return configs;
// Get the number of minimally matching EGL configurations
// int[] num_config = new int[1];
// egl.eglChooseConfig(display, configAttribsGL, null, 0, num_config);
//
// int numConfigs = num_config[0];
//
// if (numConfigs <= 0) {
// throw new IllegalArgumentException("No EGL configs match configSpec");
// }
//
// // Allocate then read the array of minimally matching EGL configs
// EGLConfig[] configs = new EGLConfig[numConfigs];
// egl.eglChooseConfig(display, configAttribsGL, configs, numConfigs,
// num_config);
}
}
///////////////////////////////////////////////////////////
// Tessellator interface
@Override
protected Tessellator createTessellator(TessellatorCallback callback) {
return new Tessellator(callback);
}
protected class Tessellator implements PGL.Tessellator {
protected PGLUtessellator tess;
protected TessellatorCallback callback;
protected GLUCallback gluCallback;
public Tessellator(TessellatorCallback callback) {
this.callback = callback;
tess = PGLU.gluNewTess();
gluCallback = new GLUCallback();
PGLU.gluTessCallback(tess, PGLU.GLU_TESS_BEGIN, gluCallback);
PGLU.gluTessCallback(tess, PGLU.GLU_TESS_END, gluCallback);
PGLU.gluTessCallback(tess, PGLU.GLU_TESS_VERTEX, gluCallback);
PGLU.gluTessCallback(tess, PGLU.GLU_TESS_COMBINE, gluCallback);
PGLU.gluTessCallback(tess, PGLU.GLU_TESS_ERROR, gluCallback);
}
public void beginPolygon() {
PGLU.gluTessBeginPolygon(tess, null);
}
public void endPolygon() {
PGLU.gluTessEndPolygon(tess);
}
public void setWindingRule(int rule) {
PGLU.gluTessProperty(tess, PGLU.GLU_TESS_WINDING_RULE, rule);
}
public void beginContour() {
PGLU.gluTessBeginContour(tess);
}
public void endContour() {
PGLU.gluTessEndContour(tess);
}
public void addVertex(double[] v) {
PGLU.gluTessVertex(tess, v, 0, v);
}
protected class GLUCallback extends PGLUtessellatorCallbackAdapter {
@Override
public void begin(int type) {
callback.begin(type);
}
@Override
public void end() {
callback.end();
}
@Override
public void vertex(Object data) {
callback.vertex(data);
}
@Override
public void combine(double[] coords, Object[] data,
float[] weight, Object[] outData) {
callback.combine(coords, data, weight, outData);
}
@Override
public void error(int errnum) {
callback.error(errnum);
}
}
}
@Override
protected String tessError(int err) {
return PGLU.gluErrorString(err);
}
///////////////////////////////////////////////////////////
// Font outline
static {
SHAPE_TEXT_SUPPORTED = false;
}
@Override
protected FontOutline createFontOutline(char ch, Object font) {
return null;
}
///////////////////////////////////////////////////////////
// Constants
//
// The values for constants not defined in the GLES20 interface can be found
// in this file:
// http://code.metager.de/source/xref/android/4.0.3/development/tools/glesv2debugger/src/com/android/glesv2debugger/GLEnum.java
static {
FALSE = GLES20.GL_FALSE;
TRUE = GLES20.GL_TRUE;
INT = GLES20.GL_INT;
BYTE = GLES20.GL_BYTE;
SHORT = GLES20.GL_SHORT;
FLOAT = GLES20.GL_FLOAT;
BOOL = GLES20.GL_BOOL;
UNSIGNED_INT = GLES20.GL_UNSIGNED_INT;
UNSIGNED_BYTE = GLES20.GL_UNSIGNED_BYTE;
UNSIGNED_SHORT = GLES20.GL_UNSIGNED_SHORT;
RGB = GLES20.GL_RGB;
RGBA = GLES20.GL_RGBA;
ALPHA = GLES20.GL_ALPHA;
LUMINANCE = GLES20.GL_LUMINANCE;
LUMINANCE_ALPHA = GLES20.GL_LUMINANCE_ALPHA;
UNSIGNED_SHORT_5_6_5 = GLES20.GL_UNSIGNED_SHORT_5_6_5;
UNSIGNED_SHORT_4_4_4_4 = GLES20.GL_UNSIGNED_SHORT_4_4_4_4;
UNSIGNED_SHORT_5_5_5_1 = GLES20.GL_UNSIGNED_SHORT_5_5_5_1;
RGBA4 = GLES20.GL_RGBA4;
RGB5_A1 = GLES20.GL_RGB5_A1;
RGB565 = GLES20.GL_RGB565;
RGB8 = 0x8051;
RGBA8 = 0x8058;
ALPHA8 = -1;
READ_ONLY = -1;
WRITE_ONLY = 0x88B9;
READ_WRITE = -1;
TESS_WINDING_NONZERO = PGLU.GLU_TESS_WINDING_NONZERO;
TESS_WINDING_ODD = PGLU.GLU_TESS_WINDING_ODD;
GENERATE_MIPMAP_HINT = GLES20.GL_GENERATE_MIPMAP_HINT;
FASTEST = GLES20.GL_FASTEST;
NICEST = GLES20.GL_NICEST;
DONT_CARE = GLES20.GL_DONT_CARE;
VENDOR = GLES20.GL_VENDOR;
RENDERER = GLES20.GL_RENDERER;
VERSION = GLES20.GL_VERSION;
EXTENSIONS = GLES20.GL_EXTENSIONS;
SHADING_LANGUAGE_VERSION = GLES20.GL_SHADING_LANGUAGE_VERSION;
MAX_SAMPLES = -1;
SAMPLES = GLES20.GL_SAMPLES;
ALIASED_LINE_WIDTH_RANGE = GLES20.GL_ALIASED_LINE_WIDTH_RANGE;
ALIASED_POINT_SIZE_RANGE = GLES20.GL_ALIASED_POINT_SIZE_RANGE;
DEPTH_BITS = GLES20.GL_DEPTH_BITS;
STENCIL_BITS = GLES20.GL_STENCIL_BITS;
CCW = GLES20.GL_CCW;
CW = GLES20.GL_CW;
VIEWPORT = GLES20.GL_VIEWPORT;
ARRAY_BUFFER = GLES20.GL_ARRAY_BUFFER;
ELEMENT_ARRAY_BUFFER = GLES20.GL_ELEMENT_ARRAY_BUFFER;
MAX_VERTEX_ATTRIBS = GLES20.GL_MAX_VERTEX_ATTRIBS;
STATIC_DRAW = GLES20.GL_STATIC_DRAW;
DYNAMIC_DRAW = GLES20.GL_DYNAMIC_DRAW;
STREAM_DRAW = GLES20.GL_STREAM_DRAW;
BUFFER_SIZE = GLES20.GL_BUFFER_SIZE;
BUFFER_USAGE = GLES20.GL_BUFFER_USAGE;
POINTS = GLES20.GL_POINTS;
LINE_STRIP = GLES20.GL_LINE_STRIP;
LINE_LOOP = GLES20.GL_LINE_LOOP;
LINES = GLES20.GL_LINES;
TRIANGLE_FAN = GLES20.GL_TRIANGLE_FAN;
TRIANGLE_STRIP = GLES20.GL_TRIANGLE_STRIP;
TRIANGLES = GLES20.GL_TRIANGLES;
CULL_FACE = GLES20.GL_CULL_FACE;
FRONT = GLES20.GL_FRONT;
BACK = GLES20.GL_BACK;
FRONT_AND_BACK = GLES20.GL_FRONT_AND_BACK;
POLYGON_OFFSET_FILL = GLES20.GL_POLYGON_OFFSET_FILL;
UNPACK_ALIGNMENT = GLES20.GL_UNPACK_ALIGNMENT;
PACK_ALIGNMENT = GLES20.GL_PACK_ALIGNMENT;
TEXTURE_2D = GLES20.GL_TEXTURE_2D;
TEXTURE_RECTANGLE = -1;
TEXTURE_BINDING_2D = GLES20.GL_TEXTURE_BINDING_2D;
TEXTURE_BINDING_RECTANGLE = -1;
MAX_TEXTURE_SIZE = GLES20.GL_MAX_TEXTURE_SIZE;
TEXTURE_MAX_ANISOTROPY = 0x84FE;
MAX_TEXTURE_MAX_ANISOTROPY = 0x84FF;
MAX_VERTEX_TEXTURE_IMAGE_UNITS = GLES20.GL_MAX_VERTEX_TEXTURE_IMAGE_UNITS;
MAX_TEXTURE_IMAGE_UNITS = GLES20.GL_MAX_TEXTURE_IMAGE_UNITS;
MAX_COMBINED_TEXTURE_IMAGE_UNITS = GLES20.GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS;
NUM_COMPRESSED_TEXTURE_FORMATS = GLES20.GL_NUM_COMPRESSED_TEXTURE_FORMATS;
COMPRESSED_TEXTURE_FORMATS = GLES20.GL_COMPRESSED_TEXTURE_FORMATS;
NEAREST = GLES20.GL_NEAREST;
LINEAR = GLES20.GL_LINEAR;
LINEAR_MIPMAP_NEAREST = GLES20.GL_LINEAR_MIPMAP_NEAREST;
LINEAR_MIPMAP_LINEAR = GLES20.GL_LINEAR_MIPMAP_LINEAR;
CLAMP_TO_EDGE = GLES20.GL_CLAMP_TO_EDGE;
REPEAT = GLES20.GL_REPEAT;
TEXTURE0 = GLES20.GL_TEXTURE0;
TEXTURE1 = GLES20.GL_TEXTURE1;
TEXTURE2 = GLES20.GL_TEXTURE2;
TEXTURE3 = GLES20.GL_TEXTURE3;
TEXTURE_MIN_FILTER = GLES20.GL_TEXTURE_MIN_FILTER;
TEXTURE_MAG_FILTER = GLES20.GL_TEXTURE_MAG_FILTER;
TEXTURE_WRAP_S = GLES20.GL_TEXTURE_WRAP_S;
TEXTURE_WRAP_T = GLES20.GL_TEXTURE_WRAP_T;
TEXTURE_WRAP_R = 0x8072;
TEXTURE_CUBE_MAP = GLES20.GL_TEXTURE_CUBE_MAP;
TEXTURE_CUBE_MAP_POSITIVE_X = GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_X;
TEXTURE_CUBE_MAP_POSITIVE_Y = GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_Y;
TEXTURE_CUBE_MAP_POSITIVE_Z = GLES20.GL_TEXTURE_CUBE_MAP_POSITIVE_Z;
TEXTURE_CUBE_MAP_NEGATIVE_X = GLES20.GL_TEXTURE_CUBE_MAP_NEGATIVE_X;
TEXTURE_CUBE_MAP_NEGATIVE_Y = GLES20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Y;
TEXTURE_CUBE_MAP_NEGATIVE_Z = GLES20.GL_TEXTURE_CUBE_MAP_NEGATIVE_Z;
VERTEX_SHADER = GLES20.GL_VERTEX_SHADER;
FRAGMENT_SHADER = GLES20.GL_FRAGMENT_SHADER;
INFO_LOG_LENGTH = GLES20.GL_INFO_LOG_LENGTH;
SHADER_SOURCE_LENGTH = GLES20.GL_SHADER_SOURCE_LENGTH;
COMPILE_STATUS = GLES20.GL_COMPILE_STATUS;
LINK_STATUS = GLES20.GL_LINK_STATUS;
VALIDATE_STATUS = GLES20.GL_VALIDATE_STATUS;
SHADER_TYPE = GLES20.GL_SHADER_TYPE;
DELETE_STATUS = GLES20.GL_DELETE_STATUS;
FLOAT_VEC2 = GLES20.GL_FLOAT_VEC2;
FLOAT_VEC3 = GLES20.GL_FLOAT_VEC3;
FLOAT_VEC4 = GLES20.GL_FLOAT_VEC4;
FLOAT_MAT2 = GLES20.GL_FLOAT_MAT2;
FLOAT_MAT3 = GLES20.GL_FLOAT_MAT3;
FLOAT_MAT4 = GLES20.GL_FLOAT_MAT4;
INT_VEC2 = GLES20.GL_INT_VEC2;
INT_VEC3 = GLES20.GL_INT_VEC3;
INT_VEC4 = GLES20.GL_INT_VEC4;
BOOL_VEC2 = GLES20.GL_BOOL_VEC2;
BOOL_VEC3 = GLES20.GL_BOOL_VEC3;
BOOL_VEC4 = GLES20.GL_BOOL_VEC4;
SAMPLER_2D = GLES20.GL_SAMPLER_2D;
SAMPLER_CUBE = GLES20.GL_SAMPLER_CUBE;
LOW_FLOAT = GLES20.GL_LOW_FLOAT;
MEDIUM_FLOAT = GLES20.GL_MEDIUM_FLOAT;
HIGH_FLOAT = GLES20.GL_HIGH_FLOAT;
LOW_INT = GLES20.GL_LOW_INT;
MEDIUM_INT = GLES20.GL_MEDIUM_INT;
HIGH_INT = GLES20.GL_HIGH_INT;
CURRENT_VERTEX_ATTRIB = GLES20.GL_CURRENT_VERTEX_ATTRIB;
VERTEX_ATTRIB_ARRAY_BUFFER_BINDING = GLES20.GL_VERTEX_ATTRIB_ARRAY_BUFFER_BINDING;
VERTEX_ATTRIB_ARRAY_ENABLED = GLES20.GL_VERTEX_ATTRIB_ARRAY_ENABLED;
VERTEX_ATTRIB_ARRAY_SIZE = GLES20.GL_VERTEX_ATTRIB_ARRAY_SIZE;
VERTEX_ATTRIB_ARRAY_STRIDE = GLES20.GL_VERTEX_ATTRIB_ARRAY_STRIDE;
VERTEX_ATTRIB_ARRAY_TYPE = GLES20.GL_VERTEX_ATTRIB_ARRAY_TYPE;
VERTEX_ATTRIB_ARRAY_NORMALIZED = GLES20.GL_VERTEX_ATTRIB_ARRAY_NORMALIZED;
VERTEX_ATTRIB_ARRAY_POINTER = GLES20.GL_VERTEX_ATTRIB_ARRAY_POINTER;
BLEND = GLES20.GL_BLEND;
ONE = GLES20.GL_ONE;
ZERO = GLES20.GL_ZERO;
SRC_ALPHA = GLES20.GL_SRC_ALPHA;
DST_ALPHA = GLES20.GL_DST_ALPHA;
ONE_MINUS_SRC_ALPHA = GLES20.GL_ONE_MINUS_SRC_ALPHA;
ONE_MINUS_DST_COLOR = GLES20.GL_ONE_MINUS_DST_COLOR;
ONE_MINUS_SRC_COLOR = GLES20.GL_ONE_MINUS_SRC_COLOR;
DST_COLOR = GLES20.GL_DST_COLOR;
SRC_COLOR = GLES20.GL_SRC_COLOR;
SAMPLE_ALPHA_TO_COVERAGE = GLES20.GL_SAMPLE_ALPHA_TO_COVERAGE;
SAMPLE_COVERAGE = GLES20.GL_SAMPLE_COVERAGE;
KEEP = GLES20.GL_KEEP;
REPLACE = GLES20.GL_REPLACE;
INCR = GLES20.GL_INCR;
DECR = GLES20.GL_DECR;
INVERT = GLES20.GL_INVERT;
INCR_WRAP = GLES20.GL_INCR_WRAP;
DECR_WRAP = GLES20.GL_DECR_WRAP;
NEVER = GLES20.GL_NEVER;
ALWAYS = GLES20.GL_ALWAYS;
EQUAL = GLES20.GL_EQUAL;
LESS = GLES20.GL_LESS;
LEQUAL = GLES20.GL_LEQUAL;
GREATER = GLES20.GL_GREATER;
GEQUAL = GLES20.GL_GEQUAL;
NOTEQUAL = GLES20.GL_NOTEQUAL;
FUNC_ADD = GLES20.GL_FUNC_ADD;
FUNC_MIN = 0x8007;
FUNC_MAX = 0x8008;
FUNC_REVERSE_SUBTRACT = GLES20.GL_FUNC_REVERSE_SUBTRACT;
FUNC_SUBTRACT = GLES20.GL_FUNC_SUBTRACT;
DITHER = GLES20.GL_DITHER;
CONSTANT_COLOR = GLES20.GL_CONSTANT_COLOR;
CONSTANT_ALPHA = GLES20.GL_CONSTANT_ALPHA;
ONE_MINUS_CONSTANT_COLOR = GLES20.GL_ONE_MINUS_CONSTANT_COLOR;
ONE_MINUS_CONSTANT_ALPHA = GLES20.GL_ONE_MINUS_CONSTANT_ALPHA;
SRC_ALPHA_SATURATE = GLES20.GL_SRC_ALPHA_SATURATE;
SCISSOR_TEST = GLES20.GL_SCISSOR_TEST;
STENCIL_TEST = GLES20.GL_STENCIL_TEST;
DEPTH_TEST = GLES20.GL_DEPTH_TEST;
DEPTH_WRITEMASK = GLES20.GL_DEPTH_WRITEMASK;
COLOR_BUFFER_BIT = GLES20.GL_COLOR_BUFFER_BIT;
DEPTH_BUFFER_BIT = GLES20.GL_DEPTH_BUFFER_BIT;
STENCIL_BUFFER_BIT = GLES20.GL_STENCIL_BUFFER_BIT;
FRAMEBUFFER = GLES20.GL_FRAMEBUFFER;
COLOR_ATTACHMENT0 = GLES20.GL_COLOR_ATTACHMENT0;
COLOR_ATTACHMENT1 = -1;
COLOR_ATTACHMENT2 = -1;
COLOR_ATTACHMENT3 = -1;
RENDERBUFFER = GLES20.GL_RENDERBUFFER;
DEPTH_ATTACHMENT = GLES20.GL_DEPTH_ATTACHMENT;
STENCIL_ATTACHMENT = GLES20.GL_STENCIL_ATTACHMENT;
READ_FRAMEBUFFER = -1;
DRAW_FRAMEBUFFER = -1;
DEPTH24_STENCIL8 = 0x88F0;
DEPTH_COMPONENT = GLES20.GL_DEPTH_COMPONENT;
DEPTH_COMPONENT16 = GLES20.GL_DEPTH_COMPONENT16;
DEPTH_COMPONENT24 = 0x81A6;
DEPTH_COMPONENT32 = 0x81A7;
STENCIL_INDEX = 6401; // GLES20.GL_STENCIL_INDEX is marked as deprecated
STENCIL_INDEX1 = 0x8D46;
STENCIL_INDEX4 = 0x8D47;
STENCIL_INDEX8 = GLES20.GL_STENCIL_INDEX8;
DEPTH_STENCIL = 0x84F9;
FRAMEBUFFER_COMPLETE = GLES20.GL_FRAMEBUFFER_COMPLETE;
FRAMEBUFFER_INCOMPLETE_ATTACHMENT = GLES20.GL_FRAMEBUFFER_INCOMPLETE_ATTACHMENT;
FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT = GLES20.GL_FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT;
FRAMEBUFFER_INCOMPLETE_DIMENSIONS = GLES20.GL_FRAMEBUFFER_INCOMPLETE_DIMENSIONS;
FRAMEBUFFER_INCOMPLETE_FORMATS = 0x8CDA;
FRAMEBUFFER_INCOMPLETE_DRAW_BUFFER = -1;
FRAMEBUFFER_INCOMPLETE_READ_BUFFER = -1;
FRAMEBUFFER_UNSUPPORTED = GLES20.GL_FRAMEBUFFER_UNSUPPORTED;
FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE = GLES20.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_TYPE;
FRAMEBUFFER_ATTACHMENT_OBJECT_NAME = GLES20.GL_FRAMEBUFFER_ATTACHMENT_OBJECT_NAME;
FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL = GLES20.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_LEVEL;
FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE = GLES20.GL_FRAMEBUFFER_ATTACHMENT_TEXTURE_CUBE_MAP_FACE;