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