summaryrefslogtreecommitdiffstats
path: root/src/glx/x11/single2.c
blob: 9724a97c02eae14b29a51c178154cacc2db37a3f (plain)
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
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
/* $XFree86: xc/lib/GL/glx/single2.c,v 1.10 2004/02/11 19:48:16 dawes Exp $ */
/*
** License Applicability. Except to the extent portions of this file are
** made subject to an alternative license as permitted in the SGI Free
** Software License B, Version 1.1 (the "License"), the contents of this
** file are subject only to the provisions of the License. You may not use
** this file except in compliance with the License. You may obtain a copy
** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
** 
** http://oss.sgi.com/projects/FreeB
** 
** Note that, as provided in the License, the Software is distributed on an
** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
** 
** Original Code. The Original Code is: OpenGL Sample Implementation,
** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
** Copyright in any portions created by third parties is as indicated
** elsewhere herein. All Rights Reserved.
** 
** Additional Notice Provisions: The application programming interfaces
** established by SGI in conjunction with the Original Code are The
** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
** Window System(R) (Version 1.3), released October 19, 1998. This software
** was created using the OpenGL(R) version 1.2.1 Sample Implementation
** published by SGI, but has not been independently verified as being
** compliant with the OpenGL(R) version 1.2.1 Specification.
**
*/

#include <stdio.h>
#include "glxclient.h"
#include "packsingle.h"
#include "glxextensions.h"

/* Used for GL_ARB_transpose_matrix */
static void TransposeMatrixf(GLfloat m[16])
{
    int i, j;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < i; j++) {
            GLfloat tmp = m[i*4+j];
            m[i*4+j] = m[j*4+i];
            m[j*4+i] = tmp;
        }
    }
}

/* Used for GL_ARB_transpose_matrix */
static void TransposeMatrixb(GLboolean m[16])
{
    int i, j;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < i; j++) {
            GLboolean tmp = m[i*4+j];
            m[i*4+j] = m[j*4+i];
            m[j*4+i] = tmp;
        }
    }
}

/* Used for GL_ARB_transpose_matrix */
static void TransposeMatrixd(GLdouble m[16])
{
    int i, j;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < i; j++) {
            GLdouble tmp = m[i*4+j];
            m[i*4+j] = m[j*4+i];
            m[j*4+i] = tmp;
        }
    }
}

/* Used for GL_ARB_transpose_matrix */
static void TransposeMatrixi(GLint m[16])
{
    int i, j;
    for (i = 0; i < 4; i++) {
        for (j = 0; j < i; j++) {
            GLint tmp = m[i*4+j];
            m[i*4+j] = m[j*4+i];
            m[j*4+i] = tmp;
        }
    }
}

GLenum __indirect_glGetError(void)
{
    __GLX_SINGLE_DECLARE_VARIABLES();
    GLuint retval = GL_NO_ERROR;
    xGLXGetErrorReply reply;

    if (gc->error) {
	/* Use internal error first */
	retval = gc->error;
	gc->error = GL_NO_ERROR;
	return retval;
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_GetError,0);
    __GLX_SINGLE_READ_XREPLY();
    retval = reply.error;
    __GLX_SINGLE_END();

    return retval;
}

#define CASE_ARRAY_ENABLE(enum_name,array,dest,gl_type) \
    case GL_ ## enum_name ## _ARRAY: \
      *dest = (gl_type) (IS_ARRAY_ENABLED(state, array)); break
