1 /* $Id: colortab.c,v 1.43 2002/06/08 12:39:18 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 #include "swrast/s_span.h" /* XXX SWRAST hack */
45 * Given an internalFormat token passed to glColorTable,
46 * return the corresponding base format.
47 * Return -1 if invalid token.
50 base_colortab_format( GLenum format
)
65 case GL_LUMINANCE_ALPHA
:
66 case GL_LUMINANCE4_ALPHA4
:
67 case GL_LUMINANCE6_ALPHA2
:
68 case GL_LUMINANCE8_ALPHA8
:
69 case GL_LUMINANCE12_ALPHA4
:
70 case GL_LUMINANCE12_ALPHA12
:
71 case GL_LUMINANCE16_ALPHA16
:
72 return GL_LUMINANCE_ALPHA
;
98 return -1; /* error */
104 _mesa_init_colortable( struct gl_color_table
*p
)
106 p
->FloatTable
= GL_FALSE
;
109 p
->IntFormat
= GL_RGBA
;
115 _mesa_free_colortable_data( struct gl_color_table
*p
)
125 * Examine table's format and set the component sizes accordingly.
128 set_component_sizes( struct gl_color_table
*table
)
130 switch (table
->Format
) {
133 table
->GreenSize
= 0;
135 table
->AlphaSize
= CHAN_BITS
;
136 table
->IntensitySize
= 0;
137 table
->LuminanceSize
= 0;
141 table
->GreenSize
= 0;
143 table
->AlphaSize
= 0;
144 table
->IntensitySize
= 0;
145 table
->LuminanceSize
= CHAN_BITS
;
147 case GL_LUMINANCE_ALPHA
:
149 table
->GreenSize
= 0;
151 table
->AlphaSize
= CHAN_BITS
;
152 table
->IntensitySize
= 0;
153 table
->LuminanceSize
= CHAN_BITS
;
157 table
->GreenSize
= 0;
159 table
->AlphaSize
= 0;
160 table
->IntensitySize
= CHAN_BITS
;
161 table
->LuminanceSize
= 0;
164 table
->RedSize
= CHAN_BITS
;
165 table
->GreenSize
= CHAN_BITS
;
166 table
->BlueSize
= CHAN_BITS
;
167 table
->AlphaSize
= 0;
168 table
->IntensitySize
= 0;
169 table
->LuminanceSize
= 0;
172 table
->RedSize
= CHAN_BITS
;
173 table
->GreenSize
= CHAN_BITS
;
174 table
->BlueSize
= CHAN_BITS
;
175 table
->AlphaSize
= CHAN_BITS
;
176 table
->IntensitySize
= 0;
177 table
->LuminanceSize
= 0;
180 _mesa_problem(NULL
, "unexpected format in set_component_sizes");
187 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
188 GLsizei width
, GLenum format
, GLenum type
,
191 GET_CURRENT_CONTEXT(ctx
);
192 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
193 struct gl_texture_object
*texObj
= NULL
;
194 struct gl_color_table
*table
= NULL
;
195 GLboolean proxy
= GL_FALSE
;
197 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
198 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
199 GLboolean floatTable
= GL_FALSE
;
201 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
205 texObj
= texUnit
->Current1D
;
206 table
= &texObj
->Palette
;
209 texObj
= texUnit
->Current2D
;
210 table
= &texObj
->Palette
;
213 texObj
= texUnit
->Current3D
;
214 table
= &texObj
->Palette
;
216 case GL_TEXTURE_CUBE_MAP_ARB
:
217 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
218 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
221 texObj
= texUnit
->CurrentCubeMap
;
222 table
= &texObj
->Palette
;
224 case GL_PROXY_TEXTURE_1D
:
225 texObj
= ctx
->Texture
.Proxy1D
;
226 table
= &texObj
->Palette
;
229 case GL_PROXY_TEXTURE_2D
:
230 texObj
= ctx
->Texture
.Proxy2D
;
231 table
= &texObj
->Palette
;
234 case GL_PROXY_TEXTURE_3D
:
235 texObj
= ctx
->Texture
.Proxy3D
;
236 table
= &texObj
->Palette
;
239 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
240 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
241 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
244 texObj
= ctx
->Texture
.ProxyCubeMap
;
245 table
= &texObj
->Palette
;
247 case GL_SHARED_TEXTURE_PALETTE_EXT
:
248 table
= &ctx
->Texture
.Palette
;
251 table
= &ctx
->ColorTable
;
252 floatTable
= GL_TRUE
;
253 rScale
= ctx
->Pixel
.ColorTableScale
[0];
254 gScale
= ctx
->Pixel
.ColorTableScale
[1];
255 bScale
= ctx
->Pixel
.ColorTableScale
[2];
256 aScale
= ctx
->Pixel
.ColorTableScale
[3];
257 rBias
= ctx
->Pixel
.ColorTableBias
[0];
258 gBias
= ctx
->Pixel
.ColorTableBias
[1];
259 bBias
= ctx
->Pixel
.ColorTableBias
[2];
260 aBias
= ctx
->Pixel
.ColorTableBias
[3];
262 case GL_PROXY_COLOR_TABLE
:
263 table
= &ctx
->ProxyColorTable
;
266 case GL_POST_CONVOLUTION_COLOR_TABLE
:
267 table
= &ctx
->PostConvolutionColorTable
;
268 floatTable
= GL_TRUE
;
269 rScale
= ctx
->Pixel
.PCCTscale
[0];
270 gScale
= ctx
->Pixel
.PCCTscale
[1];
271 bScale
= ctx
->Pixel
.PCCTscale
[2];
272 aScale
= ctx
->Pixel
.PCCTscale
[3];
273 rBias
= ctx
->Pixel
.PCCTbias
[0];
274 gBias
= ctx
->Pixel
.PCCTbias
[1];
275 bBias
= ctx
->Pixel
.PCCTbias
[2];
276 aBias
= ctx
->Pixel
.PCCTbias
[3];
278 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
279 table
= &ctx
->ProxyPostConvolutionColorTable
;
282 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
283 table
= &ctx
->PostColorMatrixColorTable
;
284 floatTable
= GL_TRUE
;
285 rScale
= ctx
->Pixel
.PCMCTscale
[0];
286 gScale
= ctx
->Pixel
.PCMCTscale
[1];
287 bScale
= ctx
->Pixel
.PCMCTscale
[2];
288 aScale
= ctx
->Pixel
.PCMCTscale
[3];
289 rBias
= ctx
->Pixel
.PCMCTbias
[0];
290 gBias
= ctx
->Pixel
.PCMCTbias
[1];
291 bBias
= ctx
->Pixel
.PCMCTbias
[2];
292 aBias
= ctx
->Pixel
.PCMCTbias
[3];
294 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
295 table
= &ctx
->ProxyPostColorMatrixColorTable
;
299 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
305 if (!_mesa_is_legal_format_and_type(format
, type
) ||
306 format
== GL_INTENSITY
) {
307 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
311 baseFormat
= base_colortab_format(internalFormat
);
312 if (baseFormat
< 0 || baseFormat
== GL_COLOR_INDEX
) {
313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
317 if (width
< 0 || (width
!= 0 && _mesa_bitcount(width
) != 1)) {
321 table
->IntFormat
= (GLenum
) 0;
322 table
->Format
= (GLenum
) 0;
326 sprintf(msg
, "glColorTable(width=%d)", width
);
327 _mesa_error(ctx
, GL_INVALID_VALUE
, msg
);
332 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
335 table
->IntFormat
= (GLenum
) 0;
336 table
->Format
= (GLenum
) 0;
339 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
345 table
->IntFormat
= internalFormat
;
346 table
->Format
= (GLenum
) baseFormat
;
347 set_component_sizes(table
);
349 comps
= _mesa_components_in_format(table
->Format
);
350 assert(comps
> 0); /* error should have been caught sooner */
353 /* free old table, if any */
360 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
364 _mesa_unpack_float_color_span(ctx
, width
, table
->Format
,
366 format
, type
, data
, &ctx
->Unpack
,
369 table
->FloatTable
= GL_TRUE
;
370 table
->Table
= MALLOC(comps
* width
* sizeof(GLfloat
));
372 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
376 tableF
= (GLfloat
*) table
->Table
;
378 switch (table
->Format
) {
380 for (i
= 0; i
< width
; i
++) {
381 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
385 for (i
= 0; i
< width
; i
++) {
386 tableF
[i
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
390 for (i
= 0; i
< width
; i
++) {
391 tableF
[i
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
394 case GL_LUMINANCE_ALPHA
:
395 for (i
= 0; i
< width
; i
++) {
396 tableF
[i
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
397 tableF
[i
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
401 for (i
= 0; i
< width
; i
++) {
402 tableF
[i
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
403 tableF
[i
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
404 tableF
[i
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
408 for (i
= 0; i
< width
; i
++) {
409 tableF
[i
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
410 tableF
[i
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
411 tableF
[i
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
412 tableF
[i
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
416 _mesa_problem(ctx
, "Bad format in _mesa_ColorTable");
421 /* store GLchan table */
422 table
->FloatTable
= GL_FALSE
;
423 table
->Table
= MALLOC(comps
* width
* sizeof(GLchan
));
425 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
428 _mesa_unpack_chan_color_span(ctx
, width
, table
->Format
,
429 (GLchan
*) table
->Table
, /* dest */
436 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
437 /* texture object palette, texObj==NULL means the shared palette */
438 if (ctx
->Driver
.UpdateTexturePalette
) {
439 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
443 ctx
->NewState
|= _NEW_PIXEL
;
449 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
450 GLsizei count
, GLenum format
, GLenum type
,
453 GET_CURRENT_CONTEXT(ctx
);
454 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
455 struct gl_texture_object
*texObj
= NULL
;
456 struct gl_color_table
*table
= NULL
;
457 GLfloat rScale
= 1.0, gScale
= 1.0, bScale
= 1.0, aScale
= 1.0;
458 GLfloat rBias
= 0.0, gBias
= 0.0, bBias
= 0.0, aBias
= 0.0;
460 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
464 texObj
= texUnit
->Current1D
;
465 table
= &texObj
->Palette
;
468 texObj
= texUnit
->Current2D
;
469 table
= &texObj
->Palette
;
472 texObj
= texUnit
->Current3D
;
473 table
= &texObj
->Palette
;
475 case GL_TEXTURE_CUBE_MAP_ARB
:
476 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
477 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
480 texObj
= texUnit
->CurrentCubeMap
;
481 table
= &texObj
->Palette
;
483 case GL_SHARED_TEXTURE_PALETTE_EXT
:
484 table
= &ctx
->Texture
.Palette
;
487 table
= &ctx
->ColorTable
;
488 rScale
= ctx
->Pixel
.ColorTableScale
[0];
489 gScale
= ctx
->Pixel
.ColorTableScale
[1];
490 bScale
= ctx
->Pixel
.ColorTableScale
[2];
491 aScale
= ctx
->Pixel
.ColorTableScale
[3];
492 rBias
= ctx
->Pixel
.ColorTableBias
[0];
493 gBias
= ctx
->Pixel
.ColorTableBias
[1];
494 bBias
= ctx
->Pixel
.ColorTableBias
[2];
495 aBias
= ctx
->Pixel
.ColorTableBias
[3];
497 case GL_POST_CONVOLUTION_COLOR_TABLE
:
498 table
= &ctx
->PostConvolutionColorTable
;
499 rScale
= ctx
->Pixel
.PCCTscale
[0];
500 gScale
= ctx
->Pixel
.PCCTscale
[1];
501 bScale
= ctx
->Pixel
.PCCTscale
[2];
502 aScale
= ctx
->Pixel
.PCCTscale
[3];
503 rBias
= ctx
->Pixel
.PCCTbias
[0];
504 gBias
= ctx
->Pixel
.PCCTbias
[1];
505 bBias
= ctx
->Pixel
.PCCTbias
[2];
506 aBias
= ctx
->Pixel
.PCCTbias
[3];
508 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
509 table
= &ctx
->PostColorMatrixColorTable
;
510 rScale
= ctx
->Pixel
.PCMCTscale
[0];
511 gScale
= ctx
->Pixel
.PCMCTscale
[1];
512 bScale
= ctx
->Pixel
.PCMCTscale
[2];
513 aScale
= ctx
->Pixel
.PCMCTscale
[3];
514 rBias
= ctx
->Pixel
.PCMCTbias
[0];
515 gBias
= ctx
->Pixel
.PCMCTbias
[1];
516 bBias
= ctx
->Pixel
.PCMCTbias
[2];
517 aBias
= ctx
->Pixel
.PCMCTbias
[3];
520 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
526 if (!_mesa_is_legal_format_and_type(format
, type
) ||
527 format
== GL_INTENSITY
) {
528 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
533 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
537 comps
= _mesa_components_in_format(table
->Format
);
538 assert(comps
> 0); /* error should have been caught sooner */
540 if (start
+ count
> (GLint
) table
->Size
) {
541 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
546 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorSubTable");
550 if (!table
->FloatTable
) {
551 GLchan
*dest
= (GLchan
*) table
->Table
+ start
* comps
* sizeof(GLchan
);
552 _mesa_unpack_chan_color_span(ctx
, count
, table
->Format
, dest
,
553 format
, type
, data
, &ctx
->Unpack
, 0);
556 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
560 ASSERT(table
->FloatTable
);
562 _mesa_unpack_float_color_span(ctx
, count
, table
->Format
,
564 format
, type
, data
, &ctx
->Unpack
,
567 tableF
= (GLfloat
*) table
->Table
;
569 switch (table
->Format
) {
571 for (i
= 0; i
< count
; i
++) {
572 GLuint j
= start
+ i
;
573 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
577 for (i
= 0; i
< count
; i
++) {
578 GLuint j
= start
+ i
;
579 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
583 for (i
= 0; i
< count
; i
++) {
584 GLuint j
= start
+ i
;
585 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
588 case GL_LUMINANCE_ALPHA
:
589 for (i
= 0; i
< count
; i
++) {
590 GLuint j
= start
+ i
;
591 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
592 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
596 for (i
= 0; i
< count
; i
++) {
597 GLuint j
= start
+ i
;
598 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
599 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
600 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
604 for (i
= 0; i
< count
; i
++) {
605 GLuint j
= start
+ i
;
606 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
607 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
608 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
609 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
613 _mesa_problem(ctx
, "Bad format in _mesa_ColorSubTable");
618 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
619 /* per-texture object palette */
620 if (ctx
->Driver
.UpdateTexturePalette
) {
621 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
625 ctx
->NewState
|= _NEW_PIXEL
;
632 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
633 GLint x
, GLint y
, GLsizei width
)
635 GET_CURRENT_CONTEXT(ctx
);
636 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
638 /* Select buffer to read from */
639 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
646 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
647 GLint x
, GLint y
, GLsizei width
)
649 GET_CURRENT_CONTEXT(ctx
);
650 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
652 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
658 _mesa_GetColorTable( GLenum target
, GLenum format
,
659 GLenum type
, GLvoid
*data
)
661 GET_CURRENT_CONTEXT(ctx
);
662 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
663 struct gl_color_table
*table
= NULL
;
664 GLchan rgba
[MAX_COLOR_TABLE_SIZE
][4];
665 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
668 _mesa_update_state(ctx
);
673 table
= &texUnit
->Current1D
->Palette
;
676 table
= &texUnit
->Current2D
->Palette
;
679 table
= &texUnit
->Current3D
->Palette
;
681 case GL_TEXTURE_CUBE_MAP_ARB
:
682 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
683 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
686 table
= &texUnit
->CurrentCubeMap
->Palette
;
688 case GL_SHARED_TEXTURE_PALETTE_EXT
:
689 table
= &ctx
->Texture
.Palette
;
692 table
= &ctx
->ColorTable
;
694 case GL_POST_CONVOLUTION_COLOR_TABLE
:
695 table
= &ctx
->PostConvolutionColorTable
;
697 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
698 table
= &ctx
->PostColorMatrixColorTable
;
701 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
707 switch (table
->Format
) {
709 if (table
->FloatTable
) {
710 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
712 for (i
= 0; i
< table
->Size
; i
++) {
716 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
720 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
722 for (i
= 0; i
< table
->Size
; i
++) {
726 rgba
[i
][ACOMP
] = tableUB
[i
];
731 if (table
->FloatTable
) {
732 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
734 for (i
= 0; i
< table
->Size
; i
++) {
735 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
736 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
737 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
738 rgba
[i
][ACOMP
] = CHAN_MAX
;
742 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
744 for (i
= 0; i
< table
->Size
; i
++) {
745 rgba
[i
][RCOMP
] = tableUB
[i
];
746 rgba
[i
][GCOMP
] = tableUB
[i
];
747 rgba
[i
][BCOMP
] = tableUB
[i
];
748 rgba
[i
][ACOMP
] = CHAN_MAX
;
752 case GL_LUMINANCE_ALPHA
:
753 if (table
->FloatTable
) {
754 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
756 for (i
= 0; i
< table
->Size
; i
++) {
757 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
758 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
759 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*2+0] * CHAN_MAXF
);
760 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
*2+1] * CHAN_MAXF
);
764 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
766 for (i
= 0; i
< table
->Size
; i
++) {
767 rgba
[i
][RCOMP
] = tableUB
[i
*2+0];
768 rgba
[i
][GCOMP
] = tableUB
[i
*2+0];
769 rgba
[i
][BCOMP
] = tableUB
[i
*2+0];
770 rgba
[i
][ACOMP
] = tableUB
[i
*2+1];
775 if (table
->FloatTable
) {
776 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
778 for (i
= 0; i
< table
->Size
; i
++) {
779 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
780 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
781 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
782 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
] * CHAN_MAXF
);
786 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
788 for (i
= 0; i
< table
->Size
; i
++) {
789 rgba
[i
][RCOMP
] = tableUB
[i
];
790 rgba
[i
][GCOMP
] = tableUB
[i
];
791 rgba
[i
][BCOMP
] = tableUB
[i
];
792 rgba
[i
][ACOMP
] = tableUB
[i
];
797 if (table
->FloatTable
) {
798 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
800 for (i
= 0; i
< table
->Size
; i
++) {
801 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*3+0] * CHAN_MAXF
);
802 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*3+1] * CHAN_MAXF
);
803 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*3+2] * CHAN_MAXF
);
804 rgba
[i
][ACOMP
] = CHAN_MAX
;
808 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
810 for (i
= 0; i
< table
->Size
; i
++) {
811 rgba
[i
][RCOMP
] = tableUB
[i
*3+0];
812 rgba
[i
][GCOMP
] = tableUB
[i
*3+1];
813 rgba
[i
][BCOMP
] = tableUB
[i
*3+2];
814 rgba
[i
][ACOMP
] = CHAN_MAX
;
819 if (table
->FloatTable
) {
820 const GLfloat
*tableF
= (const GLfloat
*) table
->Table
;
822 for (i
= 0; i
< table
->Size
; i
++) {
823 rgba
[i
][RCOMP
] = IROUND_POS(tableF
[i
*4+0] * CHAN_MAXF
);
824 rgba
[i
][GCOMP
] = IROUND_POS(tableF
[i
*4+1] * CHAN_MAXF
);
825 rgba
[i
][BCOMP
] = IROUND_POS(tableF
[i
*4+2] * CHAN_MAXF
);
826 rgba
[i
][ACOMP
] = IROUND_POS(tableF
[i
*4+3] * CHAN_MAXF
);
830 const GLchan
*tableUB
= (const GLchan
*) table
->Table
;
832 for (i
= 0; i
< table
->Size
; i
++) {
833 rgba
[i
][RCOMP
] = tableUB
[i
*4+0];
834 rgba
[i
][GCOMP
] = tableUB
[i
*4+1];
835 rgba
[i
][BCOMP
] = tableUB
[i
*4+2];
836 rgba
[i
][ACOMP
] = tableUB
[i
*4+3];
841 _mesa_problem(ctx
, "bad table format in glGetColorTable");
845 _mesa_pack_rgba_span(ctx
, table
->Size
, (const GLchan (*)[4]) rgba
,
846 format
, type
, data
, &ctx
->Pack
, GL_FALSE
);
852 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
854 GET_CURRENT_CONTEXT(ctx
);
855 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
858 case GL_COLOR_TABLE_SGI
:
859 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
860 ctx
->Pixel
.ColorTableScale
[0] = params
[0];
861 ctx
->Pixel
.ColorTableScale
[1] = params
[1];
862 ctx
->Pixel
.ColorTableScale
[2] = params
[2];
863 ctx
->Pixel
.ColorTableScale
[3] = params
[3];
865 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
866 ctx
->Pixel
.ColorTableBias
[0] = params
[0];
867 ctx
->Pixel
.ColorTableBias
[1] = params
[1];
868 ctx
->Pixel
.ColorTableBias
[2] = params
[2];
869 ctx
->Pixel
.ColorTableBias
[3] = params
[3];
872 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
876 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
877 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
878 ctx
->Pixel
.PCCTscale
[0] = params
[0];
879 ctx
->Pixel
.PCCTscale
[1] = params
[1];
880 ctx
->Pixel
.PCCTscale
[2] = params
[2];
881 ctx
->Pixel
.PCCTscale
[3] = params
[3];
883 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
884 ctx
->Pixel
.PCCTbias
[0] = params
[0];
885 ctx
->Pixel
.PCCTbias
[1] = params
[1];
886 ctx
->Pixel
.PCCTbias
[2] = params
[2];
887 ctx
->Pixel
.PCCTbias
[3] = params
[3];
890 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
894 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
895 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
896 ctx
->Pixel
.PCMCTscale
[0] = params
[0];
897 ctx
->Pixel
.PCMCTscale
[1] = params
[1];
898 ctx
->Pixel
.PCMCTscale
[2] = params
[2];
899 ctx
->Pixel
.PCMCTscale
[3] = params
[3];
901 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
902 ctx
->Pixel
.PCMCTbias
[0] = params
[0];
903 ctx
->Pixel
.PCMCTbias
[1] = params
[1];
904 ctx
->Pixel
.PCMCTbias
[2] = params
[2];
905 ctx
->Pixel
.PCMCTbias
[3] = params
[3];
908 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
913 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
917 ctx
->NewState
|= _NEW_PIXEL
;
923 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
926 if (pname
== GL_COLOR_TABLE_SGI
||
927 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
928 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
930 fparams
[0] = (GLfloat
) params
[0];
931 fparams
[1] = (GLfloat
) params
[1];
932 fparams
[2] = (GLfloat
) params
[2];
933 fparams
[3] = (GLfloat
) params
[3];
937 fparams
[0] = (GLfloat
) params
[0];
939 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
945 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
947 GET_CURRENT_CONTEXT(ctx
);
948 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
949 struct gl_color_table
*table
= NULL
;
950 ASSERT_OUTSIDE_BEGIN_END(ctx
);
954 table
= &texUnit
->Current1D
->Palette
;
957 table
= &texUnit
->Current2D
->Palette
;
960 table
= &texUnit
->Current3D
->Palette
;
962 case GL_TEXTURE_CUBE_MAP_ARB
:
963 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
964 _mesa_error(ctx
, GL_INVALID_ENUM
,
965 "glGetColorTableParameterfv(target)");
968 table
= &texUnit
->CurrentCubeMap
->Palette
;
970 case GL_PROXY_TEXTURE_1D
:
971 table
= &ctx
->Texture
.Proxy1D
->Palette
;
973 case GL_PROXY_TEXTURE_2D
:
974 table
= &ctx
->Texture
.Proxy2D
->Palette
;
976 case GL_PROXY_TEXTURE_3D
:
977 table
= &ctx
->Texture
.Proxy3D
->Palette
;
979 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
980 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
981 _mesa_error(ctx
, GL_INVALID_ENUM
,
982 "glGetColorTableParameterfv(target)");
985 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
987 case GL_SHARED_TEXTURE_PALETTE_EXT
:
988 table
= &ctx
->Texture
.Palette
;
991 table
= &ctx
->ColorTable
;
992 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
993 params
[0] = ctx
->Pixel
.ColorTableScale
[0];
994 params
[1] = ctx
->Pixel
.ColorTableScale
[1];
995 params
[2] = ctx
->Pixel
.ColorTableScale
[2];
996 params
[3] = ctx
->Pixel
.ColorTableScale
[3];
999 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1000 params
[0] = ctx
->Pixel
.ColorTableBias
[0];
1001 params
[1] = ctx
->Pixel
.ColorTableBias
[1];
1002 params
[2] = ctx
->Pixel
.ColorTableBias
[2];
1003 params
[3] = ctx
->Pixel
.ColorTableBias
[3];
1007 case GL_PROXY_COLOR_TABLE
:
1008 table
= &ctx
->ProxyColorTable
;
1010 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1011 table
= &ctx
->PostConvolutionColorTable
;
1012 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1013 params
[0] = ctx
->Pixel
.PCCTscale
[0];
1014 params
[1] = ctx
->Pixel
.PCCTscale
[1];
1015 params
[2] = ctx
->Pixel
.PCCTscale
[2];
1016 params
[3] = ctx
->Pixel
.PCCTscale
[3];
1019 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1020 params
[0] = ctx
->Pixel
.PCCTbias
[0];
1021 params
[1] = ctx
->Pixel
.PCCTbias
[1];
1022 params
[2] = ctx
->Pixel
.PCCTbias
[2];
1023 params
[3] = ctx
->Pixel
.PCCTbias
[3];
1027 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1028 table
= &ctx
->ProxyPostConvolutionColorTable
;
1030 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1031 table
= &ctx
->PostColorMatrixColorTable
;
1032 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1033 params
[0] = ctx
->Pixel
.PCMCTscale
[0];
1034 params
[1] = ctx
->Pixel
.PCMCTscale
[1];
1035 params
[2] = ctx
->Pixel
.PCMCTscale
[2];
1036 params
[3] = ctx
->Pixel
.PCMCTscale
[3];
1039 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1040 params
[0] = ctx
->Pixel
.PCMCTbias
[0];
1041 params
[1] = ctx
->Pixel
.PCMCTbias
[1];
1042 params
[2] = ctx
->Pixel
.PCMCTbias
[2];
1043 params
[3] = ctx
->Pixel
.PCMCTbias
[3];
1047 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1048 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1051 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
1058 case GL_COLOR_TABLE_FORMAT
:
1059 *params
= (GLfloat
) table
->IntFormat
;
1061 case GL_COLOR_TABLE_WIDTH
:
1062 *params
= (GLfloat
) table
->Size
;
1064 case GL_COLOR_TABLE_RED_SIZE
:
1065 *params
= table
->RedSize
;
1067 case GL_COLOR_TABLE_GREEN_SIZE
:
1068 *params
= table
->GreenSize
;
1070 case GL_COLOR_TABLE_BLUE_SIZE
:
1071 *params
= table
->BlueSize
;
1073 case GL_COLOR_TABLE_ALPHA_SIZE
:
1074 *params
= table
->AlphaSize
;
1076 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1077 *params
= table
->LuminanceSize
;
1079 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1080 *params
= table
->IntensitySize
;
1083 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
1091 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1093 GET_CURRENT_CONTEXT(ctx
);
1094 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1095 struct gl_color_table
*table
= NULL
;
1096 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1100 table
= &texUnit
->Current1D
->Palette
;
1103 table
= &texUnit
->Current2D
->Palette
;
1106 table
= &texUnit
->Current3D
->Palette
;
1108 case GL_TEXTURE_CUBE_MAP_ARB
:
1109 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1110 _mesa_error(ctx
, GL_INVALID_ENUM
,
1111 "glGetColorTableParameteriv(target)");
1114 table
= &texUnit
->CurrentCubeMap
->Palette
;
1116 case GL_PROXY_TEXTURE_1D
:
1117 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1119 case GL_PROXY_TEXTURE_2D
:
1120 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1122 case GL_PROXY_TEXTURE_3D
:
1123 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1125 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1126 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1127 _mesa_error(ctx
, GL_INVALID_ENUM
,
1128 "glGetColorTableParameteriv(target)");
1131 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
1133 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1134 table
= &ctx
->Texture
.Palette
;
1136 case GL_COLOR_TABLE
:
1137 table
= &ctx
->ColorTable
;
1138 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1139 params
[0] = (GLint
) ctx
->Pixel
.ColorTableScale
[0];
1140 params
[1] = (GLint
) ctx
->Pixel
.ColorTableScale
[1];
1141 params
[2] = (GLint
) ctx
->Pixel
.ColorTableScale
[2];
1142 params
[3] = (GLint
) ctx
->Pixel
.ColorTableScale
[3];
1145 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1146 params
[0] = (GLint
) ctx
->Pixel
.ColorTableBias
[0];
1147 params
[1] = (GLint
) ctx
->Pixel
.ColorTableBias
[1];
1148 params
[2] = (GLint
) ctx
->Pixel
.ColorTableBias
[2];
1149 params
[3] = (GLint
) ctx
->Pixel
.ColorTableBias
[3];
1153 case GL_PROXY_COLOR_TABLE
:
1154 table
= &ctx
->ProxyColorTable
;
1156 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1157 table
= &ctx
->PostConvolutionColorTable
;
1158 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1159 params
[0] = (GLint
) ctx
->Pixel
.PCCTscale
[0];
1160 params
[1] = (GLint
) ctx
->Pixel
.PCCTscale
[1];
1161 params
[2] = (GLint
) ctx
->Pixel
.PCCTscale
[2];
1162 params
[3] = (GLint
) ctx
->Pixel
.PCCTscale
[3];
1165 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1166 params
[0] = (GLint
) ctx
->Pixel
.PCCTbias
[0];
1167 params
[1] = (GLint
) ctx
->Pixel
.PCCTbias
[1];
1168 params
[2] = (GLint
) ctx
->Pixel
.PCCTbias
[2];
1169 params
[3] = (GLint
) ctx
->Pixel
.PCCTbias
[3];
1173 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1174 table
= &ctx
->ProxyPostConvolutionColorTable
;
1176 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1177 table
= &ctx
->PostColorMatrixColorTable
;
1178 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1179 params
[0] = (GLint
) ctx
->Pixel
.PCMCTscale
[0];
1180 params
[1] = (GLint
) ctx
->Pixel
.PCMCTscale
[1];
1181 params
[2] = (GLint
) ctx
->Pixel
.PCMCTscale
[2];
1182 params
[3] = (GLint
) ctx
->Pixel
.PCMCTscale
[3];
1185 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1186 params
[0] = (GLint
) ctx
->Pixel
.PCMCTbias
[0];
1187 params
[1] = (GLint
) ctx
->Pixel
.PCMCTbias
[1];
1188 params
[2] = (GLint
) ctx
->Pixel
.PCMCTbias
[2];
1189 params
[3] = (GLint
) ctx
->Pixel
.PCMCTbias
[3];
1193 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1194 table
= &ctx
->ProxyPostColorMatrixColorTable
;
1197 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1204 case GL_COLOR_TABLE_FORMAT
:
1205 *params
= table
->IntFormat
;
1207 case GL_COLOR_TABLE_WIDTH
:
1208 *params
= table
->Size
;
1210 case GL_COLOR_TABLE_RED_SIZE
:
1211 *params
= table
->RedSize
;
1213 case GL_COLOR_TABLE_GREEN_SIZE
:
1214 *params
= table
->GreenSize
;
1216 case GL_COLOR_TABLE_BLUE_SIZE
:
1217 *params
= table
->BlueSize
;
1219 case GL_COLOR_TABLE_ALPHA_SIZE
:
1220 *params
= table
->AlphaSize
;
1222 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1223 *params
= table
->LuminanceSize
;
1225 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1226 *params
= table
->IntensitySize
;
1229 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );