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
;
208 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
215 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
217 _mesa_PixelStorei( pname
, IROUND(param
) );
223 * Initialize the context's pixel store state.
226 _mesa_init_pixelstore( struct gl_context
*ctx
)
229 ctx
->Pack
.Alignment
= 4;
230 ctx
->Pack
.RowLength
= 0;
231 ctx
->Pack
.ImageHeight
= 0;
232 ctx
->Pack
.SkipPixels
= 0;
233 ctx
->Pack
.SkipRows
= 0;
234 ctx
->Pack
.SkipImages
= 0;
235 ctx
->Pack
.SwapBytes
= GL_FALSE
;
236 ctx
->Pack
.LsbFirst
= GL_FALSE
;
237 ctx
->Pack
.Invert
= GL_FALSE
;
238 #if FEATURE_EXT_pixel_buffer_object
239 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
,
240 ctx
->Shared
->NullBufferObj
);
242 ctx
->Unpack
.Alignment
= 4;
243 ctx
->Unpack
.RowLength
= 0;
244 ctx
->Unpack
.ImageHeight
= 0;
245 ctx
->Unpack
.SkipPixels
= 0;
246 ctx
->Unpack
.SkipRows
= 0;
247 ctx
->Unpack
.SkipImages
= 0;
248 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
249 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
250 ctx
->Unpack
.Invert
= GL_FALSE
;
251 #if FEATURE_EXT_pixel_buffer_object
252 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
,
253 ctx
->Shared
->NullBufferObj
);
257 * _mesa_unpack_image() returns image data in this format. When we
258 * execute image commands (glDrawPixels(), glTexImage(), etc) from
259 * within display lists we have to be sure to set the current
260 * unpacking parameters to these values!
262 ctx
->DefaultPacking
.Alignment
= 1;
263 ctx
->DefaultPacking
.RowLength
= 0;
264 ctx
->DefaultPacking
.SkipPixels
= 0;
265 ctx
->DefaultPacking
.SkipRows
= 0;
266 ctx
->DefaultPacking
.ImageHeight
= 0;
267 ctx
->DefaultPacking
.SkipImages
= 0;
268 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
269 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
270 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
271 #if FEATURE_EXT_pixel_buffer_object
272 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
,
273 ctx
->Shared
->NullBufferObj
);