-
Notifications
You must be signed in to change notification settings - Fork 0
/
gsg.c
982 lines (835 loc) · 25.7 KB
/
gsg.c
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
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
#include <dlfcn.h>
#include "gsg.h"
#include "gsga.h"
#include "gsgg.h"
#include "gsgl.h"
#include "gsgg.h"
/// name of the library to load
#define GSG_GLESLIB "GSG_GLESLIB"
/// track errors
#define GSG_TRACKERROR 1
/// debug level
/// 0 - none
/// 1 - unsupported calls
/// 2 - new gl calls
/// 3 - errors
/// 4 - everything
#define GSG_DEBUGLEVEL 3
char * gsgGLlib = "libGLESv1_CM.so";
void * gsgGLlibp = NULL;
GLenum gsgError = GL_NO_ERROR;
gsggVect gsgRasterPos = { 0.0f, 0.0f, 0.0f };
ARRDEF( int );
ARR( int ) * gsgAttrs;
ARR( int ) * gsgClientAttrs;
GLenum gsgGetError();
void gsgForwDebug( const char *, const char *, ... );
void gsgDie( const char * fmt, ... ) {
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
exit(1);
}
extern void gsgUnsupp( const char * fmt, ... ) {
#if 1 <= GSG_DEBUGLEVEL
fprintf( stderr, "Unsupported: " );
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
fprintf( stderr, "\n" );
#endif
gsgErr( GL_INVALID_OPERATION );
}
void gsgDebug( int level, const char * fmt, ... ) {
if ( level <= GSG_DEBUGLEVEL ) {
va_list args;
va_start( args, fmt );
vfprintf( stderr, fmt, args );
va_end( args );
}
}
void gsgFree( void * ptr ) {
free( ptr );
}
inline void gsgErr( GLenum value ) {
gsgError = value;
}
inline void gsgOk() {
gsgError = GL_NO_ERROR;
}
void * gsgDl( const char * name ) {
if ( ! gsgGLlibp ) {
char * libname = getenv( GSG_GLESLIB );
if (NULL == libname)
libname = gsgGLlib;
if ( ! (gsgGLlibp = dlopen( libname, RTLD_LAZY | RTLD_LOCAL )))
gsgDie("Could not load library: %s\n", dlerror());
}
gsgDebug(2, "gsgDl: %s\n", name );
void * ret;
if ( ! (ret = dlsym( gsgGLlibp, name )))
gsgDie("Could not find symbol: %s\n", dlerror());
return ret;
}
inline float * gsgToMatrixf( const GLdouble * md ) {
static GLfloat mf[16];
GLfloat * at = mf;
int n;
for (n=16; 0<n; --n)
*(at++) = *(md++);
return mf;
}
void gsgAttrEnab( GLenum cap ) {
if ( glIsEnabled( cap ))
glEnable( cap );
else glDisable( cap );
}
GLint gsgGeti( GLenum pname ) {
GLint ret;
glGetIntegerv( pname, &ret );
return ret;
}
void gsgPushAttrib( GLenum mask ) {
if (0 == mask)
return;
if ( NULL == gsgAttrs )
ARRINIT( gsgAttrs, int, 8 );
int a = glGenLists(1);
ARRADD( gsgAttrs, int, a );
glNewList(a,GL_COMPILE);
if ( GL_LIGHTING_BIT & mask ) {
gsgAttrEnab( GL_COLOR_MATERIAL );
gsgAttrEnab( GL_LIGHTING );
glShadeModel( gsgGeti( GL_SHADE_MODEL ) );
}
if ( GL_ENABLE_BIT & mask ) {
gsgAttrEnab( GL_ALPHA_TEST );
gsgAttrEnab( GL_AUTO_NORMAL );
gsgAttrEnab( GL_BLEND );
gsgAttrEnab( GL_COLOR_MATERIAL );
gsgAttrEnab( GL_CULL_FACE );
gsgAttrEnab( GL_DEPTH_TEST );
gsgAttrEnab( GL_DITHER );
gsgAttrEnab( GL_FOG );
gsgAttrEnab( GL_LIGHTING );
gsgAttrEnab( GL_LINE_SMOOTH );
gsgAttrEnab( GL_LINE_STIPPLE );
gsgAttrEnab( GL_COLOR_LOGIC_OP );
gsgAttrEnab( GL_INDEX_LOGIC_OP );
gsgAttrEnab( GL_MULTISAMPLE );
gsgAttrEnab( GL_NORMALIZE );
gsgAttrEnab( GL_SCISSOR_TEST );
gsgAttrEnab( GL_STENCIL_TEST );
}
if ( ! ((GL_LIGHTING_BIT | GL_ENABLE_BIT) & mask) )
gsgUnsupp( "gsgPushAttrib %x", mask );
glEndList();
}
void gsgPushClientAttrib( GLenum mask ) {
if (0 == mask)
return;
if ( NULL == gsgClientAttrs )
ARRINIT( gsgClientAttrs, int, 8 );
int a = glGenLists(1);
ARRADD( gsgClientAttrs, int, a );
glNewList(a,GL_COMPILE);
gsgUnsupp( "gsgPushClientAttrib %x", mask );
glEndList();
}
void gsgPopAttrib() {
if ( NULL == gsgAttrs ) return;
int n = gsgAttrs->count;
if (0 == n) return;
int idx = gsgAttrs->items[ n-1 ];
glCallList( idx );
glDeleteLists( idx, 1 );
-- gsgAttrs->count;
}
void gsgPopClientAttrib() {
if (NULL == gsgClientAttrs ) return;
int n = gsgClientAttrs->count;
if ( 0 == n ) return;
int idx = gsgClientAttrs->items[ n-1 ];
glCallList( idx );
glDeleteLists( idx, 1 );
-- gsgClientAttrs->count;
}
extern void glMultMatrixd( const GLdouble * md ) {
glMultMatrixf( gsgToMatrixf( md ) );
}
extern void glTranslated( GLdouble x, GLdouble y, GLdouble z ) {
glTranslatef( x, y, z );
}
extern void glNormal3fv( const GLfloat * v ) {
glNormal3f( v[0], v[1], v[2] );
}
extern void glNormal3dv( const GLdouble * v ) {
glNormal3f( v[0], v[1], v[2] );
}
extern void glVertex3fv( const GLfloat * v ) {
glVertex3f( v[0], v[1], v[2] );
}
extern void glVertex3dv( const GLdouble * v ) {
glVertex3f( v[0], v[1], v[2] );
}
typedef void (*gsg_)();
typedef GLenum (*gsg_e)();
typedef void (*gsgb)( GLboolean );
typedef void (*gsgbbbb)(GLboolean, GLboolean, GLboolean, GLboolean );
typedef void (*gsge)( GLenum );
typedef GLboolean (*gsge_b)( GLenum );
typedef const GLubyte * (*gsge_yvc)( GLenum );
typedef void (*gsgee)( GLenum, GLenum );
typedef void (*gsgeee)( GLenum, GLenum, GLenum );
typedef void (*gsgef)( GLenum, GLfloat );
typedef void (*gsgefvc)( GLenum, const GLfloat * );
typedef void (*gsgeef)( GLenum, GLenum, GLfloat );
typedef void (*gsgeei)( GLenum, GLenum, GLint );
typedef void (*gsgeefvc)( GLenum, GLenum, const GLfloat * );
typedef void (*gsgeeivc)( GLenum, GLenum, const GLint * );
typedef void (*gsgei)( GLenum, GLint );
typedef void (*gsgeiiiiiss)( GLenum, GLint, GLint, GLint, GLint, GLint,
GLsizei, GLsizei );
typedef void (*gsgeiissieeovc)(GLenum, GLint, GLint, GLsizei, GLsizei,
GLint, GLenum, GLenum, const GLvoid * );
typedef void (*gsgeiiisseeovc)(GLenum, GLint, GLint, GLint, GLsizei,
GLsizei, GLenum, GLenum, const GLvoid * );
typedef void (*gsgeis)( GLenum, GLint, GLsizei );
typedef void (*gsgeiu)( GLenum, GLint, GLuint );
typedef void (*gsgeiv)( GLenum, GLint * );
typedef void (*gsgesepc)( GLenum, GLsizei, GLenum, const GLvoid * );
typedef void (*gsgespc)( GLenum, GLsizei, const GLvoid * );
typedef void (*gsgeu)( GLenum, GLuint );
typedef void (*gsgf)( GLfloat );
typedef void (*gsgff)( GLfloat, GLfloat );
typedef void (*gsgfff)( GLfloat, GLfloat, GLfloat );
typedef void (*gsgffff)( GLfloat, GLfloat, GLfloat, GLfloat );
typedef void (*gsgffffff)( GLfloat, GLfloat, GLfloat, GLfloat, GLfloat, GLfloat );
typedef void (*gsgfvc)( const GLfloat * );
typedef void (*gsgi)( GLint );
typedef void (*gsgiespc)( GLint, GLenum, GLsizei, const GLvoid * );
typedef void (*gsgiiss)(GLint, GLint, GLsizei, GLsizei );
typedef void (*gsgm)( GLbitfield );
typedef void (*gsgsuv)(GLsizei, GLuint * );
typedef void (*gsgsuvc)(GLsizei, const GLuint * );
typedef GLboolean (*gsgu_b)( GLuint );
/// prepare for forwarding call
#define FORWSTART( sign, name ) \
gsgOk(); \
static gsg##sign gsgfw = NULL; \
if (NULL == gsgfw) \
gsgfw = (gsg##sign)gsgDl(name);
/// check after forwarding call
#ifdef GSG_TRACKERROR
#define FORWFINISH( sign, name, ... ) \
gsgError = gsgGetError(); \
if ( GL_NO_ERROR != gsgError ) \
gsgForwDebug( #sign, name, ##__VA_ARGS__ )
#else
#define FORWFINISH( sign, name, ... )
#endif
/// forward call without result
#define FORWARD( sign, name, ... ) \
FORWSTART( sign, name ); \
(*gsgfw)( __VA_ARGS__ ); \
FORWFINISH( sign, name, ##__VA_ARGS__ );
/// forward call with result
#define FORWARDR( rslt, sign, name, ... ) \
FORWSTART( sign, name ); \
rslt ret = (*gsgfw)( __VA_ARGS__ ); \
FORWFINISH( sign, name, ##__VA_ARGS__ ); \
return ret;
extern void glMultMatrixf( const GLfloat * m ) {
LIST( fvc, GLMULTMATRIXF, m );
FORWARD( fvc, "glMultMatrixf", m );
}
extern void glTranslatef( GLfloat x, GLfloat y, GLfloat z ) {
LIST( fff, GLTRANSLATEF, x, y, z );
FORWARD( fff, "glTranslatef", x, y, z );
}
extern void glVertexPointer( GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer )
{
FORWARD( iespc, "glVertexPointer",
size, type, stride, pointer );
}
extern void glNormalPointer( GLenum type, GLsizei stride,
const GLvoid * pointer)
{
FORWARD( espc, "glNormalPointer", type, stride, pointer );
}
gsggIndArr * gsgIndArr() {
static gsggIndArr * ret = NULL;
if ( ! ret )
ARRINIT( ret, GLushort, 16 );
return ret;
}
extern void glDrawArrays( GLenum mode, GLint first, GLsizei count) {
LIST( iii, GLDRAWARRAYS, mode, first, count );
gsggIndArr * ids = gsgIndArr();
if ( gsggInds( mode, ids, count )) {
return glDrawElements(GL_TRIANGLES, ids->count,
GL_UNSIGNED_SHORT, ids->items );
}
FORWARD( eis, "glDrawArrays", mode, first, count );
}
extern void glEnableClientState( GLenum cap ) {
FORWARD( e, "glEnableClientState", cap );
}
extern void glDisableClientState( GLenum cap ) {
FORWARD( e, "glDisableClientState", cap );
}
GLenum gsgGetError() {
// no FORWARD here, no error checking
static gsg_e gsgfw = NULL;
if ( NULL == gsgfw )
gsgfw = (gsg_e)gsgDl("glGetError");
return (*gsgfw)();
}
extern GLenum glGetError() {
GLenum ret;
#ifdef GSG_TRACKERROR
ret = gsgError;
gsgError = GL_NO_ERROR;
return ret;
#else
ret = gsgGetError();
if (GL_NO_ERROR != gsgError)
ret = gsgError;
gsgError = GL_NO_ERROR;
#endif
return ret;
}
extern void glLightfv( GLenum light, GLenum pname,
const GLfloat * params )
{
LIST( iifvc, GLLIGHTFV, light, pname, params );
FORWARD( eefvc, "glLightfv", light, pname, params );
}
extern void glLightf( GLenum light, GLenum pname, GLfloat param ) {
glLightfv( light, pname, ¶m );
}
extern void glEnable( GLenum cap ) {
switch (cap) {
case GL_TEXTURE_GEN_Q:
case GL_TEXTURE_GEN_R:
case GL_TEXTURE_GEN_S:
case GL_TEXTURE_GEN_T:
return gsgUnsupp("Enable TEXTURE_GEN");
}
LIST( i, GLENABLE, cap );
FORWARD( e, "glEnable", cap );
}
extern void glDisable( GLenum cap ) {
switch (cap) {
case GL_TEXTURE_GEN_Q:
case GL_TEXTURE_GEN_R:
case GL_TEXTURE_GEN_S:
case GL_TEXTURE_GEN_T:
return gsgUnsupp("Disable TEXTURE_GEN");
}
LIST( i, GLDISABLE, cap );
FORWARD( e, "glDisable", cap );
}
extern void glMatrixMode( GLenum mode ) {
LIST( i, GLMATRIXMODE, mode );
FORWARD( e, "glMatrixMode", mode );
}
extern void glRotatef( GLfloat angle, GLfloat x, GLfloat y, GLfloat z ) {
LIST( ffff, GLROTATEF, angle, x, y, z );
FORWARD( ffff, "glRotatef", angle, x, y, z );
}
extern void glRotated( GLdouble angle, GLdouble x, GLdouble y, GLdouble z ) {
glRotatef( angle, x, y, z );
}
extern void glViewport( GLint x, GLint y, GLsizei width, GLsizei height ) {
LIST( iiii, GLVIEWPORT, x, y, width, height );
FORWARD( iiss, "glViewport", x, y, width, height );
}
extern void glClear( GLbitfield mask ) {
LIST( i, GLCLEAR, mask );
FORWARD( m, "glClear", mask );
}
extern void glFlush() {
FORWARD( _, "glFlush" );
}
extern void glMaterialf( GLenum face, GLenum pname, GLfloat param) {
LIST( iif, GLMATERIALF, face, pname, param );
FORWARD( eef, "glMaterialf", GL_FRONT_AND_BACK, pname, param );
}
extern void glMaterialfv( GLenum face, GLenum pname,
const GLfloat * params)
{
LIST( iifvc, GLMATERIALFV, face, pname, params );
FORWARD( eefvc, "glMaterialfv", GL_FRONT_AND_BACK, pname, params );
}
extern void glNormal3f( GLfloat x, GLfloat y, GLfloat z ) {
LIST( fff, GLNORMAL3F, x, y, z );
GROUP( fff, Normal, x, y, z );
FORWARD( fff, "glNormal3f", x, y, z );
}
extern void glNormal3d( GLdouble x, GLdouble y, GLdouble z ) {
glNormal3f( x, y, z );
}
extern void glVertex3f( GLfloat x, GLfloat y, GLfloat z ) {
LIST( fff, GLVERTEX3F, x, y, z );
GROUP( fff, Vertex, x, y, z );
}
extern void glVertex3d( GLdouble x, GLdouble y, GLdouble z ) {
glVertex3f( x, y, z );
}
extern void glShadeModel( GLenum mode ) {
LIST( i, GLSHADEMODEL, mode );
FORWARD( e, "glShadeModel", mode );
}
extern void glLoadIdentity() {
LIST( _, GLLOADIDENTITY );
FORWARD( _, "glLoadIdentity" );
}
void glFrustumf( GLfloat left, GLfloat right, GLfloat bottom,
GLfloat top, GLfloat nearval, GLfloat farval )
{
LIST( ffffff, GLFRUSTUMF, left, right, bottom, top, nearval, farval );
FORWARD( ffffff, "glFrustumf", left, right, bottom, top, nearval, farval );
}
extern void glFrustum( GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble nearval, GLdouble farval )
{
glFrustumf( left, right, bottom, top, nearval, farval );
}
extern void glPushMatrix() {
LIST( _, GLPUSHMATRIX );
FORWARD( _, "glPushMatrix" );
}
extern void glPopMatrix() {
LIST( _, GLPOPMATRIX );
FORWARD( _, "glPopMatrix" );
}
extern void glClearColor( GLclampf red, GLclampf green,
GLclampf blue, GLclampf alpha )
{
LIST( ffff, GLCLEARCOLOR, red, green, blue, alpha );
FORWARD( ffff, "glClearColor", red, green, blue, alpha );
}
extern void glClearDepthf( GLfloat depth ) {
LIST( f, GLCLEARDEPTHF, depth );
FORWARD( f, "glClearDepthf", depth );
}
extern void glClearDepth( GLdouble depth ) {
glClearDepthf( depth );
}
void glOrthof( GLfloat left, GLfloat right, GLfloat bottom,
GLfloat top, GLfloat nearval, GLfloat farval )
{
LIST( ffffff, GLORTHOF, left, right, bottom, top, nearval, farval );
FORWARD( ffffff, "glOrthof", left, right, bottom, top, nearval, farval );
}
extern void glOrtho( GLdouble left, GLdouble right, GLdouble bottom,
GLdouble top, GLdouble nearval, GLdouble farval )
{
glOrthof( left, right, bottom, top, nearval, farval );
}
extern void glColor4f( GLfloat red, GLfloat green, GLfloat blue,
GLfloat alpha )
{
LIST( ffff, GLCOLOR4F, red, green, blue, alpha );
GROUP( ffff, Color, red, green, blue, alpha );
FORWARD( ffff, "glColor4f", red, green, blue, alpha );
}
extern void glColor4fv( const GLfloat * v ) {
glColor4f( v[0], v[1], v[2], v[3] );
}
extern void glColor4dv( const GLdouble * v ) {
glColor4f( v[0], v[1], v[2], v[3] );
}
extern void glColor3dv( const GLdouble * v ) {
glColor4f( v[0], v[1], v[2], 1.0f );
}
extern void glColor3f( GLfloat red, GLfloat green, GLfloat blue ) {
glColor4f( red, green, blue, 1.0f );
}
extern void glColor3fv( const GLfloat * v ) {
glColor4f( v[0], v[1], v[2], 1.0f );
}
extern void glColor4ub( GLubyte red, GLubyte green, GLubyte blue,
GLubyte alpha )
{
glColor4f( red/255.0f, green/255.0f, blue/255.0f, alpha/255.0f );
}
extern void glColorPointer( GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer )
{
FORWARD( iespc, "glColorPointer", size, type, stride, pointer );
}
extern void glVertex2f( GLfloat x, GLfloat y ) {
glVertex3f( x, y, 0.0 );
}
extern void glRectf( GLfloat x1, GLfloat y1, GLfloat x2, GLfloat y2 ) {
glBegin( GL_QUADS );
glVertex2f( x1, y1 );
glVertex2f( x2, y1 );
glVertex2f( x2, y2 );
glVertex2f( x1, y2 );
glEnd();
}
const GLubyte * gsgGetString( GLenum name ) {
FORWARDR( const GLubyte *, e_yvc, "glGetString", name );
}
extern const GLubyte * glGetString( GLenum name ) {
const GLubyte * ret = gsgGetString( name );
if (NULL == ret) {
gsgErr( GL_INVALID_ENUM );
return (const GLubyte *)"";
}
return ret;
}
extern void glBindTexture( GLenum target, GLuint texture ) {
LIST( ii, GLBINDTEXTURE, target, texture );
FORWARD( eu, "glBindTexture", target, texture );
}
extern void glBlendFunc( GLenum sfactor, GLenum dfactor ) {
LIST( ii, GLBLENDFUNC, sfactor, dfactor );
FORWARD( eu, "glBlendFunc", sfactor, dfactor );
}
extern void glGenTextures( GLsizei n, GLuint * textures ) {
FORWARD( suv, "glGenTextures", n, textures );
}
extern void glPixelStorei( GLenum pname, GLint param ) {
switch (pname) {
case GL_UNPACK_SKIP_ROWS:
case GL_UNPACK_SKIP_PIXELS:
case GL_UNPACK_SWAP_BYTES:
case GL_UNPACK_ROW_LENGTH:
if ( 0 != param )
gsgUnsupp( "glPixelStorei %x", pname );
else gsgOk();
return;
}
FORWARD( ei, "glPixelStorei", pname, param );
}
extern void glPushAttrib( GLbitfield mask ) {
LIST( i, GLPUSHATTRIB, mask );
gsgPushAttrib( mask );
}
extern void glPopAttrib() {
LIST( _, GLPOPATTRIB );
gsgPopAttrib();
}
extern void glPushClientAttrib( GLbitfield mask ) {
LIST( i, GLPUSHCLIENTATTRIB, mask );
gsgPushClientAttrib( mask );
}
extern void glPopClientAttrib() {
LIST( _, GLPOPCLIENTATTRIB );
gsgPopClientAttrib();
}
extern void glTexCoord2fv( const GLfloat * v ) {
glTexCoord2f( v[0], v[1] );
}
extern void glTexCoord2f( GLfloat s, GLfloat t ) {
GROUP( fff, Tex, s, t, 0.0f );
LIST( ff, GLTEXCOORD2F, s, t );
gsgDie( "glTexCoord2f withuot glBegin" );
}
extern void glTexCoord2d( GLdouble s, GLdouble t ) {
glTexCoord2f( s, t );
}
extern void glTexCoordPointer( GLint size, GLenum type, GLsizei stride,
const GLvoid * pointer )
{
FORWARD( iespc, "glTexCoordPointer",
size, type, stride, pointer );
}
extern void glTexEnvf( GLenum target, GLenum pname, GLfloat param ) {
LIST( iif, GLTEXENVF, target, pname, param );
FORWARD( eef, "glTexEnvf", target, pname, param );
}
extern void glTexImage2D( GLenum target, GLint level,
GLint internalFormat, GLsizei width, GLsizei height, GLint border,
GLenum format, GLenum type, const GLvoid * data )
{
switch (format) {
case GL_RGB:
if (3 == internalFormat)
internalFormat = format;
break;
case GL_RGBA:
if (4 == internalFormat)
internalFormat = format;
break;
}
if ( GL_TEXTURE_2D != target )
gsgDie("only gl_texture_2d supported\n" );
if (gsglInList())
gsgDie("in list teximage2d not supported\n" );
FORWARD( eiissieeovc, "glTexImage2D", target, level, internalFormat,
width, height, border, format, type, data );
}
extern void glTexSubImage2D( GLenum target, GLint level,
GLint xoffset, GLint yoffset, GLsizei width, GLsizei height,
GLenum format, GLenum type, const GLvoid * data )
{
if ( GL_TEXTURE_2D != target )
gsgDie("only gl_texture_2d supported\n" );
if (gsglInList())
gsgDie("in list texSubImage2d not supported\n" );
FORWARD( eiiisseeovc, "glTexSubImage2D", target, level, xoffset,
yoffset, width, height, format, type, data );
}
extern void glTexParameteri( GLenum target, GLenum pname, GLint param ) {
switch (target) {
case GL_TEXTURE_2D: switch (pname) {
case GL_TEXTURE_WRAP_S:
case GL_TEXTURE_WRAP_T:
switch (param) {
case GL_CLAMP: param = GL_CLAMP_TO_EDGE; break;
}
break;
} break;
}
LIST( iii, GLTEXPARAMETERI, target, pname, param );
FORWARD( eei, "glTexParameteri", target, pname, param );
}
extern void glTexParameterf( GLenum target, GLenum pname, GLfloat param ) {
LIST( iif, GLTEXPARAMETERF, target, pname, param );
FORWARD( eef, "glTexParameterf", target, pname, param );
}
extern void glVertex2i( GLint x, GLint y ) {
glVertex2f( x, y );
}
extern void glLightModeli( GLenum pname, GLint value ) {
if (GL_LIGHT_MODEL_TWO_SIDE == pname)
return glLightModelf( pname, value );
gsgErr( GL_INVALID_ENUM );
}
extern void glLightModelf( GLenum pname, GLfloat value ) {
LIST( if, GLLIGHTMODELF, pname, value );
FORWARD( ef, "glLightModelf", pname, value );
}
extern void glLightModelfv( GLenum pname, const GLfloat * value ) {
LIST( ifvc, GLLIGHTMODELFV, pname, value );
FORWARD( efvc, "glLightModelfv", pname, value );
}
extern void glDepthFunc( GLenum func ) {
LIST( i, GLDEPTHFUNC, func );
FORWARD( e, "glDepthFunc", func );
}
extern void glReadBuffer( GLenum mode ) {
gsgDebug(4,"glReadBuffer %x\n", mode );
gsgErr( GL_INVALID_ENUM );
}
Bool gsgGetIntegerv( GLenum pname, GLint * params ) {
switch (pname) {
case GL_PACK_ROW_LENGTH:
case GL_PACK_SKIP_ROWS:
case GL_PACK_SKIP_PIXELS:
case GL_UNPACK_ROW_LENGTH:
case GL_UNPACK_SKIP_ROWS:
case GL_UNPACK_SKIP_PIXELS:
(*params) = 0;
break;
case GL_PACK_LSB_FIRST:
case GL_PACK_SWAP_BYTES:
case GL_UNPACK_LSB_FIRST:
case GL_UNPACK_SWAP_BYTES:
(*params) = GL_FALSE;
break;
default:
return False;
}
return True;
}
extern void glGetIntegerv( GLenum pname, GLint * params ) {
if ( gsgGetIntegerv( pname, params ) )
return;
FORWARD( eiv, "glGetIntegerv", pname, params );
}
extern void glTexGeni( GLenum coord, GLenum pname, GLint param ) {
gsgUnsupp( "glTexGen" );
}
extern void glTexGenfv( GLenum coord, GLenum pname,
const GLfloat * params )
{
gsgUnsupp( "glTexGen" );
}
extern void glPolygonOffset( GLfloat factor, GLfloat units ) {
LIST( ff, GLPOLYGONOFFSET, factor, units );
FORWARD( ff, "glPolygonOffset", factor, units );
}
extern GLboolean glIsTexture( GLuint texture ) {
FORWARDR( GLboolean, u_b, "glIsTexture", texture );
}
extern GLboolean glIsEnabled( GLenum cap ) {
FORWARDR( GLboolean, e_b, "glIsEnabled", cap );
}
extern void glStencilFunc( GLenum func, GLint ref, GLuint mask ) {
LIST( iii, GLSTENCILFUNC, func, ref, mask );
FORWARD( eiu, "glStencilFunc", func, ref, mask );
}
extern void glStencilOp( GLenum fail, GLenum zfail, GLenum zpass ) {
LIST( iii, GLSTENCILOP, fail, zfail, zpass );
FORWARD( eee, "glStencilOp", fail, zfail, zpass );
}
extern void glColorMask( GLboolean red, GLboolean green, GLboolean blue,
GLboolean alpha )
{
LIST( iiii, GLCOLORMASK, red, green, blue, alpha );
FORWARD( bbbb, "glColorMask", red, green, blue, alpha );
}
extern void glDepthMask( GLboolean flag ) {
LIST( i, GLDEPTHMASK, flag );
FORWARD( b, "glDepthMask", flag );
}
extern void glFrontFace( GLenum mode ) {
LIST( i, GLFRONTFACE, mode );
FORWARD( e, "glFrontFace", mode );
}
extern void glScalef( GLfloat x, GLfloat y, GLfloat z ) {
LIST( fff, GLSCALEF, x, y, z );
FORWARD( fff, "glScalef", x, y, z );
}
extern void glScaled( GLdouble x, GLdouble y, GLdouble z ) {
glScalef( x, y, z );
}
extern void glClipPlanef( GLenum plane, const GLfloat * eq ) {
LIST( ifvc, GLCLIPPLANE, plane, eq );
FORWARD( efvc, "glClipPlanef", plane, eq );
}
extern void glClipPlane( GLenum plane, const GLdouble * eq ) {
GLfloat v [] = { eq[0], eq[1], eq[2], eq[3] };
glClipPlanef( plane, v );
}
extern void glCullFace( GLenum mode ) {
LIST( i, GLCULLFACE, mode );
FORWARD( e, "glCullFace", mode );
}
extern void glDeleteTextures( GLsizei n, const GLuint * textures ) {
FORWARD( suvc, "glDeleteTextures", n, textures );
}
extern void glFinish() {
FORWARD( _, "glFinish" );
}
extern void glScissor( GLint x, GLint y, GLsizei width, GLsizei height ) {
LIST( iiii, GLSCISSOR, x, y, width, height );
FORWARD( iiss, "glScissor", x, y, width, height );
}
extern void glFogi( GLenum pname, GLint param ) {
glFogf( pname, param );
}
extern void glFogf( GLenum pname, GLfloat param ) {
LIST( if, GLFOGF, pname, param );
FORWARD( ef, "glFogf", pname, param );
}
extern void glFogfv( GLenum pname, const GLfloat * params ) {
LIST( ifvc, GLFOGFV, pname, params );
FORWARD( efvc, "glFogfv", pname, params );
}
extern void glHint( GLenum target, GLenum mode ) {
LIST( ii, GLHINT, target, mode );
FORWARD( ee, "glHint", target, mode );
}
extern void glTexEnvi( GLenum target, GLenum pname, GLint param ) {
LIST( iii, GLTEXENVI, target, pname, param );
FORWARD( eei, "glTexEnvi", target, pname, param );
}
extern void glPolygonMode( GLenum face, GLenum mode ) {
gsgUnsupp( "glPolygonmode" );
}
extern void glCopyTexSubImage2D( GLenum target, GLint level,
GLint xoffset, GLint yoffset, GLint x, GLint y,
GLsizei width, GLsizei height )
{
LIST( iiiiiiii, GLCOPYTEXSUBIMAGE2D, target, level, xoffset, yoffset,
x, y, width, height );
FORWARD( eiiiiiss, "glCopyTexSubImage2D", target, level, xoffset,
yoffset, x, y, width, height );
}
extern void glVertex2fv( const GLfloat * v ) {
glVertex3f( v[0], v[1], 0.0f );
}
extern void glPolygonStipple( const GLubyte * mask ) {
gsgUnsupp( "glPolygonstipple" );
}
extern void glDrawBuffer( GLenum buf ) {
gsgUnsupp( "glDrawBuffer %x", buf );
}
extern void glLineWidth( GLfloat width ) {
LIST( f, GLLINEWIDTH, width );
FORWARD( f, "glLineWidth", width );
}
extern void glRasterPos2f( GLfloat x, GLfloat y ) {
glRasterPos3f( x, y, 0.0f );
}
extern void glRasterPos3f( GLfloat x, GLfloat y, GLfloat z ) {
gsggVect v = { x, y, z };
gsgRasterPos = v;
}
extern void glClearStencil( GLint s ) {
LIST( i, GLCLEARSTENCIL, s );
FORWARD( i, "glClearStencil", s );
}
extern void glDrawElements( GLenum mode, GLsizei count, GLenum type,
const GLvoid * indices )
{
LIST( iiipc, GLDRAWELEMENTS, mode, count, type, indices );
FORWARD( esepc, "glDrawElements", mode, count, type, indices );
}
extern void glAlphaFunc( GLenum func, GLclampf ref ) {
LIST( if, GLALPHAFUNC, func, ref );
FORWARD( ef, "glAlphaFunc", func, ref );
}
extern void glIndexi( GLint c ) {
glIndexf( c );
}
extern void glIndexf( GLfloat c ) {
LIST( f, GLINDEXF, c );
GROUP( f, Index, c );
}
void gsgForwDebug( const char *sign, const char *name, ... ) {
if ( 3 > GSG_DEBUGLEVEL )
return;
static char fmt[512];
const char *sgn = sign;
char * at = fmt;
char ch;
char fc;
while ( (ch = *sgn) ) {
if (fmt != at)
*(at++)=',';
*(at++)='%';
fc = '\0';
switch (ch) {
case 'e': fc = 'x'; break;
case 'i': case 's': fc ='d'; break;
case '_': fc = '_';
case 'o':
break;
default:
gsgDie("Unkonwn sign: %s\n", sign );
}
++sgn;
if ('v' == *sgn) {
fc = 'p';
++sgn;
if ('c' == *sgn)
++sgn;
}
if ( ! fc )
gsgDie("Unkown sign: %s\n", sign);
if ('_' == fc)
break;
*(at++) = fc;
}
*at = 0;
fprintf( stderr, "gl error on %s(", name );
va_list args;
va_start( args, name );
vfprintf( stderr, fmt, args );
va_end( args );
fprintf( stderr, "):%x\n", gsgError );
}