Make the transition to script-genereated GLX code easier.
[mesa.git] / src / glx / x11 / renderpix.c
1 /* $XFree86: xc/lib/GL/glx/renderpix.c,v 1.5 2003/09/28 20:15:04 alanh Exp $ */
2 /*
3 ** License Applicability. Except to the extent portions of this file are
4 ** made subject to an alternative license as permitted in the SGI Free
5 ** Software License B, Version 1.1 (the "License"), the contents of this
6 ** file are subject only to the provisions of the License. You may not use
7 ** this file except in compliance with the License. You may obtain a copy
8 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
9 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
13 ** Note that, as provided in the License, the Software is distributed on an
14 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
15 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
16 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
17 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 **
19 ** Original Code. The Original Code is: OpenGL Sample Implementation,
20 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
21 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
22 ** Copyright in any portions created by third parties is as indicated
23 ** elsewhere herein. All Rights Reserved.
24 **
25 ** Additional Notice Provisions: The application programming interfaces
26 ** established by SGI in conjunction with the Original Code are The
27 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
28 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
29 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
30 ** Window System(R) (Version 1.3), released October 19, 1998. This software
31 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
32 ** published by SGI, but has not been independently verified as being
33 ** compliant with the OpenGL(R) version 1.2.1 Specification.
34 **
35 */
36
37 #include "packrender.h"
38
39 /*
40 ** This file contains routines that deal with unpacking data from client
41 ** memory using the pixel store unpack modes and then shipping it to
42 ** the server. For all of these routines (except glPolygonStipple) there
43 ** are two forms of the transport - small and large. Small commands are
44 ** the commands that fit into the "rendering" transport buffer. Large
45 ** commands are sent to the server in chunks by __glXSendLargeCommand.
46 **
47 ** All of the commands send over a pixel header (see glxproto.h) which
48 ** describes the pixel store modes that the server must use to properly
49 ** handle the data. Any pixel store modes not done by the __glFillImage
50 ** routine are passed on to the server.
51 */
52
53 /*
54 ** Send a large image to the server. If necessary, a buffer is allocated
55 ** to hold the unpacked data that is copied from the clients memory.
56 */
57 static void SendLargeImage(__GLXcontext *gc, GLint compsize, GLint dim,
58 GLint width, GLint height, GLint depth,
59 GLenum format, GLenum type, const GLvoid *src,
60 GLubyte *pc, GLubyte *modes)
61 {
62 if (!gc->fastImageUnpack) {
63 /* Allocate a temporary holding buffer */
64 GLubyte *buf = (GLubyte *) Xmalloc(compsize);
65 if (!buf) {
66 __glXSetError(gc, GL_OUT_OF_MEMORY);
67 return;
68 }
69
70 /* Apply pixel store unpack modes to copy data into buf */
71 (*gc->fillImage)(gc, dim, width, height, depth, format, type, src, buf,
72 modes);
73
74 /* Send large command */
75 __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);
76
77 /* Free buffer */
78 Xfree((char*) buf);
79 } else {
80 /* Just send the data straight as is */
81 __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, pc, compsize);
82 }
83 }
84
85 /*
86 ** Send a large null image to the server. To be backwards compatible,
87 ** data must be sent to the server even when the application has passed
88 ** a null pointer into glTexImage1D, glTexImage2D or glTexImage3D.
89 */
90 static void SendLargeNULLImage(__GLXcontext *gc, GLint compsize,
91 GLint width, GLint height, GLint depth,
92 GLenum format, GLenum type, const GLvoid *src,
93 GLubyte *pc, GLubyte *modes)
94 {
95 GLubyte *buf = (GLubyte *) Xmalloc(compsize);
96
97 /* Allocate a temporary holding buffer */
98 if (!buf) {
99 __glXSetError(gc, GL_OUT_OF_MEMORY);
100 return;
101 }
102
103 /* Send large command */
104 __glXSendLargeCommand(gc, gc->pc, pc - gc->pc, buf, compsize);
105
106 /* Free buffer */
107 Xfree((char*) buf);
108 }
109
110 /************************************************************************/
111
112 void __indirect_glPolygonStipple(const GLubyte *mask)
113 {
114 __GLX_DECLARE_VARIABLES();
115
116 __GLX_LOAD_VARIABLES();
117 compsize = __glImageSize(32, 32, 1, GL_COLOR_INDEX, GL_BITMAP);
118 cmdlen = __GLX_PAD(__GLX_POLYGONSTIPPLE_CMD_HDR_SIZE + compsize);
119 if (!gc->currentDpy) return;
120
121 __GLX_BEGIN(X_GLrop_PolygonStipple,cmdlen);
122 pc += __GLX_RENDER_HDR_SIZE;
123 pixelHeaderPC = pc;
124 pc += __GLX_PIXEL_HDR_SIZE;
125 (*gc->fillImage)(gc, 2, 32, 32, 1, GL_COLOR_INDEX, GL_BITMAP,
126 mask, pc, pixelHeaderPC);
127 __GLX_END(__GLX_PAD(compsize));
128 }
129
130 void __indirect_glBitmap(GLsizei width, GLsizei height, GLfloat xorig, GLfloat yorig,
131 GLfloat xmove, GLfloat ymove, const GLubyte *bitmap)
132 {
133 __GLX_DECLARE_VARIABLES();
134
135 __GLX_LOAD_VARIABLES();
136 compsize = __glImageSize(width, height, 1, GL_COLOR_INDEX, GL_BITMAP);
137 cmdlen = __GLX_PAD(__GLX_BITMAP_CMD_HDR_SIZE + compsize);
138 if (!gc->currentDpy) return;
139
140 if (cmdlen <= gc->maxSmallRenderCommandSize) {
141 /* Use GLXRender protocol to send small command */
142 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_Bitmap,cmdlen);
143 __GLX_PUT_LONG(0,width);
144 __GLX_PUT_LONG(4,height);
145 __GLX_PUT_FLOAT(8,xorig);
146 __GLX_PUT_FLOAT(12,yorig);
147 __GLX_PUT_FLOAT(16,xmove);
148 __GLX_PUT_FLOAT(20,ymove);
149 pc += __GLX_BITMAP_HDR_SIZE;
150 if (compsize > 0) {
151 (*gc->fillImage)(gc, 2, width, height, 1, GL_COLOR_INDEX,
152 GL_BITMAP, bitmap, pc, pixelHeaderPC);
153 } else {
154 /* Setup default store modes */
155 GLubyte *pc = pixelHeaderPC;
156 __GLX_PUT_CHAR(0,GL_FALSE);
157 __GLX_PUT_CHAR(1,GL_FALSE);
158 __GLX_PUT_CHAR(2,0);
159 __GLX_PUT_CHAR(3,0);
160 __GLX_PUT_LONG(4,0);
161 __GLX_PUT_LONG(8,0);
162 __GLX_PUT_LONG(12,0);
163 __GLX_PUT_LONG(16,1);
164 }
165 __GLX_END(__GLX_PAD(compsize));
166 } else {
167 /* Use GLXRenderLarge protocol to send command */
168 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_Bitmap,cmdlen+4);
169 __GLX_PUT_LONG(0,width);
170 __GLX_PUT_LONG(4,height);
171 __GLX_PUT_FLOAT(8,xorig);
172 __GLX_PUT_FLOAT(12,yorig);
173 __GLX_PUT_FLOAT(16,xmove);
174 __GLX_PUT_FLOAT(20,ymove);
175 pc += __GLX_BITMAP_HDR_SIZE;
176 SendLargeImage(gc, compsize, 2, width, height, 1, GL_COLOR_INDEX,
177 GL_BITMAP, bitmap, pc, pixelHeaderPC);
178 }
179 }
180
181 void __indirect_glTexImage1D(GLenum target, GLint level, GLint components,
182 GLsizei width, GLint border, GLenum format, GLenum type,
183 const GLvoid *image)
184 {
185 __GLX_DECLARE_VARIABLES();
186
187 __GLX_LOAD_VARIABLES();
188 if (target == GL_PROXY_TEXTURE_1D) {
189 compsize = 0;
190 } else {
191 compsize = __glImageSize(width, 1, 1, format, type);
192 }
193 cmdlen = __GLX_PAD(__GLX_TEXIMAGE_CMD_HDR_SIZE + compsize);
194 if (!gc->currentDpy) return;
195
196 if (cmdlen <= gc->maxSmallRenderCommandSize) {
197 /* Use GLXRender protocol to send small command */
198 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_TexImage1D,cmdlen);
199 __GLX_PUT_LONG(0,target);
200 __GLX_PUT_LONG(4,level);
201 __GLX_PUT_LONG(8,components);
202 __GLX_PUT_LONG(12,width);
203 __GLX_PUT_LONG(20,border);
204 __GLX_PUT_LONG(24,format);
205 __GLX_PUT_LONG(28,type);
206 pc += __GLX_TEXIMAGE_HDR_SIZE;
207 if (compsize > 0 && image != NULL) {
208 (*gc->fillImage)(gc, 1, width, 1, 1, format, type,
209 image, pc, pixelHeaderPC);
210 } else {
211 /* Setup default store modes */
212 GLubyte *pc = pixelHeaderPC;
213 __GLX_PUT_CHAR(0,GL_FALSE);
214 __GLX_PUT_CHAR(1,GL_FALSE);
215 __GLX_PUT_CHAR(2,0);
216 __GLX_PUT_CHAR(3,0);
217 __GLX_PUT_LONG(4,0);
218 __GLX_PUT_LONG(8,0);
219 __GLX_PUT_LONG(12,0);
220 __GLX_PUT_LONG(16,1);
221 }
222 __GLX_END(__GLX_PAD(compsize));
223 } else {
224 /* Use GLXRenderLarge protocol to send command */
225 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_TexImage1D,cmdlen+4);
226 __GLX_PUT_LONG(0,target);
227 __GLX_PUT_LONG(4,level);
228 __GLX_PUT_LONG(8,components);
229 __GLX_PUT_LONG(12,width);
230 __GLX_PUT_LONG(16,1);
231 __GLX_PUT_LONG(20,border);
232 __GLX_PUT_LONG(24,format);
233 __GLX_PUT_LONG(28,type);
234 pc += __GLX_TEXIMAGE_HDR_SIZE;
235 if (image != NULL) {
236 SendLargeImage(gc, compsize, 1, width, 1, 1, format,
237 type, image, pc, pixelHeaderPC);
238 } else {
239 /* Setup default store modes */
240 {
241 GLubyte *pc = pixelHeaderPC;
242 __GLX_PUT_CHAR(0,GL_FALSE);
243 __GLX_PUT_CHAR(1,GL_FALSE);
244 __GLX_PUT_CHAR(2,0);
245 __GLX_PUT_CHAR(3,0);
246 __GLX_PUT_LONG(4,0);
247 __GLX_PUT_LONG(8,0);
248 __GLX_PUT_LONG(12,0);
249 __GLX_PUT_LONG(16,1);
250 }
251 SendLargeNULLImage(gc, compsize, width, 1, 1, format,
252 type, image, pc, pixelHeaderPC);
253 }
254 }
255 }
256
257 void __indirect_glTexImage2D(GLenum target, GLint level, GLint components,
258 GLsizei width, GLsizei height, GLint border, GLenum format,
259 GLenum type, const GLvoid *image)
260 {
261 __GLX_DECLARE_VARIABLES();
262
263 __GLX_LOAD_VARIABLES();
264 if (target == GL_PROXY_TEXTURE_2D ||
265 target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) {
266 compsize = 0;
267 } else {
268 compsize = __glImageSize(width, height, 1, format, type);
269 }
270 cmdlen = __GLX_PAD(__GLX_TEXIMAGE_CMD_HDR_SIZE + compsize);
271 if (!gc->currentDpy) return;
272
273 if (cmdlen <= gc->maxSmallRenderCommandSize) {
274 /* Use GLXRender protocol to send small command */
275 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_TexImage2D,cmdlen);
276 __GLX_PUT_LONG(0,target);
277 __GLX_PUT_LONG(4,level);
278 __GLX_PUT_LONG(8,components);
279 __GLX_PUT_LONG(12,width);
280 __GLX_PUT_LONG(16,height);
281 __GLX_PUT_LONG(20,border);
282 __GLX_PUT_LONG(24,format);
283 __GLX_PUT_LONG(28,type);
284 pc += __GLX_TEXIMAGE_HDR_SIZE;
285 if (compsize > 0 && image != NULL) {
286 (*gc->fillImage)(gc, 2, width, height, 1, format, type,
287 image, pc, pixelHeaderPC);
288 } else {
289 /* Setup default store modes */
290 GLubyte *pc = pixelHeaderPC;
291 __GLX_PUT_CHAR(0,GL_FALSE);
292 __GLX_PUT_CHAR(1,GL_FALSE);
293 __GLX_PUT_CHAR(2,0);
294 __GLX_PUT_CHAR(3,0);
295 __GLX_PUT_LONG(4,0);
296 __GLX_PUT_LONG(8,0);
297 __GLX_PUT_LONG(12,0);
298 __GLX_PUT_LONG(16,1);
299 }
300 __GLX_END(__GLX_PAD(compsize));
301 } else {
302 /* Use GLXRenderLarge protocol to send command */
303 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_TexImage2D,cmdlen+4);
304 __GLX_PUT_LONG(0,target);
305 __GLX_PUT_LONG(4,level);
306 __GLX_PUT_LONG(8,components);
307 __GLX_PUT_LONG(12,width);
308 __GLX_PUT_LONG(16,height);
309 __GLX_PUT_LONG(20,border);
310 __GLX_PUT_LONG(24,format);
311 __GLX_PUT_LONG(28,type);
312 pc += __GLX_TEXIMAGE_HDR_SIZE;
313 if (image != NULL) {
314 SendLargeImage(gc, compsize, 2, width, height, 1, format,
315 type, image, pc, pixelHeaderPC);
316 } else {
317 /* Setup default store modes */
318 {
319 GLubyte *pc = pixelHeaderPC;
320 __GLX_PUT_CHAR(0,GL_FALSE);
321 __GLX_PUT_CHAR(1,GL_FALSE);
322 __GLX_PUT_CHAR(2,0);
323 __GLX_PUT_CHAR(3,0);
324 __GLX_PUT_LONG(4,0);
325 __GLX_PUT_LONG(8,0);
326 __GLX_PUT_LONG(12,0);
327 __GLX_PUT_LONG(16,1);
328 }
329 SendLargeNULLImage(gc, compsize, width, height, 1, format,
330 type, image, pc, pixelHeaderPC);
331 }
332 }
333 }
334
335 void __indirect_glDrawPixels(GLsizei width, GLsizei height, GLenum format, GLenum type,
336 const GLvoid *image)
337 {
338 __GLX_DECLARE_VARIABLES();
339
340 __GLX_LOAD_VARIABLES();
341 compsize = __glImageSize(width, height, 1, format, type);
342 cmdlen = __GLX_PAD(__GLX_DRAWPIXELS_CMD_HDR_SIZE + compsize);
343 if (!gc->currentDpy) return;
344
345 if (cmdlen <= gc->maxSmallRenderCommandSize) {
346 /* Use GLXRender protocol to send small command */
347 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_DrawPixels,cmdlen);
348 __GLX_PUT_LONG(0,width);
349 __GLX_PUT_LONG(4,height);
350 __GLX_PUT_LONG(8,format);
351 __GLX_PUT_LONG(12,type);
352 pc += __GLX_DRAWPIXELS_HDR_SIZE;
353 if (compsize > 0) {
354 (*gc->fillImage)(gc, 2, width, height, 1, format, type,
355 image, pc, pixelHeaderPC);
356 } else {
357 /* Setup default store modes */
358 GLubyte *pc = pixelHeaderPC;
359 __GLX_PUT_CHAR(0,GL_FALSE);
360 __GLX_PUT_CHAR(1,GL_FALSE);
361 __GLX_PUT_CHAR(2,0);
362 __GLX_PUT_CHAR(3,0);
363 __GLX_PUT_LONG(4,0);
364 __GLX_PUT_LONG(8,0);
365 __GLX_PUT_LONG(12,0);
366 __GLX_PUT_LONG(16,1);
367 }
368 __GLX_END(__GLX_PAD(compsize));
369 } else {
370 /* Use GLXRenderLarge protocol to send command */
371 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_DrawPixels,cmdlen+4);
372 __GLX_PUT_LONG(0,width);
373 __GLX_PUT_LONG(4,height);
374 __GLX_PUT_LONG(8,format);
375 __GLX_PUT_LONG(12,type);
376 pc += __GLX_DRAWPIXELS_HDR_SIZE;
377 SendLargeImage(gc, compsize, 2, width, height, 1, format,
378 type, image, pc, pixelHeaderPC);
379 }
380 }
381
382 static void __glx_TexSubImage1D2D(GLshort opcode, GLenum target, GLint level,
383 GLint xoffset, GLint yoffset, GLsizei width,
384 GLsizei height, GLenum format, GLenum type,
385 const GLvoid *image, GLint dim)
386 {
387 __GLX_DECLARE_VARIABLES();
388
389 __GLX_LOAD_VARIABLES();
390 if (image == NULL) {
391 compsize = 0;
392 } else {
393 compsize = __glImageSize(width, height, 1, format, type);
394 }
395
396 cmdlen = __GLX_PAD(__GLX_TEXSUBIMAGE_CMD_HDR_SIZE + compsize);
397 if (!gc->currentDpy) return;
398
399 if (cmdlen <= gc->maxSmallRenderCommandSize) {
400 /* Use GLXRender protocol to send small command */
401 __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode, cmdlen);
402 __GLX_PUT_LONG(0,target);
403 __GLX_PUT_LONG(4,level);
404 __GLX_PUT_LONG(8,xoffset);
405 __GLX_PUT_LONG(12,yoffset);
406 __GLX_PUT_LONG(16,width);
407 __GLX_PUT_LONG(20,height);
408 __GLX_PUT_LONG(24,format);
409 __GLX_PUT_LONG(28,type);
410 if (image == NULL) {
411 __GLX_PUT_LONG(32,GL_TRUE);
412 } else {
413 __GLX_PUT_LONG(32,GL_FALSE);
414 }
415 pc += __GLX_TEXSUBIMAGE_HDR_SIZE;
416 if (compsize > 0) {
417 (*gc->fillImage)(gc, dim, width, height, 1, format, type, image,
418 pc, pixelHeaderPC);
419 } else {
420 /* Setup default store modes */
421 GLubyte *pc = pixelHeaderPC;
422 __GLX_PUT_CHAR(0,GL_FALSE);
423 __GLX_PUT_CHAR(1,GL_FALSE);
424 __GLX_PUT_CHAR(2,0);
425 __GLX_PUT_CHAR(3,0);
426 __GLX_PUT_LONG(4,0);
427 __GLX_PUT_LONG(8,0);
428 __GLX_PUT_LONG(12,0);
429 __GLX_PUT_LONG(16,1);
430 }
431 __GLX_END(__GLX_PAD(compsize));
432 } else {
433 /* Use GLXRenderLarge protocol to send command */
434 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,cmdlen+4);
435 __GLX_PUT_LONG(0,target);
436 __GLX_PUT_LONG(4,level);
437 __GLX_PUT_LONG(8,xoffset);
438 __GLX_PUT_LONG(12,yoffset);
439 __GLX_PUT_LONG(16,width);
440 __GLX_PUT_LONG(20,height);
441 __GLX_PUT_LONG(24,format);
442 __GLX_PUT_LONG(28,type);
443 if (image == NULL) {
444 __GLX_PUT_LONG(32,GL_TRUE);
445 } else {
446 __GLX_PUT_LONG(32,GL_FALSE);
447 }
448 pc += __GLX_TEXSUBIMAGE_HDR_SIZE;
449 SendLargeImage(gc, compsize, dim, width, height, 1,
450 format, type, image, pc, pixelHeaderPC);
451 }
452 }
453
454 void __indirect_glTexSubImage1D(GLenum target, GLint level, GLint xoffset,
455 GLsizei width, GLenum format, GLenum type,
456 const GLvoid *image)
457 {
458 __glx_TexSubImage1D2D(X_GLrop_TexSubImage1D, target, level, xoffset,
459 0, width, 1, format, type, image, 1);
460 }
461
462 void __indirect_glTexSubImage2D(GLenum target, GLint level, GLint xoffset,
463 GLint yoffset, GLsizei width, GLsizei height,
464 GLenum format, GLenum type, const GLvoid *image)
465 {
466 __glx_TexSubImage1D2D(X_GLrop_TexSubImage2D, target, level, xoffset,
467 yoffset, width, height, format, type, image, 2);
468 }
469
470 void __indirect_glColorTable(GLenum target, GLenum internalformat, GLsizei width,
471 GLenum format, GLenum type, const GLvoid *table)
472 {
473 __GLX_DECLARE_VARIABLES();
474
475 __GLX_LOAD_VARIABLES();
476 switch (target) {
477 case GL_PROXY_TEXTURE_1D:
478 case GL_PROXY_TEXTURE_2D:
479 case GL_PROXY_TEXTURE_3D:
480 case GL_PROXY_COLOR_TABLE:
481 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
482 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
483 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
484 compsize = 0;
485 break;
486 default:
487 compsize = __glImageSize(width, 1, 1, format, type);
488 break;
489 }
490 cmdlen = __GLX_PAD(__GLX_COLOR_TABLE_CMD_HDR_SIZE + compsize);
491 if (!gc->currentDpy) {
492 return;
493 }
494
495 if (cmdlen <= gc->maxSmallRenderCommandSize) {
496 /* Use GLXRender protocol to send small command */
497 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_ColorTable, (short)cmdlen);
498 __GLX_PUT_LONG(0, (long)target);
499 __GLX_PUT_LONG(4, (long)internalformat);
500 __GLX_PUT_LONG(8, width);
501 __GLX_PUT_LONG(12, (long)format);
502 __GLX_PUT_LONG(16, (long)type);
503 pc += __GLX_COLOR_TABLE_HDR_SIZE;
504 if (compsize > 0 && table != NULL) {
505 (*gc->fillImage)(gc, 1, width, 1, 1, format, type, table, pc,
506 pixelHeaderPC);
507 } else {
508 /* Setup default store modes */
509 GLubyte *pc = pixelHeaderPC;
510 __GLX_PUT_CHAR(0, GL_FALSE);
511 __GLX_PUT_CHAR(1, GL_FALSE);
512 __GLX_PUT_CHAR(2, 0);
513 __GLX_PUT_CHAR(3, 0);
514 __GLX_PUT_LONG(4, 0);
515 __GLX_PUT_LONG(8, 0);
516 __GLX_PUT_LONG(12, 0);
517 __GLX_PUT_LONG(16, 1);
518 }
519 __GLX_END(__GLX_PAD(compsize));
520 } else {
521 /* Use GLXRenderLarge protocol to send command */
522 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_ColorTable, cmdlen+4);
523 __GLX_PUT_LONG(0, (long)target);
524 __GLX_PUT_LONG(4, (long)internalformat);
525 __GLX_PUT_LONG(8, width);
526 __GLX_PUT_LONG(12, (long)format);
527 __GLX_PUT_LONG(16, (long)type);
528 pc += __GLX_COLOR_TABLE_HDR_SIZE;
529 SendLargeImage(gc, compsize, 1, width, 1, 1, format,
530 type, table, pc, pixelHeaderPC);
531 }
532 }
533
534 void __indirect_glColorSubTable(GLenum target, GLsizei start, GLsizei count,
535 GLenum format, GLenum type, const GLvoid *table)
536 {
537 __GLX_DECLARE_VARIABLES();
538
539 __GLX_LOAD_VARIABLES();
540 compsize = __glImageSize(count, 1, 1, format, type);
541 cmdlen = __GLX_PAD(__GLX_COLOR_SUBTABLE_CMD_HDR_SIZE + compsize);
542 if (!gc->currentDpy) {
543 return;
544 }
545
546 if (cmdlen <= gc->maxSmallRenderCommandSize) {
547 /* Use GLXRender protocol to send small command */
548 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_ColorSubTable, (short)cmdlen);
549 __GLX_PUT_LONG(0, (long)target);
550 __GLX_PUT_LONG(4, start);
551 __GLX_PUT_LONG(8, count);
552 __GLX_PUT_LONG(12, (long)format);
553 __GLX_PUT_LONG(16, (long)type);
554 pc += __GLX_COLOR_SUBTABLE_HDR_SIZE;
555 if (compsize > 0 && table != NULL) {
556 (*gc->fillImage)(gc, 1, start+count, 1, 1, format, type, table, pc,
557 pixelHeaderPC);
558 } else {
559 /* Setup default store modes */
560 GLubyte *pc = pixelHeaderPC;
561 __GLX_PUT_CHAR(0, GL_FALSE);
562 __GLX_PUT_CHAR(1, GL_FALSE);
563 __GLX_PUT_CHAR(2, 0);
564 __GLX_PUT_CHAR(3, 0);
565 __GLX_PUT_LONG(4, 0);
566 __GLX_PUT_LONG(8, 0);
567 __GLX_PUT_LONG(12, 0);
568 __GLX_PUT_LONG(16, 1);
569 }
570 __GLX_END(__GLX_PAD(compsize));
571 } else {
572 /* Use GLXRenderLarge protocol to send command */
573 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_ColorSubTable, cmdlen+4);
574 __GLX_PUT_LONG(0, (long)target);
575 __GLX_PUT_LONG(4, start);
576 __GLX_PUT_LONG(8, count);
577 __GLX_PUT_LONG(12, (long)format);
578 __GLX_PUT_LONG(16, (long)type);
579 pc += __GLX_COLOR_SUBTABLE_HDR_SIZE;
580 SendLargeImage(gc, compsize, 1, start+count, 1, 1, format,
581 type, table, pc, pixelHeaderPC);
582 }
583 }
584
585 static void __glx_ConvolutionFilter1D2D(GLshort opcode, GLint dim,
586 GLenum target,
587 GLenum internalformat,
588 GLsizei width, GLsizei height,
589 GLenum format, GLenum type, const GLvoid *image)
590 {
591 __GLX_DECLARE_VARIABLES();
592
593 __GLX_LOAD_VARIABLES();
594 compsize = __glImageSize(width, height, 1, format, type);
595 cmdlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE + compsize);
596 if (!gc->currentDpy) return;
597
598 if (cmdlen <= gc->maxSmallRenderCommandSize) {
599 /* Use GLXRender protocol to send small command */
600 __GLX_BEGIN_VARIABLE_WITH_PIXEL(opcode, cmdlen);
601 __GLX_PUT_LONG(0,target);
602 __GLX_PUT_LONG(4,internalformat);
603 __GLX_PUT_LONG(8,width);
604 __GLX_PUT_LONG(12,height);
605 __GLX_PUT_LONG(16,format);
606 __GLX_PUT_LONG(20,type);
607 pc += __GLX_CONV_FILT_HDR_SIZE;
608 if (compsize > 0) {
609 (*gc->fillImage)(gc, dim, width, height, 1, format, type,
610 image, pc, pixelHeaderPC);
611 } else {
612 /* Setup default store modes */
613 GLubyte *pc = pixelHeaderPC;
614 __GLX_PUT_CHAR(0,GL_FALSE);
615 __GLX_PUT_CHAR(1,GL_FALSE);
616 __GLX_PUT_CHAR(2,0);
617 __GLX_PUT_CHAR(3,0);
618 __GLX_PUT_LONG(4,0);
619 __GLX_PUT_LONG(8,0);
620 __GLX_PUT_LONG(12,0);
621 __GLX_PUT_LONG(16,1);
622 }
623 __GLX_END(__GLX_PAD(compsize));
624 } else {
625 /* Use GLXRenderLarge protocol to send command */
626 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(opcode,cmdlen+4);
627 __GLX_PUT_LONG(0,target);
628 __GLX_PUT_LONG(4,internalformat);
629 __GLX_PUT_LONG(8,width);
630 __GLX_PUT_LONG(12,height);
631 __GLX_PUT_LONG(16,format);
632 __GLX_PUT_LONG(20,type);
633 pc += __GLX_CONV_FILT_HDR_SIZE;
634 SendLargeImage(gc, compsize, dim, width, height, 1, format,
635 type, image, pc, pixelHeaderPC);
636 }
637 }
638
639 void __indirect_glConvolutionFilter1D(GLenum target, GLenum internalformat,
640 GLsizei width, GLenum format,
641 GLenum type, const GLvoid *image)
642 {
643 __glx_ConvolutionFilter1D2D(X_GLrop_ConvolutionFilter1D, 1, target,
644 internalformat, width, 1, format, type,
645 image);
646 }
647
648 void __indirect_glConvolutionFilter2D(GLenum target, GLenum internalformat,
649 GLsizei width, GLsizei height, GLenum format,
650 GLenum type, const GLvoid *image)
651 {
652 __glx_ConvolutionFilter1D2D(X_GLrop_ConvolutionFilter2D, 2, target,
653 internalformat, width, height, format, type,
654 image);
655 }
656
657 void __indirect_glSeparableFilter2D(GLenum target, GLenum internalformat,
658 GLsizei width, GLsizei height, GLenum format,
659 GLenum type, const GLvoid *row,
660 const GLvoid *column)
661 {
662 __GLX_DECLARE_VARIABLES();
663 GLuint compsize2, hdrlen, totalhdrlen, image1len, image2len;
664
665 __GLX_LOAD_VARIABLES();
666 compsize = __glImageSize(width, 1, 1, format, type);
667 compsize2 = __glImageSize(height, 1, 1, format, type);
668 totalhdrlen = __GLX_PAD(__GLX_CONV_FILT_CMD_HDR_SIZE);
669 hdrlen = __GLX_PAD(__GLX_CONV_FILT_HDR_SIZE);
670 image1len = __GLX_PAD(compsize);
671 image2len = __GLX_PAD(compsize2);
672 cmdlen = totalhdrlen + image1len + image2len;
673 if (!gc->currentDpy) return;
674
675 if (cmdlen <= gc->maxSmallRenderCommandSize) {
676 /* Use GLXRender protocol to send small command */
677 __GLX_BEGIN_VARIABLE_WITH_PIXEL(X_GLrop_SeparableFilter2D, cmdlen);
678 __GLX_PUT_LONG(0,target);
679 __GLX_PUT_LONG(4,internalformat);
680 __GLX_PUT_LONG(8,width);
681 __GLX_PUT_LONG(12,height);
682 __GLX_PUT_LONG(16,format);
683 __GLX_PUT_LONG(20,type);
684 pc += hdrlen;
685 if (compsize > 0) {
686 (*gc->fillImage)(gc, 1, width, 1, 1, format, type,
687 row, pc, pixelHeaderPC);
688 pc += image1len;
689 }
690 if (compsize2 > 0) {
691 (*gc->fillImage)(gc, 1, height, 1, 1, format, type,
692 column, pc, NULL);
693 pc += image2len;
694 }
695 if ((compsize == 0) && (compsize2 == 0)) {
696 /* Setup default store modes */
697 GLubyte *pc = pixelHeaderPC;
698 __GLX_PUT_CHAR(0,GL_FALSE);
699 __GLX_PUT_CHAR(1,GL_FALSE);
700 __GLX_PUT_CHAR(2,0);
701 __GLX_PUT_CHAR(3,0);
702 __GLX_PUT_LONG(4,0);
703 __GLX_PUT_LONG(8,0);
704 __GLX_PUT_LONG(12,0);
705 __GLX_PUT_LONG(16,1);
706 }
707 __GLX_END(0);
708 } else {
709 GLint bufsize;
710
711 bufsize = image1len + image2len;
712
713 /* Use GLXRenderLarge protocol to send command */
714 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL(X_GLrop_SeparableFilter2D,cmdlen+4);
715 __GLX_PUT_LONG(0,target);
716 __GLX_PUT_LONG(4,internalformat);
717 __GLX_PUT_LONG(8,width);
718 __GLX_PUT_LONG(12,height);
719 __GLX_PUT_LONG(16,format);
720 __GLX_PUT_LONG(20,type);
721 pc += hdrlen;
722
723 if (!gc->fastImageUnpack) {
724 /* Allocate a temporary holding buffer */
725 GLubyte *buf = (GLubyte *) Xmalloc(bufsize);
726 if (!buf) {
727 __glXSetError(gc, GL_OUT_OF_MEMORY);
728 return;
729 }
730 (*gc->fillImage)(gc, 1, width, 1, 1, format, type, row, buf, pixelHeaderPC);
731
732 (*gc->fillImage)(gc, 1, height, 1, 1, format, type, column,
733 buf + image1len, pixelHeaderPC);
734
735 /* Send large command */
736 __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), buf, bufsize);
737 /* Free buffer */
738 Xfree((char*) buf);
739 } else {
740 /* Just send the data straight as is */
741 __glXSendLargeCommand(gc, gc->pc, (GLint)(pc - gc->pc), pc, bufsize);
742 }
743 }
744 }
745
746 void __indirect_glTexImage3D(GLenum target, GLint level, GLint internalformat,
747 GLsizei width, GLsizei height, GLsizei depth, GLint border,
748 GLenum format, GLenum type, const GLvoid *image)
749 {
750 __GLX_DECLARE_VARIABLES();
751
752 __GLX_LOAD_VARIABLES();
753 if ((target == GL_PROXY_TEXTURE_3D) || (image == NULL)) {
754 compsize = 0;
755 } else {
756 compsize = __glImageSize(width, height, depth, format, type);
757 }
758 cmdlen = __GLX_PAD(__GLX_TEXIMAGE_3D_CMD_HDR_SIZE + compsize);
759 if (!gc->currentDpy) return;
760
761 if (cmdlen <= gc->maxSmallRenderCommandSize) {
762 /* Use GLXRender protocol to send small command */
763 __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(X_GLrop_TexImage3D,cmdlen);
764 __GLX_PUT_LONG(0,target);
765 __GLX_PUT_LONG(4,level);
766 __GLX_PUT_LONG(8,internalformat);
767 __GLX_PUT_LONG(12,width);
768 __GLX_PUT_LONG(16,height);
769 __GLX_PUT_LONG(20,depth);
770 __GLX_PUT_LONG(24,0); /* size4d */
771 __GLX_PUT_LONG(28,border);
772 __GLX_PUT_LONG(32,format);
773 __GLX_PUT_LONG(36,type);
774 if (image == NULL) {
775 __GLX_PUT_LONG(40,GL_TRUE);
776 } else {
777 __GLX_PUT_LONG(40,GL_FALSE);
778 }
779 pc += __GLX_TEXIMAGE_3D_HDR_SIZE;
780 if (compsize > 0 && image != NULL) {
781 (*gc->fillImage)(gc, 3, width, height, depth, format, type,
782 image, pc, pixelHeaderPC);
783 } else {
784 /* Setup default store modes */
785 GLubyte *pc = pixelHeaderPC;
786 __GLX_PUT_CHAR(0,GL_FALSE);
787 __GLX_PUT_CHAR(1,GL_FALSE);
788 __GLX_PUT_CHAR(2,0);
789 __GLX_PUT_CHAR(3,0);
790 __GLX_PUT_LONG(4,0);
791 __GLX_PUT_LONG(8,0);
792 __GLX_PUT_LONG(12,0);
793 __GLX_PUT_LONG(16,0);
794 __GLX_PUT_LONG(20,0);
795 __GLX_PUT_LONG(24,0);
796 __GLX_PUT_LONG(28,0);
797 __GLX_PUT_LONG(32,1);
798 }
799 __GLX_END(__GLX_PAD(compsize));
800 } else {
801 /* Use GLXRenderLarge protocol to send command */
802 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(X_GLrop_TexImage3D,cmdlen+4);
803 __GLX_PUT_LONG(0,target);
804 __GLX_PUT_LONG(4,level);
805 __GLX_PUT_LONG(8,internalformat);
806 __GLX_PUT_LONG(12,width);
807 __GLX_PUT_LONG(16,height);
808 __GLX_PUT_LONG(20,depth);
809 __GLX_PUT_LONG(24,0); /* size4d */
810 __GLX_PUT_LONG(28,border);
811 __GLX_PUT_LONG(32,format);
812 __GLX_PUT_LONG(36,type);
813 if (image == NULL) {
814 __GLX_PUT_LONG(40,GL_TRUE);
815 } else {
816 __GLX_PUT_LONG(40,GL_FALSE);
817 }
818 pc += __GLX_TEXIMAGE_3D_HDR_SIZE;
819 SendLargeImage(gc, compsize, 3, width, height, depth, format,
820 type, image, pc, pixelHeaderPC);
821 }
822 }
823
824 void __indirect_glTexSubImage3D(GLenum target, GLint level, GLint xoffset, GLint yoffset,
825 GLint zoffset, GLsizei width, GLsizei height,
826 GLsizei depth, GLenum format, GLenum type,
827 const GLvoid *image)
828 {
829 __GLX_DECLARE_VARIABLES();
830
831 __GLX_LOAD_VARIABLES();
832 if (image == NULL) {
833 compsize = 0;
834 } else {
835 compsize = __glImageSize(width, height, depth, format, type);
836 }
837 cmdlen = __GLX_PAD(__GLX_TEXSUBIMAGE_3D_CMD_HDR_SIZE + compsize);
838 if (!gc->currentDpy) return;
839
840 if (cmdlen <= gc->maxSmallRenderCommandSize) {
841 /* Use GLXRender protocol to send small command */
842 __GLX_BEGIN_VARIABLE_WITH_PIXEL_3D(X_GLrop_TexSubImage3D,cmdlen);
843 __GLX_PUT_LONG(0,target);
844 __GLX_PUT_LONG(4,level);
845 __GLX_PUT_LONG(8,xoffset);
846 __GLX_PUT_LONG(12,yoffset);
847 __GLX_PUT_LONG(16,zoffset);
848 __GLX_PUT_LONG(20,0); /* woffset */
849 __GLX_PUT_LONG(24,width);
850 __GLX_PUT_LONG(28,height);
851 __GLX_PUT_LONG(32,depth);
852 __GLX_PUT_LONG(36,0); /* size4d */
853 __GLX_PUT_LONG(40,format);
854 __GLX_PUT_LONG(44,type);
855 if (image == NULL) {
856 __GLX_PUT_LONG(48,GL_TRUE);
857 } else {
858 __GLX_PUT_LONG(48,GL_FALSE);
859 }
860 pc += __GLX_TEXSUBIMAGE_3D_HDR_SIZE;
861 if (compsize > 0) {
862 (*gc->fillImage)(gc, 3, width, height, depth, format, type, image,
863 pc, pixelHeaderPC);
864 } else {
865 /* Setup default store modes */
866 GLubyte *pc = pixelHeaderPC;
867 __GLX_PUT_CHAR(0,GL_FALSE);
868 __GLX_PUT_CHAR(1,GL_FALSE);
869 __GLX_PUT_CHAR(2,0);
870 __GLX_PUT_CHAR(3,0);
871 __GLX_PUT_LONG(4,0);
872 __GLX_PUT_LONG(8,0);
873 __GLX_PUT_LONG(12,0);
874 __GLX_PUT_LONG(16,0);
875 __GLX_PUT_LONG(20,0);
876 __GLX_PUT_LONG(24,0);
877 __GLX_PUT_LONG(28,0);
878 __GLX_PUT_LONG(32,1);
879 }
880 __GLX_END(__GLX_PAD(compsize));
881 } else {
882 /* Use GLXRenderLarge protocol to send command */
883 __GLX_BEGIN_VARIABLE_LARGE_WITH_PIXEL_3D(X_GLrop_TexSubImage3D,
884 cmdlen+4);
885 __GLX_PUT_LONG(0,target);
886 __GLX_PUT_LONG(4,level);
887 __GLX_PUT_LONG(8,xoffset);
888 __GLX_PUT_LONG(12,yoffset);
889 __GLX_PUT_LONG(16,zoffset);
890 __GLX_PUT_LONG(20,0); /* woffset */
891 __GLX_PUT_LONG(24,width);
892 __GLX_PUT_LONG(28,height);
893 __GLX_PUT_LONG(32,depth);
894 __GLX_PUT_LONG(36,0); /* size4d */
895 __GLX_PUT_LONG(40,format);
896 __GLX_PUT_LONG(44,type);
897 if (image == NULL) {
898 __GLX_PUT_LONG(48,GL_TRUE);
899 } else {
900 __GLX_PUT_LONG(48,GL_FALSE);
901 }
902 pc += __GLX_TEXSUBIMAGE_3D_HDR_SIZE;
903 SendLargeImage(gc, compsize, 3, width, height, depth, format, type,
904 image, pc, pixelHeaderPC);
905 }
906 }