This repository was archived by the owner on May 11, 2025. It is now read-only.
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
1604 lines (1240 loc) · 44.3 KB
/
PGLES.java
File metadata and controls
1604 lines (1240 loc) · 44.3 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-16 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.EGLContext;
import javax.microedition.khronos.opengles.GL10;
import android.opengl.GLES20;
import android.opengl.GLSurfaceView;
import android.opengl.GLU;
import android.view.SurfaceView;
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 EGLContext context;
/** The current surface view */
public GLSurfaceView glview;
// ........................................................
// 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.
public static final int EGL_CONTEXT_CLIENT_VERSION = 0x3098;
public static final int EGL_OPENGL_ES2_BIT = 0x0004;
// Coverage multisampling identifiers for nVidia Tegra2
public static final int EGL_COVERAGE_BUFFERS_NV = 0x30E0;
public static final int EGL_COVERAGE_SAMPLES_NV = 0x30E1;
public static final int GL_COVERAGE_BUFFER_BIT_NV = 0x8000;
public static boolean usingMultisampling = false;
public static boolean usingCoverageMultisampling = false;
public static int multisampleCount = 1;
///////////////////////////////////////////////////////////
// Initialization, finalization
public PGLES(PGraphicsOpenGL pg) {
super(pg);
glu = new PGLU();
}
@Override
public GLSurfaceView getNative() {
return glview;
}
@Override
public void queueEvent(Runnable runnable) {
if (glview != null) {
glview.queueEvent(runnable);
}
}
@Override
protected void initSurface(int antialias) {
SurfaceView surf = sketch.getSurface().getSurfaceView();
if (surf != null) {
glview = (GLSurfaceView)surf;
}
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;
}
public void init(GL10 igl) {
gl = igl;
context = ((EGL10)EGLContext.getEGL()).eglGetCurrentContext();
glContext = context.hashCode();
glThread = Thread.currentThread();
if (!hasFBOs()) {
throw new RuntimeException(PGL.MISSING_FBO_ERROR);
}
if (!hasShaders()) {
throw new RuntimeException(PGL.MISSING_GLSL_ERROR);
}
}
///////////////////////////////////////////////////////////
// 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);
}
public void getGL(GL10 igl) {
gl = igl;
glThread = Thread.currentThread();
}
@Override
protected boolean canDraw() { return true; }
@Override
protected void requestFocus() { }
@Override
protected void requestDraw() { }
@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);
}
}
@Override
protected void clearFrontColorBuffer() {
// Need to front clear color buffer, otherwise one can lead to the screen not clearning
// properly in sketches that do not call background() continously in draw() but only at
// specific events.
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
TEXTURE_2D, glColorTex.get(frontTex), 0);
clear(COLOR_BUFFER_BIT);
framebufferTexture2D(FRAMEBUFFER, COLOR_ATTACHMENT0,
TEXTURE_2D, glColorTex.get(backTex), 0);
}
///////////////////////////////////////////////////////////
// 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);
}
@Override
public void setCallback(int flag) {
PGLU.gluTessCallback(tess, flag, gluCallback);
}
@Override
public void setWindingRule(int rule) {
setProperty(PGLU.GLU_TESS_WINDING_RULE, rule);
}
public void setProperty(int property, int value) {
PGLU.gluTessProperty(tess, property, value);
}
@Override
public void beginPolygon() {
beginPolygon(null);
}
@Override
public void beginPolygon(Object data) {
PGLU.gluTessBeginPolygon(tess, data);
}
@Override
public void endPolygon() {
PGLU.gluTessEndPolygon(tess);
}
@Override
public void beginContour() {
PGLU.gluTessBeginContour(tess);
}
@Override
public void endContour() {
PGLU.gluTessEndContour(tess);
}
@Override
public void addVertex(double[] v) {
addVertex(v, 0, v);
}
@Override
public void addVertex(double[] v, int n, Object data) {
PGLU.gluTessVertex(tess, v, n, data);
}
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;
TESS_EDGE_FLAG = PGLU.GLU_TESS_EDGE_FLAG;
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;
RENDERBUFFER_WIDTH = GLES20.GL_RENDERBUFFER_WIDTH;
RENDERBUFFER_HEIGHT = GLES20.GL_RENDERBUFFER_HEIGHT;
RENDERBUFFER_RED_SIZE = GLES20.GL_RENDERBUFFER_RED_SIZE;
RENDERBUFFER_GREEN_SIZE = GLES20.GL_RENDERBUFFER_GREEN_SIZE;
RENDERBUFFER_BLUE_SIZE = GLES20.GL_RENDERBUFFER_BLUE_SIZE;
RENDERBUFFER_ALPHA_SIZE = GLES20.GL_RENDERBUFFER_ALPHA_SIZE;
RENDERBUFFER_DEPTH_SIZE = GLES20.GL_RENDERBUFFER_DEPTH_SIZE;
RENDERBUFFER_STENCIL_SIZE = GLES20.GL_RENDERBUFFER_STENCIL_SIZE;
RENDERBUFFER_INTERNAL_FORMAT = GLES20.GL_RENDERBUFFER_INTERNAL_FORMAT;
MULTISAMPLE = -1;
LINE_SMOOTH = -1;
POLYGON_SMOOTH = -1;
}
///////////////////////////////////////////////////////////
// Special Functions
@Override
public void flush() {
GLES20.glFlush();
}
@Override
public void finish() {
GLES20.glFinish();
}
@Override
public void hint(int target, int hint) {
GLES20.glHint(target, hint);
}
///////////////////////////////////////////////////////////
// State and State Requests
@Override
public void enable(int value) {
if (-1 < value) {
GLES20.glEnable(value);
}
}
@Override
public void disable(int value) {
if (-1 < value) {
GLES20.glDisable(value);
}
}
@Override
public void getBooleanv(int name, IntBuffer values) {
if (-1 < name) {
GLES20.glGetBooleanv(name, values);
} else {
fillIntBuffer(values, 0, values.capacity(), 0);
}
}
@Override
public void getIntegerv(int value, IntBuffer data) {
if (-1 < value) {
GLES20.glGetIntegerv(value, data);
} else {
fillIntBuffer(data, 0, data.capacity() - 1, 0);
}
}
@Override
public void getFloatv(int value, FloatBuffer data) {
if (-1 < value) {
GLES20.glGetFloatv(value, data);
} else {
fillFloatBuffer(data, 0, data.capacity() - 1, 0);
}
}
@Override
public boolean isEnabled(int value) {
return GLES20.glIsEnabled(value);
}
@Override
public String getString(int name) {
return GLES20.glGetString(name);
}
///////////////////////////////////////////////////////////
// Error Handling
@Override
public int getError() {
return GLES20.glGetError();
}
@Override
public String errorString(int err) {
return GLU.gluErrorString(err);
}
//////////////////////////////////////////////////////////////////////////////
// Buffer Objects
@Override
public void genBuffers(int n, IntBuffer buffers) {
GLES20.glGenBuffers(n, buffers);
}
@Override
public void deleteBuffers(int n, IntBuffer buffers) {
GLES20.glDeleteBuffers(n, buffers);
}
@Override
public void bindBuffer(int target, int buffer) {
GLES20.glBindBuffer(target, buffer);
}
@Override
public void bufferData(int target, int size, Buffer data, int usage) {
GLES20.glBufferData(target, size, data, usage);
}
@Override
public void bufferSubData(int target, int offset, int size, Buffer data) {
GLES20.glBufferSubData(target, offset, size, data);
}
@Override
public void isBuffer(int buffer) {
GLES20.glIsBuffer(buffer);
}
@Override
public void getBufferParameteriv(int target, int value, IntBuffer data) {
GLES20.glGetBufferParameteriv(target, value, data);
}
@Override
public ByteBuffer mapBuffer(int target, int access) {
throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glMapBuffer"));
}
@Override
public ByteBuffer mapBufferRange(int target, int offset, int length, int access) {
throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glMapBufferRange"));
}
@Override
public void unmapBuffer(int target) {
throw new RuntimeException(String.format(MISSING_GLFUNC_ERROR, "glUnmapBuffer"));
}
//////////////////////////////////////////////////////////////////////////////
// Viewport and Clipping
@Override
public void depthRangef(float n, float f) {
GLES20.glDepthRangef(n, f);
}
@Override
public void viewport(int x, int y, int w, int h) {
float scale = getPixelScale();
viewportImpl((int)scale * x, (int)(scale * y), (int)(scale * w), (int)(scale * h));
}
@Override
protected void viewportImpl(int x, int y, int w, int h) {
GLES20.glViewport(x, y, w, h);
}
//////////////////////////////////////////////////////////////////////////////
// Reading Pixels
@Override
public void readPixelsImpl(int x, int y, int width, int height, int format, int type, Buffer buffer) {
GLES20.glReadPixels(x, y, width, height, format, type, buffer);
}
@Override
protected void readPixelsImpl(int x, int y, int width, int height, int format,
int type, long offset) {
// TODO Auto-generated method stub
}
//////////////////////////////////////////////////////////////////////////////
// Vertices
@Override
public void vertexAttrib1f(int index, float value) {
GLES20.glVertexAttrib1f(index, value);
}
@Override
public void vertexAttrib2f(int index, float value0, float value1) {
GLES20.glVertexAttrib2f(index, value0, value1);
}
@Override
public void vertexAttrib3f(int index, float value0, float value1, float value2) {
GLES20.glVertexAttrib3f(index, value0, value1, value2);
}
@Override
public void vertexAttrib4f(int index, float value0, float value1, float value2, float value3) {
GLES20.glVertexAttrib4f(index, value0, value1, value2, value3);
}
@Override
public void vertexAttrib1fv(int index, FloatBuffer values) {
GLES20.glVertexAttrib1fv(index, values);
}
@Override
public void vertexAttrib2fv(int index, FloatBuffer values) {
GLES20.glVertexAttrib2fv(index, values);
}
@Override
public void vertexAttrib3fv(int index, FloatBuffer values) {
GLES20.glVertexAttrib3fv(index, values);
}
@Override
public void vertexAttrib4fv(int index, FloatBuffer values) {
GLES20.glVertexAttrib4fv(index, values);
}
@Override
public void vertexAttribPointer(int index, int size, int type, boolean normalized, int stride, int offset) {
GLES20.glVertexAttribPointer(index, size, type, normalized, stride, offset);
}
@Override
public void enableVertexAttribArray(int index) {
GLES20.glEnableVertexAttribArray(index);
}
@Override
public void disableVertexAttribArray(int index) {
GLES20.glDisableVertexAttribArray(index);
}
@Override
public void drawArraysImpl(int mode, int first, int count) {
GLES20.glDrawArrays(mode, first, count);
}
@Override
public void drawElementsImpl(int mode, int count, int type, int offset) {
GLES20.glDrawElements(mode, count, type, offset);
}
//////////////////////////////////////////////////////////////////////////////
// Rasterization
@Override
public void lineWidth(float width) {
GLES20.glLineWidth(width);
}
@Override
public void frontFace(int dir) {
GLES20.glFrontFace(dir);
}
@Override
public void cullFace(int mode) {
GLES20.glCullFace(mode);
}
@Override
public void polygonOffset(float factor, float units) {
GLES20.glPolygonOffset(factor, units);
}
//////////////////////////////////////////////////////////////////////////////
// Pixel Rectangles
@Override
public void pixelStorei(int pname, int param) {
GLES20.glPixelStorei(pname, param);
}
///////////////////////////////////////////////////////////
// Texturing
@Override
public void texImage2D(int target, int level, int internalFormat, int width, int height, int border, int format, int type, Buffer data) {
GLES20.glTexImage2D(target, level, internalFormat, width, height, border, format, type, data);
}
@Override
public void copyTexImage2D(int target, int level, int internalFormat, int x, int y, int width, int height, int border) {
GLES20.glCopyTexImage2D(target, level, internalFormat, x, y, width, height, border);
}
@Override
public void texSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int type, Buffer data) {
GLES20.glTexSubImage2D(target, level, xOffset, yOffset, width, height, format, type, data);
}
@Override
public void copyTexSubImage2D(int target, int level, int xOffset, int yOffset, int x, int y, int width, int height) {
GLES20.glCopyTexSubImage2D(target, level, x, y, xOffset, yOffset, width, height);
}
@Override
public void compressedTexImage2D(int target, int level, int internalFormat, int width, int height, int border, int imageSize, Buffer data) {
GLES20.glCompressedTexImage2D(target, level, internalFormat, width, height, border, imageSize, data);
}
@Override
public void compressedTexSubImage2D(int target, int level, int xOffset, int yOffset, int width, int height, int format, int imageSize, Buffer data) {