-
Notifications
You must be signed in to change notification settings - Fork 93
/
OpenGLDisplayDriver.ec
3871 lines (3380 loc) · 125 KB
/
OpenGLDisplayDriver.ec
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
// We were using PBUFFER for alpha compositing on Linux before, but it does not seem to work, nor be required anymore.
// #define USEPBUFFER
namespace gfx::drivers;
// OpenGL Extensions
#if defined(__unix__) || defined(__APPLE__)
#if !defined(__MINGW32__)
#define GL_GLEXT_PROTOTYPES
#endif
#ifdef ECERE_MINIGLX
//#include <GL/miniglx.h>
#else
#if defined(__ANDROID__)
#else
#define property _property
#define new _new
#define class _class
#define Window X11Window
#define Cursor X11Cursor
#define Font X11Font
#define Display X11Display
#define Time X11Time
#define KeyCode X11KeyCode
#define Picture X11Picture
#define uint _uint
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <GL/glx.h>
#include <X11/extensions/XShm.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <X11/extensions/Xrender.h>
#include <X11/extensions/shape.h>
#undef Window
#undef Cursor
#undef Font
#undef Display
#undef Time
#undef KeyCode
#undef Picture
#undef uint
#undef new
#undef property
#undef class
#endif
#endif
#endif
#if defined(__APPLE__)
#include <OpenGl/gl.h>
#endif
#if defined(__WIN32__) || defined(__unix__) || defined(__APPLE__)
#if defined(__WIN32__)
#define WIN32_LEAN_AND_MEAN
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#define String Sting_
#include <windows.h>
#undef String
#endif
#if defined(__ANDROID__)
#include <GLES/gl.h>
#include <EGL/egl.h>
#else
#include <GL/gl.h>
#include <GL/glext.h>
#endif
import "Display"
#if defined(__unix__) || defined(__APPLE__)
#ifndef __ANDROID__
import "XInterface"
#endif
#endif
static double nearPlane = 1;
#define glLoadMatrix glLoadMatrixd
#define glMultMatrix glMultMatrixd
#define glGetMatrix glGetDoublev
#define glTranslate glTranslated
#define glScale glScaled
/*
#define glVertex3v glVertex3dv
#define glNormal3v glNormal3dv
*/
/*
//#ifdef VERTEX_FORMAT_DOUBLE
#define glLoadMatrix glLoadMatrixd
#define glMultMatrix glMultMatrixd
#define glGetMatrix glGetDoublev
#define glVertex3v glVertex3dv
#define glNormal3v glNormal3dv
#define glTranslate glTranslated
#define glScale glScaled
//#define GL_VERTEX_FORMAT GL_DOUBLE
#else
#define glLoadMatrix glLoadMatrixf
#define glMultMatrix glMultMatrixf
#define glGetMatrix glGetFloatv
#define glVertex3v glVertex3fv
#define glNormal3v glNormal3fv
#define glTranslate glTranslatef
#define glScale glScalef
//#define GL_VERTEX_FORMAT GL_FLOAT
#endif
*/
#define GL_ARRAY_BUFFER_ARB 0x8892
#define GL_ELEMENT_ARRAY_BUFFER_ARB 0x8893
#define GL_STATIC_DRAW_ARB 0x88E4
#define GL_LIGHT_MODEL_COLOR_CONTROL 0x81F8
#define GL_SEPARATE_SPECULAR_COLOR 0x81FA
#define GL_MULTISAMPLE_ARB 0x809D
#if defined(__WIN32__)
#define WGL_SAMPLE_BUFFERS_ARB 0x2041
#define WGL_SAMPLES_ARB 0x2042
#define WGL_WGLEXT_VERSION 1
#define WGL_FRONT_COLOR_BUFFER_BIT_ARB 0x00000001
#define WGL_BACK_COLOR_BUFFER_BIT_ARB 0x00000002
#define WGL_DEPTH_BUFFER_BIT_ARB 0x00000004
#define WGL_STENCIL_BUFFER_BIT_ARB 0x00000008
#define WGL_NUMBER_PIXEL_FORMATS_ARB 0x2000
#define WGL_DRAW_TO_WINDOW_ARB 0x2001
#define WGL_DRAW_TO_BITMAP_ARB 0x2002
#define WGL_ACCELERATION_ARB 0x2003
#define WGL_NEED_PALETTE_ARB 0x2004
#define WGL_NEED_SYSTEM_PALETTE_ARB 0x2005
#define WGL_SWAP_LAYER_BUFFERS_ARB 0x2006
#define WGL_SWAP_METHOD_ARB 0x2007
#define WGL_NUMBER_OVERLAYS_ARB 0x2008
#define WGL_NUMBER_UNDERLAYS_ARB 0x2009
#define WGL_TRANSPARENT_ARB 0x200A
#define WGL_TRANSPARENT_RED_VALUE_ARB 0x2037
#define WGL_TRANSPARENT_GREEN_VALUE_ARB 0x2038
#define WGL_TRANSPARENT_BLUE_VALUE_ARB 0x2039
#define WGL_TRANSPARENT_ALPHA_VALUE_ARB 0x203A
#define WGL_TRANSPARENT_INDEX_VALUE_ARB 0x203B
#define WGL_SHARE_DEPTH_ARB 0x200C
#define WGL_SHARE_STENCIL_ARB 0x200D
#define WGL_SHARE_ACCUM_ARB 0x200E
#define WGL_SUPPORT_GDI_ARB 0x200F
#define WGL_SUPPORT_OPENGL_ARB 0x2010
#define WGL_DOUBLE_BUFFER_ARB 0x2011
#define WGL_STEREO_ARB 0x2012
#define WGL_PIXEL_TYPE_ARB 0x2013
#define WGL_COLOR_BITS_ARB 0x2014
#define WGL_RED_BITS_ARB 0x2015
#define WGL_RED_SHIFT_ARB 0x2016
#define WGL_GREEN_BITS_ARB 0x2017
#define WGL_GREEN_SHIFT_ARB 0x2018
#define WGL_BLUE_BITS_ARB 0x2019
#define WGL_BLUE_SHIFT_ARB 0x201A
#define WGL_ALPHA_BITS_ARB 0x201B
#define WGL_ALPHA_SHIFT_ARB 0x201C
#define WGL_ACCUM_BITS_ARB 0x201D
#define WGL_ACCUM_RED_BITS_ARB 0x201E
#define WGL_ACCUM_GREEN_BITS_ARB 0x201F
#define WGL_ACCUM_BLUE_BITS_ARB 0x2020
#define WGL_ACCUM_ALPHA_BITS_ARB 0x2021
#define WGL_DEPTH_BITS_ARB 0x2022
#define WGL_STENCIL_BITS_ARB 0x2023
#define WGL_AUX_BUFFERS_ARB 0x2024
#define WGL_NO_ACCELERATION_ARB 0x2025
#define WGL_GENERIC_ACCELERATION_ARB 0x2026
#define WGL_FULL_ACCELERATION_ARB 0x2027
#define WGL_SWAP_EXCHANGE_ARB 0x2028
#define WGL_SWAP_COPY_ARB 0x2029
#define WGL_SWAP_UNDEFINED_ARB 0x202A
#define WGL_TYPE_RGBA_ARB 0x202B
#define WGL_TYPE_COLORINDEX_ARB 0x202C
#define ERROR_INVALID_PIXEL_TYPE_ARB 0x2043
#define ERROR_INCOMPATIBLE_DEVICE_CONTEXTS_ARB 0x2054
#define WGL_DRAW_TO_PBUFFER_ARB 0x202D
#define WGL_MAX_PBUFFER_PIXELS_ARB 0x202E
#define WGL_MAX_PBUFFER_WIDTH_ARB 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_ARB 0x2030
#define WGL_PBUFFER_LARGEST_ARB 0x2033
#define WGL_PBUFFER_WIDTH_ARB 0x2034
#define WGL_PBUFFER_HEIGHT_ARB 0x2035
#define WGL_PBUFFER_LOST_ARB 0x2036
#define ERROR_INVALID_PIXEL_TYPE_EXT 0x2043
#define WGL_NUMBER_PIXEL_FORMATS_EXT 0x2000
#define WGL_DRAW_TO_WINDOW_EXT 0x2001
#define WGL_DRAW_TO_BITMAP_EXT 0x2002
#define WGL_ACCELERATION_EXT 0x2003
#define WGL_NEED_PALETTE_EXT 0x2004
#define WGL_NEED_SYSTEM_PALETTE_EXT 0x2005
#define WGL_SWAP_LAYER_BUFFERS_EXT 0x2006
#define WGL_SWAP_METHOD_EXT 0x2007
#define WGL_NUMBER_OVERLAYS_EXT 0x2008
#define WGL_NUMBER_UNDERLAYS_EXT 0x2009
#define WGL_TRANSPARENT_EXT 0x200A
#define WGL_TRANSPARENT_VALUE_EXT 0x200B
#define WGL_SHARE_DEPTH_EXT 0x200C
#define WGL_SHARE_STENCIL_EXT 0x200D
#define WGL_SHARE_ACCUM_EXT 0x200E
#define WGL_SUPPORT_GDI_EXT 0x200F
#define WGL_SUPPORT_OPENGL_EXT 0x2010
#define WGL_DOUBLE_BUFFER_EXT 0x2011
#define WGL_STEREO_EXT 0x2012
#define WGL_PIXEL_TYPE_EXT 0x2013
#define WGL_COLOR_BITS_EXT 0x2014
#define WGL_RED_BITS_EXT 0x2015
#define WGL_RED_SHIFT_EXT 0x2016
#define WGL_GREEN_BITS_EXT 0x2017
#define WGL_GREEN_SHIFT_EXT 0x2018
#define WGL_BLUE_BITS_EXT 0x2019
#define WGL_BLUE_SHIFT_EXT 0x201A
#define WGL_ALPHA_BITS_EXT 0x201B
#define WGL_ALPHA_SHIFT_EXT 0x201C
#define WGL_ACCUM_BITS_EXT 0x201D
#define WGL_ACCUM_RED_BITS_EXT 0x201E
#define WGL_ACCUM_GREEN_BITS_EXT 0x201F
#define WGL_ACCUM_BLUE_BITS_EXT 0x2020
#define WGL_ACCUM_ALPHA_BITS_EXT 0x2021
#define WGL_DEPTH_BITS_EXT 0x2022
#define WGL_STENCIL_BITS_EXT 0x2023
#define WGL_AUX_BUFFERS_EXT 0x2024
#define WGL_NO_ACCELERATION_EXT 0x2025
#define WGL_GENERIC_ACCELERATION_EXT 0x2026
#define WGL_FULL_ACCELERATION_EXT 0x2027
#define WGL_SWAP_EXCHANGE_EXT 0x2028
#define WGL_SWAP_COPY_EXT 0x2029
#define WGL_SWAP_UNDEFINED_EXT 0x202A
#define WGL_TYPE_RGBA_EXT 0x202B
#define WGL_TYPE_COLORINDEX_EXT 0x202C
#define WGL_DRAW_TO_PBUFFER_EXT 0x202D
#define WGL_MAX_PBUFFER_PIXELS_EXT 0x202E
#define WGL_MAX_PBUFFER_WIDTH_EXT 0x202F
#define WGL_MAX_PBUFFER_HEIGHT_EXT 0x2030
#define WGL_OPTIMAL_PBUFFER_WIDTH_EXT 0x2031
#define WGL_OPTIMAL_PBUFFER_HEIGHT_EXT 0x2032
#define WGL_PBUFFER_LARGEST_EXT 0x2033
#define WGL_PBUFFER_WIDTH_EXT 0x2034
#define WGL_PBUFFER_HEIGHT_EXT 0x2035
#define WGL_DEPTH_FLOAT_EXT 0x2040
#define WGL_SAMPLE_BUFFERS_3DFX 0x2060
#define WGL_SAMPLES_3DFX 0x2061
#define WGL_SAMPLE_BUFFERS_EXT 0x2041
#define WGL_SAMPLES_EXT 0x2042
#define WGL_GENLOCK_SOURCE_MULTIVIEW_I3D 0x2044
#define WGL_GENLOCK_SOURCE_EXTENAL_SYNC_I3D 0x2045
#define WGL_GENLOCK_SOURCE_EXTENAL_FIELD_I3D 0x2046
#define WGL_GENLOCK_SOURCE_EXTENAL_TTL_I3D 0x2047
#define WGL_GENLOCK_SOURCE_DIGITAL_SYNC_I3D 0x2048
#define WGL_GENLOCK_SOURCE_DIGITAL_FIELD_I3D 0x2049
#define WGL_GENLOCK_SOURCE_EDGE_FALLING_I3D 0x204A
#define WGL_GENLOCK_SOURCE_EDGE_RISING_I3D 0x204B
#define WGL_GENLOCK_SOURCE_EDGE_BOTH_I3D 0x204C
#define WGL_GAMMA_TABLE_SIZE_I3D 0x204E
#define WGL_GAMMA_EXCLUDE_DESKTOP_I3D 0x204F
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_FRAMEBUFFER_I3D 0x2050
#define WGL_DIGITAL_VIDEO_CURSOR_ALPHA_VALUE_I3D 0x2051
#define WGL_DIGITAL_VIDEO_CURSOR_INCLUDED_I3D 0x2052
#define WGL_DIGITAL_VIDEO_GAMMA_CORRECTED_I3D 0x2053
#define WGL_ARB_buffer_region 1
#define WGL_ARB_extensions_string 1
#define WGL_ARB_pixel_format 1
#define WGL_ARB_make_current_read 1
#define WGL_ARB_pbuffer 1
#define WGL_EXT_display_color_table 1
#define WGL_EXT_extensions_string 1
#define WGL_EXT_make_current_read 1
#define WGL_EXT_pbuffer 1
#define WGL_EXT_pixel_format 1
#define WGL_EXT_swap_control 1
#define WGL_WGL_EXT_depth_float 1
#define WGL_WGL_3DFX_multisample 1
#define WGL_WGL_EXT_multisample 1
#define WGL_NV_allocate_memory 1
/*
typedef void (APIENTRY * PFNGLACTIVETEXTUREARBPROC) (GLenum target);
typedef void (APIENTRY * PFNGLMULTITEXCOORD2FARBPROC) (GLenum target, GLfloat s, GLfloat t);
typedef void (APIENTRY * PFNGLCLIENTACTIVETEXTUREARBPROC) (GLenum target);
typedef void (APIENTRY * PFNGLLOCKARRAYSEXTPROC) (GLint first, GLsizei count);
typedef void (APIENTRY * PFNGLUNLOCKARRAYSEXTPROC) (void);
*/
/*
typedef int (APIENTRY * PFNGLBINDBUFFERARBPROC) (GLenum target, GLuint buffer);
typedef int (APIENTRY * PFNGLDELETEBUFFERSARBPROC) (GLsizei n, const GLuint *buffers);
typedef int (APIENTRY * PFNGLGENBUFFERSARBPROC) (GLsizei n, GLuint *buffers);
typedef int (APIENTRY * PFNGLBUFFERDATAARBPROC) (GLenum target, int size, const GLvoid *data, GLenum usage);
*/
typedef int (APIENTRY * PFNWGLCHOOSEPIXELFORMATARBPROC) ();
typedef void * (APIENTRY * PFNWGLCREATEPBUFFERARBPROC) (HDC hDC, int iPixelFormat, int iWidth, int iHeight, const int *piAttribList);
typedef HDC (APIENTRY * PFNWGLGETPBUFFERDCARBPROC) (void * hPbuffer);
typedef int (APIENTRY * PFNWGLRELEASEPBUFFERDCARBPROC) (void * hPbuffer, HDC hDC);
typedef BOOL (APIENTRY * PFNWGLDESTROYPBUFFERARBPROC) (void * hPbuffer);
typedef BOOL (APIENTRY * PFNWGLQUERYPBUFFERARBPROC) (void * hPbuffer, int iAttribute, int *piValue);
static PFNGLMAPBUFFERARBPROC glMapBufferARB = null;
static PFNGLUNMAPBUFFERARBPROC glUnmapBufferARB = null;
static PFNGLACTIVETEXTUREARBPROC glActiveTextureARB = null;
static PFNGLMULTITEXCOORD2FARBPROC glMultiTexCoord2fARB = null;
static PFNGLCLIENTACTIVETEXTUREARBPROC glClientActiveTextureARB = null;
static PFNGLLOCKARRAYSEXTPROC glLockArraysEXT = null;
static PFNGLUNLOCKARRAYSEXTPROC glUnlockArraysEXT = null;
static PFNGLBLENDFUNCSEPARATEPROC glBlendFuncSeparate = null;
static PFNGLGENBUFFERSARBPROC glGenBuffersARB = null;
static PFNGLBINDBUFFERARBPROC glBindBufferARB = null;
static PFNGLBUFFERDATAARBPROC glBufferDataARB = null;
static PFNGLDELETEBUFFERSARBPROC glDeleteBuffersARB = null;
static PFNWGLCHOOSEPIXELFORMATARBPROC wglChoosePixelFormatARB = null;
static PFNWGLGETEXTENSIONSSTRINGARBPROC wglGetExtensionsStringARB = null;
static PFNWGLCREATEPBUFFERARBPROC wglCreatePbufferARB = null;
static PFNWGLGETPBUFFERDCARBPROC wglGetPbufferDCARB = null;
static PFNWGLQUERYPBUFFERARBPROC wglQueryPbufferARB = null;
static PFNWGLDESTROYPBUFFERARBPROC wglDestroyPbufferARB = null;
static PFNWGLRELEASEPBUFFERDCARBPROC wglReleasePbufferDCARB = null;
static PFNWGLBINDTEXIMAGEARBPROC wglBindTexImageARB = null;
static PFNWGLRELEASETEXIMAGEARBPROC wglReleaseTexImageARB = null;
#ifdef WGL_WGLEXT_PROTOTYPES
extern BOOL WINAPI wglSwapIntervalEXT (int);
extern int WINAPI wglGetSwapIntervalEXT (void);
#endif /* WGL_WGLEXT_PROTOTYPES */
typedef BOOL (WINAPI * PFNWGLSWAPINTERVALEXTPROC) (int interval);
typedef int (WINAPI * PFNWGLGETSWAPINTERVALEXTPROC) (void);
static PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT = NULL;
#else
#if defined(__ANDROID__)
// Our own matrix stack
static Matrix matrixStack[3][32];
static int matrixIndex[3];
static int curStack = 0;
// OpenGL ES Porting Kit
#define glBindFramebuffer glBindFramebufferOES
#define glBindRenderbuffer glBindRenderbufferOES
#define GL_FRAMEBUFFER GL_FRAMEBUFFER_OES
#define GL_RENDERBUFFER GL_RENDERBUFFER_OES
#define glFramebufferTexture2D glFramebufferTexture2DOES
#define GL_COLOR_ATTACHMENT0 GL_COLOR_ATTACHMENT0_OES
#define glGenFramebuffers glGenFramebuffersOES
#define glGenRenderbuffers glGenRenderbuffersOES
#define glDeleteFramebuffers glDeleteFramebuffersOES
#define glDeleteRenderbuffers glDeleteRenderbuffersOES
#define GL_POLYGON_STIPPLE 0xFFFF
#define GL_LINE_STIPPLE 0xFFFF
#define GL_LINE 0xFFFF
#define GL_FILL 0xFFFF
#define GL_ALL_ATTRIB_BITS 0xFFFF
#define GL_LIGHT_MODEL_LOCAL_VIEWER 0xFFFF
#define glDrawElementsi(type, count, start) glDrawElements(type, count, GL_UNSIGNED_SHORT, start)
#define GL_UNSIGNED_INT 0x1405
#define GL_DOUBLE 0x140A
#define GL_POLYGON 9
#define GL_QUADS 7
#define glBufferDatai glesBufferDatai
#define glBufferDatad glesBufferDatad
#define glVertexPointeri glesVertexPointeri
#define glVertexPointerd glesVertexPointerd
#define glRecti glesRecti
#define glBegin glesBegin
#define glTexCoord2i glesTexCoord2i
#define glVertex2i glesVertex2i
#define glTexCoord2d glesTexCoord2d
#define glVertex2d glesVertex2d
#define glTexCoord2f glesTexCoord2f
#define glVertex2f glesVertex2f
#define glEnd glesEnd
#define glColor3f glesColor3f
#define glColor4ub glesColor4ub
#define glColor4fv glesColor4fv
#define glLineStipple glesLineStipple
#define glNormal3fv glesNormal3fv
#define glTexCoord2fv glesTexCoord2fv
#define glColorMaterial glesColorMaterial
#define glLoadMatrixd glesLoadMatrixd
#define glMultMatrixd glesMultMatrixd
#define glFrustum glesFrustum
#define glOrtho glesOrtho
#define glScaled glesScaled
#define glTranslated glesTranslated
#define glRotated glesRotated
#define glVertex3d glesVertex3d
#define glVertex3f glesVertex3f
#define glVertex3fv glesVertex3fv
#define glLightModeli glesLightModeli
#define APIENTRY
//#define GL_QUADS 0
#define GL_QUAD_STRIP 0
//#define GL_DOUBLE 0
//#define GL_UNSIGNED_INT 0
//#define GL_FILL 0
//#define GL_LINE 0
//#define GL_LINE_STIPPLE 0
#define GL_BGRA_EXT 0
#define GL_UNPACK_ROW_LENGTH 0
#define GL_UNPACK_SKIP_PIXELS 0
#define GL_UNPACK_SKIP_ROWS 0
#define GL_RGBA8 0
#define GL_PACK_ROW_LENGTH 0
#define GL_PACK_SKIP_ROWS 0
#define GL_PACK_SKIP_PIXELS 0
static EGLDisplay eglDisplay;
static EGLSurface eglSurface;
static EGLContext eglContext;
static int eglWidth, eglHeight;
static bool egl_init_display(ANativeWindow* window)
{
const EGLint attribs[] =
{
EGL_SURFACE_TYPE, EGL_WINDOW_BIT,
EGL_BLUE_SIZE, 8,
EGL_GREEN_SIZE, 8,
EGL_RED_SIZE, 8,
EGL_DEPTH_SIZE, 24,
/*EGL_SAMPLE_BUFFERS, 1,
EGL_SAMPLES, 0, //2,*/
EGL_NONE
};
EGLint w, h, dummy, format;
EGLint numConfigs;
EGLConfig config;
EGLSurface surface;
EGLContext context;
EGLDisplay display = eglGetDisplay(EGL_DEFAULT_DISPLAY);
eglInitialize(display, 0, 0);
eglChooseConfig(display, attribs, &config, 1, &numConfigs);
eglGetConfigAttrib(display, config, EGL_NATIVE_VISUAL_ID, &format);
surface = eglCreateWindowSurface(display, config, window, null);
context = eglCreateContext(display, config, null, null);
if(!eglMakeCurrent(display, surface, surface, context))
return false;
eglQuerySurface(display, surface, EGL_WIDTH, &w);
eglQuerySurface(display, surface, EGL_HEIGHT, &h);
eglDisplay = display;
eglContext = context;
eglSurface = surface;
eglWidth = w;
eglHeight = h;
glEnableClientState(GL_VERTEX_ARRAY);
/*
// Initialize GL state.
glHint(GL_PERSPECTIVE_CORRECTION_HINT, GL_FASTEST);
glEnable(GL_CULL_FACE);
glShadeModel(GL_SMOOTH);
glDisable(GL_DEPTH_TEST);
*/
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
glEnable(GL_BLEND);
matrixStack[0][0].Identity();
matrixStack[1][0].Identity();
matrixStack[2][0].Identity();
glesMatrixMode(GL_MODELVIEW);
glScaled(1.0, 1.0, -1.0);
glesMatrixMode(GL_PROJECTION);
glShadeModel(GL_FLAT);
glLightModeli(GL_LIGHT_MODEL_COLOR_CONTROL, GL_SEPARATE_SPECULAR_COLOR);
glFogi(GL_FOG_MODE, GL_EXP);
glFogf(GL_FOG_DENSITY, 0);
glEnable(GL_NORMALIZE);
glDepthFunc(GL_LESS);
glClearDepth(1.0);
glDisable(GL_MULTISAMPLE_ARB);
glViewport(0,0,w,h);
glesLoadIdentity();
glOrtho(0,w,h,0,0.0,1.0);
currentVertexBuffer = 0;
return true;
}
static void egl_term_display()
{
if(stippleTexture)
{
glDeleteTextures(1, (int *)&stippleTexture);
stippleTexture = 0;
}
if(eglDisplay != EGL_NO_DISPLAY)
{
eglMakeCurrent(eglDisplay, EGL_NO_SURFACE, EGL_NO_SURFACE, EGL_NO_CONTEXT);
if(eglContext != EGL_NO_CONTEXT)
eglDestroyContext(eglDisplay, eglContext);
if(eglSurface != EGL_NO_SURFACE)
eglDestroySurface(eglDisplay, eglSurface);
eglTerminate(eglDisplay);
}
eglDisplay = EGL_NO_DISPLAY;
eglContext = EGL_NO_CONTEXT;
eglSurface = EGL_NO_SURFACE;
}
// OpenGL Immediate Mode Porting Kit
static int beginCount;
static int vertexCount;
static int normalCount;
static float *vertexPointer;
static float *normalPointer;
static GLenum beginMode;
static unsigned int beginBufferSize, normalBufferSize;
static int numVertexCoords = 2;
void glesRecti(int a, int b, int c, int d)
{
glBegin(GL_QUADS);
glVertex2i(a, b);
glVertex2i(a, d);
glVertex2i(c, d);
glVertex2i(c, b);
glEnd();
}
void glesBegin(GLenum mode)
{
beginMode = mode;
beginCount = 0;
vertexCount = 0;
if(!vertexPointer)
{
normalBufferSize = beginBufferSize = 1024; // default number of vertices
vertexPointer = new float[beginBufferSize * 5];
normalPointer = new float[normalBufferSize * 3];
}
}
void glesTexCoord2f(float x, float y)
{
int count = vertexCount;
if(vertexCount + numVertexCoords > beginBufferSize)
{
beginBufferSize = beginBufferSize + beginBufferSize/2;
vertexPointer = renew vertexPointer float[beginBufferSize * 5];
}
vertexPointer[count*(2+numVertexCoords) ] = x;
vertexPointer[count*(2+numVertexCoords)+1] = y;
count++;
if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
{
vertexPointer[count*(2+numVertexCoords) ] = vertexPointer[(count-4)*(2+numVertexCoords)];
vertexPointer[count*(2+numVertexCoords)+1] = vertexPointer[(count-4)*(2+numVertexCoords)+1];
count++;
vertexPointer[count*(2+numVertexCoords) ] = vertexPointer[(count-3)*(2+numVertexCoords)];
vertexPointer[count*(2+numVertexCoords)+1] = vertexPointer[(count-3)*(2+numVertexCoords)+1];
count++;
}
}
void glesTexCoord2i(int x, int y) { glesTexCoord2f((float)x, (float)y); }
void glesTexCoord2d(double x, double y) { glesTexCoord2f((float)x, (float)y); }
void glesTexCoord2fv(float * a) { glesTexCoord2f(a[0], a[1]); }
void glesVertex2f(float x, float y)
{
numVertexCoords = 2;
if(vertexCount + 4 > beginBufferSize)
{
beginBufferSize = beginBufferSize + beginBufferSize/2;
vertexPointer = renew vertexPointer float[beginBufferSize * 5];
}
vertexPointer[vertexCount*4+2] = x;
vertexPointer[vertexCount*4+3] = y;
vertexCount++;
if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
{
vertexPointer[vertexCount*4+2] = vertexPointer[(vertexCount-4)*4+2];
vertexPointer[vertexCount*4+3] = vertexPointer[(vertexCount-4)*4+3];
vertexCount++;
vertexPointer[vertexCount*4+2] = vertexPointer[(vertexCount-3)*4+2];
vertexPointer[vertexCount*4+3] = vertexPointer[(vertexCount-3)*4+3];
vertexCount++;
}
beginCount++;
}
void glesVertex2i(int x, int y) { glesVertex2f((float)x, (float)y); }
void glesVertex2d(double x, double y) { glesVertex2f((float)x, (float)y); }
void glesEnd(void)
{
int mode = beginMode;
if(mode == GL_QUADS) mode = GL_TRIANGLES;
else if(mode == GL_POLYGON) mode = GL_TRIANGLE_FAN;
GLSelectVBO(0);
glEnableClientState(GL_TEXTURE_COORD_ARRAY);
glTexCoordPointer(numVertexCoords, GL_FLOAT, (numVertexCoords+2)*sizeof(float),vertexPointer);
glVertexPointer (numVertexCoords, GL_FLOAT, (numVertexCoords+2)*sizeof(float),vertexPointer+2);
if(normalCount && normalCount == vertexCount)
{
glEnableClientState(GL_NORMAL_ARRAY);
glNormalPointer (GL_FLOAT, 3*sizeof(float),normalPointer);
}
glDrawArrays(mode, 0, vertexCount);
if(normalCount)
glDisableClientState(GL_NORMAL_ARRAY);
glDisableClientState(GL_TEXTURE_COORD_ARRAY);
normalCount = 0;
}
// Vertex Pointer
static float *floatVPBuffer = null;
static short *shortVPBuffer = null;
static unsigned int shortVPSize = 0, floatVPSize = 0;
// Buffer Data
//static float *floatVPBuffer = null; // For floats we reuse floatVPBuffer
static unsigned short *shortBDBuffer = null;
static unsigned int shortBDSize = 0/*, floatVPSize = 0*/;
void glesVertexPointeri(int numCoords, int stride, int *pointer, int numVertices)
{
if(pointer)
{
int i;
if(numVertices*numCoords > shortVPSize)
{
shortVPSize = numVertices*numCoords;
shortVPBuffer = renew shortVPBuffer short[shortVPSize];
}
for(i = 0; i < numVertices*numCoords; i++)
shortVPBuffer[i] = (short)pointer[i];
glVertexPointer(numCoords, GL_SHORT, stride, shortVPBuffer);
}
else
glVertexPointer(numCoords, GL_SHORT, stride, 0);
}
void glesVertexPointerd(int numCoords, int stride, double *pointer, int numVertices)
{
if(pointer)
{
int i;
if(numVertices*numCoords > floatVPSize)
{
floatVPSize = numVertices*numCoords;
floatVPBuffer = renew floatVPBuffer float[floatVPSize];
}
for(i = 0; i < numVertices*numCoords; i++)
floatVPBuffer[i] = (float)pointer[i];
glVertexPointer(numCoords, GL_FLOAT, stride, floatVPBuffer);
}
else
glVertexPointer(numCoords, GL_FLOAT, stride, 0);
}
void glesTexReuseIntVP(int numCoords)
{
glTexCoordPointer(numCoords, GL_SHORT, 0, floatVPBuffer);
}
void glesTexReuseDoubleVP(int numCoords)
{
glTexCoordPointer(numCoords, GL_FLOAT, 0, floatVPBuffer);
}
void glesColor3f( float r, float g, float b )
{
glColor4f(r, g, b, 1.0f);
}
void glesColor4ub(unsigned char r, unsigned char g, unsigned char b, unsigned char a)
{
glColor4f(r/255.0f, g/255.0f, b/255.0f, a/255.0f);
}
void glesColor4fv(float * a)
{
glColor4f(a[0], a[1], a[2], a[3]);
}
void glesBufferDatad(int target, int size, void * data, int usage)
{
int numElems = size/sizeof(double);
double * dblPtr = (double *)data;
int i;
if (numElems > floatVPSize)
{
floatVPSize = numElems;
floatVPBuffer = renew floatVPBuffer float[floatVPSize];
}
for (i=0; i< numElems; i++)
floatVPBuffer[i] = (float)dblPtr[i];
glBufferData(target, numElems*sizeof(float), floatVPBuffer, usage);
}
void glesBufferDatai(int target, int size, void * data, int usage)
{
int numElems = size/sizeof(unsigned int);
unsigned int * pointer = (unsigned int *)data;
int i;
if (numElems > shortBDSize)
{
shortBDSize = numElems;
shortBDBuffer = renew shortBDBuffer uint16[shortBDSize];
}
for (i=0; i< numElems; i++)
shortBDBuffer[i] = (unsigned short)pointer[i];
glBufferData(target, numElems*sizeof(unsigned short), shortBDBuffer, usage);
}
// *** Our Custom Matrix Stack ***
static void LoadCurMatrix()
{
double * i = matrixStack[curStack][matrixIndex[curStack]].array;
float m[16] =
{
(float)i[0],(float)i[1],(float)i[2],(float)i[3],
(float)i[4],(float)i[5],(float)i[6],(float)i[7],
(float)i[8],(float)i[9],(float)i[10],(float)i[11],
(float)i[12],(float)i[13],(float)i[14],(float)i[15]
};
glLoadMatrixf(m);
}
void glesLoadIdentity()
{
matrixStack[curStack][matrixIndex[curStack]].Identity();
LoadCurMatrix();
}
void glesPushMatrix()
{
if(matrixIndex[curStack] + 1 < sizeof(matrixStack[0]) / sizeof(Matrix))
{
matrixIndex[curStack]++;
memcpy(matrixStack[curStack][matrixIndex[curStack]].array, matrixStack[curStack][matrixIndex[curStack]-1].array, sizeof(Matrix));
}
}
void glesPopMatrix()
{
if(matrixIndex[curStack] > 0)
{
matrixIndex[curStack]--;
LoadCurMatrix();
}
}
void glesLoadMatrixd(double * i)
{
memcpy(matrixStack[curStack][matrixIndex[curStack]].array, i, sizeof(Matrix));
LoadCurMatrix();
}
void glesOrtho( double l, double r, double b, double t, double n, double f )
{
Matrix m =
{ {
(2 / (r - l)), 0, 0, 0,
0, (2 / (t - b)), 0, 0,
0, 0, (-2 / (f - n)), 0,
(-(r + l) / (r - l)), (-(t + b) / (t - b)), (-(f + n) / (f - n)), 1
} }, res;
res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = res;
LoadCurMatrix();
}
void glesFrustum( double l, double r, double b, double t, double n, double f )
{
nearPlane = n;
n = 1;
l /= nearPlane;
r /= nearPlane;
b /= nearPlane;
t /= nearPlane;
f /= nearPlane;
{
double A = ((r + l) / (r - l));
double B = ((t + b) / (t - b));
double C = (-(f + n) / (f - n));
double D = (-2*f*n/(f-n));
Matrix m =
{ {
(2.0*n / (r - l)), 0, 0, 0,
0, (2.0*n / (t - b)), 0, 0,
A, B, C,-1,
0, 0, D, 0
} }, res;
res.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = res;
LoadCurMatrix();
}
}
void glesRotated( double a, double b, double c, double d )
{
Matrix m;
Quaternion q;
q.RotationAxis({(float)b,(float)-c,(float)d}, a );
m.RotationQuaternion(q);
matrixStack[curStack][matrixIndex[curStack]].Rotate(q);
LoadCurMatrix();
}
void glesScaled( double a, double b, double c )
{
Matrix m, r;
m.Identity();
m.Scale(a,b,c);
r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = r;
LoadCurMatrix();
}
void glesTranslated( double a, double b, double c )
{
Matrix m, r;
m.Identity();
m.Translate(a,b,c);
r.Multiply(m, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = r;
LoadCurMatrix();
}
void glesMultMatrixd( double * i )
{
Matrix r;
r.Multiply((Matrix *)i, matrixStack[curStack][matrixIndex[curStack]]);
matrixStack[curStack][matrixIndex[curStack]] = r;
LoadCurMatrix();
}
void glesMatrixMode(int mode)
{
curStack = mode == GL_MODELVIEW ? 0 : mode == GL_PROJECTION ? 1 : 2;
glMatrixMode(mode);
}
#define glPushMatrix glesPushMatrix
#define glPopMatrix glesPopMatrix
#define glLoadIdentity glesLoadIdentity
#define glMatrixMode glesMatrixMode
/* Using the built-in matrix stack
void glesLoadMatrixd( double * i )
{
float m[16] =
{
(float)i[0],(float)i[1],(float)i[2],(float)i[3],
(float)i[4],(float)i[5],(float)i[6],(float)i[7],
(float)i[8],(float)i[9],(float)i[10],(float)i[11],
(float)i[12],(float)i[13],(float)i[14],(float)i[15]
};
glLoadMatrixf(m);
}
void glesOrtho( double l, double r, double b, double t, double n, double f )
{
float matrix[4][4] =
{
{ (float)(2 / (r - l)), 0, 0, 0 },
{ 0, (float)(2 / (t - b)), 0, 0 },
{ 0, 0, (float)(-2 / (f - n)), 0 },
{ (float)(-(r + l) / (r - l)), (float)(-(t + b) / (t - b)), (float)(-(f + n) / (f - n)), 1 }
};
glMultMatrixf((float *)matrix);
}
void glesFrustum( double l, double r, double b, double t, double n, double f )
{
float A = (float)((r + l) / (r - l));
float B = (float)((t + b) / (t - b));
float C = (float)(-(f + n) / (f - n));
float D = (float)(-2*f*n/(f-n));
float matrix[4][4] =
{
{ (float)(2*n / (r - l)), 0, 0, 0 },
{ 0, (float)(2*n / (t - b)), 0, 0 },
{ A, B, C,-1 },
{ 0, 0, D, 0 }
};
glMultMatrixf((float *)matrix);
}
void glesRotated( double a, double b, double c, double d ) { glRotatef((float)a, (float)b, (float)c, (float)d); }
void glesScaled( double a, double b, double c ) { glScalef((float)a, (float)b, (float)c); }
void glesTranslated( double a, double b, double c ) { glTranslatef((float)a, (float)b, (float)c); }
void glesMultMatrixd( double * i )
{
float m[16] =
{
(float)i[0], (float)i[1], (float)i[2], (float)i[3],
(float)i[4], (float)i[5], (float)i[6], (float)i[7],
(float)i[8], (float)i[9], (float)i[10], (float)i[11],
(float)i[12], (float)i[13], (float)i[14], (float)i[15]
};
glMultMatrixf(m);
}
*/
// Need to do these...
void glesVertex3f( float x, float y, float z )
{
numVertexCoords = 3;
if(vertexCount + 4 > beginBufferSize)
{
beginBufferSize = beginBufferSize + beginBufferSize/2;
vertexPointer = renew vertexPointer float[beginBufferSize * 5];
}
vertexPointer[vertexCount*5+2] = x;
vertexPointer[vertexCount*5+3] = y;
vertexPointer[vertexCount*5+4] = z;
vertexCount++;
if(beginMode == GL_QUADS && ((beginCount % 4) == 3))
{
vertexPointer[vertexCount*5+2] = vertexPointer[(vertexCount-4)*5+2];
vertexPointer[vertexCount*5+3] = vertexPointer[(vertexCount-4)*5+3];
vertexPointer[vertexCount*5+4] = vertexPointer[(vertexCount-4)*5+4];
vertexCount++;
vertexPointer[vertexCount*5+2] = vertexPointer[(vertexCount-3)*5+2];
vertexPointer[vertexCount*5+3] = vertexPointer[(vertexCount-3)*5+3];
vertexPointer[vertexCount*5+4] = vertexPointer[(vertexCount-3)*5+4];
vertexCount++;
}
beginCount++;
}
void glesVertex3d( double x, double y, double z ) { glesVertex3f((float)x, (float)y, (float)z); }
void glesVertex3fv( float* coords ) { glesVertex3f(coords[0], coords[1], coords[2]); }
void glesNormal3f(float x, float y, float z)
{
normalCount = vertexCount;
if(vertexCount + 4 > normalBufferSize)
{
normalBufferSize = normalBufferSize + normalBufferSize/2;
normalPointer = renew normalPointer float[normalBufferSize * 2];
}
normalPointer[normalCount*3+0] = x;
normalPointer[normalCount*3+1] = y;