2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
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:
14 * The above copyright notice and this permission notice shall be included
15 * 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 * 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.
27 * glPixelStore functions.
32 #include "bufferobj.h"
34 #include "pixelstore.h"
35 #include "mfeatures.h"
40 _mesa_PixelStorei( GLenum pname
, GLint param
)
42 /* NOTE: this call can't be compiled into the display list */
43 GET_CURRENT_CONTEXT(ctx
);
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
)
51 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
52 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
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
)
59 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
60 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
62 case GL_PACK_ROW_LENGTH
:
63 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
64 goto invalid_enum_error
;
66 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
69 if (ctx
->Pack
.RowLength
== param
)
71 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
72 ctx
->Pack
.RowLength
= param
;
74 case GL_PACK_IMAGE_HEIGHT
:
75 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
76 goto invalid_enum_error
;
78 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
81 if (ctx
->Pack
.ImageHeight
== param
)
83 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
84 ctx
->Pack
.ImageHeight
= param
;
86 case GL_PACK_SKIP_PIXELS
:
87 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
88 goto invalid_enum_error
;
90 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
93 if (ctx
->Pack
.SkipPixels
== param
)
95 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
96 ctx
->Pack
.SkipPixels
= param
;
98 case GL_PACK_SKIP_ROWS
:
99 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
100 goto invalid_enum_error
;
102 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
105 if (ctx
->Pack
.SkipRows
== param
)
107 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
108 ctx
->Pack
.SkipRows
= param
;
110 case GL_PACK_SKIP_IMAGES
:
111 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
112 goto invalid_enum_error
;
114 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
117 if (ctx
->Pack
.SkipImages
== param
)
119 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
120 ctx
->Pack
.SkipImages
= param
;
122 case GL_PACK_ALIGNMENT
:
123 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
124 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
127 if (ctx
->Pack
.Alignment
== param
)
129 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
130 ctx
->Pack
.Alignment
= param
;
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)" );
139 if (ctx
->Pack
.Invert
== param
)
141 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
142 ctx
->Pack
.Invert
= param
;
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
)
150 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
152 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
153 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
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
)
160 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
162 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
163 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
165 case GL_UNPACK_ROW_LENGTH
:
166 if (ctx
->API
== API_OPENGLES
)
167 goto invalid_enum_error
;
169 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
172 if (ctx
->Unpack
.RowLength
== param
)
174 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
175 ctx
->Unpack
.RowLength
= param
;
177 case GL_UNPACK_IMAGE_HEIGHT
:
178 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
179 goto invalid_enum_error
;
181 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
184 if (ctx
->Unpack
.ImageHeight
== param
)
187 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
188 ctx
->Unpack
.ImageHeight
= param
;
190 case GL_UNPACK_SKIP_PIXELS
:
191 if (ctx
->API
== API_OPENGLES
)
192 goto invalid_enum_error
;
194 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
197 if (ctx
->Unpack
.SkipPixels
== param
)
199 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
200 ctx
->Unpack
.SkipPixels
= param
;
202 case GL_UNPACK_SKIP_ROWS
:
203 if (ctx
->API
== API_OPENGLES
)
204 goto invalid_enum_error
;
206 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
209 if (ctx
->Unpack
.SkipRows
== param
)
211 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
212 ctx
->Unpack
.SkipRows
= param
;
214 case GL_UNPACK_SKIP_IMAGES
:
215 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
216 goto invalid_enum_error
;
218 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
221 if (ctx
->Unpack
.SkipImages
== param
)
223 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
224 ctx
->Unpack
.SkipImages
= param
;
226 case GL_UNPACK_ALIGNMENT
:
227 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
228 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
231 if (ctx
->Unpack
.Alignment
== param
)
233 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
234 ctx
->Unpack
.Alignment
= param
;
237 goto invalid_enum_error
;
243 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
249 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
251 _mesa_PixelStorei( pname
, IROUND(param
) );
257 * Initialize the context's pixel store state.
260 _mesa_init_pixelstore( struct gl_context
*ctx
)
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
);
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!
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
);