#define CASE_ARRAY_SIZE(enum_name,array,dest,gl_type) \
    case GL_ ## enum_name ## _ARRAY_SIZE: \
      *dest = (gl_type) state->vertArray.arrays[array ## _ARRAY].size ; break
#define CASE_ARRAY_TYPE(enum_name,array,dest,gl_type) \
    case GL_ ## enum_name ## _ARRAY_TYPE: \
      *dest = (gl_type) state->vertArray.arrays[array ## _ARRAY].type ; break
#define CASE_ARRAY_STRIDE(enum_name,array,dest,gl_type) \
    case GL_ ## enum_name ## _ARRAY_STRIDE: \
      *dest = (gl_type) state->vertArray.arrays[array ## _ARRAY].stride ; break

#define CASE_ARRAY_ALL(enum_name,array,dest,gl_type) \
	CASE_ARRAY_ENABLE(enum_name,array,dest,gl_type); \
	CASE_ARRAY_STRIDE(enum_name,array,dest,gl_type); \
	CASE_ARRAY_TYPE(enum_name,array,dest,gl_type); \
	CASE_ARRAY_SIZE(enum_name,array,dest,gl_type)

void __indirect_glGetBooleanv(GLenum val, GLboolean *b)
{
    const GLenum origVal = val;
    __GLX_SINGLE_DECLARE_VARIABLES();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    xGLXSingleReply reply;

    if (val == GL_TRANSPOSE_MODELVIEW_MATRIX_ARB) {
       val = GL_MODELVIEW_MATRIX;
    }
    else if (val == GL_TRANSPOSE_PROJECTION_MATRIX_ARB) {
       val = GL_PROJECTION_MATRIX;
    }
    else if (val == GL_TRANSPOSE_TEXTURE_MATRIX_ARB) {
       val = GL_TEXTURE_MATRIX;
    }
    else if (val == GL_TRANSPOSE_COLOR_MATRIX_ARB) {
       val = GL_COLOR_MATRIX;
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_GetBooleanv,4);
    __GLX_SINGLE_PUT_LONG(0,val);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_SIZE(compsize);

    if (compsize == 0) {
	/*
	** Error occured; don't modify user's buffer.
	*/
    } else {
	/*
	** For all the queries listed here, we use the locally stored
	** values rather than the one returned by the server.  Note that
	** we still needed to send the request to the server in order to
	** find out whether it was legal to make a query (it's illegal,
	** for example, to call a query between glBegin() and glEnd()).
	*/
	switch (val) {
	  case GL_PACK_ROW_LENGTH:
	    *b = (GLboolean)state->storePack.rowLength;
	    break;
	  case GL_PACK_IMAGE_HEIGHT:
	    *b = (GLboolean)state->storePack.imageHeight;
	    break;
	  case GL_PACK_SKIP_ROWS:
	    *b = (GLboolean)state->storePack.skipRows;
	    break;
	  case GL_PACK_SKIP_PIXELS:
	    *b = (GLboolean)state->storePack.skipPixels;
	    break;
	  case GL_PACK_SKIP_IMAGES:
	    *b = (GLboolean)state->storePack.skipImages;
	    break;
	  case GL_PACK_ALIGNMENT:
	    *b = (GLboolean)state->storePack.alignment;
	    break;
	  case GL_PACK_SWAP_BYTES:
	    *b = (GLboolean)state->storePack.swapEndian;
	    break;
	  case GL_PACK_LSB_FIRST:
	    *b = (GLboolean)state->storePack.lsbFirst;
	    break;
	  case GL_UNPACK_ROW_LENGTH:
	    *b = (GLboolean)state->storeUnpack.rowLength;
	    break;
	  case GL_UNPACK_IMAGE_HEIGHT:
	    *b = (GLboolean)state->storeUnpack.imageHeight;
	    break;
	  case GL_UNPACK_SKIP_ROWS:
	    *b = (GLboolean)state->storeUnpack.skipRows;
	    break;
	  case GL_UNPACK_SKIP_PIXELS:
	    *b = (GLboolean)state->storeUnpack.skipPixels;
	    break;
	  case GL_UNPACK_SKIP_IMAGES:
	    *b = (GLboolean)state->storeUnpack.skipImages;
	    break;
	  case GL_UNPACK_ALIGNMENT:
	    *b = (GLboolean)state->storeUnpack.alignment;
	    break;
	  case GL_UNPACK_SWAP_BYTES:
	    *b = (GLboolean)state->storeUnpack.swapEndian;
	    break;
	  case GL_UNPACK_LSB_FIRST:
	    *b = (GLboolean)state->storeUnpack.lsbFirst;
	    break;

	  CASE_ARRAY_ALL(VERTEX, vertex, b, GLboolean);

	  CASE_ARRAY_ENABLE(NORMAL, normal, b, GLboolean);
	  CASE_ARRAY_TYPE(NORMAL, normal, b, GLboolean);
	  CASE_ARRAY_STRIDE(NORMAL, normal, b, GLboolean);

	  CASE_ARRAY_ALL(COLOR, color, b, GLboolean);

	  CASE_ARRAY_ENABLE(INDEX, index, b, GLboolean);
	  CASE_ARRAY_TYPE(INDEX, index, b, GLboolean);
	  CASE_ARRAY_STRIDE(INDEX, index, b, GLboolean);

	  case GL_TEXTURE_COORD_ARRAY:
	    *b = (GLboolean)IS_TEXARRAY_ENABLED(state, state->vertArray.activeTexture);
	    break;
	  case GL_TEXTURE_COORD_ARRAY_SIZE:
	    *b = (GLboolean)state->vertArray.texCoord[state->vertArray.activeTexture].size;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_TYPE:
	    *b = (GLboolean)state->vertArray.texCoord[state->vertArray.activeTexture].type;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_STRIDE:
	    *b = (GLboolean)state->vertArray.texCoord[state->vertArray.activeTexture].stride;
	    break;

	  CASE_ARRAY_ENABLE(EDGE_FLAG, edgeFlag, b, GLboolean);
	  CASE_ARRAY_STRIDE(EDGE_FLAG, edgeFlag, b, GLboolean);

	  CASE_ARRAY_ALL(SECONDARY_COLOR, secondaryColor, b, GLboolean);

	  CASE_ARRAY_ENABLE(FOG_COORD, fogCoord, b, GLboolean);
	  CASE_ARRAY_TYPE(FOG_COORD, fogCoord, b, GLboolean);
	  CASE_ARRAY_STRIDE(FOG_COORD, fogCoord, b, GLboolean);

	  case GL_MAX_ELEMENTS_VERTICES:
	    *b = (GLboolean)state->vertArray.maxElementsVertices;
	    break;
	  case GL_MAX_ELEMENTS_INDICES:
	    *b = (GLboolean)state->vertArray.maxElementsIndices;
	    break;
	  case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
	    *b = (GLboolean)__GL_CLIENT_ATTRIB_STACK_DEPTH;
	    break;
	  case GL_CLIENT_ACTIVE_TEXTURE_ARB:
	    *b = (GLboolean)(state->vertArray.activeTexture + GL_TEXTURE0_ARB);
	    break;
	  default:
	    /*
	    ** Not a local value, so use what we got from the server.
	    */
	    if (compsize == 1) {
		__GLX_SINGLE_GET_CHAR(b);
	    } else {
		__GLX_SINGLE_GET_CHAR_ARRAY(b,compsize);
                if (val != origVal) {
                   /* matrix transpose */
                   TransposeMatrixb(b);
                }
	    }
	}
    }
    __GLX_SINGLE_END();
}

void __indirect_glGetDoublev(GLenum val, GLdouble *d)
{
    const GLenum origVal = val;
    __GLX_SINGLE_DECLARE_VARIABLES();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    xGLXSingleReply reply;

    if (val == GL_TRANSPOSE_MODELVIEW_MATRIX_ARB) {
       val = GL_MODELVIEW_MATRIX;
    }
    else if (val == GL_TRANSPOSE_PROJECTION_MATRIX_ARB) {
       val = GL_PROJECTION_MATRIX;
    }
    else if (val == GL_TRANSPOSE_TEXTURE_MATRIX_ARB) {
       val = GL_TEXTURE_MATRIX;
    }
    else if (val == GL_TRANSPOSE_COLOR_MATRIX_ARB) {
       val = GL_COLOR_MATRIX;
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_GetDoublev,4);
    __GLX_SINGLE_PUT_LONG(0,val);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_SIZE(compsize);

    if (compsize == 0) {
	/*
	** Error occured; don't modify user's buffer.
	*/
    } else {
	/*
	** For all the queries listed here, we use the locally stored
	** values rather than the one returned by the server.  Note that
	** we still needed to send the request to the server in order to
	** find out whether it was legal to make a query (it's illegal,
	** for example, to call a query between glBegin() and glEnd()).
	*/
	switch (val) {
	  case GL_PACK_ROW_LENGTH:
	    *d = (GLdouble)state->storePack.rowLength;
	    break;
	  case GL_PACK_IMAGE_HEIGHT:
	    *d = (GLdouble)state->storePack.imageHeight;
	    break;
	  case GL_PACK_SKIP_ROWS:
	    *d = (GLdouble)state->storePack.skipRows;
	    break;
	  case GL_PACK_SKIP_PIXELS:
	    *d = (GLdouble)state->storePack.skipPixels;
	    break;
	  case GL_PACK_SKIP_IMAGES:
	    *d = (GLdouble)state->storePack.skipImages;
	    break;
	  case GL_PACK_ALIGNMENT:
	    *d = (GLdouble)state->storePack.alignment;
	    break;
	  case GL_PACK_SWAP_BYTES:
	    *d = (GLdouble)state->storePack.swapEndian;
	    break;
	  case GL_PACK_LSB_FIRST:
	    *d = (GLdouble)state->storePack.lsbFirst;
	    break;
	  case GL_UNPACK_ROW_LENGTH:
	    *d = (GLdouble)state->storeUnpack.rowLength;
	    break;
	  case GL_UNPACK_IMAGE_HEIGHT:
	    *d = (GLdouble)state->storeUnpack.imageHeight;
	    break;
	  case GL_UNPACK_SKIP_ROWS:
	    *d = (GLdouble)state->storeUnpack.skipRows;
	    break;
	  case GL_UNPACK_SKIP_PIXELS:
	    *d = (GLdouble)state->storeUnpack.skipPixels;
	    break;
	  case GL_UNPACK_SKIP_IMAGES:
	    *d = (GLdouble)state->storeUnpack.skipImages;
	    break;
	  case GL_UNPACK_ALIGNMENT:
	    *d = (GLdouble)state->storeUnpack.alignment;
	    break;
	  case GL_UNPACK_SWAP_BYTES:
	    *d = (GLdouble)state->storeUnpack.swapEndian;
	    break;
	  case GL_UNPACK_LSB_FIRST:
	    *d = (GLdouble)state->storeUnpack.lsbFirst;
	    break;

	  CASE_ARRAY_ALL(VERTEX, vertex, d, GLdouble);

	  CASE_ARRAY_ENABLE(NORMAL, normal, d, GLdouble);
	  CASE_ARRAY_TYPE(NORMAL, normal, d, GLdouble);
	  CASE_ARRAY_STRIDE(NORMAL, normal, d, GLdouble);

	  CASE_ARRAY_ALL(COLOR, color, d, GLdouble);

	  CASE_ARRAY_ENABLE(INDEX, index, d, GLdouble);
	  CASE_ARRAY_TYPE(INDEX, index, d, GLdouble);
	  CASE_ARRAY_STRIDE(INDEX, index, d, GLdouble);

	  case GL_TEXTURE_COORD_ARRAY:
	    *d = (GLdouble) IS_TEXARRAY_ENABLED(state, state->vertArray.activeTexture);
	    break;
	  case GL_TEXTURE_COORD_ARRAY_SIZE:
	    *d = (GLdouble)state->vertArray.texCoord[state->vertArray.activeTexture].size;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_TYPE:
	    *d = (GLdouble)state->vertArray.texCoord[state->vertArray.activeTexture].type;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_STRIDE:
	    *d = (GLdouble)state->vertArray.texCoord[state->vertArray.activeTexture].stride;
	    break;

	  CASE_ARRAY_ENABLE(EDGE_FLAG, edgeFlag, d, GLdouble);
	  CASE_ARRAY_STRIDE(EDGE_FLAG, edgeFlag, d, GLdouble);

	  CASE_ARRAY_ALL(SECONDARY_COLOR, secondaryColor, d, GLdouble);

	  CASE_ARRAY_ENABLE(FOG_COORD, fogCoord, d, GLdouble);
	  CASE_ARRAY_TYPE(FOG_COORD, fogCoord, d, GLdouble);
	  CASE_ARRAY_STRIDE(FOG_COORD, fogCoord, d, GLdouble);

	  case GL_MAX_ELEMENTS_VERTICES:
	    *d = (GLdouble)state->vertArray.maxElementsVertices;
	    break;
	  case GL_MAX_ELEMENTS_INDICES:
	    *d = (GLdouble)state->vertArray.maxElementsIndices;
	    break;
	  case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
	    *d = (GLdouble)__GL_CLIENT_ATTRIB_STACK_DEPTH;
	    break;
	  case GL_CLIENT_ACTIVE_TEXTURE_ARB:
	    *d = (GLdouble)(state->vertArray.activeTexture + GL_TEXTURE0_ARB);
	    break;
	  default:
	    /*
	     ** Not a local value, so use what we got from the server.
	     */
	    if (compsize == 1) {
		__GLX_SINGLE_GET_DOUBLE(d);
	    } else {
		__GLX_SINGLE_GET_DOUBLE_ARRAY(d,compsize);
                if (val != origVal) {
                   /* matrix transpose */
                   TransposeMatrixd(d);
                }
	    }
	}
    }
    __GLX_SINGLE_END();
}

void __indirect_glGetFloatv(GLenum val, GLfloat *f)
{
    const GLenum origVal = val;
    __GLX_SINGLE_DECLARE_VARIABLES();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    xGLXSingleReply reply;

    if (val == GL_TRANSPOSE_MODELVIEW_MATRIX_ARB) {
       val = GL_MODELVIEW_MATRIX;
    }
    else if (val == GL_TRANSPOSE_PROJECTION_MATRIX_ARB) {
       val = GL_PROJECTION_MATRIX;
    }
    else if (val == GL_TRANSPOSE_TEXTURE_MATRIX_ARB) {
       val = GL_TEXTURE_MATRIX;
    }
    else if (val == GL_TRANSPOSE_COLOR_MATRIX_ARB) {
       val = GL_COLOR_MATRIX;
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_GetFloatv,4);
    __GLX_SINGLE_PUT_LONG(0,val);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_SIZE(compsize);

    if (compsize == 0) {
	/*
	** Error occured; don't modify user's buffer.
	*/
    } else {
	/*
	** For all the queries listed here, we use the locally stored
	** values rather than the one returned by the server.  Note that
	** we still needed to send the request to the server in order to
	** find out whether it was legal to make a query (it's illegal,
	** for example, to call a query between glBegin() and glEnd()).
	*/
	switch (val) {
	  case GL_PACK_ROW_LENGTH:
	    *f = (GLfloat)state->storePack.rowLength;
	    break;
	  case GL_PACK_IMAGE_HEIGHT:
	    *f = (GLfloat)state->storePack.imageHeight;
	    break;
	  case GL_PACK_SKIP_ROWS:
	    *f = (GLfloat)state->storePack.skipRows;
	    break;
	  case GL_PACK_SKIP_PIXELS:
	    *f = (GLfloat)state->storePack.skipPixels;
	    break;
	  case GL_PACK_SKIP_IMAGES:
	    *f = (GLfloat)state->storePack.skipImages;
	    break;
	  case GL_PACK_ALIGNMENT:
	    *f = (GLfloat)state->storePack.alignment;
	    break;
	  case GL_PACK_SWAP_BYTES:
	    *f = (GLfloat)state->storePack.swapEndian;
	    break;
	  case GL_PACK_LSB_FIRST:
	    *f = (GLfloat)state->storePack.lsbFirst;
	    break;
	  case GL_UNPACK_ROW_LENGTH:
	    *f = (GLfloat)state->storeUnpack.rowLength;
	    break;
	  case GL_UNPACK_IMAGE_HEIGHT:
	    *f = (GLfloat)state->storeUnpack.imageHeight;
	    break;
	  case GL_UNPACK_SKIP_ROWS:
	    *f = (GLfloat)state->storeUnpack.skipRows;
	    break;
	  case GL_UNPACK_SKIP_PIXELS:
	    *f = (GLfloat)state->storeUnpack.skipPixels;
	    break;
	  case GL_UNPACK_SKIP_IMAGES:
	    *f = (GLfloat)state->storeUnpack.skipImages;
	    break;
	  case GL_UNPACK_ALIGNMENT:
	    *f = (GLfloat)state->storeUnpack.alignment;
	    break;
	  case GL_UNPACK_SWAP_BYTES:
	    *f = (GLfloat)state->storeUnpack.swapEndian;
	    break;
	  case GL_UNPACK_LSB_FIRST:
	    *f = (GLfloat)state->storeUnpack.lsbFirst;
	    break;

	  CASE_ARRAY_ALL(VERTEX, vertex, f, GLfloat);

	  CASE_ARRAY_ENABLE(NORMAL, normal, f, GLfloat);
	  CASE_ARRAY_TYPE(NORMAL, normal, f, GLfloat);
	  CASE_ARRAY_STRIDE(NORMAL, normal, f, GLfloat);

	  CASE_ARRAY_ALL(COLOR, color, f, GLfloat);

	  CASE_ARRAY_ENABLE(INDEX, index, f, GLfloat);
	  CASE_ARRAY_TYPE(INDEX, index, f, GLfloat);
	  CASE_ARRAY_STRIDE(INDEX, index, f, GLfloat);

	  case GL_TEXTURE_COORD_ARRAY:
	    *f = (GLfloat) IS_TEXARRAY_ENABLED(state, state->vertArray.activeTexture);
	    break;
	  case GL_TEXTURE_COORD_ARRAY_SIZE:
	    *f = (GLfloat)state->vertArray.texCoord[state->vertArray.activeTexture].size;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_TYPE:
	    *f = (GLfloat)state->vertArray.texCoord[state->vertArray.activeTexture].type;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_STRIDE:
	    *f = (GLfloat)state->vertArray.texCoord[state->vertArray.activeTexture].stride;
	    break;

	  CASE_ARRAY_ENABLE(EDGE_FLAG, edgeFlag, f, GLfloat);
	  CASE_ARRAY_STRIDE(EDGE_FLAG, edgeFlag, f, GLfloat);

	  CASE_ARRAY_ALL(SECONDARY_COLOR, secondaryColor, f, GLfloat);

	  CASE_ARRAY_ENABLE(FOG_COORD, fogCoord, f, GLfloat);
	  CASE_ARRAY_TYPE(FOG_COORD, fogCoord, f, GLfloat);
	  CASE_ARRAY_STRIDE(FOG_COORD, fogCoord, f, GLfloat);

	  case GL_MAX_ELEMENTS_VERTICES:
	    *f = (GLfloat)state->vertArray.maxElementsVertices;
	    break;
	  case GL_MAX_ELEMENTS_INDICES:
	    *f = (GLfloat)state->vertArray.maxElementsIndices;
	    break;
	  case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
	    *f = (GLfloat)__GL_CLIENT_ATTRIB_STACK_DEPTH;
	    break;
	  case GL_CLIENT_ACTIVE_TEXTURE_ARB:
	    *f = (GLfloat)(state->vertArray.activeTexture + GL_TEXTURE0_ARB);
	    break;
	  default:
	    /*
	    ** Not a local value, so use what we got from the server.
	    */
	    if (compsize == 1) {
		__GLX_SINGLE_GET_FLOAT(f);
	    } else {
		__GLX_SINGLE_GET_FLOAT_ARRAY(f,compsize);
                if (val != origVal) {
                   /* matrix transpose */
                   TransposeMatrixf(f);
                }
	    }
	}
    }
    __GLX_SINGLE_END();
}

void __indirect_glGetIntegerv(GLenum val, GLint *i)
{
    const GLenum origVal = val;
    __GLX_SINGLE_DECLARE_VARIABLES();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    xGLXSingleReply reply;

    if (val == GL_TRANSPOSE_MODELVIEW_MATRIX_ARB) {
       val = GL_MODELVIEW_MATRIX;
    }
    else if (val == GL_TRANSPOSE_PROJECTION_MATRIX_ARB) {
       val = GL_PROJECTION_MATRIX;
    }
    else if (val == GL_TRANSPOSE_TEXTURE_MATRIX_ARB) {
       val = GL_TEXTURE_MATRIX;
    }
    else if (val == GL_TRANSPOSE_COLOR_MATRIX_ARB) {
       val = GL_COLOR_MATRIX;
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_GetIntegerv,4);
    __GLX_SINGLE_PUT_LONG(0,val);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_SIZE(compsize);

    if (compsize == 0) {
	/*
	** Error occured; don't modify user's buffer.
	*/
    } else {
	/*
	** For all the queries listed here, we use the locally stored
	** values rather than the one returned by the server.  Note that
	** we still needed to send the request to the server in order to
	** find out whether it was legal to make a query (it's illegal,
	** for example, to call a query between glBegin() and glEnd()).
	*/
	switch (val) {
	  case GL_PACK_ROW_LENGTH:
	    *i = (GLint)state->storePack.rowLength;
	    break;
	  case GL_PACK_IMAGE_HEIGHT:
	    *i = (GLint)state->storePack.imageHeight;
	    break;
	  case GL_PACK_SKIP_ROWS:
	    *i = (GLint)state->storePack.skipRows;
	    break;
	  case GL_PACK_SKIP_PIXELS:
	    *i = (GLint)state->storePack.skipPixels;
	    break;
	  case GL_PACK_SKIP_IMAGES:
	    *i = (GLint)state->storePack.skipImages;
	    break;
	  case GL_PACK_ALIGNMENT:
	    *i = (GLint)state->storePack.alignment;
	    break;
	  case GL_PACK_SWAP_BYTES:
	    *i = (GLint)state->storePack.swapEndian;
	    break;
	  case GL_PACK_LSB_FIRST:
	    *i = (GLint)state->storePack.lsbFirst;
	    break;
	  case GL_UNPACK_ROW_LENGTH:
	    *i = (GLint)state->storeUnpack.rowLength;
	    break;
	  case GL_UNPACK_IMAGE_HEIGHT:
	    *i = (GLint)state->storeUnpack.imageHeight;
	    break;
	  case GL_UNPACK_SKIP_ROWS:
	    *i = (GLint)state->storeUnpack.skipRows;
	    break;
	  case GL_UNPACK_SKIP_PIXELS:
	    *i = (GLint)state->storeUnpack.skipPixels;
	    break;
	  case GL_UNPACK_SKIP_IMAGES:
	    *i = (GLint)state->storeUnpack.skipImages;
	    break;
	  case GL_UNPACK_ALIGNMENT:
	    *i = (GLint)state->storeUnpack.alignment;
	    break;
	  case GL_UNPACK_SWAP_BYTES:
	    *i = (GLint)state->storeUnpack.swapEndian;
	    break;
	  case GL_UNPACK_LSB_FIRST:
	    *i = (GLint)state->storeUnpack.lsbFirst;
	    break;

	  CASE_ARRAY_ALL(VERTEX, vertex, i, GLint);

	  CASE_ARRAY_ENABLE(NORMAL, normal, i, GLint);
	  CASE_ARRAY_TYPE(NORMAL, normal, i, GLint);
	  CASE_ARRAY_STRIDE(NORMAL, normal, i, GLint);

	  CASE_ARRAY_ALL(COLOR, color, i, GLint);

	  CASE_ARRAY_ENABLE(INDEX, index, i, GLint);
	  CASE_ARRAY_TYPE(INDEX, index, i, GLint);
	  CASE_ARRAY_STRIDE(INDEX, index, i, GLint);

	  case GL_TEXTURE_COORD_ARRAY:
	    *i = (GLint) IS_TEXARRAY_ENABLED(state, state->vertArray.activeTexture);
	    break;
	  case GL_TEXTURE_COORD_ARRAY_SIZE:
	    *i = (GLint)state->vertArray.texCoord[state->vertArray.activeTexture].size;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_TYPE:
	    *i = (GLint)state->vertArray.texCoord[state->vertArray.activeTexture].type;
	    break;
	  case GL_TEXTURE_COORD_ARRAY_STRIDE:
	    *i = (GLint)state->vertArray.texCoord[state->vertArray.activeTexture].stride;
	    break;

	  CASE_ARRAY_ENABLE(EDGE_FLAG, edgeFlag, i, GLint);
	  CASE_ARRAY_STRIDE(EDGE_FLAG, edgeFlag, i, GLint);

	  CASE_ARRAY_ALL(SECONDARY_COLOR, secondaryColor, i, GLint);

	  CASE_ARRAY_ENABLE(FOG_COORD, fogCoord, i, GLint);
	  CASE_ARRAY_TYPE(FOG_COORD, fogCoord, i, GLint);
	  CASE_ARRAY_STRIDE(FOG_COORD, fogCoord, i, GLint);

	  case GL_MAX_ELEMENTS_VERTICES:
	    *i = (GLint)state->vertArray.maxElementsVertices;
	    break;
	  case GL_MAX_ELEMENTS_INDICES:
	    *i = (GLint)state->vertArray.maxElementsIndices;
	    break;
	  case GL_MAX_CLIENT_ATTRIB_STACK_DEPTH:
	    *i = (GLint)__GL_CLIENT_ATTRIB_STACK_DEPTH;
	    break;
	  case GL_CLIENT_ACTIVE_TEXTURE_ARB:
	    *i = (GLint)(state->vertArray.activeTexture + GL_TEXTURE0_ARB);
	    break;
	  default:
	    /*
	    ** Not a local value, so use what we got from the server.
	    */
	    if (compsize == 1) {
		__GLX_SINGLE_GET_LONG(i);
	    } else {
		__GLX_SINGLE_GET_LONG_ARRAY(i,compsize);
                if (val != origVal) {
                   /* matrix transpose */
                   TransposeMatrixi(i);
                }
	    }
	}
    }
    __GLX_SINGLE_END();
}

/*
** Send all pending commands to server.
*/
void __indirect_glFlush(void)
{
    __GLX_SINGLE_DECLARE_VARIABLES();

    if (!dpy) return;

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_Flush,0);
    __GLX_SINGLE_END();

    /* And finally flush the X protocol data */
    XFlush(dpy);
}

void __indirect_glFeedbackBuffer(GLsizei size, GLenum type, GLfloat *buffer)
{
    __GLX_SINGLE_DECLARE_VARIABLES();

    if (!dpy) return;

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_FeedbackBuffer,8);
    __GLX_SINGLE_PUT_LONG(0,size);
    __GLX_SINGLE_PUT_LONG(4,type);
    __GLX_SINGLE_END();

    gc->feedbackBuf = buffer;
}

void __indirect_glSelectBuffer(GLsizei numnames, GLuint *buffer)
{
    __GLX_SINGLE_DECLARE_VARIABLES();

    if (!dpy) return;

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_SelectBuffer,4);
    __GLX_SINGLE_PUT_LONG(0,numnames);
    __GLX_SINGLE_END();

    gc->selectBuf = buffer;
}

