i965: Move FS instruction scheduling to a non-FS-specific file.
[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 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * OTHER DEALINGS IN THE SOFTWARE.
24 */
25
26 /**
27 * \file pixelstore.c
28 * glPixelStore functions.
29 */
30
31
32 #include "glheader.h"
33 #include "bufferobj.h"
34 #include "context.h"
35 #include "pixelstore.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 ctx->Pack.SwapBytes = param ? GL_TRUE : GL_FALSE;
52 break;
53 case GL_PACK_LSB_FIRST:
54 if (!_mesa_is_desktop_gl(ctx))
55 goto invalid_enum_error;
56 if (param == (GLint)ctx->Pack.LsbFirst)
57 return;
58 ctx->Pack.LsbFirst = param ? GL_TRUE : GL_FALSE;
59 break;
60 case GL_PACK_ROW_LENGTH:
61 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
62 goto invalid_enum_error;
63 if (param<0) {
64 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
65 return;
66 }
67 if (ctx->Pack.RowLength == param)
68 return;
69 ctx->Pack.RowLength = param;
70 break;
71 case GL_PACK_IMAGE_HEIGHT:
72 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
73 goto invalid_enum_error;
74 if (param<0) {
75 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
76 return;
77 }
78 if (ctx->Pack.ImageHeight == param)
79 return;
80 ctx->Pack.ImageHeight = param;
81 break;
82 case GL_PACK_SKIP_PIXELS:
83 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
84 goto invalid_enum_error;
85 if (param<0) {
86 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
87 return;
88 }
89 if (ctx->Pack.SkipPixels == param)
90 return;
91 ctx->Pack.SkipPixels = param;
92 break;
93 case GL_PACK_SKIP_ROWS:
94 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
95 goto invalid_enum_error;
96 if (param<0) {
97 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
98 return;
99 }
100 if (ctx->Pack.SkipRows == param)
101 return;
102 ctx->Pack.SkipRows = param;
103 break;
104 case GL_PACK_SKIP_IMAGES:
105 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
106 goto invalid_enum_error;
107 if (param<0) {
108 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
109 return;
110 }
111 if (ctx->Pack.SkipImages == param)
112 return;
113 ctx->Pack.SkipImages = param;
114 break;
115 case GL_PACK_ALIGNMENT:
116 if (param!=1 && param!=2 && param!=4 && param!=8) {
117 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
118 return;
119 }
120 if (ctx->Pack.Alignment == param)
121 return;
122 ctx->Pack.Alignment = param;
123 break;
124 case GL_PACK_INVERT_MESA:
125 if (!_mesa_is_desktop_gl(ctx))
126 goto invalid_enum_error;
127 if (!ctx->Extensions.MESA_pack_invert) {
128 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelstore(pname)" );
129 return;
130 }
131 if (ctx->Pack.Invert == param)
132 return;
133 ctx->Pack.Invert = param;
134 break;
135
136 case GL_UNPACK_SWAP_BYTES:
137 if (!_mesa_is_desktop_gl(ctx))
138 goto invalid_enum_error;
139 if (param == (GLint)ctx->Unpack.SwapBytes)
140 return;
141 if ((GLint)ctx->Unpack.SwapBytes == param)
142 return;
143 ctx->Unpack.SwapBytes = param ? GL_TRUE : GL_FALSE;
144 break;
145 case GL_UNPACK_LSB_FIRST:
146 if (!_mesa_is_desktop_gl(ctx))
147 goto invalid_enum_error;
148 if (param == (GLint)ctx->Unpack.LsbFirst)
149 return;
150 if ((GLint)ctx->Unpack.LsbFirst == param)
151 return;
152 ctx->Unpack.LsbFirst = param ? GL_TRUE : GL_FALSE;
153 break;
154 case GL_UNPACK_ROW_LENGTH:
155 if (ctx->API == API_OPENGLES)
156 goto invalid_enum_error;
157 if (param<0) {
158 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
159 return;
160 }
161 if (ctx->Unpack.RowLength == param)
162 return;
163 ctx->Unpack.RowLength = param;
164 break;
165 case GL_UNPACK_IMAGE_HEIGHT:
166 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
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.ImageHeight == param)
173 return;
174
175 ctx->Unpack.ImageHeight = param;
176 break;
177 case GL_UNPACK_SKIP_PIXELS:
178 if (ctx->API == API_OPENGLES)
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.SkipPixels == param)
185 return;
186 ctx->Unpack.SkipPixels = param;
187 break;
188 case GL_UNPACK_SKIP_ROWS:
189 if (ctx->API == API_OPENGLES)
190 goto invalid_enum_error;
191 if (param<0) {
192 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
193 return;
194 }
195 if (ctx->Unpack.SkipRows == param)
196 return;
197 ctx->Unpack.SkipRows = param;
198 break;
199 case GL_UNPACK_SKIP_IMAGES:
200 if (!_mesa_is_desktop_gl(ctx) && !_mesa_is_gles3(ctx))
201 goto invalid_enum_error;
202 if (param < 0) {
203 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore(param)" );
204 return;
205 }
206 if (ctx->Unpack.SkipImages == param)
207 return;
208 ctx->Unpack.SkipImages = param;
209 break;
210 case GL_UNPACK_ALIGNMENT:
211 if (param!=1 && param!=2 && param!=4 && param!=8) {
212 _mesa_error( ctx, GL_INVALID_VALUE, "glPixelStore" );
213 return;
214 }
215 if (ctx->Unpack.Alignment == param)
216 return;
217 ctx->Unpack.Alignment = param;
218 break;
219 default:
220 goto invalid_enum_error;
221 }
222
223 return;
224
225 invalid_enum_error:
226 _mesa_error( ctx, GL_INVALID_ENUM, "glPixelStore" );
227 return;
228 }
229
230
231 void GLAPIENTRY
232 _mesa_PixelStoref( GLenum pname, GLfloat param )
233 {
234 _mesa_PixelStorei( pname, IROUND(param) );
235 }
236
237
238
239 /**
240 * Initialize the context's pixel store state.
241 */
242 void
243 _mesa_init_pixelstore( struct gl_context *ctx )
244 {
245 /* Pixel transfer */
246 ctx->Pack.Alignment = 4;
247 ctx->Pack.RowLength = 0;
248 ctx->Pack.ImageHeight = 0;
249 ctx->Pack.SkipPixels = 0;
250 ctx->Pack.SkipRows = 0;
251 ctx->Pack.SkipImages = 0;
252 ctx->Pack.SwapBytes = GL_FALSE;
253 ctx->Pack.LsbFirst = GL_FALSE;
254 ctx->Pack.Invert = GL_FALSE;
255 _mesa_reference_buffer_object(ctx, &ctx->Pack.BufferObj,
256 ctx->Shared->NullBufferObj);
257 ctx->Unpack.Alignment = 4;
258 ctx->Unpack.RowLength = 0;
259 ctx->Unpack.ImageHeight = 0;
260 ctx->Unpack.SkipPixels = 0;
261 ctx->Unpack.SkipRows = 0;
262 ctx->Unpack.SkipImages = 0;
263 ctx->Unpack.SwapBytes = GL_FALSE;
264 ctx->Unpack.LsbFirst = GL_FALSE;
265 ctx->Unpack.Invert = GL_FALSE;
266 _mesa_reference_buffer_object(ctx, &ctx->Unpack.BufferObj,
267 ctx->Shared->NullBufferObj);
268
269 /*
270 * _mesa_unpack_image() returns image data in this format. When we
271 * execute image commands (glDrawPixels(), glTexImage(), etc) from
272 * within display lists we have to be sure to set the current
273 * unpacking parameters to these values!
274 */
275 ctx->DefaultPacking.Alignment = 1;
276 ctx->DefaultPacking.RowLength = 0;
277 ctx->DefaultPacking.SkipPixels = 0;
278 ctx->DefaultPacking.SkipRows = 0;
279 ctx->DefaultPacking.ImageHeight = 0;
280 ctx->DefaultPacking.SkipImages = 0;
281 ctx->DefaultPacking.SwapBytes = GL_FALSE;
282 ctx->DefaultPacking.LsbFirst = GL_FALSE;
283 ctx->DefaultPacking.Invert = GL_FALSE;
284 _mesa_reference_buffer_object(ctx, &ctx->DefaultPacking.BufferObj,
285 ctx->Shared->NullBufferObj);
286 }