1 /* $XFree86: xc/lib/GL/glx/pixelstore.c,v 1.4 2004/01/28 18:11:43 alanh 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.
37 #include "glxclient.h"
41 * Send glPixelStore command to the server
43 * \param gc Current GLX context
44 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
45 * \param pname Selector of which pixel parameter is to be set.
46 * \param param Value that \c pname is set to.
48 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
51 send_PixelStore( __GLXcontext
* gc
, unsigned sop
, GLenum pname
,
54 Display
* const dpy
= gc
->currentDpy
;
55 const GLuint cmdlen
= 8;
56 if (__builtin_expect(dpy
!= NULL
, 1)) {
57 GLubyte
const * pc
= __glXSetupSingleRequest(gc
, sop
, cmdlen
);
58 (void) memcpy((void *)(pc
+ 0), (void *)(&pname
), 4);
59 (void) memcpy((void *)(pc
+ 4), param
, 4);
60 UnlockDisplay(dpy
); SyncHandle();
66 ** Specify parameters that control the storage format of pixel arrays.
68 void __indirect_glPixelStoref(GLenum pname
, GLfloat param
)
70 __GLXcontext
*gc
= __glXGetCurrentContext();
71 __GLXattribute
* state
= gc
->client_state_private
;
72 Display
*dpy
= gc
->currentDpy
;
78 case GL_PACK_ROW_LENGTH
:
79 a
= (GLuint
) (param
+ 0.5);
80 if (((GLint
) a
) < 0) {
81 __glXSetError(gc
, GL_INVALID_VALUE
);
84 state
->storePack
.rowLength
= a
;
86 case GL_PACK_IMAGE_HEIGHT
:
87 a
= (GLuint
) (param
+ 0.5);
88 if (((GLint
) a
) < 0) {
89 __glXSetError(gc
, GL_INVALID_VALUE
);
92 state
->storePack
.imageHeight
= a
;
94 case GL_PACK_SKIP_ROWS
:
95 a
= (GLuint
) (param
+ 0.5);
96 if (((GLint
) a
) < 0) {
97 __glXSetError(gc
, GL_INVALID_VALUE
);
100 state
->storePack
.skipRows
= a
;
102 case GL_PACK_SKIP_PIXELS
:
103 a
= (GLuint
) (param
+ 0.5);
104 if (((GLint
) a
) < 0) {
105 __glXSetError(gc
, GL_INVALID_VALUE
);
108 state
->storePack
.skipPixels
= a
;
110 case GL_PACK_SKIP_IMAGES
:
111 a
= (GLuint
) (param
+ 0.5);
112 if (((GLint
) a
) < 0) {
113 __glXSetError(gc
, GL_INVALID_VALUE
);
116 state
->storePack
.skipImages
= a
;
118 case GL_PACK_ALIGNMENT
:
119 a
= (GLint
) (param
+ 0.5);
121 case 1: case 2: case 4: case 8:
122 state
->storePack
.alignment
= a
;
125 __glXSetError(gc
, GL_INVALID_VALUE
);
129 case GL_PACK_SWAP_BYTES
:
130 state
->storePack
.swapEndian
= (param
!= 0);
132 case GL_PACK_LSB_FIRST
:
133 state
->storePack
.lsbFirst
= (param
!= 0);
136 case GL_UNPACK_ROW_LENGTH
:
137 a
= (GLuint
) (param
+ 0.5);
138 if (((GLint
) a
) < 0) {
139 __glXSetError(gc
, GL_INVALID_VALUE
);
142 state
->storeUnpack
.rowLength
= a
;
144 case GL_UNPACK_IMAGE_HEIGHT
:
145 a
= (GLuint
) (param
+ 0.5);
146 if (((GLint
) a
) < 0) {
147 __glXSetError(gc
, GL_INVALID_VALUE
);
150 state
->storeUnpack
.imageHeight
= a
;
152 case GL_UNPACK_SKIP_ROWS
:
153 a
= (GLuint
) (param
+ 0.5);
154 if (((GLint
) a
) < 0) {
155 __glXSetError(gc
, GL_INVALID_VALUE
);
158 state
->storeUnpack
.skipRows
= a
;
160 case GL_UNPACK_SKIP_PIXELS
:
161 a
= (GLuint
) (param
+ 0.5);
162 if (((GLint
) a
) < 0) {
163 __glXSetError(gc
, GL_INVALID_VALUE
);
166 state
->storeUnpack
.skipPixels
= a
;
168 case GL_UNPACK_SKIP_IMAGES
:
169 a
= (GLuint
) (param
+ 0.5);
170 if (((GLint
) a
) < 0) {
171 __glXSetError(gc
, GL_INVALID_VALUE
);
174 state
->storeUnpack
.skipImages
= a
;
176 case GL_UNPACK_ALIGNMENT
:
177 a
= (GLint
) (param
+ 0.5);
179 case 1: case 2: case 4: case 8:
180 state
->storeUnpack
.alignment
= a
;
183 __glXSetError(gc
, GL_INVALID_VALUE
);
187 case GL_UNPACK_SWAP_BYTES
:
188 state
->storeUnpack
.swapEndian
= (param
!= 0);
190 case GL_UNPACK_LSB_FIRST
:
191 state
->storeUnpack
.lsbFirst
= (param
!= 0);
194 /* Group all of the pixel store modes that need to be sent to the
195 * server here. Care must be used to only send modes to the server that
196 * won't affect the size of the data sent to or received from the
197 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
198 * future modes may not be.
200 case GL_PACK_INVERT_MESA
:
201 send_PixelStore( gc
, X_GLsop_PixelStoref
, pname
, & param
);
205 __glXSetError(gc
, GL_INVALID_ENUM
);
210 void __indirect_glPixelStorei(GLenum pname
, GLint param
)
212 __GLXcontext
*gc
= __glXGetCurrentContext();
213 __GLXattribute
* state
= gc
->client_state_private
;
214 Display
*dpy
= gc
->currentDpy
;
219 case GL_PACK_ROW_LENGTH
:
221 __glXSetError(gc
, GL_INVALID_VALUE
);
224 state
->storePack
.rowLength
= param
;
226 case GL_PACK_IMAGE_HEIGHT
:
228 __glXSetError(gc
, GL_INVALID_VALUE
);
231 state
->storePack
.imageHeight
= param
;
233 case GL_PACK_SKIP_ROWS
:
235 __glXSetError(gc
, GL_INVALID_VALUE
);
238 state
->storePack
.skipRows
= param
;
240 case GL_PACK_SKIP_PIXELS
:
242 __glXSetError(gc
, GL_INVALID_VALUE
);
245 state
->storePack
.skipPixels
= param
;
247 case GL_PACK_SKIP_IMAGES
:
249 __glXSetError(gc
, GL_INVALID_VALUE
);
252 state
->storePack
.skipImages
= param
;
254 case GL_PACK_ALIGNMENT
:
256 case 1: case 2: case 4: case 8:
257 state
->storePack
.alignment
= param
;
260 __glXSetError(gc
, GL_INVALID_VALUE
);
264 case GL_PACK_SWAP_BYTES
:
265 state
->storePack
.swapEndian
= (param
!= 0);
267 case GL_PACK_LSB_FIRST
:
268 state
->storePack
.lsbFirst
= (param
!= 0);
271 case GL_UNPACK_ROW_LENGTH
:
273 __glXSetError(gc
, GL_INVALID_VALUE
);
276 state
->storeUnpack
.rowLength
= param
;
278 case GL_UNPACK_IMAGE_HEIGHT
:
280 __glXSetError(gc
, GL_INVALID_VALUE
);
283 state
->storeUnpack
.imageHeight
= param
;
285 case GL_UNPACK_SKIP_ROWS
:
287 __glXSetError(gc
, GL_INVALID_VALUE
);
290 state
->storeUnpack
.skipRows
= param
;
292 case GL_UNPACK_SKIP_PIXELS
:
294 __glXSetError(gc
, GL_INVALID_VALUE
);
297 state
->storeUnpack
.skipPixels
= param
;
299 case GL_UNPACK_SKIP_IMAGES
:
301 __glXSetError(gc
, GL_INVALID_VALUE
);
304 state
->storeUnpack
.skipImages
= param
;
306 case GL_UNPACK_ALIGNMENT
:
308 case 1: case 2: case 4: case 8:
309 state
->storeUnpack
.alignment
= param
;
312 __glXSetError(gc
, GL_INVALID_VALUE
);
316 case GL_UNPACK_SWAP_BYTES
:
317 state
->storeUnpack
.swapEndian
= (param
!= 0);
319 case GL_UNPACK_LSB_FIRST
:
320 state
->storeUnpack
.lsbFirst
= (param
!= 0);
323 /* Group all of the pixel store modes that need to be sent to the
324 * server here. Care must be used to only send modes to the server that
325 * won't affect the size of the data sent to or received from the
326 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
327 * future modes may not be.
329 case GL_PACK_INVERT_MESA
:
330 send_PixelStore( gc
, X_GLsop_PixelStorei
, pname
, & param
);
334 __glXSetError(gc
, GL_INVALID_ENUM
);