summaryrefslogtreecommitdiffstats
path: root/src/glx/x11/renderpix.c
blob: c24d3aa1c7c534a8eba346b0c48e168adff2b71f (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
/* $XFree86: xc/lib/GL/glx/renderpix.c,v 1.5 2003/09/28 20:15:04 alanh 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 "packrender.h"

/*
** This file contains routines that deal with unpacking data from client
** memory using the pixel store unpack modes and then shipping it to
** the server.  For all of these routines (except glPolygonStipple) there
** are two forms of the transport - small and large.  Small commands are
** the commands that fit into the "rendering" transport buffer.  Large
** commands are sent to the server in chunks by __glXSendLargeCommand.
**
** All of the commands send over a pixel header (see glxproto.h) which
** describes the pixel store modes that the server must use to properly
** handle the data.  Any pixel store modes not done by the __glFillImage
** routine are passed on to the server.
*/

/*
** Send a large image to the server.  If necessary, a buffer is allocated
** to hold the unpacked data that is copied from the clients memory.
*/
static void SendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
			   GLint width, GLint height, GLint depth,
			   GLenum format, GLenum type, const GLvoid *src,
			   GLubyte *pc, GLubyte *modes)
{
    if (!gc->fastImageUnpack) {
	/* Allocate a temporary holding buffer */
	GLubyte *buf = (GLubyte *) Xmalloc(compsize);
	if (!buf) {
	    __glXSetError(gc, GL_OUT_OF_MEMORY);
	    return;
	}

	/* Apply pixel store unpack modes to copy data into buf */
	(*gc->fillImage)(gc, dim, width, height, depth, format, type, src, buf,
			 modes);

	/* Send large command */
	__glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);

	/* Free buffer */
	Xfree((char*) buf);
    } else {
	/* Just send the data straight as is */
	__glXSendLargeCommand(gc, gc->pc, pc - gc->pc, pc, compsize);
    }
}

/*
** Send a large null image to the server.  To be backwards compatible,
** data must be sent to the server even when the application has passed
** a null pointer into glTexImage1D, glTexImage2D or glTexImage3D.
*/
static void SendLargeNULLImage(__GLXcontext *gc, GLint compsize,
			       GLint width, GLint height, GLint depth,
			       GLenum format, GLenum type, const GLvoid *src,
			       GLubyte *pc, GLubyte *modes)
{
    GLubyte *buf = (GLubyte *) Xmalloc(compsize);

    /* Allocate a temporary holding buffer */
    if (!buf) {
	__glXSetError(gc, GL_OUT_OF_MEMORY);
	return;
    }

    /* Send large command */
    __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);

    /* Free buffer */
    Xfree((char*) buf);
}

/************************************************************************/

void __indirect_glPolygonStipple(const GLubyte *mask)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(32, 32, 1, GL_COLOR_INDEX, GL_BITMAP);
    cmdlen = __GLX_PAD(__GLX_POLYGONSTIPPLE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    __GLX_BEGIN(X_GLrop_PolygonStipple,cmdlen);
    pc += __GLX_RENDER_HDR_SIZE;
    pixelHeaderPC = pc;
    pc += __GLX_PIXEL_HDR_SIZE;
    (*gc->fillImage)(gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP,
		     mask, pc, pixelHeaderPC);
    __GLX_END(__GLX_PAD(compsize));
}

void __indirect_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig,
	      GLfloat xmove, GLfloat ymove, const GLubyte *bitmap)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(width, height, 1, GL_COLOR_INDEX, GL_BITMAP);
    cmdlen = __GLX_PAD(__GLX_BITMAP_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_Bitmap,cmdlen);
	__GLX_PUT_LONG(0,width);
	__GLX_PUT_LONG(4,height);
	__GLX_PUT_FLOAT(8,xorig);
	__GLX_PUT_FLOAT(12,yorig);
	__GLX_PUT_FLOAT(16,xmove);
	__GLX_PUT_FLOAT(20,ymove);
	pc += __GLX_BITMAP_HDR_SIZE;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, 2, width, height, 1, GL_COLOR_INDEX,
			     GL_BITMAP, bitmap, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_Bitmap,cmdlen+4);
	__GLX_PUT_LONG(0,width);
	__GLX_PUT_LONG(4,height);
	__GLX_PUT_FLOAT(8,xorig);
	__GLX_PUT_FLOAT(12,yorig);
	__GLX_PUT_FLOAT(16,xmove);
	__GLX_PUT_FLOAT(20,ymove);
	pc += __GLX_BITMAP_HDR_SIZE;
	SendLargeImage(gc, compsize, 2, width, height, 1, GL_COLOR_INDEX,
		       GL_BITMAP, bitmap, pc, pixelHeaderPC);
    }
}

