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.
38 #include "glxclient.h"
42 * Send glPixelStore command to the server
44 * \param gc Current GLX context
45 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
46 * \param pname Selector of which pixel parameter is to be set.
47 * \param param Value that \c pname is set to.
49 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
52 send_PixelStore( __GLXcontext
* gc
, unsigned sop
, GLenum pname
,
55 Display
* const dpy
= gc
->currentDpy
;
56 const GLuint cmdlen
= 8;
57 if (__builtin_expect(dpy
!= NULL
, 1)) {
58 GLubyte
const * pc
= __glXSetupSingleRequest(gc
, sop
, cmdlen
);
59 (void) memcpy((void *)(pc
+ 0), (void *)(&pname
), 4);
60 (void) memcpy((void *)(pc
+ 4), param
, 4);
61 UnlockDisplay(dpy
); SyncHandle();
67 ** Specify parameters that control the storage format of pixel arrays.
69 void __indirect_glPixelStoref(GLenum pname
, GLfloat param
)
71 __GLXcontext
*gc
= __glXGetCurrentContext();
72 __GLXattribute
* state
= gc
->client_state_private
;
73 Display
*dpy
= gc
->currentDpy
;
79 case GL_PACK_ROW_LENGTH
:
80 a
= (GLuint
) (param
+ 0.5);
81 if (((GLint
) a
) < 0) {
82 __glXSetError(gc
, GL_INVALID_VALUE
);
85 state
->storePack
.rowLength
= a
;
87 case GL_PACK_IMAGE_HEIGHT
:
88 a
= (GLuint
) (param
+ 0.5);
89 if (((GLint
) a
) < 0) {
90 __glXSetError(gc
, GL_INVALID_VALUE
);
93 state
->storePack
.imageHeight
= a
;
95 case GL_PACK_SKIP_ROWS
:
96 a
= (GLuint
) (param
+ 0.5);
97 if (((GLint
) a
) < 0) {
98 __glXSetError(gc
, GL_INVALID_VALUE
);
101 state
->storePack
.skipRows
= a
;
103 case GL_PACK_SKIP_PIXELS
:
104 a
= (GLuint
) (param
+ 0.5);
105 if (((GLint
) a
) < 0) {
106 __glXSetError(gc
, GL_INVALID_VALUE
);
109 state
->storePack
.skipPixels
= a
;
111 case GL_PACK_SKIP_IMAGES
:
112 a
= (GLuint
) (param
+ 0.5);
113 if (((GLint
) a
) < 0) {
114 __glXSetError(gc
, GL_INVALID_VALUE
);
117 state
->storePack
.skipImages
= a
;
119 case GL_PACK_ALIGNMENT
:
120 a
= (GLint
) (param
+ 0.5);
122 case 1: case 2: case 4: case 8:
123 state
->storePack
.alignment
= a
;
126 __glXSetError(gc
, GL_INVALID_VALUE
);
130 case GL_PACK_SWAP_BYTES
:
131 state
->storePack
.swapEndian
= (param
!= 0);
133 case GL_PACK_LSB_FIRST
:
134 state
->storePack
.lsbFirst
= (param
!= 0);
137 case GL_UNPACK_ROW_LENGTH
:
138 a
= (GLuint
) (param
+ 0.5);
139 if (((GLint
) a
) < 0) {
140 __glXSetError(gc
, GL_INVALID_VALUE
);
143 state
->storeUnpack
.rowLength
= a
;
145 case GL_UNPACK_IMAGE_HEIGHT
:
146 a
= (GLuint
) (param
+ 0.5);
147 if (((GLint
) a
) < 0) {
148 __glXSetError(gc
, GL_INVALID_VALUE
);
151 state
->storeUnpack
.imageHeight
= a
;
153 case GL_UNPACK_SKIP_ROWS
:
154 a
= (GLuint
) (param
+ 0.5);
155 if (((GLint
) a
) < 0) {
156 __glXSetError(gc
, GL_INVALID_VALUE
);
159 state
->storeUnpack
.skipRows
= a
;
161 case GL_UNPACK_SKIP_PIXELS
:
162 a
= (GLuint
) (param
+ 0.5);
163 if (((GLint
) a
) < 0) {
164 __glXSetError(gc
, GL_INVALID_VALUE
);
167 state
->storeUnpack
.skipPixels
= a
;
169 case GL_UNPACK_SKIP_IMAGES
:
170 a
= (GLuint
) (param
+ 0.5);
171 if (((GLint
) a
) < 0) {
172 __glXSetError(gc
, GL_INVALID_VALUE
);
175 state
->storeUnpack
.skipImages
= a
;
177 case GL_UNPACK_ALIGNMENT
:
178 a
= (GLint
) (param
+ 0.5);
180 case 1: case 2: case 4: case 8:
181 state
->storeUnpack
.alignment
= a
;
184 __glXSetError(gc
, GL_INVALID_VALUE
);
188 case GL_UNPACK_SWAP_BYTES
:
189 state
->storeUnpack
.swapEndian
= (param
!= 0);
191 case GL_UNPACK_LSB_FIRST
:
192 state
->storeUnpack
.lsbFirst
= (param
!= 0);
195 /* Group all of the pixel store modes that need to be sent to the
196 * server here. Care must be used to only send modes to the server that
197 * won't affect the size of the data sent to or received from the
198 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
199 * future modes may not be.
201 case GL_PACK_INVERT_MESA
:
202 send_PixelStore( gc
, X_GLsop_PixelStoref
, pname
, & param
);
206 __glXSetError(gc
, GL_INVALID_ENUM
);
211 void __indirect_glPixelStorei(GLenum pname
, GLint param
)
213 __GLXcontext
*gc
= __glXGetCurrentContext();
214 __GLXattribute
* state
= gc
->client_state_private
;
215 Display
*dpy
= gc
->currentDpy
;
220 case GL_PACK_ROW_LENGTH
:
222 __glXSetError(gc
, GL_INVALID_VALUE
);
225 state
->storePack
.rowLength
= param
;
227 case GL_PACK_IMAGE_HEIGHT
:
229 __glXSetError(gc
, GL_INVALID_VALUE
);
232 state
->storePack
.imageHeight
= param
;
234 case GL_PACK_SKIP_ROWS
:
236 __glXSetError(gc
, GL_INVALID_VALUE
);
239 state
->storePack
.skipRows
= param
;
241 case GL_PACK_SKIP_PIXELS
:
243 __glXSetError(gc
, GL_INVALID_VALUE
);
246 state
->storePack
.skipPixels
= param
;
248 case GL_PACK_SKIP_IMAGES
:
250 __glXSetError(gc
, GL_INVALID_VALUE
);
253 state
->storePack
.skipImages
= param
;
255 case GL_PACK_ALIGNMENT
:
257 case 1: case 2: case 4: case 8:
258 state
->storePack
.alignment
= param
;
261 __glXSetError(gc
, GL_INVALID_VALUE
);
265 case GL_PACK_SWAP_BYTES
:
266 state
->storePack
.swapEndian
= (param
!= 0);
268 case GL_PACK_LSB_FIRST
:
269 state
->storePack
.lsbFirst
= (param
!= 0);
272 case GL_UNPACK_ROW_LENGTH
:
274 __glXSetError(gc
, GL_INVALID_VALUE
);
277 state
->storeUnpack
.rowLength
= param
;
279 case GL_UNPACK_IMAGE_HEIGHT
:
281 __glXSetError(gc
, GL_INVALID_VALUE
);
284 state
->storeUnpack
.imageHeight
= param
;
286 case GL_UNPACK_SKIP_ROWS
:
288 __glXSetError(gc
, GL_INVALID_VALUE
);
291 state
->storeUnpack
.skipRows
= param
;
293 case GL_UNPACK_SKIP_PIXELS
:
295 __glXSetError(gc
, GL_INVALID_VALUE
);
298 state
->storeUnpack
.skipPixels
= param
;
300 case GL_UNPACK_SKIP_IMAGES
:
302 __glXSetError(gc
, GL_INVALID_VALUE
);
305 state
->storeUnpack
.skipImages
= param
;
307 case GL_UNPACK_ALIGNMENT
:
309 case 1: case 2: case 4: case 8:
310 state
->storeUnpack
.alignment
= param
;
313 __glXSetError(gc
, GL_INVALID_VALUE
);
317 case GL_UNPACK_SWAP_BYTES
:
318 state
->storeUnpack
.swapEndian
= (param
!= 0);
320 case GL_UNPACK_LSB_FIRST
:
321 state
->storeUnpack
.lsbFirst
= (param
!= 0);
324 /* Group all of the pixel store modes that need to be sent to the
325 * server here. Care must be used to only send modes to the server that
326 * won't affect the size of the data sent to or received from the
327 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
328 * future modes may not be.
330 case GL_PACK_INVERT_MESA
:
331 send_PixelStore( gc
, X_GLsop_PixelStorei
, pname
, & param
);
335 __glXSetError(gc
, GL_INVALID_ENUM
);