Merge branch 'master' of git+ssh://keithw@git.freedesktop.org/git/mesa/mesa into...
[mesa.git] / src / glx / x11 / pixelstore.c
1 /* $XFree86: xc/lib/GL/glx/pixelstore.c,v 1.4 2004/01/28 18:11:43 alanh Exp $ */
2 /*
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:
10 **
11 ** http://oss.sgi.com/projects/FreeB
12 **
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.
18 **
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.
24 **
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.
34 **
35 */
36
37 #include "glxclient.h"
38 #include "indirect.h"
39
40 /**
41 * Send glPixelStore command to the server
42 *
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.
47 *
48 * \sa __indirect_glPixelStorei, __indirect_glPixelStoref
49 */
50 static void
51 send_PixelStore( __GLXcontext * gc, unsigned sop, GLenum pname,
52 const void * param )
53 {
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();
61 }
62 return;
63 }
64
65 /*
66 ** Specify parameters that control the storage format of pixel arrays.
67 */
68 void __indirect_glPixelStoref(GLenum pname, GLfloat param)
69 {
70 __GLXcontext *gc = __glXGetCurrentContext();
71 __GLXattribute * state = gc->client_state_private;
72 Display *dpy = gc->currentDpy;
73 GLuint a;
74
75 if (!dpy) return;
76
77 switch (pname) {
78 case GL_PACK_ROW_LENGTH:
79 a = (GLuint) (param + 0.5);
80 if (((GLint) a) < 0) {
81 __glXSetError(gc, GL_INVALID_VALUE);
82 return;
83 }
84 state->storePack.rowLength = a;
85 break;
86 case GL_PACK_IMAGE_HEIGHT:
87 a = (GLuint) (param + 0.5);
88 if (((GLint) a) < 0) {
89 __glXSetError(gc, GL_INVALID_VALUE);
90 return;
91 }
92 state->storePack.imageHeight = a;
93 break;
94 case GL_PACK_SKIP_ROWS:
95 a = (GLuint) (param + 0.5);
96 if (((GLint) a) < 0) {
97 __glXSetError(gc, GL_INVALID_VALUE);
98 return;
99 }
100 state->storePack.skipRows = a;
101 break;
102 case GL_PACK_SKIP_PIXELS:
103 a = (GLuint) (param + 0.5);
104 if (((GLint) a) < 0) {
105 __glXSetError(gc, GL_INVALID_VALUE);
106 return;
107 }
108 state->storePack.skipPixels = a;
109 break;
110 case GL_PACK_SKIP_IMAGES:
111 a = (GLuint) (param + 0.5);
112 if (((GLint) a) < 0) {
113 __glXSetError(gc, GL_INVALID_VALUE);
114 return;
115 }
116 state->storePack.skipImages = a;
117 break;
118 case GL_PACK_ALIGNMENT:
119 a = (GLint) (param + 0.5);
120 switch (a) {
121 case 1: case 2: case 4: case 8:
122 state->storePack.alignment = a;
123 break;
124 default:
125 __glXSetError(gc, GL_INVALID_VALUE);
126 return;
127 }
128 break;
129 case GL_PACK_SWAP_BYTES:
130 state->storePack.swapEndian = (param != 0);
131 break;
132 case GL_PACK_LSB_FIRST:
133 state->storePack.lsbFirst = (param != 0);
134 break;
135
136 case GL_UNPACK_ROW_LENGTH:
137 a = (GLuint) (param + 0.5);
138 if (((GLint) a) < 0) {
139 __glXSetError(gc, GL_INVALID_VALUE);
140 return;
141 }
142 state->storeUnpack.rowLength = a;
143 break;
144 case GL_UNPACK_IMAGE_HEIGHT:
145 a = (GLuint) (param + 0.5);
146 if (((GLint) a) < 0) {
147 __glXSetError(gc, GL_INVALID_VALUE);
148 return;
149 }
150 state->storeUnpack.imageHeight = a;
151 break;
152 case GL_UNPACK_SKIP_ROWS:
153 a = (GLuint) (param + 0.5);
154 if (((GLint) a) < 0) {
155 __glXSetError(gc, GL_INVALID_VALUE);
156 return;
157 }
158 state->storeUnpack.skipRows = a;
159 break;
160 case GL_UNPACK_SKIP_PIXELS:
161 a = (GLuint) (param + 0.5);
162 if (((GLint) a) < 0) {
163 __glXSetError(gc, GL_INVALID_VALUE);
164 return;
165 }
166 state->storeUnpack.skipPixels = a;
167 break;
168 case GL_UNPACK_SKIP_IMAGES:
169 a = (GLuint) (param + 0.5);
170 if (((GLint) a) < 0) {
171 __glXSetError(gc, GL_INVALID_VALUE);
172 return;
173 }
174 state->storeUnpack.skipImages = a;
175 break;
176 case GL_UNPACK_ALIGNMENT:
177 a = (GLint) (param + 0.5);
178 switch (a) {
179 case 1: case 2: case 4: case 8:
180 state->storeUnpack.alignment = a;
181 break;
182 default:
183 __glXSetError(gc, GL_INVALID_VALUE);
184 return;
185 }
186 break;
187 case GL_UNPACK_SWAP_BYTES:
188 state->storeUnpack.swapEndian = (param != 0);
189 break;
190 case GL_UNPACK_LSB_FIRST:
191 state->storeUnpack.lsbFirst = (param != 0);
192 break;
193
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.
199 */
200 case GL_PACK_INVERT_MESA:
201 send_PixelStore( gc, X_GLsop_PixelStoref, pname, & param );
202 break;
203
204 default:
205 __glXSetError(gc, GL_INVALID_ENUM);
206 break;
207 }
208 }
209
210 void __indirect_glPixelStorei(GLenum pname, GLint param)
211 {
212 __GLXcontext *gc = __glXGetCurrentContext();
213 __GLXattribute * state = gc->client_state_private;
214 Display *dpy = gc->currentDpy;
215
216 if (!dpy) return;
217
218 switch (pname) {
219 case GL_PACK_ROW_LENGTH:
220 if (param < 0) {
221 __glXSetError(gc, GL_INVALID_VALUE);
222 return;
223 }
224 state->storePack.rowLength = param;
225 break;
226 case GL_PACK_IMAGE_HEIGHT:
227 if (param < 0) {
228 __glXSetError(gc, GL_INVALID_VALUE);
229 return;
230 }
231 state->storePack.imageHeight = param;
232 break;
233 case GL_PACK_SKIP_ROWS:
234 if (param < 0) {
235 __glXSetError(gc, GL_INVALID_VALUE);
236 return;
237 }
238 state->storePack.skipRows = param;
239 break;
240 case GL_PACK_SKIP_PIXELS:
241 if (param < 0) {
242 __glXSetError(gc, GL_INVALID_VALUE);
243 return;
244 }
245 state->storePack.skipPixels = param;
246 break;
247 case GL_PACK_SKIP_IMAGES:
248 if (param < 0) {
249 __glXSetError(gc, GL_INVALID_VALUE);
250 return;
251 }
252 state->storePack.skipImages = param;
253 break;
254 case GL_PACK_ALIGNMENT:
255 switch (param) {
256 case 1: case 2: case 4: case 8:
257 state->storePack.alignment = param;
258 break;
259 default:
260 __glXSetError(gc, GL_INVALID_VALUE);
261 return;
262 }
263 break;
264 case GL_PACK_SWAP_BYTES:
265 state->storePack.swapEndian = (param != 0);
266 break;
267 case GL_PACK_LSB_FIRST:
268 state->storePack.lsbFirst = (param != 0);
269 break;
270
271 case GL_UNPACK_ROW_LENGTH:
272 if (param < 0) {
273 __glXSetError(gc, GL_INVALID_VALUE);
274 return;
275 }
276 state->storeUnpack.rowLength = param;
277 break;
278 case GL_UNPACK_IMAGE_HEIGHT:
279 if (param < 0) {
280 __glXSetError(gc, GL_INVALID_VALUE);
281 return;
282 }
283 state->storeUnpack.imageHeight = param;
284 break;
285 case GL_UNPACK_SKIP_ROWS:
286 if (param < 0) {
287 __glXSetError(gc, GL_INVALID_VALUE);
288 return;
289 }
290 state->storeUnpack.skipRows = param;
291 break;
292 case GL_UNPACK_SKIP_PIXELS:
293 if (param < 0) {
294 __glXSetError(gc, GL_INVALID_VALUE);
295 return;
296 }
297 state->storeUnpack.skipPixels = param;
298 break;
299 case GL_UNPACK_SKIP_IMAGES:
300 if (param < 0) {
301 __glXSetError(gc, GL_INVALID_VALUE);
302 return;
303 }
304 state->storeUnpack.skipImages = param;
305 break;
306 case GL_UNPACK_ALIGNMENT:
307 switch (param) {
308 case 1: case 2: case 4: case 8:
309 state->storeUnpack.alignment = param;
310 break;
311 default:
312 __glXSetError(gc, GL_INVALID_VALUE);
313 return;
314 }
315 break;
316 case GL_UNPACK_SWAP_BYTES:
317 state->storeUnpack.swapEndian = (param != 0);
318 break;
319 case GL_UNPACK_LSB_FIRST:
320 state->storeUnpack.lsbFirst = (param != 0);
321 break;
322
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.
328 */
329 case GL_PACK_INVERT_MESA:
330 send_PixelStore( gc, X_GLsop_PixelStorei, pname, & param );
331 break;
332
333 default:
334 __glXSetError(gc, GL_INVALID_ENUM);
335 break;
336 }
337 }