void __indirect_glTexImage1D(GLenum target, GLint level, GLint components,
		  GLsizei width, GLint border, GLenum format, GLenum type,
		  const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    if (target == GL_PROXY_TEXTURE_1D) {
	compsize = 0;
    } else {
	compsize = __glImageSize(width, 1, 1, format, type);
    }
    cmdlen = __GLX_PAD(__GLX_TEXIMAGE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_TexImage1D,cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,components);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(20,border);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	pc += __GLX_TEXIMAGE_HDR_SIZE;
	if (compsize > 0 && image != NULL) {
	    (*gc->fillImage)(gc, 1, width, 1, 1, format, type,
			     image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_TexImage1D,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,components);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(16,1);
	__GLX_PUT_LONG(20,border);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	pc += __GLX_TEXIMAGE_HDR_SIZE;
	if (image != NULL) {
	    SendLargeImage(gc, compsize, 1, width, 1, 1, format,
			   type, image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    {
		GLubyte *pc = pixelHeaderPC;
		__GLX_PUT_CHAR(0,GL_FALSE);
		__GLX_PUT_CHAR(1,GL_FALSE);
		__GLX_PUT_CHAR(2,0);
		__GLX_PUT_CHAR(3,0);
		__GLX_PUT_LONG(4,0);
		__GLX_PUT_LONG(8,0);
		__GLX_PUT_LONG(12,0);
		__GLX_PUT_LONG(16,1);
	    }
	    SendLargeNULLImage(gc, compsize, width, 1, 1, format,
			       type, image, pc, pixelHeaderPC);
	}
    }
}

void __indirect_glTexImage2D(GLenum target, GLint level, GLint components,
		  GLsizei width, GLsizei height, GLint border, GLenum format,
		  GLenum type, const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    if (target == GL_PROXY_TEXTURE_2D ||
        target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
	compsize = 0;
    } else {
	compsize = __glImageSize(width, height, 1, format, type);
    }
    cmdlen = __GLX_PAD(__GLX_TEXIMAGE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_TexImage2D,cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,components);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(16,height);
	__GLX_PUT_LONG(20,border);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	pc += __GLX_TEXIMAGE_HDR_SIZE;
	if (compsize > 0 && image != NULL) {
	    (*gc->fillImage)(gc, 2, width, height, 1, format, type,
			     image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_TexImage2D,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,components);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(16,height);
	__GLX_PUT_LONG(20,border);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	pc += __GLX_TEXIMAGE_HDR_SIZE;
	if (image != NULL) {
	    SendLargeImage(gc, compsize, 2, width, height, 1, format,
			   type, image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    {
		GLubyte *pc = pixelHeaderPC;
		__GLX_PUT_CHAR(0,GL_FALSE);
		__GLX_PUT_CHAR(1,GL_FALSE);
		__GLX_PUT_CHAR(2,0);
		__GLX_PUT_CHAR(3,0);
		__GLX_PUT_LONG(4,0);
		__GLX_PUT_LONG(8,0);
		__GLX_PUT_LONG(12,0);
		__GLX_PUT_LONG(16,1);
	    }
	    SendLargeNULLImage(gc, compsize, width, height, 1, format,
			       type, image, pc, pixelHeaderPC);
	}
    }
}

void __indirect_glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type,
		  const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(width, height, 1, format, type);
    cmdlen = __GLX_PAD(__GLX_DRAWPIXELS_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_DrawPixels,cmdlen);
	__GLX_PUT_LONG(0,width);
	__GLX_PUT_LONG(4,height);
	__GLX_PUT_LONG(8,format);
	__GLX_PUT_LONG(12,type);
	pc += __GLX_DRAWPIXELS_HDR_SIZE;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, 2, width, height, 1, format, type,
			     image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_DrawPixels,cmdlen+4);
	__GLX_PUT_LONG(0,width);
	__GLX_PUT_LONG(4,height);
	__GLX_PUT_LONG(8,format);
	__GLX_PUT_LONG(12,type);
	pc += __GLX_DRAWPIXELS_HDR_SIZE;
	SendLargeImage(gc, compsize, 2, width, height, 1, format,
		       type, image, pc, pixelHeaderPC);
    }
}

