2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 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.
26 #include "bufferobj.h"
35 /**********************************************************************/
36 /***** glPixelZoom *****/
37 /**********************************************************************/
42 _mesa_PixelZoom( GLfloat xfactor
, GLfloat yfactor
)
44 GET_CURRENT_CONTEXT(ctx
);
46 if (ctx
->Pixel
.ZoomX
== xfactor
&&
47 ctx
->Pixel
.ZoomY
== yfactor
)
50 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
51 ctx
->Pixel
.ZoomX
= xfactor
;
52 ctx
->Pixel
.ZoomY
= yfactor
;
57 /**********************************************************************/
58 /***** glPixelStore *****/
59 /**********************************************************************/
63 _mesa_PixelStorei( GLenum pname
, GLint param
)
65 /* NOTE: this call can't be compiled into the display list */
66 GET_CURRENT_CONTEXT(ctx
);
67 ASSERT_OUTSIDE_BEGIN_END(ctx
);
70 case GL_PACK_SWAP_BYTES
:
71 if (param
== (GLint
)ctx
->Pack
.SwapBytes
)
73 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
74 ctx
->Pack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
76 case GL_PACK_LSB_FIRST
:
77 if (param
== (GLint
)ctx
->Pack
.LsbFirst
)
79 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
80 ctx
->Pack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
82 case GL_PACK_ROW_LENGTH
:
84 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
87 if (ctx
->Pack
.RowLength
== param
)
89 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
90 ctx
->Pack
.RowLength
= param
;
92 case GL_PACK_IMAGE_HEIGHT
:
94 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
97 if (ctx
->Pack
.ImageHeight
== param
)
99 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
100 ctx
->Pack
.ImageHeight
= param
;
102 case GL_PACK_SKIP_PIXELS
:
104 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
107 if (ctx
->Pack
.SkipPixels
== param
)
109 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
110 ctx
->Pack
.SkipPixels
= param
;
112 case GL_PACK_SKIP_ROWS
:
114 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
117 if (ctx
->Pack
.SkipRows
== param
)
119 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
120 ctx
->Pack
.SkipRows
= param
;
122 case GL_PACK_SKIP_IMAGES
:
124 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
127 if (ctx
->Pack
.SkipImages
== param
)
129 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
130 ctx
->Pack
.SkipImages
= param
;
132 case GL_PACK_ALIGNMENT
:
133 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
134 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
137 if (ctx
->Pack
.Alignment
== param
)
139 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
140 ctx
->Pack
.Alignment
= param
;
142 case GL_PACK_INVERT_MESA
:
143 if (!ctx
->Extensions
.MESA_pack_invert
) {
144 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelstore(pname)" );
147 if (ctx
->Pack
.Invert
== param
)
149 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
150 ctx
->Pack
.Invert
= param
;
153 case GL_UNPACK_SWAP_BYTES
:
154 if (param
== (GLint
)ctx
->Unpack
.SwapBytes
)
156 if ((GLint
)ctx
->Unpack
.SwapBytes
== param
)
158 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
159 ctx
->Unpack
.SwapBytes
= param
? GL_TRUE
: GL_FALSE
;
161 case GL_UNPACK_LSB_FIRST
:
162 if (param
== (GLint
)ctx
->Unpack
.LsbFirst
)
164 if ((GLint
)ctx
->Unpack
.LsbFirst
== param
)
166 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
167 ctx
->Unpack
.LsbFirst
= param
? GL_TRUE
: GL_FALSE
;
169 case GL_UNPACK_ROW_LENGTH
:
171 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
174 if (ctx
->Unpack
.RowLength
== param
)
176 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
177 ctx
->Unpack
.RowLength
= param
;
179 case GL_UNPACK_IMAGE_HEIGHT
:
181 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
184 if (ctx
->Unpack
.ImageHeight
== param
)
187 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
188 ctx
->Unpack
.ImageHeight
= param
;
190 case GL_UNPACK_SKIP_PIXELS
:
192 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
195 if (ctx
->Unpack
.SkipPixels
== param
)
197 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
198 ctx
->Unpack
.SkipPixels
= param
;
200 case GL_UNPACK_SKIP_ROWS
:
202 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
205 if (ctx
->Unpack
.SkipRows
== param
)
207 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
208 ctx
->Unpack
.SkipRows
= param
;
210 case GL_UNPACK_SKIP_IMAGES
:
212 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore(param)" );
215 if (ctx
->Unpack
.SkipImages
== param
)
217 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
218 ctx
->Unpack
.SkipImages
= param
;
220 case GL_UNPACK_ALIGNMENT
:
221 if (param
!=1 && param
!=2 && param
!=4 && param
!=8) {
222 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelStore" );
225 if (ctx
->Unpack
.Alignment
== param
)
227 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
228 ctx
->Unpack
.Alignment
= param
;
230 case GL_UNPACK_CLIENT_STORAGE_APPLE
:
231 if (param
== (GLint
)ctx
->Unpack
.ClientStorage
)
233 FLUSH_VERTICES(ctx
, _NEW_PACKUNPACK
);
234 ctx
->Unpack
.ClientStorage
= param
? GL_TRUE
: GL_FALSE
;
237 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelStore" );
244 _mesa_PixelStoref( GLenum pname
, GLfloat param
)
246 _mesa_PixelStorei( pname
, (GLint
) param
);
251 /**********************************************************************/
252 /***** glPixelMap *****/
253 /**********************************************************************/
257 * Helper routine used by the other _mesa_PixelMap() functions.
260 pixelmap(GLcontext
*ctx
, GLenum map
, GLsizei mapsize
, const GLfloat
*values
)
264 case GL_PIXEL_MAP_S_TO_S
:
265 ctx
->Pixel
.MapStoSsize
= mapsize
;
266 for (i
= 0; i
< mapsize
; i
++) {
267 ctx
->Pixel
.MapStoS
[i
] = (GLint
) values
[i
];
270 case GL_PIXEL_MAP_I_TO_I
:
271 ctx
->Pixel
.MapItoIsize
= mapsize
;
272 for (i
= 0; i
< mapsize
; i
++) {
273 ctx
->Pixel
.MapItoI
[i
] = (GLint
) values
[i
];
276 case GL_PIXEL_MAP_I_TO_R
:
277 ctx
->Pixel
.MapItoRsize
= mapsize
;
278 for (i
= 0; i
< mapsize
; i
++) {
279 GLfloat val
= CLAMP( values
[i
], 0.0F
, 1.0F
);
280 ctx
->Pixel
.MapItoR
[i
] = val
;
281 ctx
->Pixel
.MapItoR8
[i
] = (GLint
) (val
* 255.0F
);
284 case GL_PIXEL_MAP_I_TO_G
:
285 ctx
->Pixel
.MapItoGsize
= mapsize
;
286 for (i
= 0; i
< mapsize
; i
++) {
287 GLfloat val
= CLAMP( values
[i
], 0.0F
, 1.0F
);
288 ctx
->Pixel
.MapItoG
[i
] = val
;
289 ctx
->Pixel
.MapItoG8
[i
] = (GLint
) (val
* 255.0F
);
292 case GL_PIXEL_MAP_I_TO_B
:
293 ctx
->Pixel
.MapItoBsize
= mapsize
;
294 for (i
= 0; i
< mapsize
; i
++) {
295 GLfloat val
= CLAMP( values
[i
], 0.0F
, 1.0F
);
296 ctx
->Pixel
.MapItoB
[i
] = val
;
297 ctx
->Pixel
.MapItoB8
[i
] = (GLint
) (val
* 255.0F
);
300 case GL_PIXEL_MAP_I_TO_A
:
301 ctx
->Pixel
.MapItoAsize
= mapsize
;
302 for (i
= 0; i
< mapsize
; i
++) {
303 GLfloat val
= CLAMP( values
[i
], 0.0F
, 1.0F
);
304 ctx
->Pixel
.MapItoA
[i
] = val
;
305 ctx
->Pixel
.MapItoA8
[i
] = (GLint
) (val
* 255.0F
);
308 case GL_PIXEL_MAP_R_TO_R
:
309 ctx
->Pixel
.MapRtoRsize
= mapsize
;
310 for (i
= 0; i
< mapsize
; i
++) {
311 ctx
->Pixel
.MapRtoR
[i
] = CLAMP( values
[i
], 0.0F
, 1.0F
);
314 case GL_PIXEL_MAP_G_TO_G
:
315 ctx
->Pixel
.MapGtoGsize
= mapsize
;
316 for (i
= 0; i
< mapsize
; i
++) {
317 ctx
->Pixel
.MapGtoG
[i
] = CLAMP( values
[i
], 0.0F
, 1.0F
);
320 case GL_PIXEL_MAP_B_TO_B
:
321 ctx
->Pixel
.MapBtoBsize
= mapsize
;
322 for (i
= 0; i
< mapsize
; i
++) {
323 ctx
->Pixel
.MapBtoB
[i
] = CLAMP( values
[i
], 0.0F
, 1.0F
);
326 case GL_PIXEL_MAP_A_TO_A
:
327 ctx
->Pixel
.MapAtoAsize
= mapsize
;
328 for (i
= 0; i
< mapsize
; i
++) {
329 ctx
->Pixel
.MapAtoA
[i
] = CLAMP( values
[i
], 0.0F
, 1.0F
);
333 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelMap(map)" );
339 _mesa_PixelMapfv( GLenum map
, GLsizei mapsize
, const GLfloat
*values
)
341 GET_CURRENT_CONTEXT(ctx
);
342 ASSERT_OUTSIDE_BEGIN_END(ctx
);
344 /* XXX someday, test against ctx->Const.MaxPixelMapTableSize */
345 if (mapsize
< 1 || mapsize
> MAX_PIXEL_MAP_TABLE
) {
346 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
350 if (map
>= GL_PIXEL_MAP_S_TO_S
&& map
<= GL_PIXEL_MAP_I_TO_A
) {
351 /* test that mapsize is a power of two */
352 if (_mesa_bitcount((GLuint
) mapsize
) != 1) {
353 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapfv(mapsize)" );
358 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
360 if (ctx
->Unpack
.BufferObj
->Name
) {
361 /* unpack pixelmap from PBO */
363 /* Note, need to use DefaultPacking and Unpack's buffer object */
364 ctx
->DefaultPacking
.BufferObj
= ctx
->Unpack
.BufferObj
;
365 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
366 GL_INTENSITY
, GL_FLOAT
, values
)) {
367 _mesa_error(ctx
, GL_INVALID_OPERATION
,
368 "glPixelMapfv(invalid PBO access)");
372 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
373 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
375 ctx
->Unpack
.BufferObj
);
377 /* buffer is already mapped - that's an error */
378 _mesa_error(ctx
, GL_INVALID_OPERATION
,
379 "glPixelMapfv(PBO is mapped)");
382 values
= (const GLfloat
*) ADD_POINTERS(buf
, values
);
388 pixelmap(ctx
, map
, mapsize
, values
);
390 if (ctx
->Unpack
.BufferObj
->Name
) {
391 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
392 ctx
->Unpack
.BufferObj
);
399 _mesa_PixelMapuiv(GLenum map
, GLsizei mapsize
, const GLuint
*values
)
401 GLfloat fvalues
[MAX_PIXEL_MAP_TABLE
];
402 GET_CURRENT_CONTEXT(ctx
);
403 ASSERT_OUTSIDE_BEGIN_END(ctx
);
405 if (mapsize
< 1 || mapsize
> MAX_PIXEL_MAP_TABLE
) {
406 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapuiv(mapsize)" );
410 if (map
>= GL_PIXEL_MAP_S_TO_S
&& map
<= GL_PIXEL_MAP_I_TO_A
) {
411 /* test that mapsize is a power of two */
412 if (_mesa_bitcount((GLuint
) mapsize
) != 1) {
413 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapuiv(mapsize)" );
418 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
420 if (ctx
->Unpack
.BufferObj
->Name
) {
421 /* unpack pixelmap from PBO */
423 /* Note, need to use DefaultPacking and Unpack's buffer object */
424 ctx
->DefaultPacking
.BufferObj
= ctx
->Unpack
.BufferObj
;
425 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
426 GL_INTENSITY
, GL_UNSIGNED_INT
, values
)) {
427 _mesa_error(ctx
, GL_INVALID_OPERATION
,
428 "glPixelMapuiv(invalid PBO access)");
432 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
433 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
435 ctx
->Unpack
.BufferObj
);
437 /* buffer is already mapped - that's an error */
438 _mesa_error(ctx
, GL_INVALID_OPERATION
,
439 "glPixelMapuiv(PBO is mapped)");
442 values
= (const GLuint
*) ADD_POINTERS(buf
, values
);
448 /* convert to floats */
449 if (map
== GL_PIXEL_MAP_I_TO_I
|| map
== GL_PIXEL_MAP_S_TO_S
) {
451 for (i
= 0; i
< mapsize
; i
++) {
452 fvalues
[i
] = (GLfloat
) values
[i
];
457 for (i
= 0; i
< mapsize
; i
++) {
458 fvalues
[i
] = UINT_TO_FLOAT( values
[i
] );
462 if (ctx
->Unpack
.BufferObj
->Name
) {
463 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
464 ctx
->Unpack
.BufferObj
);
467 pixelmap(ctx
, map
, mapsize
, fvalues
);
473 _mesa_PixelMapusv(GLenum map
, GLsizei mapsize
, const GLushort
*values
)
475 GLfloat fvalues
[MAX_PIXEL_MAP_TABLE
];
476 GET_CURRENT_CONTEXT(ctx
);
477 ASSERT_OUTSIDE_BEGIN_END(ctx
);
479 if (mapsize
< 1 || mapsize
> MAX_PIXEL_MAP_TABLE
) {
480 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapusv(mapsize)" );
484 if (map
>= GL_PIXEL_MAP_S_TO_S
&& map
<= GL_PIXEL_MAP_I_TO_A
) {
485 /* test that mapsize is a power of two */
486 if (_mesa_bitcount((GLuint
) mapsize
) != 1) {
487 _mesa_error( ctx
, GL_INVALID_VALUE
, "glPixelMapuiv(mapsize)" );
492 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
494 if (ctx
->Unpack
.BufferObj
->Name
) {
495 /* unpack pixelmap from PBO */
497 /* Note, need to use DefaultPacking and Unpack's buffer object */
498 ctx
->DefaultPacking
.BufferObj
= ctx
->Unpack
.BufferObj
;
499 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
500 GL_INTENSITY
, GL_UNSIGNED_SHORT
,
502 _mesa_error(ctx
, GL_INVALID_OPERATION
,
503 "glPixelMapusv(invalid PBO access)");
507 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
508 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
510 ctx
->Unpack
.BufferObj
);
512 /* buffer is already mapped - that's an error */
513 _mesa_error(ctx
, GL_INVALID_OPERATION
,
514 "glPixelMapusv(PBO is mapped)");
517 values
= (const GLushort
*) ADD_POINTERS(buf
, values
);
523 /* convert to floats */
524 if (map
== GL_PIXEL_MAP_I_TO_I
|| map
== GL_PIXEL_MAP_S_TO_S
) {
526 for (i
= 0; i
< mapsize
; i
++) {
527 fvalues
[i
] = (GLfloat
) values
[i
];
532 for (i
= 0; i
< mapsize
; i
++) {
533 fvalues
[i
] = USHORT_TO_FLOAT( values
[i
] );
537 if (ctx
->Unpack
.BufferObj
->Name
) {
538 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
539 ctx
->Unpack
.BufferObj
);
542 pixelmap(ctx
, map
, mapsize
, fvalues
);
547 * Return size of the named map.
550 get_map_size(GLcontext
*ctx
, GLenum map
)
553 case GL_PIXEL_MAP_I_TO_I
:
554 return ctx
->Pixel
.MapItoIsize
;
555 case GL_PIXEL_MAP_S_TO_S
:
556 return ctx
->Pixel
.MapStoSsize
;
557 case GL_PIXEL_MAP_I_TO_R
:
558 return ctx
->Pixel
.MapItoRsize
;
559 case GL_PIXEL_MAP_I_TO_G
:
560 return ctx
->Pixel
.MapItoGsize
;
561 case GL_PIXEL_MAP_I_TO_B
:
562 return ctx
->Pixel
.MapItoBsize
;
563 case GL_PIXEL_MAP_I_TO_A
:
564 return ctx
->Pixel
.MapItoAsize
;
565 case GL_PIXEL_MAP_R_TO_R
:
566 return ctx
->Pixel
.MapRtoRsize
;
567 case GL_PIXEL_MAP_G_TO_G
:
568 return ctx
->Pixel
.MapGtoGsize
;
569 case GL_PIXEL_MAP_B_TO_B
:
570 return ctx
->Pixel
.MapBtoBsize
;
571 case GL_PIXEL_MAP_A_TO_A
:
572 return ctx
->Pixel
.MapAtoAsize
;
580 _mesa_GetPixelMapfv( GLenum map
, GLfloat
*values
)
582 GET_CURRENT_CONTEXT(ctx
);
584 ASSERT_OUTSIDE_BEGIN_END(ctx
);
586 mapsize
= get_map_size(ctx
, map
);
588 if (ctx
->Pack
.BufferObj
->Name
) {
589 /* pack pixelmap into PBO */
591 /* Note, need to use DefaultPacking and Pack's buffer object */
592 ctx
->DefaultPacking
.BufferObj
= ctx
->Pack
.BufferObj
;
593 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
594 GL_INTENSITY
, GL_FLOAT
, values
)) {
595 _mesa_error(ctx
, GL_INVALID_OPERATION
,
596 "glGetPixelMapfv(invalid PBO access)");
600 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
601 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
603 ctx
->Pack
.BufferObj
);
605 /* buffer is already mapped - that's an error */
606 _mesa_error(ctx
, GL_INVALID_OPERATION
,
607 "glGetPixelMapfv(PBO is mapped)");
610 values
= (GLfloat
*) ADD_POINTERS(buf
, values
);
617 case GL_PIXEL_MAP_I_TO_I
:
618 for (i
= 0; i
< mapsize
; i
++) {
619 values
[i
] = (GLfloat
) ctx
->Pixel
.MapItoI
[i
];
622 case GL_PIXEL_MAP_S_TO_S
:
623 for (i
= 0; i
< mapsize
; i
++) {
624 values
[i
] = (GLfloat
) ctx
->Pixel
.MapStoS
[i
];
627 case GL_PIXEL_MAP_I_TO_R
:
628 MEMCPY(values
, ctx
->Pixel
.MapItoR
, mapsize
* sizeof(GLfloat
));
630 case GL_PIXEL_MAP_I_TO_G
:
631 MEMCPY(values
, ctx
->Pixel
.MapItoG
, mapsize
* sizeof(GLfloat
));
633 case GL_PIXEL_MAP_I_TO_B
:
634 MEMCPY(values
, ctx
->Pixel
.MapItoB
, mapsize
* sizeof(GLfloat
));
636 case GL_PIXEL_MAP_I_TO_A
:
637 MEMCPY(values
, ctx
->Pixel
.MapItoA
, mapsize
* sizeof(GLfloat
));
639 case GL_PIXEL_MAP_R_TO_R
:
640 MEMCPY(values
, ctx
->Pixel
.MapRtoR
, mapsize
* sizeof(GLfloat
));
642 case GL_PIXEL_MAP_G_TO_G
:
643 MEMCPY(values
, ctx
->Pixel
.MapGtoG
, mapsize
* sizeof(GLfloat
));
645 case GL_PIXEL_MAP_B_TO_B
:
646 MEMCPY(values
, ctx
->Pixel
.MapBtoB
, mapsize
* sizeof(GLfloat
));
648 case GL_PIXEL_MAP_A_TO_A
:
649 MEMCPY(values
, ctx
->Pixel
.MapAtoA
, mapsize
* sizeof(GLfloat
));
652 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
655 if (ctx
->Pack
.BufferObj
->Name
) {
656 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
657 ctx
->Pack
.BufferObj
);
663 _mesa_GetPixelMapuiv( GLenum map
, GLuint
*values
)
665 GET_CURRENT_CONTEXT(ctx
);
667 ASSERT_OUTSIDE_BEGIN_END(ctx
);
669 mapsize
= get_map_size(ctx
, map
);
671 if (ctx
->Pack
.BufferObj
->Name
) {
672 /* pack pixelmap into PBO */
674 /* Note, need to use DefaultPacking and Pack's buffer object */
675 ctx
->DefaultPacking
.BufferObj
= ctx
->Pack
.BufferObj
;
676 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
677 GL_INTENSITY
, GL_UNSIGNED_INT
, values
)) {
678 _mesa_error(ctx
, GL_INVALID_OPERATION
,
679 "glGetPixelMapuiv(invalid PBO access)");
683 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
684 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
686 ctx
->Pack
.BufferObj
);
688 /* buffer is already mapped - that's an error */
689 _mesa_error(ctx
, GL_INVALID_OPERATION
,
690 "glGetPixelMapuiv(PBO is mapped)");
693 values
= (GLuint
*) ADD_POINTERS(buf
, values
);
700 case GL_PIXEL_MAP_I_TO_I
:
701 MEMCPY(values
, ctx
->Pixel
.MapItoI
, mapsize
* sizeof(GLint
));
703 case GL_PIXEL_MAP_S_TO_S
:
704 MEMCPY(values
, ctx
->Pixel
.MapStoS
, mapsize
* sizeof(GLint
));
706 case GL_PIXEL_MAP_I_TO_R
:
707 for (i
= 0; i
< mapsize
; i
++) {
708 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoR
[i
] );
711 case GL_PIXEL_MAP_I_TO_G
:
712 for (i
= 0; i
< mapsize
; i
++) {
713 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoG
[i
] );
716 case GL_PIXEL_MAP_I_TO_B
:
717 for (i
= 0; i
< mapsize
; i
++) {
718 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoB
[i
] );
721 case GL_PIXEL_MAP_I_TO_A
:
722 for (i
= 0; i
< mapsize
; i
++) {
723 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapItoA
[i
] );
726 case GL_PIXEL_MAP_R_TO_R
:
727 for (i
= 0; i
< mapsize
; i
++) {
728 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapRtoR
[i
] );
731 case GL_PIXEL_MAP_G_TO_G
:
732 for (i
= 0; i
< mapsize
; i
++) {
733 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapGtoG
[i
] );
736 case GL_PIXEL_MAP_B_TO_B
:
737 for (i
= 0; i
< mapsize
; i
++) {
738 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapBtoB
[i
] );
741 case GL_PIXEL_MAP_A_TO_A
:
742 for (i
= 0; i
< mapsize
; i
++) {
743 values
[i
] = FLOAT_TO_UINT( ctx
->Pixel
.MapAtoA
[i
] );
747 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
750 if (ctx
->Pack
.BufferObj
->Name
) {
751 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
752 ctx
->Pack
.BufferObj
);
758 _mesa_GetPixelMapusv( GLenum map
, GLushort
*values
)
760 GET_CURRENT_CONTEXT(ctx
);
762 ASSERT_OUTSIDE_BEGIN_END(ctx
);
764 mapsize
= get_map_size(ctx
, map
);
766 if (ctx
->Pack
.BufferObj
->Name
) {
767 /* pack pixelmap into PBO */
769 /* Note, need to use DefaultPacking and Pack's buffer object */
770 ctx
->DefaultPacking
.BufferObj
= ctx
->Pack
.BufferObj
;
771 if (!_mesa_validate_pbo_access(1, &ctx
->DefaultPacking
, mapsize
, 1, 1,
772 GL_INTENSITY
, GL_UNSIGNED_SHORT
,
774 _mesa_error(ctx
, GL_INVALID_OPERATION
,
775 "glGetPixelMapusv(invalid PBO access)");
779 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
780 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
782 ctx
->Pack
.BufferObj
);
784 /* buffer is already mapped - that's an error */
785 _mesa_error(ctx
, GL_INVALID_OPERATION
,
786 "glGetPixelMapusv(PBO is mapped)");
789 values
= (GLushort
*) ADD_POINTERS(buf
, values
);
796 case GL_PIXEL_MAP_I_TO_I
:
797 for (i
= 0; i
< mapsize
; i
++) {
798 values
[i
] = (GLushort
) ctx
->Pixel
.MapItoI
[i
];
801 case GL_PIXEL_MAP_S_TO_S
:
802 for (i
= 0; i
< mapsize
; i
++) {
803 values
[i
] = (GLushort
) ctx
->Pixel
.MapStoS
[i
];
806 case GL_PIXEL_MAP_I_TO_R
:
807 for (i
= 0; i
< mapsize
; i
++) {
808 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoR
[i
] );
811 case GL_PIXEL_MAP_I_TO_G
:
812 for (i
= 0; i
< mapsize
; i
++) {
813 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoG
[i
] );
816 case GL_PIXEL_MAP_I_TO_B
:
817 for (i
= 0; i
< mapsize
; i
++) {
818 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoB
[i
] );
821 case GL_PIXEL_MAP_I_TO_A
:
822 for (i
= 0; i
< mapsize
; i
++) {
823 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapItoA
[i
] );
826 case GL_PIXEL_MAP_R_TO_R
:
827 for (i
= 0; i
< mapsize
; i
++) {
828 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapRtoR
[i
] );
831 case GL_PIXEL_MAP_G_TO_G
:
832 for (i
= 0; i
< mapsize
; i
++) {
833 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapGtoG
[i
] );
836 case GL_PIXEL_MAP_B_TO_B
:
837 for (i
= 0; i
< mapsize
; i
++) {
838 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapBtoB
[i
] );
841 case GL_PIXEL_MAP_A_TO_A
:
842 for (i
= 0; i
< mapsize
; i
++) {
843 values
[i
] = FLOAT_TO_USHORT( ctx
->Pixel
.MapAtoA
[i
] );
847 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetPixelMapfv" );
850 if (ctx
->Pack
.BufferObj
->Name
) {
851 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
852 ctx
->Pack
.BufferObj
);
858 /**********************************************************************/
859 /***** glPixelTransfer *****/
860 /**********************************************************************/
864 * Implements glPixelTransfer[fi] whether called immediately or from a
868 _mesa_PixelTransferf( GLenum pname
, GLfloat param
)
870 GET_CURRENT_CONTEXT(ctx
);
871 ASSERT_OUTSIDE_BEGIN_END(ctx
);
875 if (ctx
->Pixel
.MapColorFlag
== (param
? GL_TRUE
: GL_FALSE
))
877 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
878 ctx
->Pixel
.MapColorFlag
= param
? GL_TRUE
: GL_FALSE
;
881 if (ctx
->Pixel
.MapStencilFlag
== (param
? GL_TRUE
: GL_FALSE
))
883 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
884 ctx
->Pixel
.MapStencilFlag
= param
? GL_TRUE
: GL_FALSE
;
887 if (ctx
->Pixel
.IndexShift
== (GLint
) param
)
889 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
890 ctx
->Pixel
.IndexShift
= (GLint
) param
;
892 case GL_INDEX_OFFSET
:
893 if (ctx
->Pixel
.IndexOffset
== (GLint
) param
)
895 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
896 ctx
->Pixel
.IndexOffset
= (GLint
) param
;
899 if (ctx
->Pixel
.RedScale
== param
)
901 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
902 ctx
->Pixel
.RedScale
= param
;
905 if (ctx
->Pixel
.RedBias
== param
)
907 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
908 ctx
->Pixel
.RedBias
= param
;
911 if (ctx
->Pixel
.GreenScale
== param
)
913 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
914 ctx
->Pixel
.GreenScale
= param
;
917 if (ctx
->Pixel
.GreenBias
== param
)
919 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
920 ctx
->Pixel
.GreenBias
= param
;
923 if (ctx
->Pixel
.BlueScale
== param
)
925 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
926 ctx
->Pixel
.BlueScale
= param
;
929 if (ctx
->Pixel
.BlueBias
== param
)
931 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
932 ctx
->Pixel
.BlueBias
= param
;
935 if (ctx
->Pixel
.AlphaScale
== param
)
937 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
938 ctx
->Pixel
.AlphaScale
= param
;
941 if (ctx
->Pixel
.AlphaBias
== param
)
943 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
944 ctx
->Pixel
.AlphaBias
= param
;
947 if (ctx
->Pixel
.DepthScale
== param
)
949 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
950 ctx
->Pixel
.DepthScale
= param
;
953 if (ctx
->Pixel
.DepthBias
== param
)
955 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
956 ctx
->Pixel
.DepthBias
= param
;
958 case GL_POST_COLOR_MATRIX_RED_SCALE
:
959 if (ctx
->Pixel
.PostColorMatrixScale
[0] == param
)
961 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
962 ctx
->Pixel
.PostColorMatrixScale
[0] = param
;
964 case GL_POST_COLOR_MATRIX_RED_BIAS
:
965 if (ctx
->Pixel
.PostColorMatrixBias
[0] == param
)
967 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
968 ctx
->Pixel
.PostColorMatrixBias
[0] = param
;
970 case GL_POST_COLOR_MATRIX_GREEN_SCALE
:
971 if (ctx
->Pixel
.PostColorMatrixScale
[1] == param
)
973 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
974 ctx
->Pixel
.PostColorMatrixScale
[1] = param
;
976 case GL_POST_COLOR_MATRIX_GREEN_BIAS
:
977 if (ctx
->Pixel
.PostColorMatrixBias
[1] == param
)
979 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
980 ctx
->Pixel
.PostColorMatrixBias
[1] = param
;
982 case GL_POST_COLOR_MATRIX_BLUE_SCALE
:
983 if (ctx
->Pixel
.PostColorMatrixScale
[2] == param
)
985 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
986 ctx
->Pixel
.PostColorMatrixScale
[2] = param
;
988 case GL_POST_COLOR_MATRIX_BLUE_BIAS
:
989 if (ctx
->Pixel
.PostColorMatrixBias
[2] == param
)
991 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
992 ctx
->Pixel
.PostColorMatrixBias
[2] = param
;
994 case GL_POST_COLOR_MATRIX_ALPHA_SCALE
:
995 if (ctx
->Pixel
.PostColorMatrixScale
[3] == param
)
997 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
998 ctx
->Pixel
.PostColorMatrixScale
[3] = param
;
1000 case GL_POST_COLOR_MATRIX_ALPHA_BIAS
:
1001 if (ctx
->Pixel
.PostColorMatrixBias
[3] == param
)
1003 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1004 ctx
->Pixel
.PostColorMatrixBias
[3] = param
;
1006 case GL_POST_CONVOLUTION_RED_SCALE
:
1007 if (ctx
->Pixel
.PostConvolutionScale
[0] == param
)
1009 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1010 ctx
->Pixel
.PostConvolutionScale
[0] = param
;
1012 case GL_POST_CONVOLUTION_RED_BIAS
:
1013 if (ctx
->Pixel
.PostConvolutionBias
[0] == param
)
1015 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1016 ctx
->Pixel
.PostConvolutionBias
[0] = param
;
1018 case GL_POST_CONVOLUTION_GREEN_SCALE
:
1019 if (ctx
->Pixel
.PostConvolutionScale
[1] == param
)
1021 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1022 ctx
->Pixel
.PostConvolutionScale
[1] = param
;
1024 case GL_POST_CONVOLUTION_GREEN_BIAS
:
1025 if (ctx
->Pixel
.PostConvolutionBias
[1] == param
)
1027 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1028 ctx
->Pixel
.PostConvolutionBias
[1] = param
;
1030 case GL_POST_CONVOLUTION_BLUE_SCALE
:
1031 if (ctx
->Pixel
.PostConvolutionScale
[2] == param
)
1033 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1034 ctx
->Pixel
.PostConvolutionScale
[2] = param
;
1036 case GL_POST_CONVOLUTION_BLUE_BIAS
:
1037 if (ctx
->Pixel
.PostConvolutionBias
[2] == param
)
1039 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1040 ctx
->Pixel
.PostConvolutionBias
[2] = param
;
1042 case GL_POST_CONVOLUTION_ALPHA_SCALE
:
1043 if (ctx
->Pixel
.PostConvolutionScale
[2] == param
)
1045 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1046 ctx
->Pixel
.PostConvolutionScale
[2] = param
;
1048 case GL_POST_CONVOLUTION_ALPHA_BIAS
:
1049 if (ctx
->Pixel
.PostConvolutionBias
[2] == param
)
1051 FLUSH_VERTICES(ctx
, _NEW_PIXEL
);
1052 ctx
->Pixel
.PostConvolutionBias
[2] = param
;
1055 _mesa_error( ctx
, GL_INVALID_ENUM
, "glPixelTransfer(pname)" );
1062 _mesa_PixelTransferi( GLenum pname
, GLint param
)
1064 _mesa_PixelTransferf( pname
, (GLfloat
) param
);
1069 /**********************************************************************/
1070 /***** Pixel processing functions ******/
1071 /**********************************************************************/
1074 * Apply scale and bias factors to an array of RGBA pixels.
1077 _mesa_scale_and_bias_rgba(GLuint n
, GLfloat rgba
[][4],
1078 GLfloat rScale
, GLfloat gScale
,
1079 GLfloat bScale
, GLfloat aScale
,
1080 GLfloat rBias
, GLfloat gBias
,
1081 GLfloat bBias
, GLfloat aBias
)
1083 if (rScale
!= 1.0 || rBias
!= 0.0) {
1085 for (i
= 0; i
< n
; i
++) {
1086 rgba
[i
][RCOMP
] = rgba
[i
][RCOMP
] * rScale
+ rBias
;
1089 if (gScale
!= 1.0 || gBias
!= 0.0) {
1091 for (i
= 0; i
< n
; i
++) {
1092 rgba
[i
][GCOMP
] = rgba
[i
][GCOMP
] * gScale
+ gBias
;
1095 if (bScale
!= 1.0 || bBias
!= 0.0) {
1097 for (i
= 0; i
< n
; i
++) {
1098 rgba
[i
][BCOMP
] = rgba
[i
][BCOMP
] * bScale
+ bBias
;
1101 if (aScale
!= 1.0 || aBias
!= 0.0) {
1103 for (i
= 0; i
< n
; i
++) {
1104 rgba
[i
][ACOMP
] = rgba
[i
][ACOMP
] * aScale
+ aBias
;
1111 * Apply pixel mapping to an array of floating point RGBA pixels.
1114 _mesa_map_rgba( const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4] )
1116 const GLfloat rscale
= (GLfloat
) (ctx
->Pixel
.MapRtoRsize
- 1);
1117 const GLfloat gscale
= (GLfloat
) (ctx
->Pixel
.MapGtoGsize
- 1);
1118 const GLfloat bscale
= (GLfloat
) (ctx
->Pixel
.MapBtoBsize
- 1);
1119 const GLfloat ascale
= (GLfloat
) (ctx
->Pixel
.MapAtoAsize
- 1);
1120 const GLfloat
*rMap
= ctx
->Pixel
.MapRtoR
;
1121 const GLfloat
*gMap
= ctx
->Pixel
.MapGtoG
;
1122 const GLfloat
*bMap
= ctx
->Pixel
.MapBtoB
;
1123 const GLfloat
*aMap
= ctx
->Pixel
.MapAtoA
;
1126 GLfloat r
= CLAMP(rgba
[i
][RCOMP
], 0.0F
, 1.0F
);
1127 GLfloat g
= CLAMP(rgba
[i
][GCOMP
], 0.0F
, 1.0F
);
1128 GLfloat b
= CLAMP(rgba
[i
][BCOMP
], 0.0F
, 1.0F
);
1129 GLfloat a
= CLAMP(rgba
[i
][ACOMP
], 0.0F
, 1.0F
);
1130 rgba
[i
][RCOMP
] = rMap
[IROUND(r
* rscale
)];
1131 rgba
[i
][GCOMP
] = gMap
[IROUND(g
* gscale
)];
1132 rgba
[i
][BCOMP
] = bMap
[IROUND(b
* bscale
)];
1133 rgba
[i
][ACOMP
] = aMap
[IROUND(a
* ascale
)];
1139 * Apply the color matrix and post color matrix scaling and biasing.
1142 _mesa_transform_rgba(const GLcontext
*ctx
, GLuint n
, GLfloat rgba
[][4])
1144 const GLfloat rs
= ctx
->Pixel
.PostColorMatrixScale
[0];
1145 const GLfloat rb
= ctx
->Pixel
.PostColorMatrixBias
[0];
1146 const GLfloat gs
= ctx
->Pixel
.PostColorMatrixScale
[1];
1147 const GLfloat gb
= ctx
->Pixel
.PostColorMatrixBias
[1];
1148 const GLfloat bs
= ctx
->Pixel
.PostColorMatrixScale
[2];
1149 const GLfloat bb
= ctx
->Pixel
.PostColorMatrixBias
[2];
1150 const GLfloat as
= ctx
->Pixel
.PostColorMatrixScale
[3];
1151 const GLfloat ab
= ctx
->Pixel
.PostColorMatrixBias
[3];
1152 const GLfloat
*m
= ctx
->ColorMatrixStack
.Top
->m
;
1154 for (i
= 0; i
< n
; i
++) {
1155 const GLfloat r
= rgba
[i
][RCOMP
];
1156 const GLfloat g
= rgba
[i
][GCOMP
];
1157 const GLfloat b
= rgba
[i
][BCOMP
];
1158 const GLfloat a
= rgba
[i
][ACOMP
];
1159 rgba
[i
][RCOMP
] = (m
[0] * r
+ m
[4] * g
+ m
[ 8] * b
+ m
[12] * a
) * rs
+ rb
;
1160 rgba
[i
][GCOMP
] = (m
[1] * r
+ m
[5] * g
+ m
[ 9] * b
+ m
[13] * a
) * gs
+ gb
;
1161 rgba
[i
][BCOMP
] = (m
[2] * r
+ m
[6] * g
+ m
[10] * b
+ m
[14] * a
) * bs
+ bb
;
1162 rgba
[i
][ACOMP
] = (m
[3] * r
+ m
[7] * g
+ m
[11] * b
+ m
[15] * a
) * as
+ ab
;
1168 * Apply a color table lookup to an array of floating point RGBA colors.
1171 _mesa_lookup_rgba_float(const struct gl_color_table
*table
,
1172 GLuint n
, GLfloat rgba
[][4])
1174 if (!table
->Table
|| table
->Size
== 0)
1177 switch (table
->Format
) {
1179 /* replace RGBA with I */
1180 if (table
->Type
== GL_FLOAT
) {
1181 const GLint max
= table
->Size
- 1;
1182 const GLfloat scale
= (GLfloat
) max
;
1183 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1185 for (i
= 0; i
< n
; i
++) {
1186 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1187 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1188 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] =
1189 rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = c
;
1193 const GLint max
= table
->Size
- 1;
1194 const GLfloat scale
= (GLfloat
) max
;
1195 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1197 for (i
= 0; i
< n
; i
++) {
1198 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1199 GLfloat c
= CHAN_TO_FLOAT(lut
[CLAMP(j
, 0, max
)]);
1200 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] =
1201 rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = c
;
1206 /* replace RGB with L */
1207 if (table
->Type
== GL_FLOAT
) {
1208 const GLint max
= table
->Size
- 1;
1209 const GLfloat scale
= (GLfloat
) max
;
1210 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1212 for (i
= 0; i
< n
; i
++) {
1213 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1214 GLfloat c
= lut
[CLAMP(j
, 0, max
)];
1215 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = c
;
1219 const GLint max
= table
->Size
- 1;
1220 const GLfloat scale
= (GLfloat
) max
;
1221 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1223 for (i
= 0; i
< n
; i
++) {
1224 GLint j
= IROUND(rgba
[i
][RCOMP
] * scale
);
1225 GLfloat c
= CHAN_TO_FLOAT(lut
[CLAMP(j
, 0, max
)]);
1226 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = c
;
1231 /* replace A with A */
1232 if (table
->Type
== GL_FLOAT
) {
1233 const GLint max
= table
->Size
- 1;
1234 const GLfloat scale
= (GLfloat
) max
;
1235 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1237 for (i
= 0; i
< n
; i
++) {
1238 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1239 rgba
[i
][ACOMP
] = lut
[CLAMP(j
, 0, max
)];
1243 const GLint max
= table
->Size
- 1;
1244 const GLfloat scale
= (GLfloat
) max
;
1245 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1247 for (i
= 0; i
< n
; i
++) {
1248 GLint j
= IROUND(rgba
[i
][ACOMP
] * scale
);
1249 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(lut
[CLAMP(j
, 0, max
)]);
1253 case GL_LUMINANCE_ALPHA
:
1254 /* replace RGBA with LLLA */
1255 if (table
->Type
== GL_FLOAT
) {
1256 const GLint max
= table
->Size
- 1;
1257 const GLfloat scale
= (GLfloat
) max
;
1258 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1260 for (i
= 0; i
< n
; i
++) {
1261 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1262 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1263 GLfloat luminance
, alpha
;
1264 jL
= CLAMP(jL
, 0, max
);
1265 jA
= CLAMP(jA
, 0, max
);
1266 luminance
= lut
[jL
* 2 + 0];
1267 alpha
= lut
[jA
* 2 + 1];
1268 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = luminance
;
1269 rgba
[i
][ACOMP
] = alpha
;;
1273 const GLint max
= table
->Size
- 1;
1274 const GLfloat scale
= (GLfloat
) max
;
1275 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1277 for (i
= 0; i
< n
; i
++) {
1278 GLint jL
= IROUND(rgba
[i
][RCOMP
] * scale
);
1279 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1280 GLfloat luminance
, alpha
;
1281 jL
= CLAMP(jL
, 0, max
);
1282 jA
= CLAMP(jA
, 0, max
);
1283 luminance
= CHAN_TO_FLOAT(lut
[jL
* 2 + 0]);
1284 alpha
= CHAN_TO_FLOAT(lut
[jA
* 2 + 1]);
1285 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = luminance
;
1286 rgba
[i
][ACOMP
] = alpha
;;
1291 /* replace RGB with RGB */
1292 if (table
->Type
== GL_FLOAT
) {
1293 const GLint max
= table
->Size
- 1;
1294 const GLfloat scale
= (GLfloat
) max
;
1295 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1297 for (i
= 0; i
< n
; i
++) {
1298 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1299 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1300 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1301 jR
= CLAMP(jR
, 0, max
);
1302 jG
= CLAMP(jG
, 0, max
);
1303 jB
= CLAMP(jB
, 0, max
);
1304 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1305 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1306 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1310 const GLint max
= table
->Size
- 1;
1311 const GLfloat scale
= (GLfloat
) max
;
1312 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1314 for (i
= 0; i
< n
; i
++) {
1315 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1316 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1317 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1318 jR
= CLAMP(jR
, 0, max
);
1319 jG
= CLAMP(jG
, 0, max
);
1320 jB
= CLAMP(jB
, 0, max
);
1321 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(lut
[jR
* 3 + 0]);
1322 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(lut
[jG
* 3 + 1]);
1323 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(lut
[jB
* 3 + 2]);
1328 /* replace RGBA with RGBA */
1329 if (table
->Type
== GL_FLOAT
) {
1330 const GLint max
= table
->Size
- 1;
1331 const GLfloat scale
= (GLfloat
) max
;
1332 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1334 for (i
= 0; i
< n
; i
++) {
1335 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1336 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1337 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1338 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1339 jR
= CLAMP(jR
, 0, max
);
1340 jG
= CLAMP(jG
, 0, max
);
1341 jB
= CLAMP(jB
, 0, max
);
1342 jA
= CLAMP(jA
, 0, max
);
1343 rgba
[i
][RCOMP
] = lut
[jR
* 4 + 0];
1344 rgba
[i
][GCOMP
] = lut
[jG
* 4 + 1];
1345 rgba
[i
][BCOMP
] = lut
[jB
* 4 + 2];
1346 rgba
[i
][ACOMP
] = lut
[jA
* 4 + 3];
1350 const GLint max
= table
->Size
- 1;
1351 const GLfloat scale
= (GLfloat
) max
;
1352 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1354 for (i
= 0; i
< n
; i
++) {
1355 GLint jR
= IROUND(rgba
[i
][RCOMP
] * scale
);
1356 GLint jG
= IROUND(rgba
[i
][GCOMP
] * scale
);
1357 GLint jB
= IROUND(rgba
[i
][BCOMP
] * scale
);
1358 GLint jA
= IROUND(rgba
[i
][ACOMP
] * scale
);
1359 jR
= CLAMP(jR
, 0, max
);
1360 jG
= CLAMP(jG
, 0, max
);
1361 jB
= CLAMP(jB
, 0, max
);
1362 jA
= CLAMP(jA
, 0, max
);
1363 rgba
[i
][RCOMP
] = CHAN_TO_FLOAT(lut
[jR
* 4 + 0]);
1364 rgba
[i
][GCOMP
] = CHAN_TO_FLOAT(lut
[jG
* 4 + 1]);
1365 rgba
[i
][BCOMP
] = CHAN_TO_FLOAT(lut
[jB
* 4 + 2]);
1366 rgba
[i
][ACOMP
] = CHAN_TO_FLOAT(lut
[jA
* 4 + 3]);
1371 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_float");
1379 * Apply a color table lookup to an array of GLchan RGBA colors.
1382 _mesa_lookup_rgba_chan(const struct gl_color_table
*table
,
1383 GLuint n
, GLchan rgba
[][4])
1385 if (!table
->Table
|| table
->Size
== 0)
1388 switch (table
->Format
) {
1390 /* replace RGBA with I */
1391 if (table
->Type
== GL_FLOAT
) {
1392 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1393 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1395 for (i
= 0; i
< n
; i
++) {
1396 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1398 CLAMPED_FLOAT_TO_CHAN(c
, lut
[j
]);
1399 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] =
1400 rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = c
;
1404 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1405 if (table
->Size
== 256) {
1407 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1409 for (i
= 0; i
< n
; i
++) {
1410 const GLchan c
= lut
[rgba
[i
][RCOMP
]];
1411 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] =
1412 rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = c
;
1418 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1419 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1421 for (i
= 0; i
< n
; i
++) {
1422 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1423 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] =
1424 rgba
[i
][BCOMP
] = rgba
[i
][ACOMP
] = lut
[j
];
1430 /* replace RGB with L */
1431 if (table
->Type
== GL_FLOAT
) {
1432 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1433 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1435 for (i
= 0; i
< n
; i
++) {
1436 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1438 CLAMPED_FLOAT_TO_CHAN(c
, lut
[j
]);
1439 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = c
;
1443 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1444 if (table
->Size
== 256) {
1446 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1448 for (i
= 0; i
< n
; i
++) {
1449 const GLchan c
= lut
[rgba
[i
][RCOMP
]];
1450 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = c
;
1456 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1457 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1459 for (i
= 0; i
< n
; i
++) {
1460 GLint j
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1461 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = lut
[j
];
1467 /* replace A with A */
1468 if (table
->Type
== GL_FLOAT
) {
1469 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1470 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1472 for (i
= 0; i
< n
; i
++) {
1473 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1475 CLAMPED_FLOAT_TO_CHAN(c
, lut
[j
]);
1480 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1481 if (table
->Size
== 256) {
1483 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1485 for (i
= 0; i
< n
; i
++) {
1486 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
]];
1492 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1493 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1495 for (i
= 0; i
< n
; i
++) {
1496 GLint j
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1497 rgba
[i
][ACOMP
] = lut
[j
];
1502 case GL_LUMINANCE_ALPHA
:
1503 /* replace RGBA with LLLA */
1504 if (table
->Type
== GL_FLOAT
) {
1505 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1506 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1508 for (i
= 0; i
< n
; i
++) {
1509 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1510 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1511 GLchan luminance
, alpha
;
1512 CLAMPED_FLOAT_TO_CHAN(luminance
, lut
[jL
* 2 + 0]);
1513 CLAMPED_FLOAT_TO_CHAN(alpha
, lut
[jA
* 2 + 1]);
1514 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = luminance
;
1515 rgba
[i
][ACOMP
] = alpha
;;
1519 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1520 if (table
->Size
== 256) {
1522 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1524 for (i
= 0; i
< n
; i
++) {
1525 GLchan l
= lut
[rgba
[i
][RCOMP
] * 2 + 0];
1526 GLchan a
= lut
[rgba
[i
][ACOMP
] * 2 + 1];;
1527 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = l
;
1534 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1535 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1537 for (i
= 0; i
< n
; i
++) {
1538 GLint jL
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1539 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1540 GLchan luminance
= lut
[jL
* 2 + 0];
1541 GLchan alpha
= lut
[jA
* 2 + 1];
1542 rgba
[i
][RCOMP
] = rgba
[i
][GCOMP
] = rgba
[i
][BCOMP
] = luminance
;
1543 rgba
[i
][ACOMP
] = alpha
;
1549 /* replace RGB with RGB */
1550 if (table
->Type
== GL_FLOAT
) {
1551 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1552 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1554 for (i
= 0; i
< n
; i
++) {
1555 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1556 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1557 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1558 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 3 + 0]);
1559 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 3 + 1]);
1560 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 3 + 2]);
1564 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1565 if (table
->Size
== 256) {
1567 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1569 for (i
= 0; i
< n
; i
++) {
1570 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 3 + 0];
1571 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 3 + 1];
1572 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 3 + 2];
1578 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1579 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1581 for (i
= 0; i
< n
; i
++) {
1582 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1583 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1584 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1585 rgba
[i
][RCOMP
] = lut
[jR
* 3 + 0];
1586 rgba
[i
][GCOMP
] = lut
[jG
* 3 + 1];
1587 rgba
[i
][BCOMP
] = lut
[jB
* 3 + 2];
1593 /* replace RGBA with RGBA */
1594 if (table
->Type
== GL_FLOAT
) {
1595 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1596 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1598 for (i
= 0; i
< n
; i
++) {
1599 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1600 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1601 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1602 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1603 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1604 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1605 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1606 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1610 #if CHAN_TYPE == GL_UNSIGNED_BYTE
1611 if (table
->Size
== 256) {
1613 const GLchan
*lut
= (const GLchan
*) table
->Table
;
1615 for (i
= 0; i
< n
; i
++) {
1616 rgba
[i
][RCOMP
] = lut
[rgba
[i
][RCOMP
] * 4 + 0];
1617 rgba
[i
][GCOMP
] = lut
[rgba
[i
][GCOMP
] * 4 + 1];
1618 rgba
[i
][BCOMP
] = lut
[rgba
[i
][BCOMP
] * 4 + 2];
1619 rgba
[i
][ACOMP
] = lut
[rgba
[i
][ACOMP
] * 4 + 3];
1625 const GLfloat scale
= (GLfloat
) (table
->Size
- 1) / CHAN_MAXF
;
1626 const GLfloat
*lut
= (const GLfloat
*) table
->Table
;
1628 for (i
= 0; i
< n
; i
++) {
1629 GLint jR
= IROUND((GLfloat
) rgba
[i
][RCOMP
] * scale
);
1630 GLint jG
= IROUND((GLfloat
) rgba
[i
][GCOMP
] * scale
);
1631 GLint jB
= IROUND((GLfloat
) rgba
[i
][BCOMP
] * scale
);
1632 GLint jA
= IROUND((GLfloat
) rgba
[i
][ACOMP
] * scale
);
1633 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], lut
[jR
* 4 + 0]);
1634 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], lut
[jG
* 4 + 1]);
1635 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], lut
[jB
* 4 + 2]);
1636 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], lut
[jA
* 4 + 3]);
1642 _mesa_problem(NULL
, "Bad format in _mesa_lookup_rgba_chan");
1650 * Apply color index shift and offset to an array of pixels.
1653 _mesa_shift_and_offset_ci( const GLcontext
*ctx
, GLuint n
, GLuint indexes
[] )
1655 GLint shift
= ctx
->Pixel
.IndexShift
;
1656 GLint offset
= ctx
->Pixel
.IndexOffset
;
1660 indexes
[i
] = (indexes
[i
] << shift
) + offset
;
1663 else if (shift
< 0) {
1666 indexes
[i
] = (indexes
[i
] >> shift
) + offset
;
1671 indexes
[i
] = indexes
[i
] + offset
;
1678 * Apply color index mapping to color indexes.
1681 _mesa_map_ci( const GLcontext
*ctx
, GLuint n
, GLuint index
[] )
1683 GLuint mask
= ctx
->Pixel
.MapItoIsize
- 1;
1686 index
[i
] = ctx
->Pixel
.MapItoI
[ index
[i
] & mask
];
1692 * Map color indexes to rgba values.
1695 _mesa_map_ci_to_rgba_chan( const GLcontext
*ctx
, GLuint n
,
1696 const GLuint index
[], GLchan rgba
[][4] )
1699 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
1700 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
1701 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
1702 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
1703 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
1704 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
1705 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
1706 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
1709 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1710 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1711 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1712 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1715 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
1716 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
1717 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
1718 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
1719 const GLfloat
*rMap
= ctx
->Pixel
.MapItoR
;
1720 const GLfloat
*gMap
= ctx
->Pixel
.MapItoG
;
1721 const GLfloat
*bMap
= ctx
->Pixel
.MapItoB
;
1722 const GLfloat
*aMap
= ctx
->Pixel
.MapItoA
;
1725 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], rMap
[index
[i
] & rmask
]);
1726 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], gMap
[index
[i
] & gmask
]);
1727 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], bMap
[index
[i
] & bmask
]);
1728 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], aMap
[index
[i
] & amask
]);
1735 * Map color indexes to float rgba values.
1738 _mesa_map_ci_to_rgba( const GLcontext
*ctx
, GLuint n
,
1739 const GLuint index
[], GLfloat rgba
[][4] )
1741 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
1742 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
1743 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
1744 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
1745 const GLfloat
*rMap
= ctx
->Pixel
.MapItoR
;
1746 const GLfloat
*gMap
= ctx
->Pixel
.MapItoG
;
1747 const GLfloat
*bMap
= ctx
->Pixel
.MapItoB
;
1748 const GLfloat
*aMap
= ctx
->Pixel
.MapItoA
;
1751 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1752 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1753 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1754 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1760 * Map 8-bit color indexes to rgb values.
1763 _mesa_map_ci8_to_rgba( const GLcontext
*ctx
, GLuint n
, const GLubyte index
[],
1767 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
1768 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
1769 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
1770 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
1771 const GLubyte
*rMap
= ctx
->Pixel
.MapItoR8
;
1772 const GLubyte
*gMap
= ctx
->Pixel
.MapItoG8
;
1773 const GLubyte
*bMap
= ctx
->Pixel
.MapItoB8
;
1774 const GLubyte
*aMap
= ctx
->Pixel
.MapItoA8
;
1777 rgba
[i
][RCOMP
] = rMap
[index
[i
] & rmask
];
1778 rgba
[i
][GCOMP
] = gMap
[index
[i
] & gmask
];
1779 rgba
[i
][BCOMP
] = bMap
[index
[i
] & bmask
];
1780 rgba
[i
][ACOMP
] = aMap
[index
[i
] & amask
];
1783 GLuint rmask
= ctx
->Pixel
.MapItoRsize
- 1;
1784 GLuint gmask
= ctx
->Pixel
.MapItoGsize
- 1;
1785 GLuint bmask
= ctx
->Pixel
.MapItoBsize
- 1;
1786 GLuint amask
= ctx
->Pixel
.MapItoAsize
- 1;
1787 const GLfloat
*rMap
= ctx
->Pixel
.MapItoR
;
1788 const GLfloat
*gMap
= ctx
->Pixel
.MapItoG
;
1789 const GLfloat
*bMap
= ctx
->Pixel
.MapItoB
;
1790 const GLfloat
*aMap
= ctx
->Pixel
.MapItoA
;
1793 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][RCOMP
], rMap
[index
[i
] & rmask
]);
1794 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][GCOMP
], gMap
[index
[i
] & gmask
]);
1795 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][BCOMP
], bMap
[index
[i
] & bmask
]);
1796 CLAMPED_FLOAT_TO_CHAN(rgba
[i
][ACOMP
], aMap
[index
[i
] & amask
]);
1803 _mesa_shift_and_offset_stencil( const GLcontext
*ctx
, GLuint n
,
1804 GLstencil stencil
[] )
1807 GLint shift
= ctx
->Pixel
.IndexShift
;
1808 GLint offset
= ctx
->Pixel
.IndexOffset
;
1811 stencil
[i
] = (stencil
[i
] << shift
) + offset
;
1814 else if (shift
< 0) {
1817 stencil
[i
] = (stencil
[i
] >> shift
) + offset
;
1822 stencil
[i
] = stencil
[i
] + offset
;
1830 _mesa_map_stencil( const GLcontext
*ctx
, GLuint n
, GLstencil stencil
[] )
1832 GLuint mask
= ctx
->Pixel
.MapStoSsize
- 1;
1835 stencil
[i
] = ctx
->Pixel
.MapStoS
[ stencil
[i
] & mask
];
1842 * This function converts an array of GLchan colors to GLfloat colors.
1843 * Most importantly, it undoes the non-uniform quantization of pixel
1844 * values introduced when we convert shallow (< 8 bit) pixel values
1845 * to GLubytes in the ctx->Driver.ReadRGBASpan() functions.
1846 * This fixes a number of OpenGL conformance failures when running on
1847 * 16bpp displays, for example.
1850 _mesa_chan_to_float_span(const GLcontext
*ctx
, GLuint n
,
1851 CONST GLchan rgba
[][4], GLfloat rgbaf
[][4])
1853 #if CHAN_TYPE == GL_FLOAT
1854 MEMCPY(rgbaf
, rgba
, n
* 4 * sizeof(GLfloat
));
1856 const GLuint rShift
= CHAN_BITS
- ctx
->Visual
.redBits
;
1857 const GLuint gShift
= CHAN_BITS
- ctx
->Visual
.greenBits
;
1858 const GLuint bShift
= CHAN_BITS
- ctx
->Visual
.blueBits
;
1860 const GLfloat rScale
= 1.0F
/ (GLfloat
) ((1 << ctx
->Visual
.redBits
) - 1);
1861 const GLfloat gScale
= 1.0F
/ (GLfloat
) ((1 << ctx
->Visual
.greenBits
) - 1);
1862 const GLfloat bScale
= 1.0F
/ (GLfloat
) ((1 << ctx
->Visual
.blueBits
) - 1);
1866 if (ctx
->Visual
.alphaBits
> 0) {
1867 aShift
= CHAN_BITS
- ctx
->Visual
.alphaBits
;
1868 aScale
= 1.0F
/ (GLfloat
) ((1 << ctx
->Visual
.alphaBits
) - 1);
1872 aScale
= 1.0F
/ CHAN_MAXF
;
1875 for (i
= 0; i
< n
; i
++) {
1876 const GLint r
= rgba
[i
][RCOMP
] >> rShift
;
1877 const GLint g
= rgba
[i
][GCOMP
] >> gShift
;
1878 const GLint b
= rgba
[i
][BCOMP
] >> bShift
;
1879 const GLint a
= rgba
[i
][ACOMP
] >> aShift
;
1880 rgbaf
[i
][RCOMP
] = (GLfloat
) r
* rScale
;
1881 rgbaf
[i
][GCOMP
] = (GLfloat
) g
* gScale
;
1882 rgbaf
[i
][BCOMP
] = (GLfloat
) b
* bScale
;
1883 rgbaf
[i
][ACOMP
] = (GLfloat
) a
* aScale
;
1888 /**********************************************************************/
1889 /***** State Management *****/
1890 /**********************************************************************/
1893 * Return a bitmask of IMAGE_*_BIT flags which to indicate which
1894 * pixel transfer operations are enabled.
1897 update_image_transfer_state(GLcontext
*ctx
)
1901 if (ctx
->Pixel
.RedScale
!= 1.0F
|| ctx
->Pixel
.RedBias
!= 0.0F
||
1902 ctx
->Pixel
.GreenScale
!= 1.0F
|| ctx
->Pixel
.GreenBias
!= 0.0F
||
1903 ctx
->Pixel
.BlueScale
!= 1.0F
|| ctx
->Pixel
.BlueBias
!= 0.0F
||
1904 ctx
->Pixel
.AlphaScale
!= 1.0F
|| ctx
->Pixel
.AlphaBias
!= 0.0F
)
1905 mask
|= IMAGE_SCALE_BIAS_BIT
;
1907 if (ctx
->Pixel
.IndexShift
|| ctx
->Pixel
.IndexOffset
)
1908 mask
|= IMAGE_SHIFT_OFFSET_BIT
;
1910 if (ctx
->Pixel
.MapColorFlag
)
1911 mask
|= IMAGE_MAP_COLOR_BIT
;
1913 if (ctx
->Pixel
.ColorTableEnabled
)
1914 mask
|= IMAGE_COLOR_TABLE_BIT
;
1916 if (ctx
->Pixel
.Convolution1DEnabled
||
1917 ctx
->Pixel
.Convolution2DEnabled
||
1918 ctx
->Pixel
.Separable2DEnabled
) {
1919 mask
|= IMAGE_CONVOLUTION_BIT
;
1920 if (ctx
->Pixel
.PostConvolutionScale
[0] != 1.0F
||
1921 ctx
->Pixel
.PostConvolutionScale
[1] != 1.0F
||
1922 ctx
->Pixel
.PostConvolutionScale
[2] != 1.0F
||
1923 ctx
->Pixel
.PostConvolutionScale
[3] != 1.0F
||
1924 ctx
->Pixel
.PostConvolutionBias
[0] != 0.0F
||
1925 ctx
->Pixel
.PostConvolutionBias
[1] != 0.0F
||
1926 ctx
->Pixel
.PostConvolutionBias
[2] != 0.0F
||
1927 ctx
->Pixel
.PostConvolutionBias
[3] != 0.0F
) {
1928 mask
|= IMAGE_POST_CONVOLUTION_SCALE_BIAS
;
1932 if (ctx
->Pixel
.PostConvolutionColorTableEnabled
)
1933 mask
|= IMAGE_POST_CONVOLUTION_COLOR_TABLE_BIT
;
1935 if (ctx
->ColorMatrixStack
.Top
->type
!= MATRIX_IDENTITY
||
1936 ctx
->Pixel
.PostColorMatrixScale
[0] != 1.0F
||
1937 ctx
->Pixel
.PostColorMatrixBias
[0] != 0.0F
||
1938 ctx
->Pixel
.PostColorMatrixScale
[1] != 1.0F
||
1939 ctx
->Pixel
.PostColorMatrixBias
[1] != 0.0F
||
1940 ctx
->Pixel
.PostColorMatrixScale
[2] != 1.0F
||
1941 ctx
->Pixel
.PostColorMatrixBias
[2] != 0.0F
||
1942 ctx
->Pixel
.PostColorMatrixScale
[3] != 1.0F
||
1943 ctx
->Pixel
.PostColorMatrixBias
[3] != 0.0F
)
1944 mask
|= IMAGE_COLOR_MATRIX_BIT
;
1946 if (ctx
->Pixel
.PostColorMatrixColorTableEnabled
)
1947 mask
|= IMAGE_POST_COLOR_MATRIX_COLOR_TABLE_BIT
;
1949 if (ctx
->Pixel
.HistogramEnabled
)
1950 mask
|= IMAGE_HISTOGRAM_BIT
;
1952 if (ctx
->Pixel
.MinMaxEnabled
)
1953 mask
|= IMAGE_MIN_MAX_BIT
;
1955 ctx
->_ImageTransferState
= mask
;
1959 void _mesa_update_pixel( GLcontext
*ctx
, GLuint new_state
)
1961 if (new_state
& _NEW_COLOR_MATRIX
)
1962 _math_matrix_analyse( ctx
->ColorMatrixStack
.Top
);
1964 /* References ColorMatrix.type (derived above).
1966 if (new_state
& _IMAGE_NEW_TRANSFER_STATE
)
1967 update_image_transfer_state(ctx
);
1971 /**********************************************************************/
1972 /***** Initialization *****/
1973 /**********************************************************************/
1977 * Initialize the context's PIXEL attribute group.
1980 _mesa_init_pixel( GLcontext
*ctx
)
1985 ctx
->Pixel
.RedBias
= 0.0;
1986 ctx
->Pixel
.RedScale
= 1.0;
1987 ctx
->Pixel
.GreenBias
= 0.0;
1988 ctx
->Pixel
.GreenScale
= 1.0;
1989 ctx
->Pixel
.BlueBias
= 0.0;
1990 ctx
->Pixel
.BlueScale
= 1.0;
1991 ctx
->Pixel
.AlphaBias
= 0.0;
1992 ctx
->Pixel
.AlphaScale
= 1.0;
1993 ctx
->Pixel
.DepthBias
= 0.0;
1994 ctx
->Pixel
.DepthScale
= 1.0;
1995 ctx
->Pixel
.IndexOffset
= 0;
1996 ctx
->Pixel
.IndexShift
= 0;
1997 ctx
->Pixel
.ZoomX
= 1.0;
1998 ctx
->Pixel
.ZoomY
= 1.0;
1999 ctx
->Pixel
.MapColorFlag
= GL_FALSE
;
2000 ctx
->Pixel
.MapStencilFlag
= GL_FALSE
;
2001 ctx
->Pixel
.MapStoSsize
= 1;
2002 ctx
->Pixel
.MapItoIsize
= 1;
2003 ctx
->Pixel
.MapItoRsize
= 1;
2004 ctx
->Pixel
.MapItoGsize
= 1;
2005 ctx
->Pixel
.MapItoBsize
= 1;
2006 ctx
->Pixel
.MapItoAsize
= 1;
2007 ctx
->Pixel
.MapRtoRsize
= 1;
2008 ctx
->Pixel
.MapGtoGsize
= 1;
2009 ctx
->Pixel
.MapBtoBsize
= 1;
2010 ctx
->Pixel
.MapAtoAsize
= 1;
2011 ctx
->Pixel
.MapStoS
[0] = 0;
2012 ctx
->Pixel
.MapItoI
[0] = 0;
2013 ctx
->Pixel
.MapItoR
[0] = 0.0;
2014 ctx
->Pixel
.MapItoG
[0] = 0.0;
2015 ctx
->Pixel
.MapItoB
[0] = 0.0;
2016 ctx
->Pixel
.MapItoA
[0] = 0.0;
2017 ctx
->Pixel
.MapItoR8
[0] = 0;
2018 ctx
->Pixel
.MapItoG8
[0] = 0;
2019 ctx
->Pixel
.MapItoB8
[0] = 0;
2020 ctx
->Pixel
.MapItoA8
[0] = 0;
2021 ctx
->Pixel
.MapRtoR
[0] = 0.0;
2022 ctx
->Pixel
.MapGtoG
[0] = 0.0;
2023 ctx
->Pixel
.MapBtoB
[0] = 0.0;
2024 ctx
->Pixel
.MapAtoA
[0] = 0.0;
2025 ctx
->Pixel
.HistogramEnabled
= GL_FALSE
;
2026 ctx
->Pixel
.MinMaxEnabled
= GL_FALSE
;
2027 ctx
->Pixel
.PixelTextureEnabled
= GL_FALSE
;
2028 ctx
->Pixel
.FragmentRgbSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2029 ctx
->Pixel
.FragmentAlphaSource
= GL_PIXEL_GROUP_COLOR_SGIS
;
2030 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixScale
, 1.0, 1.0, 1.0, 1.0);
2031 ASSIGN_4V(ctx
->Pixel
.PostColorMatrixBias
, 0.0, 0.0, 0.0, 0.0);
2032 ASSIGN_4V(ctx
->Pixel
.ColorTableScale
, 1.0, 1.0, 1.0, 1.0);
2033 ASSIGN_4V(ctx
->Pixel
.ColorTableBias
, 0.0, 0.0, 0.0, 0.0);
2034 ASSIGN_4V(ctx
->Pixel
.PCCTscale
, 1.0, 1.0, 1.0, 1.0);
2035 ASSIGN_4V(ctx
->Pixel
.PCCTbias
, 0.0, 0.0, 0.0, 0.0);
2036 ASSIGN_4V(ctx
->Pixel
.PCMCTscale
, 1.0, 1.0, 1.0, 1.0);
2037 ASSIGN_4V(ctx
->Pixel
.PCMCTbias
, 0.0, 0.0, 0.0, 0.0);
2038 ctx
->Pixel
.ColorTableEnabled
= GL_FALSE
;
2039 ctx
->Pixel
.PostConvolutionColorTableEnabled
= GL_FALSE
;
2040 ctx
->Pixel
.PostColorMatrixColorTableEnabled
= GL_FALSE
;
2041 ctx
->Pixel
.Convolution1DEnabled
= GL_FALSE
;
2042 ctx
->Pixel
.Convolution2DEnabled
= GL_FALSE
;
2043 ctx
->Pixel
.Separable2DEnabled
= GL_FALSE
;
2044 for (i
= 0; i
< 3; i
++) {
2045 ASSIGN_4V(ctx
->Pixel
.ConvolutionBorderColor
[i
], 0.0, 0.0, 0.0, 0.0);
2046 ctx
->Pixel
.ConvolutionBorderMode
[i
] = GL_REDUCE
;
2047 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterScale
[i
], 1.0, 1.0, 1.0, 1.0);
2048 ASSIGN_4V(ctx
->Pixel
.ConvolutionFilterBias
[i
], 0.0, 0.0, 0.0, 0.0);
2050 for (i
= 0; i
< MAX_CONVOLUTION_WIDTH
* MAX_CONVOLUTION_WIDTH
* 4; i
++) {
2051 ctx
->Convolution1D
.Filter
[i
] = 0.0;
2052 ctx
->Convolution2D
.Filter
[i
] = 0.0;
2053 ctx
->Separable2D
.Filter
[i
] = 0.0;
2055 ASSIGN_4V(ctx
->Pixel
.PostConvolutionScale
, 1.0, 1.0, 1.0, 1.0);
2056 ASSIGN_4V(ctx
->Pixel
.PostConvolutionBias
, 0.0, 0.0, 0.0, 0.0);
2057 /* GL_SGI_texture_color_table */
2058 ASSIGN_4V(ctx
->Pixel
.TextureColorTableScale
, 1.0, 1.0, 1.0, 1.0);
2059 ASSIGN_4V(ctx
->Pixel
.TextureColorTableBias
, 0.0, 0.0, 0.0, 0.0);
2061 /* Pixel transfer */
2062 ctx
->Pack
.Alignment
= 4;
2063 ctx
->Pack
.RowLength
= 0;
2064 ctx
->Pack
.ImageHeight
= 0;
2065 ctx
->Pack
.SkipPixels
= 0;
2066 ctx
->Pack
.SkipRows
= 0;
2067 ctx
->Pack
.SkipImages
= 0;
2068 ctx
->Pack
.SwapBytes
= GL_FALSE
;
2069 ctx
->Pack
.LsbFirst
= GL_FALSE
;
2070 ctx
->Pack
.ClientStorage
= GL_FALSE
;
2071 ctx
->Pack
.Invert
= GL_FALSE
;
2072 #if FEATURE_EXT_pixel_buffer_object
2073 ctx
->Pack
.BufferObj
= ctx
->Array
.NullBufferObj
;
2075 ctx
->Unpack
.Alignment
= 4;
2076 ctx
->Unpack
.RowLength
= 0;
2077 ctx
->Unpack
.ImageHeight
= 0;
2078 ctx
->Unpack
.SkipPixels
= 0;
2079 ctx
->Unpack
.SkipRows
= 0;
2080 ctx
->Unpack
.SkipImages
= 0;
2081 ctx
->Unpack
.SwapBytes
= GL_FALSE
;
2082 ctx
->Unpack
.LsbFirst
= GL_FALSE
;
2083 ctx
->Unpack
.ClientStorage
= GL_FALSE
;
2084 ctx
->Unpack
.Invert
= GL_FALSE
;
2085 #if FEATURE_EXT_pixel_buffer_object
2086 ctx
->Unpack
.BufferObj
= ctx
->Array
.NullBufferObj
;
2090 * _mesa_unpack_image() returns image data in this format. When we
2091 * execute image commands (glDrawPixels(), glTexImage(), etc) from
2092 * within display lists we have to be sure to set the current
2093 * unpacking parameters to these values!
2095 ctx
->DefaultPacking
.Alignment
= 1;
2096 ctx
->DefaultPacking
.RowLength
= 0;
2097 ctx
->DefaultPacking
.SkipPixels
= 0;
2098 ctx
->DefaultPacking
.SkipRows
= 0;
2099 ctx
->DefaultPacking
.ImageHeight
= 0;
2100 ctx
->DefaultPacking
.SkipImages
= 0;
2101 ctx
->DefaultPacking
.SwapBytes
= GL_FALSE
;
2102 ctx
->DefaultPacking
.LsbFirst
= GL_FALSE
;
2103 ctx
->DefaultPacking
.ClientStorage
= GL_FALSE
;
2104 ctx
->DefaultPacking
.Invert
= GL_FALSE
;
2105 #if FEATURE_EXT_pixel_buffer_object
2106 ctx
->DefaultPacking
.BufferObj
= ctx
->Array
.NullBufferObj
;
2109 if (ctx
->Visual
.doubleBufferMode
) {
2110 ctx
->Pixel
.ReadBuffer
= GL_BACK
;
2113 ctx
->Pixel
.ReadBuffer
= GL_FRONT
;
2117 ctx
->_ImageTransferState
= 0;