GLint __indirect_glRenderMode(GLenum mode)
{
    __GLX_SINGLE_DECLARE_VARIABLES();
    GLint retval = 0;
    xGLXRenderModeReply reply;

    if (!dpy) return -1;

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_RenderMode,4);
    __GLX_SINGLE_PUT_LONG(0,mode);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_RETVAL(retval,GLint);

    if (reply.newMode != mode) {
	/*
	** Switch to new mode did not take effect, therefore an error
	** occured.  When an error happens the server won't send us any
	** other data.
	*/
    } else {
	/* Read the feedback or selection data */
	if (gc->renderMode == GL_FEEDBACK) {
	    __GLX_SINGLE_GET_SIZE(compsize);
	    __GLX_SINGLE_GET_FLOAT_ARRAY(gc->feedbackBuf, compsize);
	} else
	if (gc->renderMode == GL_SELECT) {
	    __GLX_SINGLE_GET_SIZE(compsize);
	    __GLX_SINGLE_GET_LONG_ARRAY(gc->selectBuf, compsize);
	}
	gc->renderMode = mode;
    }
    __GLX_SINGLE_END();

    return retval;
}

void __indirect_glFinish(void)
{
    __GLX_SINGLE_DECLARE_VARIABLES();
    xGLXSingleReply reply;

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_Finish,0);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_END();
}