static void __glx_TexSubImage1D2D(GLshort opcode, GLenum target, GLint level,
			GLint xoffset, GLint yoffset, GLsizei width, 	
			GLsizei height, GLenum format, GLenum type, 	
			const GLvoid *image, GLint dim)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    if (image == NULL) {
	compsize = 0;
    } else {
        compsize = __glImageSize(width, height, 1, format, type);
    }

    cmdlen = __GLX_PAD(__GLX_TEXSUBIMAGE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode, cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,xoffset);
	__GLX_PUT_LONG(12,yoffset);
	__GLX_PUT_LONG(16,width);
	__GLX_PUT_LONG(20,height);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(32,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(32,GL_FALSE);
	}
	pc += __GLX_TEXSUBIMAGE_HDR_SIZE;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, dim, width, height, 1, format, type, image, 
			     pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,xoffset);
	__GLX_PUT_LONG(12,yoffset);
	__GLX_PUT_LONG(16,width);
	__GLX_PUT_LONG(20,height);
	__GLX_PUT_LONG(24,format);
	__GLX_PUT_LONG(28,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(32,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(32,GL_FALSE);
	}
	pc += __GLX_TEXSUBIMAGE_HDR_SIZE;
	SendLargeImage(gc, compsize, dim, width, height, 1,
		       format, type, image, pc, pixelHeaderPC);
    }
}
	
void __indirect_glTexSubImage1D(GLenum target, GLint level, GLint xoffset, 
			GLsizei width, GLenum format, GLenum type,
		      	const GLvoid *image)
{
    __glx_TexSubImage1D2D(X_GLrop_TexSubImage1D, target, level, xoffset, 
			 0, width, 1, format, type, image, 1);
}

void __indirect_glTexSubImage2D(GLenum target, GLint level, GLint xoffset, 
			GLint yoffset, GLsizei width, GLsizei height, 
			GLenum format, GLenum type, const GLvoid *image)
{
    __glx_TexSubImage1D2D(X_GLrop_TexSubImage2D, target, level, xoffset, 
			 yoffset, width, height, format, type, image, 2);
}

void __indirect_glColorTable(GLenum target, GLenum internalformat, GLsizei width,
		  GLenum format, GLenum type, const GLvoid *table)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    switch (target) {
	case GL_PROXY_TEXTURE_1D:
	case GL_PROXY_TEXTURE_2D:
	case GL_PROXY_TEXTURE_3D:
	case GL_PROXY_COLOR_TABLE:
	case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
	case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
	case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
	    compsize = 0;
	    break;
	default:
	    compsize = __glImageSize(width, 1, 1, format, type);
	    break;
    }
    cmdlen = __GLX_PAD(__GLX_COLOR_TABLE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) {
	 return;
    }

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
        /* Use GLXRender protocol to send small command */
        __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_ColorTable, (short)cmdlen);
        __GLX_PUT_LONG(0, (long)target);
        __GLX_PUT_LONG(4, (long)internalformat);
        __GLX_PUT_LONG(8, width);
        __GLX_PUT_LONG(12, (long)format);
        __GLX_PUT_LONG(16, (long)type);
        pc += __GLX_COLOR_TABLE_HDR_SIZE;
        if (compsize > 0 && table != NULL) {
            (*gc->fillImage)(gc, 1, width, 1, 1, format, type, table, pc,
                             pixelHeaderPC);
        } else {
            /* Setup default store modes */
            GLubyte *pc = pixelHeaderPC;
            __GLX_PUT_CHAR(0, GL_FALSE);
            __GLX_PUT_CHAR(1, GL_FALSE);
            __GLX_PUT_CHAR(2, 0);
            __GLX_PUT_CHAR(3, 0);
            __GLX_PUT_LONG(4, 0);
            __GLX_PUT_LONG(8, 0);
            __GLX_PUT_LONG(12, 0);
            __GLX_PUT_LONG(16, 1);
        }
        __GLX_END(__GLX_PAD(compsize));
    } else {
        /* Use GLXRenderLarge protocol to send command */
        __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_ColorTable, cmdlen+4);
        __GLX_PUT_LONG(0, (long)target);
        __GLX_PUT_LONG(4, (long)internalformat);
        __GLX_PUT_LONG(8, width);
        __GLX_PUT_LONG(12, (long)format);
        __GLX_PUT_LONG(16, (long)type);
        pc += __GLX_COLOR_TABLE_HDR_SIZE;
        SendLargeImage(gc, compsize, 1, width, 1, 1, format,
                       type, table, pc, pixelHeaderPC);
    }
}

