1 /* $Id: colortab.c,v 1.46 2002/10/24 23:57:19 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39 * Given an internalFormat token passed to glColorTable,
40 * return the corresponding base format.
41 * Return -1 if invalid token.
44 base_colortab_format( GLenum format
)
59 case GL_LUMINANCE_ALPHA
:
60 case GL_LUMINANCE4_ALPHA4
:
61 case GL_LUMINANCE6_ALPHA2
:
62 case GL_LUMINANCE8_ALPHA8
:
63 case GL_LUMINANCE12_ALPHA4
:
64 case GL_LUMINANCE12_ALPHA12
:
65 case GL_LUMINANCE16_ALPHA16
:
66 return GL_LUMINANCE_ALPHA
;
92 return -1; /* error */
98 _mesa_init_colortable( struct gl_color_table
*p
)
100 p
->FloatTable
= GL_FALSE
;
103 p
->IntFormat
= GL_RGBA
;
109 _mesa_free_colortable_data( struct gl_color_table
*p
)
119 * Examine table's format and set the component sizes accordingly.
122 set_component_sizes( struct gl_color_table
*table
)
124 switch (table
->Format
) {
127 table
->GreenSize
= 0;
129 table
->AlphaSize
= CHAN_BITS
;
130 table
->IntensitySize
= 0;
131 table
->LuminanceSize
= 0;
135 table
->GreenSize
= 0;
137 table
->AlphaSize
= 0;
138 table
->IntensitySize
= 0;
139 table
->LuminanceSize
= CHAN_BITS
;
141 case GL_LUMINANCE_ALPHA
:
143 table
->GreenSize
= 0;
145 table
->AlphaSize
= CHAN_BITS
;
146 table
->IntensitySize
= 0;
147 table
->LuminanceSize
= CHAN_BITS
;
151 table
->GreenSize
= 0;
153 table
->AlphaSize
= 0;
154 table
->IntensitySize
= CHAN_BITS
;
155 table
->LuminanceSize
= 0;
158 table
->RedSize
= CHAN_BITS
;
159 table
->GreenSize
= CHAN_BITS
;
160 table
->BlueSize
= CHAN_BITS
;
161 table
->AlphaSize
= 0;
162 table
->IntensitySize
= 0;
163 table
->LuminanceSize
= 0;
166 table
->RedSize
= CHAN_BITS
;
167 table
->GreenSize
= CHAN_BITS
;
168 table
->BlueSize
= CHAN_BITS
;
169 table
->AlphaSize
= CHAN_BITS
;
170 table
->IntensitySize
= 0;
171 table
->LuminanceSize
= 0;
174 _mesa_problem(NULL
, "unexpected format in set_component_sizes");
181 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
182 GLsizei width
, GLenum format
, GLenum type
,
185 GET_CURRENT_CONTEXT(ctx
);
186 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
187 struct gl_texture_object
*texObj
= NULL
;
188 struct gl_color_table
*table
= NULL
;
189 GLboolean proxy
= GL_FALSE
;
191 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
192 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
193 GLboolean floatTable
= GL_FALSE
;
195 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
199 texObj
= texUnit
->Current1D
;
200 table
= &texObj
->Palette
;
203 texObj
= texUnit
->Current2D
;
204 table
= &texObj
->Palette
;
207 texObj
= texUnit
->Current3D
;
208 table
= &texObj
->Palette
;
210 case GL_TEXTURE_CUBE_MAP_ARB
:
211 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
212 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
215 texObj
= texUnit
->CurrentCubeMap
;
216 table
= &texObj
->Palette
;
218 case GL_PROXY_TEXTURE_1D
:
219 texObj
= ctx
->Texture
.Proxy1D
;
220 table
= &texObj
->Palette
;
223 case GL_PROXY_TEXTURE_2D
:
224 texObj
= ctx
->Texture
.Proxy2D
;
225 table
= &texObj
->Palette
;
228 case GL_PROXY_TEXTURE_3D
:
229 texObj
= ctx
->Texture
.Proxy3D
;
230 table
= &texObj
->Palette
;
233 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
234 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
235 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
238 texObj
= ctx
->Texture
.ProxyCubeMap
;
239 table
= &texObj
->Palette
;
241 case GL_SHARED_TEXTURE_PALETTE_EXT
:
242 table
= &ctx
->Texture
.Palette
;
245 table
= &ctx
->ColorTable
;
246 floatTable
= GL_TRUE
;
247 rScale
= ctx
->Pixel
.ColorTableScale
[0];
248 gScale
= ctx
->Pixel
.ColorTableScale
[1];
249 bScale
= ctx
->Pixel
.ColorTableScale
[2];
250 aScale
= ctx
->Pixel
.ColorTableScale
[3];
251 rBias
= ctx
->Pixel
.ColorTableBias
[0];
252 gBias
= ctx
->Pixel
.ColorTableBias
[1];
253 bBias
= ctx
->Pixel
.ColorTableBias
[2];
254 aBias
= ctx
->Pixel
.ColorTableBias
[3];
256 case GL_PROXY_COLOR_TABLE
:
257 table
= &ctx
->ProxyColorTable
;
260 case GL_POST_CONVOLUTION_COLOR_TABLE
:
261 table
= &ctx
->PostConvolutionColorTable
;
262 floatTable
= GL_TRUE
;
263 rScale
= ctx
->Pixel
.PCCTscale
[0];
264 gScale
= ctx
->Pixel
.PCCTscale
[1];
265 bScale
= ctx
->Pixel
.PCCTscale
[2];
266 aScale
= ctx
->Pixel
.PCCTscale
[3];
267 rBias
= ctx
->Pixel
.PCCTbias
[0];
268 gBias
= ctx
->Pixel
.PCCTbias
[1];
269 bBias
= ctx
->Pixel
.PCCTbias
[2];
270 aBias
= ctx
->Pixel
.PCCTbias
[3];
272 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
273 table
= &ctx
->ProxyPostConvolutionColorTable
;
276 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
277 table
= &ctx
->PostColorMatrixColorTable
;
278 floatTable
= GL_TRUE
;
279 rScale
= ctx
->Pixel
.PCMCTscale
[0];
280 gScale
= ctx
->Pixel
.PCMCTscale
[1];
281 bScale
= ctx
->Pixel
.PCMCTscale
[2];
282 aScale
= ctx
->Pixel
.PCMCTscale
[3];
283 rBias
= ctx
->Pixel
.PCMCTbias
[0];
284 gBias
= ctx
->Pixel
.PCMCTbias
[1];
285 bBias
= ctx
->Pixel
.PCMCTbias
[2];
286 aBias
= ctx
->Pixel
.PCMCTbias
[3];
288 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
289 table
= &ctx
->ProxyPostColorMatrixColorTable
;
293 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
299 if (!_mesa_is_legal_format_and_type(format
, type
) ||
300 format
== GL_INTENSITY
) {
301 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
305 baseFormat
= base_colortab_format(internalFormat
);
306 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
311 if (width
< 0 || (width
!= 0 && _mesa_bitcount(width
) != 1)) {
315 table
->IntFormat
= (GLenum
) 0;
316 table
->Format
= (GLenum
) 0;
319 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width=%d)", width
);
324 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
327 table
->IntFormat
= (GLenum
) 0;
328 table
->Format
= (GLenum
) 0;
331 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
337 table
->IntFormat
= internalFormat
;
338 table
->Format
= (GLenum
) baseFormat
;
339 set_component_sizes(table
);
341 comps
= _mesa_components_in_format(table
->Format
);
342 assert(comps
> 0); /* error should have been caught sooner */
345 /* free old table, if any */
352 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
356 _mesa_unpack_float_color_span(ctx
, width
, table
->Format
,
358 format
, type
, data
, &ctx
->Unpack
,
361 table
->FloatTable
= GL_TRUE
;
362 table
->Table
= MALLOC(comps
* width
* sizeof(GLfloat
));
364 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
368 tableF
= (GLfloat
*) table
->Table
;
370 switch (table
->Format
) {
372 for (i
= 0; i
< width
; i
++) {
373 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
377 for (i
= 0; i
< width
; i
++) {
378 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
382 for (i
= 0; i
< width
; i
++) {
383 tableF
[i
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
386 case GL_LUMINANCE_ALPHA
:
387 for (i
= 0; i
< width
; i
++) {
388 tableF
[i
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
389 tableF
[i
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
393 for (i
= 0; i
< width
; i
++) {
394 tableF
[i
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
395 tableF
[i
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
396 tableF
[i
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
400 for (i
= 0; i
< width
; i
++) {
401 tableF
[i
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
402 tableF
[i
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
403 tableF
[i
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
404 tableF
[i
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
408 _mesa_problem(ctx
, "Bad format in _mesa_ColorTable");
413 /* store GLchan table */
414 table
->FloatTable
= GL_FALSE
;
415 table
->Table
= MALLOC(comps
* width
* sizeof(GLchan
));
417 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
420 _mesa_unpack_chan_color_span(ctx
, width
, table
->Format
,
421 (GLchan
*) table
->Table
, /* dest */
428 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
429 /* texture object palette, texObj==NULL means the shared palette */
430 if (ctx
->Driver
.UpdateTexturePalette
) {
431 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
435 ctx
->NewState
|= _NEW_PIXEL
;
441 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
442 GLsizei count
, GLenum format
, GLenum type
,
445 GET_CURRENT_CONTEXT(ctx
);
446 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
447 struct gl_texture_object
*texObj
= NULL
;
448 struct gl_color_table
*table
= NULL
;
449 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
450 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
452 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
456 texObj
= texUnit
->Current1D
;
457 table
= &texObj
->Palette
;
460 texObj
= texUnit
->Current2D
;
461 table
= &texObj
->Palette
;
464 texObj
= texUnit
->Current3D
;
465 table
= &texObj
->Palette
;
467 case GL_TEXTURE_CUBE_MAP_ARB
:
468 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
469 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
472 texObj
= texUnit
->CurrentCubeMap
;
473 table
= &texObj
->Palette
;
475 case GL_SHARED_TEXTURE_PALETTE_EXT
:
476 table
= &ctx
->Texture
.Palette
;
479 table
= &ctx
->ColorTable
;
480 rScale
= ctx
->Pixel
.ColorTableScale
[0];
481 gScale
= ctx
->Pixel
.ColorTableScale
[1];
482 bScale
= ctx
->Pixel
.ColorTableScale
[2];
483 aScale
= ctx
->Pixel
.ColorTableScale
[3];
484 rBias
= ctx
->Pixel
.ColorTableBias
[0];
485 gBias
= ctx
->Pixel
.ColorTableBias
[1];
486 bBias
= ctx
->Pixel
.ColorTableBias
[2];
487 aBias
= ctx
->Pixel
.ColorTableBias
[3];
489 case GL_POST_CONVOLUTION_COLOR_TABLE
:
490 table
= &ctx
->PostConvolutionColorTable
;
491 rScale
= ctx
->Pixel
.PCCTscale
[0];
492 gScale
= ctx
->Pixel
.PCCTscale
[1];
493 bScale
= ctx
->Pixel
.PCCTscale
[2];
494 aScale
= ctx
->Pixel
.PCCTscale
[3];
495 rBias
= ctx
->Pixel
.PCCTbias
[0];
496 gBias
= ctx
->Pixel
.PCCTbias
[1];
497 bBias
= ctx
->Pixel
.PCCTbias
[2];
498 aBias
= ctx
->Pixel
.PCCTbias
[3];
500 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
501 table
= &ctx
->PostColorMatrixColorTable
;
502 rScale
= ctx
->Pixel
.PCMCTscale
[0];
503 gScale
= ctx
->Pixel
.PCMCTscale
[1];
504 bScale
= ctx
->Pixel
.PCMCTscale
[2];
505 aScale
= ctx
->Pixel
.PCMCTscale
[3];
506 rBias
= ctx
->Pixel
.PCMCTbias
[0];
507 gBias
= ctx
->Pixel
.PCMCTbias
[1];
508 bBias
= ctx
->Pixel
.PCMCTbias
[2];
509 aBias
= ctx
->Pixel
.PCMCTbias
[3];
512 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
518 if (!_mesa_is_legal_format_and_type(format
, type
) ||
519 format
== GL_INTENSITY
) {
520 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
525 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
529 comps
= _mesa_components_in_format(table
->Format
);
530 assert(comps
> 0); /* error should have been caught sooner */
532 if (start
+ count
> (GLint
) table
->Size
) {
533 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
538 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorSubTable");
542 if (!table
->FloatTable
) {
543 GLchan
*dest
= (GLchan
*) table
->Table
+ start
* comps
* sizeof(GLchan
);
544 _mesa_unpack_chan_color_span(ctx
, count
, table
->Format
, dest
,
545 format
, type
, data
, &ctx
->Unpack
, 0);
548 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
552 ASSERT(table
->FloatTable
);
554 _mesa_unpack_float_color_span(ctx
, count
, table
->Format
,
556 format
, type
, data
, &ctx
->Unpack
,
559 tableF
= (GLfloat
*) table
->Table
;
561 switch (table
->Format
) {
563 for (i
= 0; i
< count
; i
++) {
564 GLuint j
= start
+ i
;
565 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
569 for (i
= 0; i
< count
; i
++) {
570 GLuint j
= start
+ i
;
571 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
575 for (i
= 0; i
< count
; i
++) {
576 GLuint j
= start
+ i
;
577 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
580 case GL_LUMINANCE_ALPHA
:
581 for (i
= 0; i
< count
; i
++) {
582 GLuint j
= start
+ i
;
583 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
584 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
588 for (i
= 0; i
< count
; i
++) {
589 GLuint j
= start
+ i
;
590 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
591 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
592 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
596 for (i
= 0; i
< count
; i
++) {
597 GLuint j
= start
+ i
;
598 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
599 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
600 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
601 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
605 _mesa_problem(ctx
, "Bad format in _mesa_ColorSubTable");
610 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
611 /* per-texture object palette */
612 if (ctx
->Driver
.UpdateTexturePalette
) {
613 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
617 ctx
->NewState
|= _NEW_PIXEL
;
624 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
625 GLint x
, GLint y
, GLsizei width
)
627 GET_CURRENT_CONTEXT(ctx
);
628 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
630 /* Select buffer to read from */
631 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
638 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
639 GLint x
, GLint y
, GLsizei width
)
641 GET_CURRENT_CONTEXT(ctx
);
642 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
644 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
650 _mesa_GetColorTable( GLenum target
, GLenum format
,
651 GLenum type
, GLvoid
*data
)
653 GET_CURRENT_CONTEXT(ctx
);
654 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
655 struct gl_color_table
*table
= NULL
;
656 GLchan rgba
[MAX_COLOR_TABLE_SIZE
][4];
657 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
660 _mesa_update_state(ctx
);
665 table
= &texUnit
->Current1D
->Palette
;
668 table
= &texUnit
->Current2D
->Palette
;
671 table
= &texUnit
->Current3D
->Palette
;
673 case GL_TEXTURE_CUBE_MAP_ARB
:
674 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
675 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
678 table
= &texUnit
->CurrentCubeMap
->Palette
;
680 case GL_SHARED_TEXTURE_PALETTE_EXT
:
681 table
= &ctx
->Texture
.Palette
;
684 table
= &ctx
->ColorTable
;
686 case GL_POST_CONVOLUTION_COLOR_TABLE
:
687 table
= &ctx
->PostConvolutionColorTable
;
689 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
690 table
= &ctx
->PostColorMatrixColorTable
;
693 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
699 switch (table
->Format
) {
701 if (table
->FloatTable
) {
702 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
704 for (i
= 0; i
< table
->Size
; i
++) {
708 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
712 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
714 for (i
= 0; i
< table
->Size
; i
++) {
718 rgba
[i
][ACOMP
] = tableUB
[i
];
723 if (table
->FloatTable
) {
724 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
726 for (i
= 0; i
< table
->Size
; i
++) {
727 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
728 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
729 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
730 rgba
[i
][ACOMP
] = CHAN_MAX
;
734 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
736 for (i
= 0; i
< table
->Size
; i
++) {
737 rgba
[i
][RCOMP
] = tableUB
[i
];
738 rgba
[i
][GCOMP
] = tableUB
[i
];
739 rgba
[i
][BCOMP
] = tableUB
[i
];
740 rgba
[i
][ACOMP
] = CHAN_MAX
;
744 case GL_LUMINANCE_ALPHA
:
745 if (table
->FloatTable
) {
746 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
748 for (i
= 0; i
< table
->Size
; i
++) {
749 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
750 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
751 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
752 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
*2+1] * CHAN_MAXF
);
756 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
758 for (i
= 0; i
< table
->Size
; i
++) {
759 rgba
[i
][RCOMP
] = tableUB
[i
*2+0];
760 rgba
[i
][GCOMP
] = tableUB
[i
*2+0];
761 rgba
[i
][BCOMP
] = tableUB
[i
*2+0];
762 rgba
[i
][ACOMP
] = tableUB
[i
*2+1];
767 if (table
->FloatTable
) {
768 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
770 for (i
= 0; i
< table
->Size
; i
++) {
771 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
772 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
773 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
774 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
778 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
780 for (i
= 0; i
< table
->Size
; i
++) {
781 rgba
[i
][RCOMP
] = tableUB
[i
];
782 rgba
[i
][GCOMP
] = tableUB
[i
];
783 rgba
[i
][BCOMP
] = tableUB
[i
];
784 rgba
[i
][ACOMP
] = tableUB
[i
];
789 if (table
->FloatTable
) {
790 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
792 for (i
= 0; i
< table
->Size
; i
++) {
793 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*3+0] * CHAN_MAXF
);
794 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*3+1] * CHAN_MAXF
);
795 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*3+2] * CHAN_MAXF
);
796 rgba
[i
][ACOMP
] = CHAN_MAX
;
800 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
802 for (i
= 0; i
< table
->Size
; i
++) {
803 rgba
[i
][RCOMP
] = tableUB
[i
*3+0];
804 rgba
[i
][GCOMP
] = tableUB
[i
*3+1];
805 rgba
[i
][BCOMP
] = tableUB
[i
*3+2];
806 rgba
[i
][ACOMP
] = CHAN_MAX
;
811 if (table
->FloatTable
) {
812 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
814 for (i
= 0; i
< table
->Size
; i
++) {
815 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*4+0] * CHAN_MAXF
);
816 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*4+1] * CHAN_MAXF
);
817 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*4+2] * CHAN_MAXF
);
818 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
*4+3] * CHAN_MAXF
);
822 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
824 for (i
= 0; i
< table
->Size
; i
++) {
825 rgba
[i
][RCOMP
] = tableUB
[i
*4+0];
826 rgba
[i
][GCOMP
] = tableUB
[i
*4+1];
827 rgba
[i
][BCOMP
] = tableUB
[i
*4+2];
828 rgba
[i
][ACOMP
] = tableUB
[i
*4+3];
833 _mesa_problem(ctx
, "bad table format in glGetColorTable");
837 _mesa_pack_rgba_span(ctx
, table
->Size
, (const GLchan (*)[4]) rgba
,
838 format
, type
, data
, &ctx
->Pack
, GL_FALSE
);
844 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
846 GET_CURRENT_CONTEXT(ctx
);
847 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
850 case GL_COLOR_TABLE_SGI
:
851 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
852 ctx
->Pixel
.ColorTableScale
[0] = params
[0];
853 ctx
->Pixel
.ColorTableScale
[1] = params
[1];
854 ctx
->Pixel
.ColorTableScale
[2] = params
[2];
855 ctx
->Pixel
.ColorTableScale
[3] = params
[3];
857 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
858 ctx
->Pixel
.ColorTableBias
[0] = params
[0];
859 ctx
->Pixel
.ColorTableBias
[1] = params
[1];
860 ctx
->Pixel
.ColorTableBias
[2] = params
[2];
861 ctx
->Pixel
.ColorTableBias
[3] = params
[3];
864 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
868 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
869 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
870 ctx
->Pixel
.PCCTscale
[0] = params
[0];
871 ctx
->Pixel
.PCCTscale
[1] = params
[1];
872 ctx
->Pixel
.PCCTscale
[2] = params
[2];
873 ctx
->Pixel
.PCCTscale
[3] = params
[3];
875 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
876 ctx
->Pixel
.PCCTbias
[0] = params
[0];
877 ctx
->Pixel
.PCCTbias
[1] = params
[1];
878 ctx
->Pixel
.PCCTbias
[2] = params
[2];
879 ctx
->Pixel
.PCCTbias
[3] = params
[3];
882 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
886 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
887 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
888 ctx
->Pixel
.PCMCTscale
[0] = params
[0];
889 ctx
->Pixel
.PCMCTscale
[1] = params
[1];
890 ctx
->Pixel
.PCMCTscale
[2] = params
[2];
891 ctx
->Pixel
.PCMCTscale
[3] = params
[3];
893 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
894 ctx
->Pixel
.PCMCTbias
[0] = params
[0];
895 ctx
->Pixel
.PCMCTbias
[1] = params
[1];
896 ctx
->Pixel
.PCMCTbias
[2] = params
[2];
897 ctx
->Pixel
.PCMCTbias
[3] = params
[3];
900 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
905 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
909 ctx
->NewState
|= _NEW_PIXEL
;
915 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
918 if (pname
== GL_COLOR_TABLE_SGI
||
919 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
920 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
922 fparams
[0] = (GLfloat
) params
[0];
923 fparams
[1] = (GLfloat
) params
[1];
924 fparams
[2] = (GLfloat
) params
[2];
925 fparams
[3] = (GLfloat
) params
[3];
929 fparams
[0] = (GLfloat
) params
[0];
931 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
937 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
939 GET_CURRENT_CONTEXT(ctx
);
940 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
941 struct gl_color_table
*table
= NULL
;
942 ASSERT_OUTSIDE_BEGIN_END(ctx
);
946 table
= &texUnit
->Current1D
->Palette
;
949 table
= &texUnit
->Current2D
->Palette
;
952 table
= &texUnit
->Current3D
->Palette
;
954 case GL_TEXTURE_CUBE_MAP_ARB
:
955 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
956 _mesa_error(ctx
, GL_INVALID_ENUM
,
957 "glGetColorTableParameterfv(target)");
960 table
= &texUnit
->CurrentCubeMap
->Palette
;
962 case GL_PROXY_TEXTURE_1D
:
963 table
= &ctx
->Texture
.Proxy1D
->Palette
;
965 case GL_PROXY_TEXTURE_2D
:
966 table
= &ctx
->Texture
.Proxy2D
->Palette
;
968 case GL_PROXY_TEXTURE_3D
:
969 table
= &ctx
->Texture
.Proxy3D
->Palette
;
971 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
972 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
973 _mesa_error(ctx
, GL_INVALID_ENUM
,
974 "glGetColorTableParameterfv(target)");
977 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
979 case GL_SHARED_TEXTURE_PALETTE_EXT
:
980 table
= &ctx
->Texture
.Palette
;
983 table
= &ctx
->ColorTable
;
984 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
985 params
[0] = ctx
->Pixel
.ColorTableScale
[0];
986 params
[1] = ctx
->Pixel
.ColorTableScale
[1];
987 params
[2] = ctx
->Pixel
.ColorTableScale
[2];
988 params
[3] = ctx
->Pixel
.ColorTableScale
[3];
991 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
992 params
[0] = ctx
->Pixel
.ColorTableBias
[0];
993 params
[1] = ctx
->Pixel
.ColorTableBias
[1];
994 params
[2] = ctx
->Pixel
.ColorTableBias
[2];
995 params
[3] = ctx
->Pixel
.ColorTableBias
[3];
999 case GL_PROXY_COLOR_TABLE
:
1000 table
= &ctx
->ProxyColorTable
;
1002 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1003 table
= &ctx
->PostConvolutionColorTable
;
1004 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1005 params
[0] = ctx
->Pixel
.PCCTscale
[0];
1006 params
[1] = ctx
->Pixel
.PCCTscale
[1];
1007 params
[2] = ctx
->Pixel
.PCCTscale
[2];
1008 params
[3] = ctx
->Pixel
.PCCTscale
[3];
1011 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1012 params
[0] = ctx
->Pixel
.PCCTbias
[0];
1013 params
[1] = ctx
->Pixel
.PCCTbias
[1];
1014 params
[2] = ctx
->Pixel
.PCCTbias
[2];
1015 params
[3] = ctx
->Pixel
.PCCTbias
[3];
1019 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1020 table
= &ctx
->ProxyPostConvolutionColorTable
;
1022 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1023 table
= &ctx
->PostColorMatrixColorTable
;
1024 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1025 params
[0] = ctx
->Pixel
.PCMCTscale
[0];
1026 params
[1] = ctx
->Pixel
.PCMCTscale
[1];
1027 params
[2] = ctx
->Pixel
.PCMCTscale
[2];
1028 params
[3] = ctx
->Pixel
.PCMCTscale
[3];
1031 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1032 params
[0] = ctx
->Pixel
.PCMCTbias
[0];
1033 params
[1] = ctx
->Pixel
.PCMCTbias
[1];
1034 params
[2] = ctx
->Pixel
.PCMCTbias
[2];
1035 params
[3] = ctx
->Pixel
.PCMCTbias
[3];
1039 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1040 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1043 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
1050 case GL_COLOR_TABLE_FORMAT
:
1051 *params
= (GLfloat
) table
->IntFormat
;
1053 case GL_COLOR_TABLE_WIDTH
:
1054 *params
= (GLfloat
) table
->Size
;
1056 case GL_COLOR_TABLE_RED_SIZE
:
1057 *params
= table
->RedSize
;
1059 case GL_COLOR_TABLE_GREEN_SIZE
:
1060 *params
= table
->GreenSize
;
1062 case GL_COLOR_TABLE_BLUE_SIZE
:
1063 *params
= table
->BlueSize
;
1065 case GL_COLOR_TABLE_ALPHA_SIZE
:
1066 *params
= table
->AlphaSize
;
1068 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1069 *params
= table
->LuminanceSize
;
1071 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1072 *params
= table
->IntensitySize
;
1075 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
1083 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1085 GET_CURRENT_CONTEXT(ctx
);
1086 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1087 struct gl_color_table
*table
= NULL
;
1088 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1092 table
= &texUnit
->Current1D
->Palette
;
1095 table
= &texUnit
->Current2D
->Palette
;
1098 table
= &texUnit
->Current3D
->Palette
;
1100 case GL_TEXTURE_CUBE_MAP_ARB
:
1101 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1102 _mesa_error(ctx
, GL_INVALID_ENUM
,
1103 "glGetColorTableParameteriv(target)");
1106 table
= &texUnit
->CurrentCubeMap
->Palette
;
1108 case GL_PROXY_TEXTURE_1D
:
1109 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1111 case GL_PROXY_TEXTURE_2D
:
1112 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1114 case GL_PROXY_TEXTURE_3D
:
1115 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1117 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1118 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1119 _mesa_error(ctx
, GL_INVALID_ENUM
,
1120 "glGetColorTableParameteriv(target)");
1123 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
1125 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1126 table
= &ctx
->Texture
.Palette
;
1128 case GL_COLOR_TABLE
:
1129 table
= &ctx
->ColorTable
;
1130 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1131 params
[0] = (GLint
) ctx
->Pixel
.ColorTableScale
[0];
1132 params
[1] = (GLint
) ctx
->Pixel
.ColorTableScale
[1];
1133 params
[2] = (GLint
) ctx
->Pixel
.ColorTableScale
[2];
1134 params
[3] = (GLint
) ctx
->Pixel
.ColorTableScale
[3];
1137 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1138 params
[0] = (GLint
) ctx
->Pixel
.ColorTableBias
[0];
1139 params
[1] = (GLint
) ctx
->Pixel
.ColorTableBias
[1];
1140 params
[2] = (GLint
) ctx
->Pixel
.ColorTableBias
[2];
1141 params
[3] = (GLint
) ctx
->Pixel
.ColorTableBias
[3];
1145 case GL_PROXY_COLOR_TABLE
:
1146 table
= &ctx
->ProxyColorTable
;
1148 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1149 table
= &ctx
->PostConvolutionColorTable
;
1150 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1151 params
[0] = (GLint
) ctx
->Pixel
.PCCTscale
[0];
1152 params
[1] = (GLint
) ctx
->Pixel
.PCCTscale
[1];
1153 params
[2] = (GLint
) ctx
->Pixel
.PCCTscale
[2];
1154 params
[3] = (GLint
) ctx
->Pixel
.PCCTscale
[3];
1157 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1158 params
[0] = (GLint
) ctx
->Pixel
.PCCTbias
[0];
1159 params
[1] = (GLint
) ctx
->Pixel
.PCCTbias
[1];
1160 params
[2] = (GLint
) ctx
->Pixel
.PCCTbias
[2];
1161 params
[3] = (GLint
) ctx
->Pixel
.PCCTbias
[3];
1165 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1166 table
= &ctx
->ProxyPostConvolutionColorTable
;
1168 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1169 table
= &ctx
->PostColorMatrixColorTable
;
1170 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1171 params
[0] = (GLint
) ctx
->Pixel
.PCMCTscale
[0];
1172 params
[1] = (GLint
) ctx
->Pixel
.PCMCTscale
[1];
1173 params
[2] = (GLint
) ctx
->Pixel
.PCMCTscale
[2];
1174 params
[3] = (GLint
) ctx
->Pixel
.PCMCTscale
[3];
1177 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1178 params
[0] = (GLint
) ctx
->Pixel
.PCMCTbias
[0];
1179 params
[1] = (GLint
) ctx
->Pixel
.PCMCTbias
[1];
1180 params
[2] = (GLint
) ctx
->Pixel
.PCMCTbias
[2];
1181 params
[3] = (GLint
) ctx
->Pixel
.PCMCTbias
[3];
1185 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1186 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1189 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1196 case GL_COLOR_TABLE_FORMAT
:
1197 *params
= table
->IntFormat
;
1199 case GL_COLOR_TABLE_WIDTH
:
1200 *params
= table
->Size
;
1202 case GL_COLOR_TABLE_RED_SIZE
:
1203 *params
= table
->RedSize
;
1205 case GL_COLOR_TABLE_GREEN_SIZE
:
1206 *params
= table
->GreenSize
;
1208 case GL_COLOR_TABLE_BLUE_SIZE
:
1209 *params
= table
->BlueSize
;
1211 case GL_COLOR_TABLE_ALPHA_SIZE
:
1212 *params
= table
->AlphaSize
;
1214 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1215 *params
= table
->LuminanceSize
;
1217 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1218 *params
= table
->IntensitySize
;
1221 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );