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
);
44 ASSERT_OUTSIDE_BEGIN_END(ctx
);
47 case GL_PACK_SWAP_BYTES
:
48 if (param
== (GLint
)ctx
->Pack
.SwapBytes
)
50 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
51 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
53 case GL_PACK_LSB_FIRST
:
54 if (param
== (GLint
)ctx
->Pack
.LsbFirst
)
56 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
57 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
59 case GL_PACK_ROW_LENGTH
:
61 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
64 if (ctx
->Pack
.RowLength
== param
)
66 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
67 ctx
->Pack
.RowLength
= param
;
69 case GL_PACK_IMAGE_HEIGHT
:
71 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
74 if (ctx
->Pack
.ImageHeight
== param
)
76 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
77 ctx
->Pack
.ImageHeight
= param
;
79 case GL_PACK_SKIP_PIXELS
:
81 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
84 if (ctx
->Pack
.SkipPixels
== param
)
86 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
87 ctx
->Pack
.SkipPixels
= param
;
89 case GL_PACK_SKIP_ROWS
:
91 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
94 if (ctx
->Pack
.SkipRows
== param
)
96 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
97 ctx
->Pack
.SkipRows
= param
;
99 case GL_PACK_SKIP_IMAGES
:
101 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
104 if (ctx
->Pack
.SkipImages
== param
)
106 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
107 ctx
->Pack
.SkipImages
= param
;
109 case GL_PACK_ALIGNMENT
:
110 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
111 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
114 if (ctx
->Pack
.Alignment
== param
)
116 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
117 ctx
->Pack
.Alignment
= param
;
119 case GL_PACK_INVERT_MESA
:
120 if (!ctx
->Extensions
.MESA_pack_invert
) {
121 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelstore(pname)" );
124 if (ctx
->Pack
.Invert
== param
)
126 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
127 ctx
->Pack
.Invert
= param
;
130 case GL_UNPACK_SWAP_BYTES
:
131 if (param
== (GLint
)ctx
->Unpack
.SwapBytes
)
133 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
135 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
136 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
138 case GL_UNPACK_LSB_FIRST
:
139 if (param
== (GLint
)ctx
->Unpack
.LsbFirst
)
141 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
143 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
144 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
146 case GL_UNPACK_ROW_LENGTH
:
148 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
151 if (ctx
->Unpack
.RowLength
== param
)
153 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
154 ctx
->Unpack
.RowLength
= param
;
156 case GL_UNPACK_IMAGE_HEIGHT
:
158 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
161 if (ctx
->Unpack
.ImageHeight
== param
)
164 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
165 ctx
->Unpack
.ImageHeight
= param
;
167 case GL_UNPACK_SKIP_PIXELS
:
169 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
172 if (ctx
->Unpack
.SkipPixels
== param
)
174 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
175 ctx
->Unpack
.SkipPixels
= param
;
177 case GL_UNPACK_SKIP_ROWS
:
179 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
182 if (ctx
->Unpack
.SkipRows
== param
)
184 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
185 ctx
->Unpack
.SkipRows
= param
;
187 case GL_UNPACK_SKIP_IMAGES
:
189 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
192 if (ctx
->Unpack
.SkipImages
== param
)
194 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
195 ctx
->Unpack
.SkipImages
= param
;
197 case GL_UNPACK_ALIGNMENT
:
198 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
199 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
202 if (ctx
->Unpack
.Alignment
== param
)
204 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
205 ctx
->Unpack
.Alignment
= param
;
207 case GL_UNPACK_CLIENT_STORAGE_APPLE
:
208 if (param
== (GLint
)ctx
->Unpack
.ClientStorage
)
210 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
211 ctx
->Unpack
.ClientStorage
= param
? GL_TRUE
: GL_FALSE
;
214 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
221 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
223 _mesa_PixelStorei( pname
, (GLint
) param
);
229 * Initialize the context's pixel store state.
232 _mesa_init_pixelstore( struct gl_context
*ctx
)
235 ctx
->Pack
.Alignment
= 4;
236 ctx
->Pack
.RowLength
= 0;
237 ctx
->Pack
.ImageHeight
= 0;
238 ctx
->Pack
.SkipPixels
= 0;
239 ctx
->Pack
.SkipRows
= 0;
240 ctx
->Pack
.SkipImages
= 0;
241 ctx
->Pack
.SwapBytes
= GL_FALSE
;
242 ctx
->Pack
.LsbFirst
= GL_FALSE
;
243 ctx
->Pack
.ClientStorage
= GL_FALSE
;
244 ctx
->Pack
.Invert
= GL_FALSE
;
245 #if FEATURE_EXT_pixel_buffer_object
246 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
,
247 ctx
->Shared
->NullBufferObj
);
249 ctx
->Unpack
.Alignment
= 4;
250 ctx
->Unpack
.RowLength
= 0;
251 ctx
->Unpack
.ImageHeight
= 0;
252 ctx
->Unpack
.SkipPixels
= 0;
253 ctx
->Unpack
.SkipRows
= 0;
254 ctx
->Unpack
.SkipImages
= 0;
255 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
256 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
257 ctx
->Unpack
.ClientStorage
= GL_FALSE
;
258 ctx
->Unpack
.Invert
= GL_FALSE
;
259 #if FEATURE_EXT_pixel_buffer_object
260 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
,
261 ctx
->Shared
->NullBufferObj
);
265 * _mesa_unpack_image() returns image data in this format. When we
266 * execute image commands (glDrawPixels(), glTexImage(), etc) from
267 * within display lists we have to be sure to set the current
268 * unpacking parameters to these values!
270 ctx
->DefaultPacking
.Alignment
= 1;
271 ctx
->DefaultPacking
.RowLength
= 0;
272 ctx
->DefaultPacking
.SkipPixels
= 0;
273 ctx
->DefaultPacking
.SkipRows
= 0;
274 ctx
->DefaultPacking
.ImageHeight
= 0;
275 ctx
->DefaultPacking
.SkipImages
= 0;
276 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
277 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
278 ctx
->DefaultPacking
.ClientStorage
= GL_FALSE
;
279 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
280 #if FEATURE_EXT_pixel_buffer_object
281 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
,
282 ctx
->Shared
->NullBufferObj
);