void __indirect_glColorSubTable(GLenum target, GLsizei start, GLsizei count,
		     GLenum format, GLenum type, const GLvoid *table)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(count, 1, 1, format, type);
    cmdlen = __GLX_PAD(__GLX_COLOR_SUBTABLE_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) {
	 return;
    }

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
        /* Use GLXRender protocol to send small command */
        __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_ColorSubTable, (short)cmdlen);
        __GLX_PUT_LONG(0, (long)target);
        __GLX_PUT_LONG(4, start);
        __GLX_PUT_LONG(8, count);
        __GLX_PUT_LONG(12, (long)format);
        __GLX_PUT_LONG(16, (long)type);
        pc += __GLX_COLOR_SUBTABLE_HDR_SIZE;
        if (compsize > 0 && table != NULL) {
            (*gc->fillImage)(gc, 1, start+count, 1, 1, format, type, table, pc,
                             pixelHeaderPC);
        } else {
            /* Setup default store modes */
            GLubyte *pc = pixelHeaderPC;
            __GLX_PUT_CHAR(0, GL_FALSE);
            __GLX_PUT_CHAR(1, GL_FALSE);
            __GLX_PUT_CHAR(2, 0);
            __GLX_PUT_CHAR(3, 0);
            __GLX_PUT_LONG(4, 0);
            __GLX_PUT_LONG(8, 0);
            __GLX_PUT_LONG(12, 0);
            __GLX_PUT_LONG(16, 1);
        }
        __GLX_END(__GLX_PAD(compsize));
    } else {
        /* Use GLXRenderLarge protocol to send command */
        __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_ColorSubTable, cmdlen+4);
        __GLX_PUT_LONG(0, (long)target);
        __GLX_PUT_LONG(4, start);
        __GLX_PUT_LONG(8, count);
        __GLX_PUT_LONG(12, (long)format);
        __GLX_PUT_LONG(16, (long)type);
        pc += __GLX_COLOR_SUBTABLE_HDR_SIZE;
        SendLargeImage(gc, compsize, 1, start+count, 1, 1, format,
                       type, table, pc, pixelHeaderPC);
    }
}

static void __glx_ConvolutionFilter1D2D(GLshort opcode, GLint dim,
			GLenum target,
			GLenum internalformat,
			GLsizei width, GLsizei height,
			GLenum format, GLenum type, const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(width, height, 1, format, type);
    cmdlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode, cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,internalformat);
	__GLX_PUT_LONG(8,width);
	__GLX_PUT_LONG(12,height);
	__GLX_PUT_LONG(16,format);
	__GLX_PUT_LONG(20,type);
	pc += __GLX_CONV_FILT_HDR_SIZE;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, dim, width, height, 1, format, type,
			     image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,internalformat);
	__GLX_PUT_LONG(8,width);
	__GLX_PUT_LONG(12,height);
	__GLX_PUT_LONG(16,format);
	__GLX_PUT_LONG(20,type);
	pc += __GLX_CONV_FILT_HDR_SIZE;
	SendLargeImage(gc, compsize, dim, width, height, 1, format,
		       type, image, pc, pixelHeaderPC);
    }
}

void __indirect_glConvolutionFilter1D(GLenum target, GLenum internalformat,
				GLsizei width, GLenum format,
				GLenum type, const GLvoid *image)
{
     __glx_ConvolutionFilter1D2D(X_GLrop_ConvolutionFilter1D, 1, target, 
				 internalformat, width, 1, format, type,
				 image);
}

void __indirect_glConvolutionFilter2D(GLenum target, GLenum internalformat,
				GLsizei width, GLsizei height, GLenum format,
				GLenum type, const GLvoid *image)
{
     __glx_ConvolutionFilter1D2D(X_GLrop_ConvolutionFilter2D, 2, target,
				internalformat, width, height, format, type,
				image);
}

void __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat,
				GLsizei width, GLsizei height, GLenum format,
				GLenum type, const GLvoid *row,
				const GLvoid *column)
{
    __GLX_DECLARE_VARIABLES();
    GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len;

    __GLX_LOAD_VARIABLES();
    compsize = __glImageSize(width, 1, 1, format, type);
    compsize2 = __glImageSize(height, 1, 1, format, type);
    totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
    hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE);
    image1len = __GLX_PAD(compsize);
    image2len = __GLX_PAD(compsize2);
    cmdlen = totalhdrlen + image1len + image2len;
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,internalformat);
	__GLX_PUT_LONG(8,width);
	__GLX_PUT_LONG(12,height);
	__GLX_PUT_LONG(16,format);
	__GLX_PUT_LONG(20,type);
	pc += hdrlen;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, 1, width, 1, 1, format, type,
			     row, pc, pixelHeaderPC);
	    pc += image1len;
	}
	if (compsize2 > 0) {
            (*gc->fillImage)(gc, 1, height, 1, 1, format, type,
			     column, pc, NULL);
	    pc += image2len;
	}
	if ((compsize == 0) && (compsize2 == 0)) {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,1);
	}
	__GLX_END(0);
    } else {
	GLint bufsize;

	bufsize = image1len + image2len;

	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,internalformat);
	__GLX_PUT_LONG(8,width);
	__GLX_PUT_LONG(12,height);
	__GLX_PUT_LONG(16,format);
	__GLX_PUT_LONG(20,type);
	pc += hdrlen;

	if (!gc->fastImageUnpack) {
	    /* Allocate a temporary holding buffer */
	    GLubyte *buf = (GLubyte *) Xmalloc(bufsize);
	    if (!buf) {
		__glXSetError(gc, GL_OUT_OF_MEMORY);
		return;
	    }
	    (*gc->fillImage)(gc, 1, width, 1, 1, format, type, row, buf, pixelHeaderPC);

	    (*gc->fillImage)(gc, 1, height, 1, 1, format, type, column,
				 buf + image1len, pixelHeaderPC);

	    /* Send large command */
	    __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), buf, bufsize);
	    /* Free buffer */
	    Xfree((char*) buf);
	} else {
	    /* Just send the data straight as is */
	    __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), pc, bufsize);
	}
    }
}

void __indirect_glTexImage3D(GLenum target, GLint level, GLint internalformat,
		  GLsizei width, GLsizei height, GLsizei depth, GLint border,
		  GLenum format, GLenum type, const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    if ((target == GL_PROXY_TEXTURE_3D) || (image == NULL)) {
	compsize = 0;
    } else {
	compsize = __glImageSize(width, height, depth, format, type);
    }
    cmdlen = __GLX_PAD(__GLX_TEXIMAGE_3D_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(X_GLrop_TexImage3D,cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,internalformat);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(16,height);
	__GLX_PUT_LONG(20,depth);
	__GLX_PUT_LONG(24,0);    /* size4d */
	__GLX_PUT_LONG(28,border);
	__GLX_PUT_LONG(32,format);
	__GLX_PUT_LONG(36,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(40,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(40,GL_FALSE);
	}
	pc += __GLX_TEXIMAGE_3D_HDR_SIZE;
	if (compsize > 0 && image != NULL) {
	    (*gc->fillImage)(gc, 3, width, height, depth, format, type,
			     image, pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,0);
	    __GLX_PUT_LONG(20,0);
	    __GLX_PUT_LONG(24,0);
	    __GLX_PUT_LONG(28,0);
	    __GLX_PUT_LONG(32,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(X_GLrop_TexImage3D,cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,internalformat);
	__GLX_PUT_LONG(12,width);
	__GLX_PUT_LONG(16,height);
	__GLX_PUT_LONG(20,depth);
	__GLX_PUT_LONG(24,0);    /* size4d */
	__GLX_PUT_LONG(28,border);
	__GLX_PUT_LONG(32,format);
	__GLX_PUT_LONG(36,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(40,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(40,GL_FALSE);
	}
	pc += __GLX_TEXIMAGE_3D_HDR_SIZE;
	SendLargeImage(gc, compsize, 3, width, height, depth, format,
		       type, image, pc, pixelHeaderPC);
    }
}

void __indirect_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
		     GLint zoffset, GLsizei width, GLsizei height,
		     GLsizei depth, GLenum format, GLenum type,
		     const GLvoid *image)
{
    __GLX_DECLARE_VARIABLES();

    __GLX_LOAD_VARIABLES();
    if (image == NULL) {
	compsize = 0;
    } else {
        compsize = __glImageSize(width, height, depth, format, type);
    }
    cmdlen = __GLX_PAD(__GLX_TEXSUBIMAGE_3D_CMD_HDR_SIZE + compsize);
    if (!gc->currentDpy) return;

    if (cmdlen <= gc->maxSmallRenderCommandSize) {
	/* Use GLXRender protocol to send small command */
	__GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(X_GLrop_TexSubImage3D,cmdlen);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,xoffset);
	__GLX_PUT_LONG(12,yoffset);
	__GLX_PUT_LONG(16,zoffset);
	__GLX_PUT_LONG(20,0); /* woffset */
	__GLX_PUT_LONG(24,width);
	__GLX_PUT_LONG(28,height);
	__GLX_PUT_LONG(32,depth);
	__GLX_PUT_LONG(36,0);      /* size4d */
	__GLX_PUT_LONG(40,format);
	__GLX_PUT_LONG(44,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(48,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(48,GL_FALSE);
	}
	pc += __GLX_TEXSUBIMAGE_3D_HDR_SIZE;
	if (compsize > 0) {
	    (*gc->fillImage)(gc, 3, width, height, depth, format, type, image,
			     pc, pixelHeaderPC);
	} else {
	    /* Setup default store modes */
	    GLubyte *pc = pixelHeaderPC;
	    __GLX_PUT_CHAR(0,GL_FALSE);
	    __GLX_PUT_CHAR(1,GL_FALSE);
	    __GLX_PUT_CHAR(2,0);
	    __GLX_PUT_CHAR(3,0);
	    __GLX_PUT_LONG(4,0);
	    __GLX_PUT_LONG(8,0);
	    __GLX_PUT_LONG(12,0);
	    __GLX_PUT_LONG(16,0);
	    __GLX_PUT_LONG(20,0);
	    __GLX_PUT_LONG(24,0);
	    __GLX_PUT_LONG(28,0);
	    __GLX_PUT_LONG(32,1);
	}
	__GLX_END(__GLX_PAD(compsize));
    } else {
	/* Use GLXRenderLarge protocol to send command */
	__GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(X_GLrop_TexSubImage3D,
						 cmdlen+4);
	__GLX_PUT_LONG(0,target);
	__GLX_PUT_LONG(4,level);
	__GLX_PUT_LONG(8,xoffset);
	__GLX_PUT_LONG(12,yoffset);
	__GLX_PUT_LONG(16,zoffset);
	__GLX_PUT_LONG(20,0);    /* woffset */
	__GLX_PUT_LONG(24,width);
	__GLX_PUT_LONG(28,height);
	__GLX_PUT_LONG(32,depth);
	__GLX_PUT_LONG(36,0);    /* size4d */
	__GLX_PUT_LONG(40,format);
	__GLX_PUT_LONG(44,type);
	if (image == NULL) {
	    __GLX_PUT_LONG(48,GL_TRUE);
	} else {
	    __GLX_PUT_LONG(48,GL_FALSE);
	}
	pc += __GLX_TEXSUBIMAGE_3D_HDR_SIZE;
	SendLargeImage(gc, compsize, 3, width, height, depth, format, type,
		       image, pc, pixelHeaderPC);
    }
}