1
/* $XFree86: xc/programs/Xserver/GL/glx/singlepixswap.c,v 1.5 2001/03/21 16:29:37 dawes Exp $ */
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:
11
** http://oss.sgi.com/projects/FreeB
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.
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.
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.
38
#ifdef HAVE_DIX_CONFIG_H
39
#include <dix-config.h>
42
#include "glxserver.h"
44
#include "singlesize.h"
46
#include "indirect_dispatch.h"
47
#include "indirect_size_get.h"
48
#include "glapitable.h"
53
int __glXDispSwap_ReadPixels(__GLXclientState *cl, GLbyte *pc)
55
GLsizei width, height;
57
GLboolean swapBytes, lsbFirst;
59
__GLX_DECLARE_SWAP_VARIABLES;
61
ClientPtr client = cl->client;
63
char *answer, answerBuffer[200];
65
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
66
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
71
pc += __GLX_SINGLE_HDR_SIZE;
75
__GLX_SWAP_INT(pc+12);
76
__GLX_SWAP_INT(pc+16);
77
__GLX_SWAP_INT(pc+20);
79
width = *(GLsizei *)(pc + 8);
80
height = *(GLsizei *)(pc + 12);
81
format = *(GLenum *)(pc + 16);
82
type = *(GLenum *)(pc + 20);
83
swapBytes = *(GLboolean *)(pc + 24);
84
lsbFirst = *(GLboolean *)(pc + 25);
85
compsize = __glReadPixels_size(format,type,width,height);
86
if (compsize < 0) compsize = 0;
88
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
89
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
90
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
91
__glXClearErrorOccured();
92
CALL_ReadPixels( GET_DISPATCH(),
96
*(GLsizei *)(pc + 12),
102
if (__glXErrorOccured()) {
103
__GLX_BEGIN_REPLY(0);
104
__GLX_SWAP_REPLY_HEADER();
107
__GLX_BEGIN_REPLY(compsize);
108
__GLX_SWAP_REPLY_HEADER();
110
__GLX_SEND_VOID_ARRAY(compsize);
115
int __glXDispSwap_GetTexImage(__GLXclientState *cl, GLbyte *pc)
117
GLint level, compsize;
118
GLenum format, type, target;
120
__GLX_DECLARE_SWAP_VARIABLES;
122
ClientPtr client = cl->client;
124
char *answer, answerBuffer[200];
125
GLint width=0, height=0, depth=1;
127
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
128
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
133
pc += __GLX_SINGLE_HDR_SIZE;
134
__GLX_SWAP_INT(pc+0);
135
__GLX_SWAP_INT(pc+4);
136
__GLX_SWAP_INT(pc+8);
137
__GLX_SWAP_INT(pc+12);
139
level = *(GLint *)(pc + 4);
140
format = *(GLenum *)(pc + 8);
141
type = *(GLenum *)(pc + 12);
142
target = *(GLenum *)(pc + 0);
143
swapBytes = *(GLboolean *)(pc + 16);
145
CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_WIDTH, &width) );
146
CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_HEIGHT, &height) );
147
if ( target == GL_TEXTURE_3D) {
148
CALL_GetTexLevelParameteriv( GET_DISPATCH(), (target, level, GL_TEXTURE_DEPTH, &depth) );
151
* The three queries above might fail if we're in a state where queries
152
* are illegal, but then width, height, and depth would still be zero anyway.
154
compsize = __glGetTexImage_size(target,level,format,type,width,height,depth);
155
if (compsize < 0) compsize = 0;
157
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
158
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
159
__glXClearErrorOccured();
160
CALL_GetTexImage( GET_DISPATCH(), (
164
*(GLenum *)(pc + 12),
168
if (__glXErrorOccured()) {
169
__GLX_BEGIN_REPLY(0);
170
__GLX_SWAP_REPLY_HEADER();
173
__GLX_BEGIN_REPLY(compsize);
174
__GLX_SWAP_REPLY_HEADER();
175
__GLX_SWAP_INT(&width);
176
__GLX_SWAP_INT(&height);
177
__GLX_SWAP_INT(&depth);
178
((xGLXGetTexImageReply *)&__glXReply)->width = width;
179
((xGLXGetTexImageReply *)&__glXReply)->height = height;
180
((xGLXGetTexImageReply *)&__glXReply)->depth = depth;
182
__GLX_SEND_VOID_ARRAY(compsize);
187
int __glXDispSwap_GetPolygonStipple(__GLXclientState *cl, GLbyte *pc)
191
ClientPtr client = cl->client;
193
GLubyte answerBuffer[200];
195
__GLX_DECLARE_SWAP_VARIABLES;
197
__GLX_SWAP_INT(&((xGLXSingleReq *)pc)->contextTag);
198
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
202
pc += __GLX_SINGLE_HDR_SIZE;
203
lsbFirst = *(GLboolean *)(pc + 0);
205
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_LSB_FIRST, lsbFirst) );
206
__GLX_GET_ANSWER_BUFFER(answer,cl,128,1);
208
__glXClearErrorOccured();
209
CALL_GetPolygonStipple( GET_DISPATCH(), ((GLubyte *) answer) );
210
if (__glXErrorOccured()) {
211
__GLX_BEGIN_REPLY(0);
212
__GLX_SWAP_REPLY_HEADER();
215
__GLX_BEGIN_REPLY(128);
216
__GLX_SWAP_REPLY_HEADER();
218
__GLX_SEND_BYTE_ARRAY(128);
223
int __glXDispSwap_GetSeparableFilter(__GLXclientState *cl, GLbyte *pc)
225
GLint compsize, compsize2;
226
GLenum format, type, target;
229
ClientPtr client = cl->client;
231
__GLX_DECLARE_SWAP_VARIABLES;
232
char *answer, answerBuffer[200];
233
GLint width=0, height=0;
235
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
240
pc += __GLX_SINGLE_HDR_SIZE;
241
__GLX_SWAP_INT(pc+0);
242
__GLX_SWAP_INT(pc+4);
243
__GLX_SWAP_INT(pc+8);
245
format = *(GLenum *)(pc + 4);
246
type = *(GLenum *)(pc + 8);
247
target = *(GLenum *)(pc + 0);
248
swapBytes = *(GLboolean *)(pc + 12);
250
/* target must be SEPARABLE_2D, however I guess we can let the GL
251
barf on this one.... */
253
CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
254
CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
256
* The two queries above might fail if we're in a state where queries
257
* are illegal, but then width and height would still be zero anyway.
259
compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
260
compsize2 = __glGetTexImage_size(target,1,format,type,height,1,1);
262
if (compsize < 0) compsize = 0;
263
if (compsize2 < 0) compsize2 = 0;
264
compsize = __GLX_PAD(compsize);
265
compsize2 = __GLX_PAD(compsize2);
267
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
268
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize + compsize2,1);
269
__glXClearErrorOccured();
270
CALL_GetSeparableFilter( GET_DISPATCH(), (
279
if (__glXErrorOccured()) {
280
__GLX_BEGIN_REPLY(0);
281
__GLX_SWAP_REPLY_HEADER();
283
__GLX_BEGIN_REPLY(compsize + compsize2);
284
__GLX_SWAP_REPLY_HEADER();
285
__GLX_SWAP_INT(&width);
286
__GLX_SWAP_INT(&height);
287
((xGLXGetSeparableFilterReply *)&__glXReply)->width = width;
288
((xGLXGetSeparableFilterReply *)&__glXReply)->height = height;
289
__GLX_SEND_VOID_ARRAY(compsize + compsize2);
295
int __glXDispSwap_GetConvolutionFilter(__GLXclientState *cl, GLbyte *pc)
298
GLenum format, type, target;
301
ClientPtr client = cl->client;
303
__GLX_DECLARE_SWAP_VARIABLES;
304
char *answer, answerBuffer[200];
305
GLint width=0, height=0;
307
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
312
pc += __GLX_SINGLE_HDR_SIZE;
313
__GLX_SWAP_INT(pc+0);
314
__GLX_SWAP_INT(pc+4);
315
__GLX_SWAP_INT(pc+8);
317
format = *(GLenum *)(pc + 4);
318
type = *(GLenum *)(pc + 8);
319
target = *(GLenum *)(pc + 0);
320
swapBytes = *(GLboolean *)(pc + 12);
322
CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_WIDTH, &width) );
323
if (target == GL_CONVOLUTION_2D) {
326
CALL_GetConvolutionParameteriv( GET_DISPATCH(), (target, GL_CONVOLUTION_HEIGHT, &height) );
329
* The two queries above might fail if we're in a state where queries
330
* are illegal, but then width and height would still be zero anyway.
332
compsize = __glGetTexImage_size(target,1,format,type,width,height,1);
333
if (compsize < 0) compsize = 0;
335
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
336
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
337
__glXClearErrorOccured();
338
CALL_GetConvolutionFilter( GET_DISPATCH(), (
345
if (__glXErrorOccured()) {
346
__GLX_BEGIN_REPLY(0);
347
__GLX_SWAP_REPLY_HEADER();
349
__GLX_BEGIN_REPLY(compsize);
350
__GLX_SWAP_REPLY_HEADER();
351
__GLX_SWAP_INT(&width);
352
__GLX_SWAP_INT(&height);
353
((xGLXGetConvolutionFilterReply *)&__glXReply)->width = width;
354
((xGLXGetConvolutionFilterReply *)&__glXReply)->height = height;
355
__GLX_SEND_VOID_ARRAY(compsize);
361
int __glXDispSwap_GetHistogram(__GLXclientState *cl, GLbyte *pc)
364
GLenum format, type, target;
365
GLboolean swapBytes, reset;
367
ClientPtr client = cl->client;
369
__GLX_DECLARE_SWAP_VARIABLES;
370
char *answer, answerBuffer[200];
373
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
378
pc += __GLX_SINGLE_HDR_SIZE;
379
__GLX_SWAP_INT(pc+0);
380
__GLX_SWAP_INT(pc+4);
381
__GLX_SWAP_INT(pc+8);
383
format = *(GLenum *)(pc + 4);
384
type = *(GLenum *)(pc + 8);
385
target = *(GLenum *)(pc + 0);
386
swapBytes = *(GLboolean *)(pc + 12);
387
reset = *(GLboolean *)(pc + 13);
389
CALL_GetHistogramParameteriv( GET_DISPATCH(), (target, GL_HISTOGRAM_WIDTH, &width) );
391
* The one query above might fail if we're in a state where queries
392
* are illegal, but then width would still be zero anyway.
394
compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
395
if (compsize < 0) compsize = 0;
397
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
398
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
399
__glXClearErrorOccured();
400
CALL_GetHistogram( GET_DISPATCH(), (target, reset, format, type, answer) );
402
if (__glXErrorOccured()) {
403
__GLX_BEGIN_REPLY(0);
404
__GLX_SWAP_REPLY_HEADER();
406
__GLX_BEGIN_REPLY(compsize);
407
__GLX_SWAP_REPLY_HEADER();
408
__GLX_SWAP_INT(&width);
409
((xGLXGetHistogramReply *)&__glXReply)->width = width;
410
__GLX_SEND_VOID_ARRAY(compsize);
416
int __glXDispSwap_GetMinmax(__GLXclientState *cl, GLbyte *pc)
419
GLenum format, type, target;
420
GLboolean swapBytes, reset;
422
ClientPtr client = cl->client;
424
__GLX_DECLARE_SWAP_VARIABLES;
425
char *answer, answerBuffer[200];
427
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
432
pc += __GLX_SINGLE_HDR_SIZE;
433
__GLX_SWAP_INT(pc+0);
434
__GLX_SWAP_INT(pc+4);
435
__GLX_SWAP_INT(pc+8);
437
format = *(GLenum *)(pc + 4);
438
type = *(GLenum *)(pc + 8);
439
target = *(GLenum *)(pc + 0);
440
swapBytes = *(GLboolean *)(pc + 12);
441
reset = *(GLboolean *)(pc + 13);
443
compsize = __glGetTexImage_size(target,1,format,type,2,1,1);
444
if (compsize < 0) compsize = 0;
446
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
447
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
448
__glXClearErrorOccured();
449
CALL_GetMinmax( GET_DISPATCH(), (target, reset, format, type, answer) );
451
if (__glXErrorOccured()) {
452
__GLX_BEGIN_REPLY(0);
453
__GLX_SWAP_REPLY_HEADER();
455
__GLX_BEGIN_REPLY(compsize);
456
__GLX_SWAP_REPLY_HEADER();
457
__GLX_SEND_VOID_ARRAY(compsize);
463
int __glXDispSwap_GetColorTable(__GLXclientState *cl, GLbyte *pc)
466
GLenum format, type, target;
469
ClientPtr client = cl->client;
471
__GLX_DECLARE_SWAP_VARIABLES;
472
char *answer, answerBuffer[200];
475
cx = __glXForceCurrent(cl, __GLX_GET_SINGLE_CONTEXT_TAG(pc), &error);
480
pc += __GLX_SINGLE_HDR_SIZE;
481
__GLX_SWAP_INT(pc+0);
482
__GLX_SWAP_INT(pc+4);
483
__GLX_SWAP_INT(pc+8);
485
format = *(GLenum *)(pc + 4);
486
type = *(GLenum *)(pc + 8);
487
target = *(GLenum *)(pc + 0);
488
swapBytes = *(GLboolean *)(pc + 12);
490
CALL_GetColorTableParameteriv( GET_DISPATCH(), (target, GL_COLOR_TABLE_WIDTH, &width) );
492
* The one query above might fail if we're in a state where queries
493
* are illegal, but then width would still be zero anyway.
495
compsize = __glGetTexImage_size(target,1,format,type,width,1,1);
496
if (compsize < 0) compsize = 0;
498
CALL_PixelStorei( GET_DISPATCH(), (GL_PACK_SWAP_BYTES, !swapBytes) );
499
__GLX_GET_ANSWER_BUFFER(answer,cl,compsize,1);
500
__glXClearErrorOccured();
501
CALL_GetColorTable( GET_DISPATCH(), (
508
if (__glXErrorOccured()) {
509
__GLX_BEGIN_REPLY(0);
510
__GLX_SWAP_REPLY_HEADER();
512
__GLX_BEGIN_REPLY(compsize);
513
__GLX_SWAP_REPLY_HEADER();
514
__GLX_SWAP_INT(&width);
515
((xGLXGetColorTableReply *)&__glXReply)->width = width;
516
__GLX_SEND_VOID_ARRAY(compsize);