mesa: Use PROGRAM_ERROR_STRING_ARB instead of the _NV name
[mesa.git] / src / mesa / main / pixelstore.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25 /**
26 * \file pixelstore.c
27 * glPixelStore functions.
28 */
29
30
31 #include "glheader.h"
32 #include "bufferobj.h"
33 #include "context.h"
34 #include "pixelstore.h"
35 #include "mfeatures.h"
36 #include "mtypes.h"
37
38
39 void GLAPIENTRY
40 _mesa_PixelStorei( GLenum pname, GLint param )
41 {
42 /* NOTE: this call can't be compiled into the display list */
43 GET_CURRENT_CONTEXT(ctx);
44
45 switch (pname) {
46 case GL_PACK_SWAP_BYTES:
47 if (!_mesa_is_desktop_gl(ctx))
48 goto invalid_enum_error;
49 if (param == (GLint)ctx->Pack.SwapBytes)
50 return;
51 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
52 ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE;
53 break;
54 case GL_PACK_LSB_FIRST:
55 if (!_mesa_is_desktop_gl(ctx))
56 goto invalid_enum_error;
57 if (param == (GLint)ctx->Pack.LsbFirst)
58 return;
59 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
60 ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE;
61 break;
62 case GL_PACK_ROW_LENGTH:
63 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
64 goto invalid_enum_error;
65 if (param<0) {
66 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
67 return;
68 }
69 if (ctx->Pack.RowLength == param)
70 return;
71 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
72 ctx->Pack.RowLength = param;
73 break;
74 case GL_PACK_IMAGE_HEIGHT:
75 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
76 goto invalid_enum_error;
77 if (param<0) {
78 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
79 return;
80 }
81 if (ctx->Pack.ImageHeight == param)
82 return;
83 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
84 ctx->Pack.ImageHeight = param;
85 break;
86 case GL_PACK_SKIP_PIXELS:
87 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
88 goto invalid_enum_error;
89 if (param<0) {
90 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
91 return;
92 }
93 if (ctx->Pack.SkipPixels == param)
94 return;
95 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
96 ctx->Pack.SkipPixels = param;
97 break;
98 case GL_PACK_SKIP_ROWS:
99 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
100 goto invalid_enum_error;
101 if (param<0) {
102 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
103 return;
104 }
105 if (ctx->Pack.SkipRows == param)
106 return;
107 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
108 ctx->Pack.SkipRows = param;
109 break;
110 case GL_PACK_SKIP_IMAGES:
111 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
112 goto invalid_enum_error;
113 if (param<0) {
114 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
115 return;
116 }
117 if (ctx->Pack.SkipImages == param)
118 return;
119 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
120 ctx->Pack.SkipImages = param;
121 break;
122 case GL_PACK_ALIGNMENT:
123 if (param!=1 && param!=2 && param!=4 && param!=8) {
124 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
125 return;
126 }
127 if (ctx->Pack.Alignment == param)
128 return;
129 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
130 ctx->Pack.Alignment = param;
131 break;
132 case GL_PACK_INVERT_MESA:
133 if (!_mesa_is_desktop_gl(ctx))
134 goto invalid_enum_error;
135 if (!ctx->Extensions.MESA_pack_invert) {
136 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" );
137 return;
138 }
139 if (ctx->Pack.Invert == param)
140 return;
141 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
142 ctx->Pack.Invert = param;
143 break;
144
145 case GL_UNPACK_SWAP_BYTES:
146 if (!_mesa_is_desktop_gl(ctx))
147 goto invalid_enum_error;
148 if (param == (GLint)ctx->Unpack.SwapBytes)
149 return;
150 if ((GLint)ctx->Unpack.SwapBytes == param)
151 return;
152 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
153 ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE;
154 break;
155 case GL_UNPACK_LSB_FIRST:
156 if (!_mesa_is_desktop_gl(ctx))
157 goto invalid_enum_error;
158 if (param == (GLint)ctx->Unpack.LsbFirst)
159 return;
160 if ((GLint)ctx->Unpack.LsbFirst == param)
161 return;
162 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
163 ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE;
164 break;
165 case GL_UNPACK_ROW_LENGTH:
166 if (ctx->API == API_OPENGLES)
167 goto invalid_enum_error;
168 if (param<0) {
169 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
170 return;
171 }
172 if (ctx->Unpack.RowLength == param)
173 return;
174 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
175 ctx->Unpack.RowLength = param;
176 break;
177 case GL_UNPACK_IMAGE_HEIGHT:
178 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
179 goto invalid_enum_error;
180 if (param<0) {
181 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
182 return;
183 }
184 if (ctx->Unpack.ImageHeight == param)
185 return;
186
187 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
188 ctx->Unpack.ImageHeight = param;
189 break;
190 case GL_UNPACK_SKIP_PIXELS:
191 if (ctx->API == API_OPENGLES)
192 goto invalid_enum_error;
193 if (param<0) {
194 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
195 return;
196 }
197 if (ctx->Unpack.SkipPixels == param)
198 return;
199 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
200 ctx->Unpack.SkipPixels = param;
201 break;
202 case GL_UNPACK_SKIP_ROWS:
203 if (ctx->API == API_OPENGLES)
204 goto invalid_enum_error;
205 if (param<0) {
206 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
207 return;
208 }
209 if (ctx->Unpack.SkipRows == param)
210 return;
211 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
212 ctx->Unpack.SkipRows = param;
213 break;
214 case GL_UNPACK_SKIP_IMAGES:
215 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
216 goto invalid_enum_error;
217 if (param < 0) {
218 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
219 return;
220 }
221 if (ctx->Unpack.SkipImages == param)
222 return;
223 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
224 ctx->Unpack.SkipImages = param;
225 break;
226 case GL_UNPACK_ALIGNMENT:
227 if (param!=1 && param!=2 && param!=4 && param!=8) {
228 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore" );
229 return;
230 }
231 if (ctx->Unpack.Alignment == param)
232 return;
233 FLUSH_VERTICES(ctx, _NEW_PACKUNPACK);
234 ctx->Unpack.Alignment = param;
235 break;
236 default:
237 goto invalid_enum_error;
238 }
239
240 return;
241
242 invalid_enum_error:
243 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelStore" );
244 return;
245 }
246
247
248 void GLAPIENTRY
249 _mesa_PixelStoref( GLenum pname, GLfloat param )
250 {
251 _mesa_PixelStorei( pname, IROUND(param) );
252 }
253
254
255
256 /**
257 * Initialize the context's pixel store state.
258 */
259 void
260 _mesa_init_pixelstore( struct gl_context *ctx )
261 {
262 /* Pixel transfer */
263 ctx->Pack.Alignment = 4;
264 ctx->Pack.RowLength = 0;
265 ctx->Pack.ImageHeight = 0;
266 ctx->Pack.SkipPixels = 0;
267 ctx->Pack.SkipRows = 0;
268 ctx->Pack.SkipImages = 0;
269 ctx->Pack.SwapBytes = GL_FALSE;
270 ctx->Pack.LsbFirst = GL_FALSE;
271 ctx->Pack.Invert = GL_FALSE;
272 _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj,
273 ctx->Shared->NullBufferObj);
274 ctx->Unpack.Alignment = 4;
275 ctx->Unpack.RowLength = 0;
276 ctx->Unpack.ImageHeight = 0;
277 ctx->Unpack.SkipPixels = 0;
278 ctx->Unpack.SkipRows = 0;
279 ctx->Unpack.SkipImages = 0;
280 ctx->Unpack.SwapBytes = GL_FALSE;
281 ctx->Unpack.LsbFirst = GL_FALSE;
282 ctx->Unpack.Invert = GL_FALSE;
283 _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj,
284 ctx->Shared->NullBufferObj);
285
286 /*
287 * _mesa_unpack_image() returns image data in this format. When we
288 * execute image commands (glDrawPixels(), glTexImage(), etc) from
289 * within display lists we have to be sure to set the current
290 * unpacking parameters to these values!
291 */
292 ctx->DefaultPacking.Alignment = 1;
293 ctx->DefaultPacking.RowLength = 0;
294 ctx->DefaultPacking.SkipPixels = 0;
295 ctx->DefaultPacking.SkipRows = 0;
296 ctx->DefaultPacking.ImageHeight = 0;
297 ctx->DefaultPacking.SkipImages = 0;
298 ctx->DefaultPacking.SwapBytes = GL_FALSE;
299 ctx->DefaultPacking.LsbFirst = GL_FALSE;
300 ctx->DefaultPacking.Invert = GL_FALSE;
301 _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj,
302 ctx->Shared->NullBufferObj);
303 }