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 * 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.
28 * glPixelStore functions.
33 #include "bufferobj.h"
35 #include "pixelstore.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 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
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
)
58 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
60 case GL_PACK_ROW_LENGTH
:
61 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
62 goto invalid_enum_error
;
64 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
67 if (ctx
->Pack
.RowLength
== param
)
69 ctx
->Pack
.RowLength
= param
;
71 case GL_PACK_IMAGE_HEIGHT
:
72 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
73 goto invalid_enum_error
;
75 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
78 if (ctx
->Pack
.ImageHeight
== param
)
80 ctx
->Pack
.ImageHeight
= param
;
82 case GL_PACK_SKIP_PIXELS
:
83 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
84 goto invalid_enum_error
;
86 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
89 if (ctx
->Pack
.SkipPixels
== param
)
91 ctx
->Pack
.SkipPixels
= param
;
93 case GL_PACK_SKIP_ROWS
:
94 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
95 goto invalid_enum_error
;
97 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
100 if (ctx
->Pack
.SkipRows
== param
)
102 ctx
->Pack
.SkipRows
= param
;
104 case GL_PACK_SKIP_IMAGES
:
105 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
106 goto invalid_enum_error
;
108 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
111 if (ctx
->Pack
.SkipImages
== param
)
113 ctx
->Pack
.SkipImages
= param
;
115 case GL_PACK_ALIGNMENT
:
116 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
117 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
120 if (ctx
->Pack
.Alignment
== param
)
122 ctx
->Pack
.Alignment
= param
;
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)" );
131 if (ctx
->Pack
.Invert
== param
)
133 ctx
->Pack
.Invert
= param
;
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
)
141 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
143 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
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
)
150 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
152 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
154 case GL_UNPACK_ROW_LENGTH
:
155 if (ctx
->API
== API_OPENGLES
)
156 goto invalid_enum_error
;
158 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
161 if (ctx
->Unpack
.RowLength
== param
)
163 ctx
->Unpack
.RowLength
= param
;
165 case GL_UNPACK_IMAGE_HEIGHT
:
166 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
167 goto invalid_enum_error
;
169 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
172 if (ctx
->Unpack
.ImageHeight
== param
)
175 ctx
->Unpack
.ImageHeight
= param
;
177 case GL_UNPACK_SKIP_PIXELS
:
178 if (ctx
->API
== API_OPENGLES
)
179 goto invalid_enum_error
;
181 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
184 if (ctx
->Unpack
.SkipPixels
== param
)
186 ctx
->Unpack
.SkipPixels
= param
;
188 case GL_UNPACK_SKIP_ROWS
:
189 if (ctx
->API
== API_OPENGLES
)
190 goto invalid_enum_error
;
192 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
195 if (ctx
->Unpack
.SkipRows
== param
)
197 ctx
->Unpack
.SkipRows
= param
;
199 case GL_UNPACK_SKIP_IMAGES
:
200 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
201 goto invalid_enum_error
;
203 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
206 if (ctx
->Unpack
.SkipImages
== param
)
208 ctx
->Unpack
.SkipImages
= param
;
210 case GL_UNPACK_ALIGNMENT
:
211 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
212 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
215 if (ctx
->Unpack
.Alignment
== param
)
217 ctx
->Unpack
.Alignment
= param
;
220 goto invalid_enum_error
;
226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
232 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
234 _mesa_PixelStorei( pname
, IROUND(param
) );
240 * Initialize the context's pixel store state.
243 _mesa_init_pixelstore( struct gl_context
*ctx
)
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
);
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!
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
);