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
);
45 case GL_PACK_SWAP_BYTES
:
46 if (!_mesa_is_desktop_gl(ctx
))
47 goto invalid_enum_error
;
48 if (param
== (GLint
)ctx
->Pack
.SwapBytes
)
50 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
52 case GL_PACK_LSB_FIRST
:
53 if (!_mesa_is_desktop_gl(ctx
))
54 goto invalid_enum_error
;
55 if (param
== (GLint
)ctx
->Pack
.LsbFirst
)
57 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
59 case GL_PACK_ROW_LENGTH
:
60 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
61 goto invalid_enum_error
;
63 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
66 if (ctx
->Pack
.RowLength
== param
)
68 ctx
->Pack
.RowLength
= param
;
70 case GL_PACK_IMAGE_HEIGHT
:
71 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
72 goto invalid_enum_error
;
74 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
77 if (ctx
->Pack
.ImageHeight
== param
)
79 ctx
->Pack
.ImageHeight
= param
;
81 case GL_PACK_SKIP_PIXELS
:
82 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
83 goto invalid_enum_error
;
85 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
88 if (ctx
->Pack
.SkipPixels
== param
)
90 ctx
->Pack
.SkipPixels
= param
;
92 case GL_PACK_SKIP_ROWS
:
93 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
94 goto invalid_enum_error
;
96 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
99 if (ctx
->Pack
.SkipRows
== param
)
101 ctx
->Pack
.SkipRows
= param
;
103 case GL_PACK_SKIP_IMAGES
:
104 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
105 goto invalid_enum_error
;
107 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
110 if (ctx
->Pack
.SkipImages
== param
)
112 ctx
->Pack
.SkipImages
= param
;
114 case GL_PACK_ALIGNMENT
:
115 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
116 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
119 if (ctx
->Pack
.Alignment
== param
)
121 ctx
->Pack
.Alignment
= param
;
123 case GL_PACK_INVERT_MESA
:
124 if (!_mesa_is_desktop_gl(ctx
))
125 goto invalid_enum_error
;
126 if (!ctx
->Extensions
.MESA_pack_invert
) {
127 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelstore(pname)" );
130 if (ctx
->Pack
.Invert
== param
)
132 ctx
->Pack
.Invert
= param
;
135 case GL_UNPACK_SWAP_BYTES
:
136 if (!_mesa_is_desktop_gl(ctx
))
137 goto invalid_enum_error
;
138 if (param
== (GLint
)ctx
->Unpack
.SwapBytes
)
140 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
142 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
144 case GL_UNPACK_LSB_FIRST
:
145 if (!_mesa_is_desktop_gl(ctx
))
146 goto invalid_enum_error
;
147 if (param
== (GLint
)ctx
->Unpack
.LsbFirst
)
149 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
151 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
153 case GL_UNPACK_ROW_LENGTH
:
154 if (ctx
->API
== API_OPENGLES
)
155 goto invalid_enum_error
;
157 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
160 if (ctx
->Unpack
.RowLength
== param
)
162 ctx
->Unpack
.RowLength
= param
;
164 case GL_UNPACK_IMAGE_HEIGHT
:
165 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
166 goto invalid_enum_error
;
168 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
171 if (ctx
->Unpack
.ImageHeight
== param
)
174 ctx
->Unpack
.ImageHeight
= param
;
176 case GL_UNPACK_SKIP_PIXELS
:
177 if (ctx
->API
== API_OPENGLES
)
178 goto invalid_enum_error
;
180 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
183 if (ctx
->Unpack
.SkipPixels
== param
)
185 ctx
->Unpack
.SkipPixels
= param
;
187 case GL_UNPACK_SKIP_ROWS
:
188 if (ctx
->API
== API_OPENGLES
)
189 goto invalid_enum_error
;
191 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
194 if (ctx
->Unpack
.SkipRows
== param
)
196 ctx
->Unpack
.SkipRows
= param
;
198 case GL_UNPACK_SKIP_IMAGES
:
199 if (!_mesa_is_desktop_gl(ctx
) && !_mesa_is_gles3(ctx
))
200 goto invalid_enum_error
;
202 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
205 if (ctx
->Unpack
.SkipImages
== param
)
207 ctx
->Unpack
.SkipImages
= param
;
209 case GL_UNPACK_ALIGNMENT
:
210 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
211 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
214 if (ctx
->Unpack
.Alignment
== param
)
216 ctx
->Unpack
.Alignment
= param
;
219 goto invalid_enum_error
;
225 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
231 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
233 _mesa_PixelStorei( pname
, IROUND(param
) );
239 * Initialize the context's pixel store state.
242 _mesa_init_pixelstore( struct gl_context
*ctx
)
245 ctx
->Pack
.Alignment
= 4;
246 ctx
->Pack
.RowLength
= 0;
247 ctx
->Pack
.ImageHeight
= 0;
248 ctx
->Pack
.SkipPixels
= 0;
249 ctx
->Pack
.SkipRows
= 0;
250 ctx
->Pack
.SkipImages
= 0;
251 ctx
->Pack
.SwapBytes
= GL_FALSE
;
252 ctx
->Pack
.LsbFirst
= GL_FALSE
;
253 ctx
->Pack
.Invert
= GL_FALSE
;
254 _mesa_reference_buffer_object(ctx
, &ctx
->Pack
.BufferObj
,
255 ctx
->Shared
->NullBufferObj
);
256 ctx
->Unpack
.Alignment
= 4;
257 ctx
->Unpack
.RowLength
= 0;
258 ctx
->Unpack
.ImageHeight
= 0;
259 ctx
->Unpack
.SkipPixels
= 0;
260 ctx
->Unpack
.SkipRows
= 0;
261 ctx
->Unpack
.SkipImages
= 0;
262 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
263 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
264 ctx
->Unpack
.Invert
= GL_FALSE
;
265 _mesa_reference_buffer_object(ctx
, &ctx
->Unpack
.BufferObj
,
266 ctx
->Shared
->NullBufferObj
);
269 * _mesa_unpack_image() returns image data in this format. When we
270 * execute image commands (glDrawPixels(), glTexImage(), etc) from
271 * within display lists we have to be sure to set the current
272 * unpacking parameters to these values!
274 ctx
->DefaultPacking
.Alignment
= 1;
275 ctx
->DefaultPacking
.RowLength
= 0;
276 ctx
->DefaultPacking
.SkipPixels
= 0;
277 ctx
->DefaultPacking
.SkipRows
= 0;
278 ctx
->DefaultPacking
.ImageHeight
= 0;
279 ctx
->DefaultPacking
.SkipImages
= 0;
280 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
281 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
282 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
283 _mesa_reference_buffer_object(ctx
, &ctx
->DefaultPacking
.BufferObj
,
284 ctx
->Shared
->NullBufferObj
);