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"
37 #include "pixelstore.h"
42 _mesa_PixelStorei( GLenum pname
, GLint param
)
44 /* NOTE: this call can't be compiled into the display list */
45 GET_CURRENT_CONTEXT(ctx
);
46 ASSERT_OUTSIDE_BEGIN_END(ctx
);
49 case GL_PACK_SWAP_BYTES
:
50 if (param
== (GLint
)ctx
->Pack
.SwapBytes
)
52 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
53 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
55 case GL_PACK_LSB_FIRST
:
56 if (param
== (GLint
)ctx
->Pack
.LsbFirst
)
58 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
59 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
61 case GL_PACK_ROW_LENGTH
:
63 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
66 if (ctx
->Pack
.RowLength
== param
)
68 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
69 ctx
->Pack
.RowLength
= param
;
71 case GL_PACK_IMAGE_HEIGHT
:
73 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
76 if (ctx
->Pack
.ImageHeight
== param
)
78 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
79 ctx
->Pack
.ImageHeight
= param
;
81 case GL_PACK_SKIP_PIXELS
:
83 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
86 if (ctx
->Pack
.SkipPixels
== param
)
88 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
89 ctx
->Pack
.SkipPixels
= param
;
91 case GL_PACK_SKIP_ROWS
:
93 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
96 if (ctx
->Pack
.SkipRows
== param
)
98 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
99 ctx
->Pack
.SkipRows
= param
;
101 case GL_PACK_SKIP_IMAGES
:
103 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
106 if (ctx
->Pack
.SkipImages
== param
)
108 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
109 ctx
->Pack
.SkipImages
= param
;
111 case GL_PACK_ALIGNMENT
:
112 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
113 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
116 if (ctx
->Pack
.Alignment
== param
)
118 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
119 ctx
->Pack
.Alignment
= param
;
121 case GL_PACK_INVERT_MESA
:
122 if (!ctx
->Extensions
.MESA_pack_invert
) {
123 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelstore(pname)" );
126 if (ctx
->Pack
.Invert
== param
)
128 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
129 ctx
->Pack
.Invert
= param
;
132 case GL_UNPACK_SWAP_BYTES
:
133 if (param
== (GLint
)ctx
->Unpack
.SwapBytes
)
135 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
137 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
138 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
140 case GL_UNPACK_LSB_FIRST
:
141 if (param
== (GLint
)ctx
->Unpack
.LsbFirst
)
143 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
145 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
146 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
148 case GL_UNPACK_ROW_LENGTH
:
150 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
153 if (ctx
->Unpack
.RowLength
== param
)
155 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
156 ctx
->Unpack
.RowLength
= param
;
158 case GL_UNPACK_IMAGE_HEIGHT
:
160 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
163 if (ctx
->Unpack
.ImageHeight
== param
)
166 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
167 ctx
->Unpack
.ImageHeight
= param
;
169 case GL_UNPACK_SKIP_PIXELS
:
171 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
174 if (ctx
->Unpack
.SkipPixels
== param
)
176 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
177 ctx
->Unpack
.SkipPixels
= param
;
179 case GL_UNPACK_SKIP_ROWS
:
181 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
184 if (ctx
->Unpack
.SkipRows
== param
)
186 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
187 ctx
->Unpack
.SkipRows
= param
;
189 case GL_UNPACK_SKIP_IMAGES
:
191 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
194 if (ctx
->Unpack
.SkipImages
== param
)
196 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
197 ctx
->Unpack
.SkipImages
= param
;
199 case GL_UNPACK_ALIGNMENT
:
200 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
201 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
204 if (ctx
->Unpack
.Alignment
== param
)
206 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
207 ctx
->Unpack
.Alignment
= param
;
209 case GL_UNPACK_CLIENT_STORAGE_APPLE
:
210 if (param
== (GLint
)ctx
->Unpack
.ClientStorage
)
212 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
213 ctx
->Unpack
.ClientStorage
= param
? GL_TRUE
: GL_FALSE
;
216 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
223 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
225 _mesa_PixelStorei( pname
, (GLint
) param
);
231 * Initialize the context's pixel store state.
234 _mesa_init_pixelstore( GLcontext
*ctx
)
237 ctx
->Pack
.Alignment
= 4;
238 ctx
->Pack
.RowLength
= 0;
239 ctx
->Pack
.ImageHeight
= 0;
240 ctx
->Pack
.SkipPixels
= 0;
241 ctx
->Pack
.SkipRows
= 0;
242 ctx
->Pack
.SkipImages
= 0;
243 ctx
->Pack
.SwapBytes
= GL_FALSE
;
244 ctx
->Pack
.LsbFirst
= GL_FALSE
;
245 ctx
->Pack
.ClientStorage
= GL_FALSE
;
246 ctx
->Pack
.Invert
= GL_FALSE
;
247 #if FEATURE_EXT_pixel_buffer_object
248 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
,
249 ctx
->Shared
->NullBufferObj
);
251 ctx
->Unpack
.Alignment
= 4;
252 ctx
->Unpack
.RowLength
= 0;
253 ctx
->Unpack
.ImageHeight
= 0;
254 ctx
->Unpack
.SkipPixels
= 0;
255 ctx
->Unpack
.SkipRows
= 0;
256 ctx
->Unpack
.SkipImages
= 0;
257 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
258 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
259 ctx
->Unpack
.ClientStorage
= GL_FALSE
;
260 ctx
->Unpack
.Invert
= GL_FALSE
;
261 #if FEATURE_EXT_pixel_buffer_object
262 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
,
263 ctx
->Shared
->NullBufferObj
);
267 * _mesa_unpack_image() returns image data in this format. When we
268 * execute image commands (glDrawPixels(), glTexImage(), etc) from
269 * within display lists we have to be sure to set the current
270 * unpacking parameters to these values!
272 ctx
->DefaultPacking
.Alignment
= 1;
273 ctx
->DefaultPacking
.RowLength
= 0;
274 ctx
->DefaultPacking
.SkipPixels
= 0;
275 ctx
->DefaultPacking
.SkipRows
= 0;
276 ctx
->DefaultPacking
.ImageHeight
= 0;
277 ctx
->DefaultPacking
.SkipImages
= 0;
278 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
279 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
280 ctx
->DefaultPacking
.ClientStorage
= GL_FALSE
;
281 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
282 #if FEATURE_EXT_pixel_buffer_object
283 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
,
284 ctx
->Shared
->NullBufferObj
);