/**
 * Extract the major and minor version numbers from a version string.
 */
static void
version_from_string( const char * ver, 
		     int * major_version, int * minor_version )
{
    const char * end;
    long major;
    long minor;

    major = strtol( ver, (char **) & end, 10 );
    minor = strtol( end + 1, NULL, 10 );
    *major_version = major;
    *minor_version = minor;
}


const GLubyte *__indirect_glGetString(GLenum name)
{
    __GLXcontext *gc = __glXGetCurrentContext();
    Display *dpy = gc->currentDpy;
    GLubyte *s = NULL;

    if (!dpy) return 0;

    /*
    ** Return the cached copy if the string has already been fetched
    */
    switch(name) {
      case GL_VENDOR:
	if (gc->vendor) return gc->vendor;
	break;
      case GL_RENDERER:
	if (gc->renderer) return gc->renderer;
	break;
      case GL_VERSION:
	if (gc->version) return gc->version;
	break;
      case GL_EXTENSIONS:
	if (gc->extensions) return gc->extensions;
	break;
      default:
	__glXSetError(gc, GL_INVALID_ENUM);
	return 0;
    }

    /*
    ** Get requested string from server
    */

    (void) __glXFlushRenderBuffer( gc, gc->pc );
    s = (GLubyte *) __glXGetStringFromServer( dpy, gc->majorOpcode,
				  X_GLsop_GetString, gc->currentContextTag,
				  name );
    if (!s) {
	/* Throw data on the floor */
	__glXSetError(gc, GL_OUT_OF_MEMORY);
    } else {
	/*
	** Update local cache
	*/
	switch(name) {
	case GL_VENDOR:
	    gc->vendor = s;
	    break;

	case GL_RENDERER:
	    gc->renderer = s;
	    break;

	case GL_VERSION: {
	    int client_major;
	    int client_minor;

	    version_from_string( (char *) s, 
				 & gc->server_major, & gc->server_minor );
	    __glXGetGLVersion( & client_major, & client_minor );

	    if ( (gc->server_major < client_major)
		 || ((gc->server_major == client_major) 
		     && (gc->server_minor <= client_minor)) ) {
		gc->version = s;
	    }
	    else {
		/* Allow 7 bytes for the client-side GL version.  This allows
		 * for upto version 999.999.  I'm not holding my breath for
		 * that one!  The extra 4 is for the ' ()\0' that will be
		 * added.
		 */
		const size_t size = 7 + strlen( (char *) s ) + 4;

		gc->version = Xmalloc( size );
		if ( gc->version == NULL ) {
		    /* If we couldn't allocate memory for the new string,
		     * make a best-effort and just copy the client-side version
		     * to the string and use that.  It probably doesn't
		     * matter what is done here.  If there not memory available
		     * for a short string, the system is probably going to die
		     * soon anyway.
		     */
		    snprintf( (char *) s, strlen( (char *) s ) + 1, "%u.%u",
			      client_major, client_minor );
		    gc->version = s;
		}
		else {
		    snprintf( (char *)gc->version, size, "%u.%u (%s)",
			      client_major, client_minor, s );
		    Xfree( s );
		    s = gc->version;
		}
	    }
	    break;
	}

	case GL_EXTENSIONS: {
	    int major = 1;
	    int minor = 0;

	    /* This code is currently disabled.  I was reminded that some
	     * vendors intentionally exclude some extensions from their
	     * extension string that are part of the core version they
	     * advertise.  In particular, on Nvidia drivers this means that
	     * the functionality is supported by the driver, but is not
	     * hardware accelerated.  For example, a TNT will show core
	     * version 1.5, but most of the post-1.2 functionality is a
	     * software fallback.
	     * 
	     * I don't want to break applications that rely on this odd
	     * behavior.  At the same time, the code is written and tested,
	     * so I didn't want to throw it away.  Therefore, the code is here
	     * but disabled.  In the future, we may wish to and an environment
	     * variable to enable it.
	     */
	    
#if 0
	    /* Call glGetString just to make sure that gc->server_major and
	     * gc->server_minor are set.  This version may be higher than we
	     * can completely support, but it may imply support for some
	     * extensions that we can support.
	     * 
	     * For example, at the time of this writing, the client-side
	     * library only supports upto core GL version 1.2.  However, cubic
	     * textures, multitexture, multisampling, and some other 1.3
	     * features are supported.  If the server reports back version
	     * 1.3, but does not report all of those extensions, we will
	     * enable them.
	     */
	    (void *) glGetString( GL_VERSION );
	    major = gc->server_major,
	    minor = gc->server_minor;
#endif

	    __glXCalculateUsableGLExtensions( gc, (char *) s, major, minor );
	    XFree( s );
	    s = gc->extensions;
	    break;
	}
	}
    }
    return s;
}

