2 ** License Applicability. Except to the extent portions of this file are
3 ** made subject to an alternative license as permitted in the SGI Free
4 ** Software License B, Version 1.1 (the "License"), the contents of this
5 ** file are subject only to the provisions of the License. You may not use
6 ** this file except in compliance with the License. You may obtain a copy
7 ** of the License at Silicon Graphics, Inc., attn: Legal Services, 1600
8 ** Amphitheatre Parkway, Mountain View, CA 94043-1351, or at:
10 ** http://oss.sgi.com/projects/FreeB
12 ** Note that, as provided in the License, the Software is distributed on an
13 ** "AS IS" basis, with ALL EXPRESS AND IMPLIED WARRANTIES AND CONDITIONS
14 ** DISCLAIMED, INCLUDING, WITHOUT LIMITATION, ANY IMPLIED WARRANTIES AND
15 ** CONDITIONS OF MERCHANTABILITY, SATISFACTORY QUALITY, FITNESS FOR A
16 ** PARTICULAR PURPOSE, AND NON-INFRINGEMENT.
18 ** Original Code. The Original Code is: OpenGL Sample Implementation,
19 ** Version 1.2.1, released January 26, 2000, developed by Silicon Graphics,
20 ** Inc. The Original Code is Copyright (c) 1991-2000 Silicon Graphics, Inc.
21 ** Copyright in any portions created by third parties is as indicated
22 ** elsewhere herein. All Rights Reserved.
24 ** Additional Notice Provisions: The application programming interfaces
25 ** established by SGI in conjunction with the Original Code are The
26 ** OpenGL(R) Graphics System: A Specification (Version 1.2.1), released
27 ** April 1, 1999; The OpenGL(R) Graphics System Utility Library (Version
28 ** 1.3), released November 4, 1998; and OpenGL(R) Graphics with the X
29 ** Window System(R) (Version 1.3), released October 19, 1998. This software
30 ** was created using the OpenGL(R) version 1.2.1 Sample Implementation
31 ** published by SGI, but has not been independently verified as being
32 ** compliant with the OpenGL(R) version 1.2.1 Specification.
37 #ifdef HAVE_DIX_CONFIG_H
38 #include <dix-config.h>
41 #include "glxserver.h"
43 #include "singlesize.h"
45 #include "indirect_dispatch.h"
46 #include "indirect_size_get.h"
47 #include "glapitable.h"
52 int __glXDispSwap_ReadPixels(__GLXclientState
*cl
, GLbyte
*pc
)
54 GLsizei width
, height
;
56 GLboolean swapBytes
, lsbFirst
;
58 __GLX_DECLARE_SWAP_VARIABLES
;
60 ClientPtr client
= cl
->client
;
62 char *answer
, answerBuffer
[200];
64 __GLX_SWAP_INT(&((xGLXSingleReq
*)pc
)->contextTag
);
65 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
70 pc
+= __GLX_SINGLE_HDR_SIZE
;
74 __GLX_SWAP_INT(pc
+12);
75 __GLX_SWAP_INT(pc
+16);
76 __GLX_SWAP_INT(pc
+20);
78 width
= *(GLsizei
*)(pc
+ 8);
79 height
= *(GLsizei
*)(pc
+ 12);
80 format
= *(GLenum
*)(pc
+ 16);
81 type
= *(GLenum
*)(pc
+ 20);
82 swapBytes
= *(GLboolean
*)(pc
+ 24);
83 lsbFirst
= *(GLboolean
*)(pc
+ 25);
84 compsize
= __glReadPixels_size(format
,type
,width
,height
);
85 if (compsize
< 0) compsize
= 0;
87 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
88 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST
, lsbFirst
) );
89 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
90 __glXClearErrorOccured();
91 CALL_ReadPixels( GET_DISPATCH(),
95 *(GLsizei
*)(pc
+ 12),
101 if (__glXErrorOccured()) {
102 __GLX_BEGIN_REPLY(0);
103 __GLX_SWAP_REPLY_HEADER();
106 __GLX_BEGIN_REPLY(compsize
);
107 __GLX_SWAP_REPLY_HEADER();
109 __GLX_SEND_VOID_ARRAY(compsize
);
114 int __glXDispSwap_GetTexImage(__GLXclientState
*cl
, GLbyte
*pc
)
116 GLint level
, compsize
;
117 GLenum format
, type
, target
;
119 __GLX_DECLARE_SWAP_VARIABLES
;
121 ClientPtr client
= cl
->client
;
123 char *answer
, answerBuffer
[200];
124 GLint width
=0, height
=0, depth
=1;
126 __GLX_SWAP_INT(&((xGLXSingleReq
*)pc
)->contextTag
);
127 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
132 pc
+= __GLX_SINGLE_HDR_SIZE
;
133 __GLX_SWAP_INT(pc
+0);
134 __GLX_SWAP_INT(pc
+4);
135 __GLX_SWAP_INT(pc
+8);
136 __GLX_SWAP_INT(pc
+12);
138 level
= *(GLint
*)(pc
+ 4);
139 format
= *(GLenum
*)(pc
+ 8);
140 type
= *(GLenum
*)(pc
+ 12);
141 target
= *(GLenum
*)(pc
+ 0);
142 swapBytes
= *(GLboolean
*)(pc
+ 16);
144 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target
, level
, GL_TEXTURE_WIDTH
, &width
) );
145 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target
, level
, GL_TEXTURE_HEIGHT
, &height
) );
146 if ( target
== GL_TEXTURE_3D
) {
147 CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target
, level
, GL_TEXTURE_DEPTH
, &depth
) );
150 * The three queries above might fail if we're in a state where queries
151 * are illegal, but then width, height, and depth would still be zero anyway.
153 compsize
= __glGetTexImage_size(target
,level
,format
,type
,width
,height
,depth
);
154 if (compsize
< 0) compsize
= 0;
156 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
157 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
158 __glXClearErrorOccured();
159 CALL_GetTexImage( GET_DISPATCH(), (
163 *(GLenum
*)(pc
+ 12),
167 if (__glXErrorOccured()) {
168 __GLX_BEGIN_REPLY(0);
169 __GLX_SWAP_REPLY_HEADER();
172 __GLX_BEGIN_REPLY(compsize
);
173 __GLX_SWAP_REPLY_HEADER();
174 __GLX_SWAP_INT(&width
);
175 __GLX_SWAP_INT(&height
);
176 __GLX_SWAP_INT(&depth
);
177 ((xGLXGetTexImageReply
*)&__glXReply
)->width
= width
;
178 ((xGLXGetTexImageReply
*)&__glXReply
)->height
= height
;
179 ((xGLXGetTexImageReply
*)&__glXReply
)->depth
= depth
;
181 __GLX_SEND_VOID_ARRAY(compsize
);
186 int __glXDispSwap_GetPolygonStipple(__GLXclientState
*cl
, GLbyte
*pc
)
190 ClientPtr client
= cl
->client
;
192 GLubyte answerBuffer
[200];
194 __GLX_DECLARE_SWAP_VARIABLES
;
196 __GLX_SWAP_INT(&((xGLXSingleReq
*)pc
)->contextTag
);
197 cx
= __glXForceCurrent(cl
, __GLX_GET_SINGLE_CONTEXT_TAG(pc
), &error
);
201 pc
+= __GLX_SINGLE_HDR_SIZE
;
202 lsbFirst
= *(GLboolean
*)(pc
+ 0);
204 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST
, lsbFirst
) );
205 __GLX_GET_ANSWER_BUFFER(answer
,cl
,128,1);
207 __glXClearErrorOccured();
208 CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte
*) answer
) );
209 if (__glXErrorOccured()) {
210 __GLX_BEGIN_REPLY(0);
211 __GLX_SWAP_REPLY_HEADER();
214 __GLX_BEGIN_REPLY(128);
215 __GLX_SWAP_REPLY_HEADER();
217 __GLX_SEND_BYTE_ARRAY(128);
222 static int GetSeparableFilter(__GLXclientState
*cl
, GLbyte
*pc
, GLXContextTag tag
)
224 GLint compsize
, compsize2
;
225 GLenum format
, type
, target
;
228 ClientPtr client
= cl
->client
;
230 __GLX_DECLARE_SWAP_VARIABLES
;
231 char *answer
, answerBuffer
[200];
232 GLint width
=0, height
=0;
234 cx
= __glXForceCurrent(cl
, tag
, &error
);
239 __GLX_SWAP_INT(pc
+0);
240 __GLX_SWAP_INT(pc
+4);
241 __GLX_SWAP_INT(pc
+8);
243 format
= *(GLenum
*)(pc
+ 4);
244 type
= *(GLenum
*)(pc
+ 8);
245 target
= *(GLenum
*)(pc
+ 0);
246 swapBytes
= *(GLboolean
*)(pc
+ 12);
248 /* target must be SEPARABLE_2D, however I guess we can let the GL
249 barf on this one.... */
251 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target
, GL_CONVOLUTION_WIDTH
, &width
) );
252 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target
, GL_CONVOLUTION_HEIGHT
, &height
) );
254 * The two queries above might fail if we're in a state where queries
255 * are illegal, but then width and height would still be zero anyway.
257 compsize
= __glGetTexImage_size(target
,1,format
,type
,width
,1,1);
258 compsize2
= __glGetTexImage_size(target
,1,format
,type
,height
,1,1);
260 if (compsize
< 0) compsize
= 0;
261 if (compsize2
< 0) compsize2
= 0;
262 compsize
= __GLX_PAD(compsize
);
263 compsize2
= __GLX_PAD(compsize2
);
265 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
266 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
+ compsize2
,1);
267 __glXClearErrorOccured();
268 CALL_GetSeparableFilter( GET_DISPATCH(), (
277 if (__glXErrorOccured()) {
278 __GLX_BEGIN_REPLY(0);
279 __GLX_SWAP_REPLY_HEADER();
281 __GLX_BEGIN_REPLY(compsize
+ compsize2
);
282 __GLX_SWAP_REPLY_HEADER();
283 __GLX_SWAP_INT(&width
);
284 __GLX_SWAP_INT(&height
);
285 ((xGLXGetSeparableFilterReply
*)&__glXReply
)->width
= width
;
286 ((xGLXGetSeparableFilterReply
*)&__glXReply
)->height
= height
;
287 __GLX_SEND_VOID_ARRAY(compsize
+ compsize2
);
293 int __glXDispSwap_GetSeparableFilter(__GLXclientState
*cl
, GLbyte
*pc
)
295 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
297 return GetSeparableFilter(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
300 int __glXDispSwap_GetSeparableFilterEXT(__GLXclientState
*cl
, GLbyte
*pc
)
302 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
304 return GetSeparableFilter(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
307 static int GetConvolutionFilter(__GLXclientState
*cl
, GLbyte
*pc
, GLXContextTag tag
)
310 GLenum format
, type
, target
;
313 ClientPtr client
= cl
->client
;
315 __GLX_DECLARE_SWAP_VARIABLES
;
316 char *answer
, answerBuffer
[200];
317 GLint width
=0, height
=0;
319 cx
= __glXForceCurrent(cl
, tag
, &error
);
324 __GLX_SWAP_INT(pc
+0);
325 __GLX_SWAP_INT(pc
+4);
326 __GLX_SWAP_INT(pc
+8);
328 format
= *(GLenum
*)(pc
+ 4);
329 type
= *(GLenum
*)(pc
+ 8);
330 target
= *(GLenum
*)(pc
+ 0);
331 swapBytes
= *(GLboolean
*)(pc
+ 12);
333 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target
, GL_CONVOLUTION_WIDTH
, &width
) );
334 if (target
== GL_CONVOLUTION_2D
) {
337 CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target
, GL_CONVOLUTION_HEIGHT
, &height
) );
340 * The two queries above might fail if we're in a state where queries
341 * are illegal, but then width and height would still be zero anyway.
343 compsize
= __glGetTexImage_size(target
,1,format
,type
,width
,height
,1);
344 if (compsize
< 0) compsize
= 0;
346 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
347 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
348 __glXClearErrorOccured();
349 CALL_GetConvolutionFilter( GET_DISPATCH(), (
356 if (__glXErrorOccured()) {
357 __GLX_BEGIN_REPLY(0);
358 __GLX_SWAP_REPLY_HEADER();
360 __GLX_BEGIN_REPLY(compsize
);
361 __GLX_SWAP_REPLY_HEADER();
362 __GLX_SWAP_INT(&width
);
363 __GLX_SWAP_INT(&height
);
364 ((xGLXGetConvolutionFilterReply
*)&__glXReply
)->width
= width
;
365 ((xGLXGetConvolutionFilterReply
*)&__glXReply
)->height
= height
;
366 __GLX_SEND_VOID_ARRAY(compsize
);
372 int __glXDispSwap_GetConvolutionFilter(__GLXclientState
*cl
, GLbyte
*pc
)
374 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
376 return GetConvolutionFilter(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
379 int __glXDispSwap_GetConvolutionFilterEXT(__GLXclientState
*cl
, GLbyte
*pc
)
381 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
383 return GetConvolutionFilter(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
386 static int GetHistogram(__GLXclientState
*cl
, GLbyte
*pc
, GLXContextTag tag
)
389 GLenum format
, type
, target
;
390 GLboolean swapBytes
, reset
;
392 ClientPtr client
= cl
->client
;
394 __GLX_DECLARE_SWAP_VARIABLES
;
395 char *answer
, answerBuffer
[200];
398 cx
= __glXForceCurrent(cl
, tag
, &error
);
403 __GLX_SWAP_INT(pc
+0);
404 __GLX_SWAP_INT(pc
+4);
405 __GLX_SWAP_INT(pc
+8);
407 format
= *(GLenum
*)(pc
+ 4);
408 type
= *(GLenum
*)(pc
+ 8);
409 target
= *(GLenum
*)(pc
+ 0);
410 swapBytes
= *(GLboolean
*)(pc
+ 12);
411 reset
= *(GLboolean
*)(pc
+ 13);
413 CALL_GetHistogramParameteriv( GET_DISPATCH(), (target
, GL_HISTOGRAM_WIDTH
, &width
) );
415 * The one query above might fail if we're in a state where queries
416 * are illegal, but then width would still be zero anyway.
418 compsize
= __glGetTexImage_size(target
,1,format
,type
,width
,1,1);
419 if (compsize
< 0) compsize
= 0;
421 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
422 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
423 __glXClearErrorOccured();
424 CALL_GetHistogram( GET_DISPATCH(), (target
, reset
, format
, type
, answer
) );
426 if (__glXErrorOccured()) {
427 __GLX_BEGIN_REPLY(0);
428 __GLX_SWAP_REPLY_HEADER();
430 __GLX_BEGIN_REPLY(compsize
);
431 __GLX_SWAP_REPLY_HEADER();
432 __GLX_SWAP_INT(&width
);
433 ((xGLXGetHistogramReply
*)&__glXReply
)->width
= width
;
434 __GLX_SEND_VOID_ARRAY(compsize
);
440 int __glXDispSwap_GetHistogram(__GLXclientState
*cl
, GLbyte
*pc
)
442 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
444 return GetHistogram(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
447 int __glXDispSwap_GetHistogramEXT(__GLXclientState
*cl
, GLbyte
*pc
)
449 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
451 return GetHistogram(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
454 static int GetMinmax(__GLXclientState
*cl
, GLbyte
*pc
, GLXContextTag tag
)
457 GLenum format
, type
, target
;
458 GLboolean swapBytes
, reset
;
460 ClientPtr client
= cl
->client
;
462 __GLX_DECLARE_SWAP_VARIABLES
;
463 char *answer
, answerBuffer
[200];
465 cx
= __glXForceCurrent(cl
, tag
, &error
);
470 __GLX_SWAP_INT(pc
+0);
471 __GLX_SWAP_INT(pc
+4);
472 __GLX_SWAP_INT(pc
+8);
474 format
= *(GLenum
*)(pc
+ 4);
475 type
= *(GLenum
*)(pc
+ 8);
476 target
= *(GLenum
*)(pc
+ 0);
477 swapBytes
= *(GLboolean
*)(pc
+ 12);
478 reset
= *(GLboolean
*)(pc
+ 13);
480 compsize
= __glGetTexImage_size(target
,1,format
,type
,2,1,1);
481 if (compsize
< 0) compsize
= 0;
483 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
484 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
485 __glXClearErrorOccured();
486 CALL_GetMinmax( GET_DISPATCH(), (target
, reset
, format
, type
, answer
) );
488 if (__glXErrorOccured()) {
489 __GLX_BEGIN_REPLY(0);
490 __GLX_SWAP_REPLY_HEADER();
492 __GLX_BEGIN_REPLY(compsize
);
493 __GLX_SWAP_REPLY_HEADER();
494 __GLX_SEND_VOID_ARRAY(compsize
);
500 int __glXDispSwap_GetMinmax(__GLXclientState
*cl
, GLbyte
*pc
)
502 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
504 return GetMinmax(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
507 int __glXDispSwap_GetMinmaxEXT(__GLXclientState
*cl
, GLbyte
*pc
)
509 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
511 return GetMinmax(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);
514 static int GetColorTable(__GLXclientState
*cl
, GLbyte
*pc
, GLXContextTag tag
)
517 GLenum format
, type
, target
;
520 ClientPtr client
= cl
->client
;
522 __GLX_DECLARE_SWAP_VARIABLES
;
523 char *answer
, answerBuffer
[200];
526 cx
= __glXForceCurrent(cl
, tag
, &error
);
531 __GLX_SWAP_INT(pc
+0);
532 __GLX_SWAP_INT(pc
+4);
533 __GLX_SWAP_INT(pc
+8);
535 format
= *(GLenum
*)(pc
+ 4);
536 type
= *(GLenum
*)(pc
+ 8);
537 target
= *(GLenum
*)(pc
+ 0);
538 swapBytes
= *(GLboolean
*)(pc
+ 12);
540 CALL_GetColorTableParameteriv( GET_DISPATCH(), (target
, GL_COLOR_TABLE_WIDTH
, &width
) );
542 * The one query above might fail if we're in a state where queries
543 * are illegal, but then width would still be zero anyway.
545 compsize
= __glGetTexImage_size(target
,1,format
,type
,width
,1,1);
546 if (compsize
< 0) compsize
= 0;
548 CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES
, !swapBytes
) );
549 __GLX_GET_ANSWER_BUFFER(answer
,cl
,compsize
,1);
550 __glXClearErrorOccured();
551 CALL_GetColorTable( GET_DISPATCH(), (
558 if (__glXErrorOccured()) {
559 __GLX_BEGIN_REPLY(0);
560 __GLX_SWAP_REPLY_HEADER();
562 __GLX_BEGIN_REPLY(compsize
);
563 __GLX_SWAP_REPLY_HEADER();
564 __GLX_SWAP_INT(&width
);
565 ((xGLXGetColorTableReply
*)&__glXReply
)->width
= width
;
566 __GLX_SEND_VOID_ARRAY(compsize
);
572 int __glXDispSwap_GetColorTable(__GLXclientState
*cl
, GLbyte
*pc
)
574 const GLXContextTag tag
= __GLX_GET_SINGLE_CONTEXT_TAG(pc
);
576 return GetColorTable(cl
, pc
+ __GLX_SINGLE_HDR_SIZE
, tag
);
579 int __glXDispSwap_GetColorTableSGI(__GLXclientState
*cl
, GLbyte
*pc
)
581 const GLXContextTag tag
= __GLX_GET_VENDPRIV_CONTEXT_TAG(pc
);
583 return GetColorTable(cl
, pc
+ __GLX_VENDPRIV_HDR_SIZE
, tag
);