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"
39 _mesa_PixelStorei( GLenum pname
, GLint param
)
41 /* NOTE: this call can't be compiled into the display list */
42 GET_CURRENT_CONTEXT(ctx
);
43 ASSERT_OUTSIDE_BEGIN_END(ctx
);
46 case GL_PACK_SWAP_BYTES
:
47 if (param
== (GLint
)ctx
->Pack
.SwapBytes
)
49 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
50 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
52 case GL_PACK_LSB_FIRST
:
53 if (param
== (GLint
)ctx
->Pack
.LsbFirst
)
55 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
56 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
58 case GL_PACK_ROW_LENGTH
:
60 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
63 if (ctx
->Pack
.RowLength
== param
)
65 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
66 ctx
->Pack
.RowLength
= param
;
68 case GL_PACK_IMAGE_HEIGHT
:
70 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
73 if (ctx
->Pack
.ImageHeight
== param
)
75 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
76 ctx
->Pack
.ImageHeight
= param
;
78 case GL_PACK_SKIP_PIXELS
:
80 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
83 if (ctx
->Pack
.SkipPixels
== param
)
85 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
86 ctx
->Pack
.SkipPixels
= param
;
88 case GL_PACK_SKIP_ROWS
:
90 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
93 if (ctx
->Pack
.SkipRows
== param
)
95 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
96 ctx
->Pack
.SkipRows
= param
;
98 case GL_PACK_SKIP_IMAGES
:
100 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
103 if (ctx
->Pack
.SkipImages
== param
)
105 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
106 ctx
->Pack
.SkipImages
= param
;
108 case GL_PACK_ALIGNMENT
:
109 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
110 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
113 if (ctx
->Pack
.Alignment
== param
)
115 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
116 ctx
->Pack
.Alignment
= param
;
118 case GL_PACK_INVERT_MESA
:
119 if (!ctx
->Extensions
.MESA_pack_invert
) {
120 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelstore(pname)" );
123 if (ctx
->Pack
.Invert
== param
)
125 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
126 ctx
->Pack
.Invert
= param
;
129 case GL_UNPACK_SWAP_BYTES
:
130 if (param
== (GLint
)ctx
->Unpack
.SwapBytes
)
132 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
134 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
135 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
137 case GL_UNPACK_LSB_FIRST
:
138 if (param
== (GLint
)ctx
->Unpack
.LsbFirst
)
140 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
142 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
143 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
145 case GL_UNPACK_ROW_LENGTH
:
147 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
150 if (ctx
->Unpack
.RowLength
== param
)
152 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
153 ctx
->Unpack
.RowLength
= param
;
155 case GL_UNPACK_IMAGE_HEIGHT
:
157 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
160 if (ctx
->Unpack
.ImageHeight
== param
)
163 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
164 ctx
->Unpack
.ImageHeight
= param
;
166 case GL_UNPACK_SKIP_PIXELS
:
168 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
171 if (ctx
->Unpack
.SkipPixels
== param
)
173 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
174 ctx
->Unpack
.SkipPixels
= param
;
176 case GL_UNPACK_SKIP_ROWS
:
178 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
181 if (ctx
->Unpack
.SkipRows
== param
)
183 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
184 ctx
->Unpack
.SkipRows
= param
;
186 case GL_UNPACK_SKIP_IMAGES
:
188 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
191 if (ctx
->Unpack
.SkipImages
== param
)
193 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
194 ctx
->Unpack
.SkipImages
= param
;
196 case GL_UNPACK_ALIGNMENT
:
197 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
198 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
201 if (ctx
->Unpack
.Alignment
== param
)
203 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
204 ctx
->Unpack
.Alignment
= param
;
206 case GL_UNPACK_CLIENT_STORAGE_APPLE
:
207 if (param
== (GLint
)ctx
->Unpack
.ClientStorage
)
209 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
210 ctx
->Unpack
.ClientStorage
= param
? GL_TRUE
: GL_FALSE
;
213 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
220 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
222 _mesa_PixelStorei( pname
, (GLint
) param
);
228 * Initialize the context's pixel store state.
231 _mesa_init_pixelstore( GLcontext
*ctx
)
234 ctx
->Pack
.Alignment
= 4;
235 ctx
->Pack
.RowLength
= 0;
236 ctx
->Pack
.ImageHeight
= 0;
237 ctx
->Pack
.SkipPixels
= 0;
238 ctx
->Pack
.SkipRows
= 0;
239 ctx
->Pack
.SkipImages
= 0;
240 ctx
->Pack
.SwapBytes
= GL_FALSE
;
241 ctx
->Pack
.LsbFirst
= GL_FALSE
;
242 ctx
->Pack
.ClientStorage
= GL_FALSE
;
243 ctx
->Pack
.Invert
= GL_FALSE
;
244 #if FEATURE_EXT_pixel_buffer_object
245 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
,
246 ctx
->Shared
->NullBufferObj
);
248 ctx
->Unpack
.Alignment
= 4;
249 ctx
->Unpack
.RowLength
= 0;
250 ctx
->Unpack
.ImageHeight
= 0;
251 ctx
->Unpack
.SkipPixels
= 0;
252 ctx
->Unpack
.SkipRows
= 0;
253 ctx
->Unpack
.SkipImages
= 0;
254 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
255 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
256 ctx
->Unpack
.ClientStorage
= GL_FALSE
;
257 ctx
->Unpack
.Invert
= GL_FALSE
;
258 #if FEATURE_EXT_pixel_buffer_object
259 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
,
260 ctx
->Shared
->NullBufferObj
);
264 * _mesa_unpack_image() returns image data in this format. When we
265 * execute image commands (glDrawPixels(), glTexImage(), etc) from
266 * within display lists we have to be sure to set the current
267 * unpacking parameters to these values!
269 ctx
->DefaultPacking
.Alignment
= 1;
270 ctx
->DefaultPacking
.RowLength
= 0;
271 ctx
->DefaultPacking
.SkipPixels
= 0;
272 ctx
->DefaultPacking
.SkipRows
= 0;
273 ctx
->DefaultPacking
.ImageHeight
= 0;
274 ctx
->DefaultPacking
.SkipImages
= 0;
275 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
276 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
277 ctx
->DefaultPacking
.ClientStorage
= GL_FALSE
;
278 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
279 #if FEATURE_EXT_pixel_buffer_object
280 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
,
281 ctx
->Shared
->NullBufferObj
);