GLboolean __indirect_glIsEnabled(GLenum cap)
{
    __GLX_SINGLE_DECLARE_VARIABLES();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    xGLXSingleReply reply;
    GLboolean retval = 0;

    if (!dpy) return 0;

    switch(cap) {
      case GL_VERTEX_ARRAY:
	  return IS_ARRAY_ENABLED(state, vertex);
      case GL_NORMAL_ARRAY:
	  return IS_ARRAY_ENABLED(state, normal);
      case GL_COLOR_ARRAY:
	  return IS_ARRAY_ENABLED(state, color);
      case GL_INDEX_ARRAY:
	  return IS_ARRAY_ENABLED(state, index);
      case GL_TEXTURE_COORD_ARRAY:
	  return IS_TEXARRAY_ENABLED(state, state->vertArray.activeTexture);
      case GL_EDGE_FLAG_ARRAY:
	  return IS_ARRAY_ENABLED(state, edgeFlag);
      case GL_SECONDARY_COLOR_ARRAY:
	  return IS_ARRAY_ENABLED(state, secondaryColor);
      case GL_FOG_COORD_ARRAY:
	  return IS_ARRAY_ENABLED(state, fogCoord);
    }

    __GLX_SINGLE_LOAD_VARIABLES();
    __GLX_SINGLE_BEGIN(X_GLsop_IsEnabled,4);
    __GLX_SINGLE_PUT_LONG(0,cap);
    __GLX_SINGLE_READ_XREPLY();
    __GLX_SINGLE_GET_RETVAL(retval, GLboolean);
    __GLX_SINGLE_END();
    return retval;
}

