2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 #include "bufferobj.h"
37 * Given an internalFormat token passed to glColorTable,
38 * return the corresponding base format.
39 * Return -1 if invalid token.
42 base_colortab_format( GLenum format
)
57 case GL_LUMINANCE_ALPHA
:
58 case GL_LUMINANCE4_ALPHA4
:
59 case GL_LUMINANCE6_ALPHA2
:
60 case GL_LUMINANCE8_ALPHA8
:
61 case GL_LUMINANCE12_ALPHA4
:
62 case GL_LUMINANCE12_ALPHA12
:
63 case GL_LUMINANCE16_ALPHA16
:
64 return GL_LUMINANCE_ALPHA
;
90 return -1; /* error */
97 * Examine table's format and set the component sizes accordingly.
100 set_component_sizes( struct gl_color_table
*table
)
102 /* assuming the ubyte table */
103 const GLubyte sz
= 8;
105 switch (table
->_BaseFormat
) {
108 table
->GreenSize
= 0;
110 table
->AlphaSize
= sz
;
111 table
->IntensitySize
= 0;
112 table
->LuminanceSize
= 0;
116 table
->GreenSize
= 0;
118 table
->AlphaSize
= 0;
119 table
->IntensitySize
= 0;
120 table
->LuminanceSize
= sz
;
122 case GL_LUMINANCE_ALPHA
:
124 table
->GreenSize
= 0;
126 table
->AlphaSize
= sz
;
127 table
->IntensitySize
= 0;
128 table
->LuminanceSize
= sz
;
132 table
->GreenSize
= 0;
134 table
->AlphaSize
= 0;
135 table
->IntensitySize
= sz
;
136 table
->LuminanceSize
= 0;
140 table
->GreenSize
= sz
;
141 table
->BlueSize
= sz
;
142 table
->AlphaSize
= 0;
143 table
->IntensitySize
= 0;
144 table
->LuminanceSize
= 0;
148 table
->GreenSize
= sz
;
149 table
->BlueSize
= sz
;
150 table
->AlphaSize
= sz
;
151 table
->IntensitySize
= 0;
152 table
->LuminanceSize
= 0;
155 _mesa_problem(NULL
, "unexpected format in set_component_sizes");
162 * Update/replace all or part of a color table. Helper function
163 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
164 * The table->Table buffer should already be allocated.
165 * \param start first entry to update
166 * \param count number of entries to update
167 * \param format format of user-provided table data
168 * \param type datatype of user-provided table data
169 * \param data user-provided table data
170 * \param [rgba]Scale - RGBA scale factors
171 * \param [rgba]Bias - RGBA bias factors
174 store_colortable_entries(GLcontext
*ctx
, struct gl_color_table
*table
,
175 GLsizei start
, GLsizei count
,
176 GLenum format
, GLenum type
, const GLvoid
*data
,
177 GLfloat rScale
, GLfloat rBias
,
178 GLfloat gScale
, GLfloat gBias
,
179 GLfloat bScale
, GLfloat bBias
,
180 GLfloat aScale
, GLfloat aBias
)
182 data
= _mesa_map_validate_pbo_source(ctx
,
183 1, &ctx
->Unpack
, count
, 1, 1,
185 "glColor[Sub]Table");
190 /* convert user-provided data to GLfloat values */
191 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
195 _mesa_unpack_color_span_float(ctx
,
196 count
, /* number of pixels */
197 table
->_BaseFormat
, /* dest format */
198 tempTab
, /* dest address */
199 format
, type
, /* src format/type */
202 IMAGE_CLAMP_BIT
); /* transfer ops */
204 /* the destination */
205 tableF
= table
->TableF
;
207 /* Apply scale & bias & clamp now */
208 switch (table
->_BaseFormat
) {
210 for (i
= 0; i
< count
; i
++) {
211 GLuint j
= start
+ i
;
212 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
216 for (i
= 0; i
< count
; i
++) {
217 GLuint j
= start
+ i
;
218 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
222 for (i
= 0; i
< count
; i
++) {
223 GLuint j
= start
+ i
;
224 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
227 case GL_LUMINANCE_ALPHA
:
228 for (i
= 0; i
< count
; i
++) {
229 GLuint j
= start
+ i
;
230 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
231 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
235 for (i
= 0; i
< count
; i
++) {
236 GLuint j
= start
+ i
;
237 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
238 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
239 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
243 for (i
= 0; i
< count
; i
++) {
244 GLuint j
= start
+ i
;
245 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
246 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
247 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
248 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
252 _mesa_problem(ctx
, "Bad format in store_colortable_entries");
257 /* update the ubyte table */
259 const GLint comps
= _mesa_components_in_format(table
->_BaseFormat
);
260 const GLfloat
*tableF
= table
->TableF
+ start
* comps
;
261 GLubyte
*tableUB
= table
->TableUB
+ start
* comps
;
263 for (i
= 0; i
< count
* comps
; i
++) {
264 CLAMPED_FLOAT_TO_UBYTE(tableUB
[i
], tableF
[i
]);
268 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
274 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
275 GLsizei width
, GLenum format
, GLenum type
,
278 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
279 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
280 GET_CURRENT_CONTEXT(ctx
);
281 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
282 struct gl_texture_object
*texObj
= NULL
;
283 struct gl_color_table
*table
= NULL
;
284 GLboolean proxy
= GL_FALSE
;
286 const GLfloat
*scale
= one
, *bias
= zero
;
289 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
292 case GL_SHARED_TEXTURE_PALETTE_EXT
:
293 table
= &ctx
->Texture
.Palette
;
296 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
297 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
298 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
300 case GL_PROXY_COLOR_TABLE
:
301 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
304 case GL_TEXTURE_COLOR_TABLE_SGI
:
305 if (!ctx
->Extensions
.SGI_texture_color_table
) {
306 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
309 table
= &(texUnit
->ColorTable
);
310 scale
= ctx
->Pixel
.TextureColorTableScale
;
311 bias
= ctx
->Pixel
.TextureColorTableBias
;
313 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
314 if (!ctx
->Extensions
.SGI_texture_color_table
) {
315 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
318 table
= &(texUnit
->ProxyColorTable
);
321 case GL_POST_CONVOLUTION_COLOR_TABLE
:
322 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
323 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
324 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
326 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
327 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
330 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
331 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
332 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
333 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
335 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
336 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
340 /* try texture targets */
342 struct gl_texture_object
*texobj
343 = _mesa_select_tex_object(ctx
, texUnit
, target
);
345 table
= &texobj
->Palette
;
346 proxy
= _mesa_is_proxy_texture(target
);
349 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
357 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
358 format
== GL_INTENSITY
) {
359 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
363 baseFormat
= base_colortab_format(internalFormat
);
364 if (baseFormat
< 0) {
365 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
369 if (width
< 0 || (width
!= 0 && !_mesa_is_pow_two(width
))) {
373 table
->InternalFormat
= (GLenum
) 0;
374 table
->_BaseFormat
= (GLenum
) 0;
377 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width=%d)", width
);
382 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
385 table
->InternalFormat
= (GLenum
) 0;
386 table
->_BaseFormat
= (GLenum
) 0;
389 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
395 table
->InternalFormat
= internalFormat
;
396 table
->_BaseFormat
= (GLenum
) baseFormat
;
398 comps
= _mesa_components_in_format(table
->_BaseFormat
);
399 assert(comps
> 0); /* error should have been caught sooner */
402 _mesa_free_colortable_data(table
);
405 table
->TableF
= (GLfloat
*) _mesa_malloc(comps
* width
* sizeof(GLfloat
));
406 table
->TableUB
= (GLubyte
*) _mesa_malloc(comps
* width
* sizeof(GLubyte
));
408 if (!table
->TableF
|| !table
->TableUB
) {
409 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
413 store_colortable_entries(ctx
, table
,
414 0, width
, /* start, count */
423 /* do this after the table's Type and Format are set */
424 set_component_sizes(table
);
426 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
427 /* texture object palette, texObj==NULL means the shared palette */
428 if (ctx
->Driver
.UpdateTexturePalette
) {
429 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
433 ctx
->NewState
|= _NEW_PIXEL
;
439 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
440 GLsizei count
, GLenum format
, GLenum type
,
443 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
444 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
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 const GLfloat
*scale
= one
, *bias
= zero
;
451 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
454 case GL_SHARED_TEXTURE_PALETTE_EXT
:
455 table
= &ctx
->Texture
.Palette
;
458 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
459 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
460 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
462 case GL_TEXTURE_COLOR_TABLE_SGI
:
463 if (!ctx
->Extensions
.SGI_texture_color_table
) {
464 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
467 table
= &(texUnit
->ColorTable
);
468 scale
= ctx
->Pixel
.TextureColorTableScale
;
469 bias
= ctx
->Pixel
.TextureColorTableBias
;
471 case GL_POST_CONVOLUTION_COLOR_TABLE
:
472 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
473 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
474 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
476 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
477 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
478 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
479 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
482 /* try texture targets */
483 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
484 if (texObj
&& !_mesa_is_proxy_texture(target
)) {
485 table
= &texObj
->Palette
;
488 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
495 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
496 format
== GL_INTENSITY
) {
497 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
502 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
506 /* error should have been caught sooner */
507 assert(_mesa_components_in_format(table
->_BaseFormat
) > 0);
509 if (start
+ count
> (GLint
) table
->Size
) {
510 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
514 if (!table
->TableF
|| !table
->TableUB
) {
515 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
519 store_colortable_entries(ctx
, table
, start
, count
,
526 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
527 /* per-texture object palette */
528 if (ctx
->Driver
.UpdateTexturePalette
) {
529 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
533 ctx
->NewState
|= _NEW_PIXEL
;
539 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
540 GLint x
, GLint y
, GLsizei width
)
542 GET_CURRENT_CONTEXT(ctx
);
543 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
545 /* Select buffer to read from */
546 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
552 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
553 GLint x
, GLint y
, GLsizei width
)
555 GET_CURRENT_CONTEXT(ctx
);
556 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
558 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
564 _mesa_GetColorTable( GLenum target
, GLenum format
,
565 GLenum type
, GLvoid
*data
)
567 GET_CURRENT_CONTEXT(ctx
);
568 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
569 struct gl_color_table
*table
= NULL
;
570 GLfloat rgba
[MAX_COLOR_TABLE_SIZE
][4];
571 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
574 _mesa_update_state(ctx
);
578 case GL_SHARED_TEXTURE_PALETTE_EXT
:
579 table
= &ctx
->Texture
.Palette
;
582 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
584 case GL_TEXTURE_COLOR_TABLE_SGI
:
585 if (!ctx
->Extensions
.SGI_texture_color_table
) {
586 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
589 table
= &(texUnit
->ColorTable
);
591 case GL_POST_CONVOLUTION_COLOR_TABLE
:
592 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
594 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
595 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
598 /* try texture targets */
600 struct gl_texture_object
*texobj
601 = _mesa_select_tex_object(ctx
, texUnit
, target
);
602 if (texobj
&& !_mesa_is_proxy_texture(target
)) {
603 table
= &texobj
->Palette
;
606 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
614 if (table
->Size
<= 0) {
618 switch (table
->_BaseFormat
) {
622 for (i
= 0; i
< table
->Size
; i
++) {
626 rgba
[i
][ACOMP
] = table
->TableF
[i
];
633 for (i
= 0; i
< table
->Size
; i
++) {
636 rgba
[i
][BCOMP
] = table
->TableF
[i
];
637 rgba
[i
][ACOMP
] = 1.0F
;
641 case GL_LUMINANCE_ALPHA
:
644 for (i
= 0; i
< table
->Size
; i
++) {
647 rgba
[i
][BCOMP
] = table
->TableF
[i
*2+0];
648 rgba
[i
][ACOMP
] = table
->TableF
[i
*2+1];
655 for (i
= 0; i
< table
->Size
; i
++) {
659 rgba
[i
][ACOMP
] = table
->TableF
[i
];
666 for (i
= 0; i
< table
->Size
; i
++) {
667 rgba
[i
][RCOMP
] = table
->TableF
[i
*3+0];
668 rgba
[i
][GCOMP
] = table
->TableF
[i
*3+1];
669 rgba
[i
][BCOMP
] = table
->TableF
[i
*3+2];
670 rgba
[i
][ACOMP
] = 1.0F
;
675 _mesa_memcpy(rgba
, table
->TableF
, 4 * table
->Size
* sizeof(GLfloat
));
678 _mesa_problem(ctx
, "bad table format in glGetColorTable");
682 data
= _mesa_map_validate_pbo_dest(ctx
,
683 1, &ctx
->Pack
, table
->Size
, 1, 1,
689 _mesa_pack_rgba_span_float(ctx
, table
->Size
, rgba
,
690 format
, type
, data
, &ctx
->Pack
, 0x0);
692 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
698 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
700 GLfloat
*scale
, *bias
;
701 GET_CURRENT_CONTEXT(ctx
);
702 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
705 case GL_COLOR_TABLE_SGI
:
706 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
707 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
709 case GL_TEXTURE_COLOR_TABLE_SGI
:
710 scale
= ctx
->Pixel
.TextureColorTableScale
;
711 bias
= ctx
->Pixel
.TextureColorTableBias
;
713 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
714 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
715 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
717 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
718 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
719 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
722 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
726 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
727 COPY_4V(scale
, params
);
729 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
730 COPY_4V(bias
, params
);
733 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
737 ctx
->NewState
|= _NEW_PIXEL
;
743 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
746 if (pname
== GL_COLOR_TABLE_SGI
||
747 pname
== GL_TEXTURE_COLOR_TABLE_SGI
||
748 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
749 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
751 fparams
[0] = (GLfloat
) params
[0];
752 fparams
[1] = (GLfloat
) params
[1];
753 fparams
[2] = (GLfloat
) params
[2];
754 fparams
[3] = (GLfloat
) params
[3];
758 fparams
[0] = (GLfloat
) params
[0];
760 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
766 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
768 GET_CURRENT_CONTEXT(ctx
);
769 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
770 struct gl_color_table
*table
= NULL
;
771 ASSERT_OUTSIDE_BEGIN_END(ctx
);
774 case GL_SHARED_TEXTURE_PALETTE_EXT
:
775 table
= &ctx
->Texture
.Palette
;
778 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
779 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
780 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
]);
783 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
784 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
]);
788 case GL_PROXY_COLOR_TABLE
:
789 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
791 case GL_TEXTURE_COLOR_TABLE_SGI
:
792 if (!ctx
->Extensions
.SGI_texture_color_table
) {
793 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
796 table
= &(texUnit
->ColorTable
);
797 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
798 COPY_4V(params
, ctx
->Pixel
.TextureColorTableScale
);
801 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
802 COPY_4V(params
, ctx
->Pixel
.TextureColorTableBias
);
806 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
807 if (!ctx
->Extensions
.SGI_texture_color_table
) {
808 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
811 table
= &(texUnit
->ProxyColorTable
);
813 case GL_POST_CONVOLUTION_COLOR_TABLE
:
814 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
815 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
816 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
]);
819 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
820 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
]);
824 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
825 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
827 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
828 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
829 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
830 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
]);
833 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
834 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
]);
838 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
839 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
842 /* try texture targets */
844 struct gl_texture_object
*texobj
845 = _mesa_select_tex_object(ctx
, texUnit
, target
);
847 table
= &texobj
->Palette
;
850 _mesa_error(ctx
, GL_INVALID_ENUM
,
851 "glGetColorTableParameterfv(target)");
860 case GL_COLOR_TABLE_FORMAT
:
861 *params
= (GLfloat
) table
->InternalFormat
;
863 case GL_COLOR_TABLE_WIDTH
:
864 *params
= (GLfloat
) table
->Size
;
866 case GL_COLOR_TABLE_RED_SIZE
:
867 *params
= (GLfloat
) table
->RedSize
;
869 case GL_COLOR_TABLE_GREEN_SIZE
:
870 *params
= (GLfloat
) table
->GreenSize
;
872 case GL_COLOR_TABLE_BLUE_SIZE
:
873 *params
= (GLfloat
) table
->BlueSize
;
875 case GL_COLOR_TABLE_ALPHA_SIZE
:
876 *params
= (GLfloat
) table
->AlphaSize
;
878 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
879 *params
= (GLfloat
) table
->LuminanceSize
;
881 case GL_COLOR_TABLE_INTENSITY_SIZE
:
882 *params
= (GLfloat
) table
->IntensitySize
;
885 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
893 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
895 GET_CURRENT_CONTEXT(ctx
);
896 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
897 struct gl_color_table
*table
= NULL
;
898 ASSERT_OUTSIDE_BEGIN_END(ctx
);
901 case GL_SHARED_TEXTURE_PALETTE_EXT
:
902 table
= &ctx
->Texture
.Palette
;
905 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
906 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
907 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
908 params
[0] = (GLint
) scale
[0];
909 params
[1] = (GLint
) scale
[1];
910 params
[2] = (GLint
) scale
[2];
911 params
[3] = (GLint
) scale
[3];
914 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
915 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
916 params
[0] = (GLint
) bias
[0];
917 params
[1] = (GLint
) bias
[1];
918 params
[2] = (GLint
) bias
[2];
919 params
[3] = (GLint
) bias
[3];
923 case GL_PROXY_COLOR_TABLE
:
924 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
926 case GL_TEXTURE_COLOR_TABLE_SGI
:
927 if (!ctx
->Extensions
.SGI_texture_color_table
) {
928 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
931 table
= &(texUnit
->ColorTable
);
932 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
933 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[0];
934 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[1];
935 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[2];
936 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[3];
939 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
940 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[0];
941 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[1];
942 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[2];
943 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[3];
947 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
948 if (!ctx
->Extensions
.SGI_texture_color_table
) {
949 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
952 table
= &(texUnit
->ProxyColorTable
);
954 case GL_POST_CONVOLUTION_COLOR_TABLE
:
955 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
956 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
957 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
958 params
[0] = (GLint
) scale
[0];
959 params
[1] = (GLint
) scale
[1];
960 params
[2] = (GLint
) scale
[2];
961 params
[3] = (GLint
) scale
[3];
964 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
965 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
966 params
[0] = (GLint
) bias
[0];
967 params
[1] = (GLint
) bias
[1];
968 params
[2] = (GLint
) bias
[2];
969 params
[3] = (GLint
) bias
[3];
973 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
974 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
976 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
977 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
978 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
979 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
980 params
[0] = (GLint
) scale
[0];
981 params
[0] = (GLint
) scale
[1];
982 params
[0] = (GLint
) scale
[2];
983 params
[0] = (GLint
) scale
[3];
986 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
987 GLfloat
*bias
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
988 params
[0] = (GLint
) bias
[0];
989 params
[1] = (GLint
) bias
[1];
990 params
[2] = (GLint
) bias
[2];
991 params
[3] = (GLint
) bias
[3];
995 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
996 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
999 /* Try texture targets */
1001 struct gl_texture_object
*texobj
1002 = _mesa_select_tex_object(ctx
, texUnit
, target
);
1004 table
= &texobj
->Palette
;
1007 _mesa_error(ctx
, GL_INVALID_ENUM
,
1008 "glGetColorTableParameteriv(target)");
1017 case GL_COLOR_TABLE_FORMAT
:
1018 *params
= table
->InternalFormat
;
1020 case GL_COLOR_TABLE_WIDTH
:
1021 *params
= table
->Size
;
1023 case GL_COLOR_TABLE_RED_SIZE
:
1024 *params
= table
->RedSize
;
1026 case GL_COLOR_TABLE_GREEN_SIZE
:
1027 *params
= table
->GreenSize
;
1029 case GL_COLOR_TABLE_BLUE_SIZE
:
1030 *params
= table
->BlueSize
;
1032 case GL_COLOR_TABLE_ALPHA_SIZE
:
1033 *params
= table
->AlphaSize
;
1035 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1036 *params
= table
->LuminanceSize
;
1038 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1039 *params
= table
->IntensitySize
;
1042 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );
1047 /**********************************************************************/
1048 /***** Initialization *****/
1049 /**********************************************************************/
1053 _mesa_init_colortable( struct gl_color_table
*p
)
1058 p
->InternalFormat
= GL_RGBA
;
1064 _mesa_free_colortable_data( struct gl_color_table
*p
)
1067 _mesa_free(p
->TableF
);
1071 _mesa_free(p
->TableUB
);
1078 * Initialize all colortables for a context.
1081 _mesa_init_colortables( GLcontext
* ctx
)
1084 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1085 _mesa_init_colortable(&ctx
->ColorTable
[i
]);
1086 _mesa_init_colortable(&ctx
->ProxyColorTable
[i
]);
1092 * Free all colortable data for a context
1095 _mesa_free_colortables_data( GLcontext
*ctx
)
1098 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1099 _mesa_free_colortable_data(&ctx
->ColorTable
[i
]);
1100 _mesa_free_colortable_data(&ctx
->ProxyColorTable
[i
]);