2 * SGI FREE SOFTWARE LICENSE B (Version 2.0, Sept. 18, 2008)
3 * Copyright (C) 1991-2000 Silicon Graphics, Inc. All Rights Reserved.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 * and/or sell copies of the Software, and to permit persons to whom the
10 * Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice including the dates of first publication and
13 * either this permission notice or a reference to
14 * http://oss.sgi.com/projects/FreeB/
15 * shall be included in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * SILICON GRAPHICS, INC. BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
21 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF
22 * OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
25 * Except as contained in this notice, the name of Silicon Graphics, Inc.
26 * shall not be used in advertising or otherwise to promote the sale, use or
27 * other dealings in this Software without prior written authorization from
28 * Silicon Graphics, Inc.
31 #include "glxclient.h"
34 #if !defined(__GNUC__)
35 # define __builtin_expect(x, y) x
39 * Send glPixelStore command to the server
41 * \param gc Current GLX context
42 * \param sop Either \c X_GLsop_PixelStoref or \c X_GLsop_PixelStorei
43 * \param pname Selector of which pixel parameter is to be set.
44 * \param param Value that \c pname is set to.
46 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
49 send_PixelStore(struct glx_context
* gc
, unsigned sop
, GLenum pname
,
52 Display
*const dpy
= gc
->currentDpy
;
53 const GLuint cmdlen
= 8;
54 if (__builtin_expect(dpy
!= NULL
, 1)) {
55 GLubyte
const *pc
= __glXSetupSingleRequest(gc
, sop
, cmdlen
);
56 (void) memcpy((void *) (pc
+ 0), (void *) (&pname
), 4);
57 (void) memcpy((void *) (pc
+ 4), param
, 4);
65 ** Specify parameters that control the storage format of pixel arrays.
68 __indirect_glPixelStoref(GLenum pname
, GLfloat param
)
70 struct glx_context
*gc
= __glXGetCurrentContext();
71 __GLXattribute
*state
= gc
->client_state_private
;
72 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);
126 state
->storePack
.alignment
= a
;
129 __glXSetError(gc
, GL_INVALID_VALUE
);
133 case GL_PACK_SWAP_BYTES
:
134 state
->storePack
.swapEndian
= (param
!= 0);
136 case GL_PACK_LSB_FIRST
:
137 state
->storePack
.lsbFirst
= (param
!= 0);
140 case GL_UNPACK_ROW_LENGTH
:
141 a
= (GLuint
) (param
+ 0.5);
142 if (((GLint
) a
) < 0) {
143 __glXSetError(gc
, GL_INVALID_VALUE
);
146 state
->storeUnpack
.rowLength
= a
;
148 case GL_UNPACK_IMAGE_HEIGHT
:
149 a
= (GLuint
) (param
+ 0.5);
150 if (((GLint
) a
) < 0) {
151 __glXSetError(gc
, GL_INVALID_VALUE
);
154 state
->storeUnpack
.imageHeight
= a
;
156 case GL_UNPACK_SKIP_ROWS
:
157 a
= (GLuint
) (param
+ 0.5);
158 if (((GLint
) a
) < 0) {
159 __glXSetError(gc
, GL_INVALID_VALUE
);
162 state
->storeUnpack
.skipRows
= a
;
164 case GL_UNPACK_SKIP_PIXELS
:
165 a
= (GLuint
) (param
+ 0.5);
166 if (((GLint
) a
) < 0) {
167 __glXSetError(gc
, GL_INVALID_VALUE
);
170 state
->storeUnpack
.skipPixels
= a
;
172 case GL_UNPACK_SKIP_IMAGES
:
173 a
= (GLuint
) (param
+ 0.5);
174 if (((GLint
) a
) < 0) {
175 __glXSetError(gc
, GL_INVALID_VALUE
);
178 state
->storeUnpack
.skipImages
= a
;
180 case GL_UNPACK_ALIGNMENT
:
181 a
= (GLint
) (param
+ 0.5);
187 state
->storeUnpack
.alignment
= a
;
190 __glXSetError(gc
, GL_INVALID_VALUE
);
194 case GL_UNPACK_SWAP_BYTES
:
195 state
->storeUnpack
.swapEndian
= (param
!= 0);
197 case GL_UNPACK_LSB_FIRST
:
198 state
->storeUnpack
.lsbFirst
= (param
!= 0);
201 /* Group all of the pixel store modes that need to be sent to the
202 * server here. Care must be used to only send modes to the server that
203 * won't affect the size of the data sent to or received from the
204 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
205 * future modes may not be.
207 case GL_PACK_INVERT_MESA
:
208 send_PixelStore(gc
, X_GLsop_PixelStoref
, pname
, ¶m
);
212 __glXSetError(gc
, GL_INVALID_ENUM
);
218 __indirect_glPixelStorei(GLenum pname
, GLint param
)
220 struct glx_context
*gc
= __glXGetCurrentContext();
221 __GLXattribute
*state
= gc
->client_state_private
;
222 Display
*dpy
= gc
->currentDpy
;
228 case GL_PACK_ROW_LENGTH
:
230 __glXSetError(gc
, GL_INVALID_VALUE
);
233 state
->storePack
.rowLength
= param
;
235 case GL_PACK_IMAGE_HEIGHT
:
237 __glXSetError(gc
, GL_INVALID_VALUE
);
240 state
->storePack
.imageHeight
= param
;
242 case GL_PACK_SKIP_ROWS
:
244 __glXSetError(gc
, GL_INVALID_VALUE
);
247 state
->storePack
.skipRows
= param
;
249 case GL_PACK_SKIP_PIXELS
:
251 __glXSetError(gc
, GL_INVALID_VALUE
);
254 state
->storePack
.skipPixels
= param
;
256 case GL_PACK_SKIP_IMAGES
:
258 __glXSetError(gc
, GL_INVALID_VALUE
);
261 state
->storePack
.skipImages
= param
;
263 case GL_PACK_ALIGNMENT
:
269 state
->storePack
.alignment
= param
;
272 __glXSetError(gc
, GL_INVALID_VALUE
);
276 case GL_PACK_SWAP_BYTES
:
277 state
->storePack
.swapEndian
= (param
!= 0);
279 case GL_PACK_LSB_FIRST
:
280 state
->storePack
.lsbFirst
= (param
!= 0);
283 case GL_UNPACK_ROW_LENGTH
:
285 __glXSetError(gc
, GL_INVALID_VALUE
);
288 state
->storeUnpack
.rowLength
= param
;
290 case GL_UNPACK_IMAGE_HEIGHT
:
292 __glXSetError(gc
, GL_INVALID_VALUE
);
295 state
->storeUnpack
.imageHeight
= param
;
297 case GL_UNPACK_SKIP_ROWS
:
299 __glXSetError(gc
, GL_INVALID_VALUE
);
302 state
->storeUnpack
.skipRows
= param
;
304 case GL_UNPACK_SKIP_PIXELS
:
306 __glXSetError(gc
, GL_INVALID_VALUE
);
309 state
->storeUnpack
.skipPixels
= param
;
311 case GL_UNPACK_SKIP_IMAGES
:
313 __glXSetError(gc
, GL_INVALID_VALUE
);
316 state
->storeUnpack
.skipImages
= param
;
318 case GL_UNPACK_ALIGNMENT
:
324 state
->storeUnpack
.alignment
= param
;
327 __glXSetError(gc
, GL_INVALID_VALUE
);
331 case GL_UNPACK_SWAP_BYTES
:
332 state
->storeUnpack
.swapEndian
= (param
!= 0);
334 case GL_UNPACK_LSB_FIRST
:
335 state
->storeUnpack
.lsbFirst
= (param
!= 0);
338 /* Group all of the pixel store modes that need to be sent to the
339 * server here. Care must be used to only send modes to the server that
340 * won't affect the size of the data sent to or received from the
341 * server. GL_PACK_INVERT_MESA is safe in this respect, but other,
342 * future modes may not be.
344 case GL_PACK_INVERT_MESA
:
345 send_PixelStore(gc
, X_GLsop_PixelStorei
, pname
, ¶m
);
349 __glXSetError(gc
, GL_INVALID_ENUM
);