void __indirect_glGetPointerv(GLenum pname, void **params)
{
    __GLXcontext *gc = __glXGetCurrentContext();
    __GLXattribute * state = (__GLXattribute *)(gc->client_state_private);
    Display *dpy = gc->currentDpy;

    if (!dpy) return;

    switch(pname) {
      case GL_VERTEX_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ vertex_ARRAY ].ptr;
	  return;
      case GL_NORMAL_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ normal_ARRAY ].ptr;
	  return;
      case GL_COLOR_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ color_ARRAY ].ptr;
	  return;
      case GL_INDEX_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ index_ARRAY ].ptr;
	  return;
      case GL_TEXTURE_COORD_ARRAY_POINTER:
	  *params = (void *)state->vertArray.texCoord[state->vertArray.activeTexture].ptr;
	  return;
      case GL_EDGE_FLAG_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ edgeFlag_ARRAY ].ptr;
	return;
      case GL_SECONDARY_COLOR_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ secondaryColor_ARRAY ].ptr;
	return;
      case GL_FOG_COORD_ARRAY_POINTER:
	  *params = (void *)state->vertArray.arrays[ fogCoord_ARRAY ].ptr;
	return;
      case GL_FEEDBACK_BUFFER_POINTER:
	*params = (void *)gc->feedbackBuf;
	return;
      case GL_SELECTION_BUFFER_POINTER:
	*params = (void *)gc->selectBuf;
	return;
      default:
	__glXSetError(gc, GL_INVALID_ENUM);
	return;
    }
}