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"
38 * Given an internalFormat token passed to glColorTable,
39 * return the corresponding base format.
40 * Return -1 if invalid token.
43 base_colortab_format( GLenum format
)
58 case GL_LUMINANCE_ALPHA
:
59 case GL_LUMINANCE4_ALPHA4
:
60 case GL_LUMINANCE6_ALPHA2
:
61 case GL_LUMINANCE8_ALPHA8
:
62 case GL_LUMINANCE12_ALPHA4
:
63 case GL_LUMINANCE12_ALPHA12
:
64 case GL_LUMINANCE16_ALPHA16
:
65 return GL_LUMINANCE_ALPHA
;
91 return -1; /* error */
98 * Examine table's format and set the component sizes accordingly.
101 set_component_sizes( struct gl_color_table
*table
)
103 /* assuming the ubyte table */
104 const GLubyte sz
= 8;
106 switch (table
->_BaseFormat
) {
109 table
->GreenSize
= 0;
111 table
->AlphaSize
= sz
;
112 table
->IntensitySize
= 0;
113 table
->LuminanceSize
= 0;
117 table
->GreenSize
= 0;
119 table
->AlphaSize
= 0;
120 table
->IntensitySize
= 0;
121 table
->LuminanceSize
= sz
;
123 case GL_LUMINANCE_ALPHA
:
125 table
->GreenSize
= 0;
127 table
->AlphaSize
= sz
;
128 table
->IntensitySize
= 0;
129 table
->LuminanceSize
= sz
;
133 table
->GreenSize
= 0;
135 table
->AlphaSize
= 0;
136 table
->IntensitySize
= sz
;
137 table
->LuminanceSize
= 0;
141 table
->GreenSize
= sz
;
142 table
->BlueSize
= sz
;
143 table
->AlphaSize
= 0;
144 table
->IntensitySize
= 0;
145 table
->LuminanceSize
= 0;
149 table
->GreenSize
= sz
;
150 table
->BlueSize
= sz
;
151 table
->AlphaSize
= sz
;
152 table
->IntensitySize
= 0;
153 table
->LuminanceSize
= 0;
156 _mesa_problem(NULL
, "unexpected format in set_component_sizes");
163 * Update/replace all or part of a color table. Helper function
164 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
165 * The table->Table buffer should already be allocated.
166 * \param start first entry to update
167 * \param count number of entries to update
168 * \param format format of user-provided table data
169 * \param type datatype of user-provided table data
170 * \param data user-provided table data
171 * \param [rgba]Scale - RGBA scale factors
172 * \param [rgba]Bias - RGBA bias factors
175 store_colortable_entries(GLcontext
*ctx
, struct gl_color_table
*table
,
176 GLsizei start
, GLsizei count
,
177 GLenum format
, GLenum type
, const GLvoid
*data
,
178 GLfloat rScale
, GLfloat rBias
,
179 GLfloat gScale
, GLfloat gBias
,
180 GLfloat bScale
, GLfloat bBias
,
181 GLfloat aScale
, GLfloat aBias
)
183 data
= _mesa_map_validate_pbo_source(ctx
,
184 1, &ctx
->Unpack
, count
, 1, 1,
186 "glColor[Sub]Table");
191 /* convert user-provided data to GLfloat values */
192 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
196 _mesa_unpack_color_span_float(ctx
,
197 count
, /* number of pixels */
198 table
->_BaseFormat
, /* dest format */
199 tempTab
, /* dest address */
200 format
, type
, /* src format/type */
203 IMAGE_CLAMP_BIT
); /* transfer ops */
205 /* the destination */
206 tableF
= table
->TableF
;
208 /* Apply scale & bias & clamp now */
209 switch (table
->_BaseFormat
) {
211 for (i
= 0; i
< count
; i
++) {
212 GLuint j
= start
+ i
;
213 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
217 for (i
= 0; i
< count
; i
++) {
218 GLuint j
= start
+ i
;
219 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
223 for (i
= 0; i
< count
; i
++) {
224 GLuint j
= start
+ i
;
225 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
228 case GL_LUMINANCE_ALPHA
:
229 for (i
= 0; i
< count
; i
++) {
230 GLuint j
= start
+ i
;
231 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
232 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
236 for (i
= 0; i
< count
; i
++) {
237 GLuint j
= start
+ i
;
238 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
239 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
240 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
244 for (i
= 0; i
< count
; i
++) {
245 GLuint j
= start
+ i
;
246 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
247 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
248 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
249 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
253 _mesa_problem(ctx
, "Bad format in store_colortable_entries");
258 /* update the ubyte table */
260 const GLint comps
= _mesa_components_in_format(table
->_BaseFormat
);
261 const GLfloat
*tableF
= table
->TableF
+ start
* comps
;
262 GLubyte
*tableUB
= table
->TableUB
+ start
* comps
;
264 for (i
= 0; i
< count
* comps
; i
++) {
265 CLAMPED_FLOAT_TO_UBYTE(tableUB
[i
], tableF
[i
]);
269 _mesa_unmap_pbo_source(ctx
, &ctx
->Unpack
);
275 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
276 GLsizei width
, GLenum format
, GLenum type
,
279 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
280 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
281 GET_CURRENT_CONTEXT(ctx
);
282 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
283 struct gl_texture_object
*texObj
= NULL
;
284 struct gl_color_table
*table
= NULL
;
285 GLboolean proxy
= GL_FALSE
;
287 const GLfloat
*scale
= one
, *bias
= zero
;
290 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
293 case GL_SHARED_TEXTURE_PALETTE_EXT
:
294 table
= &ctx
->Texture
.Palette
;
297 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
298 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
299 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
301 case GL_PROXY_COLOR_TABLE
:
302 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
305 case GL_TEXTURE_COLOR_TABLE_SGI
:
306 if (!ctx
->Extensions
.SGI_texture_color_table
) {
307 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
310 table
= &(texUnit
->ColorTable
);
311 scale
= ctx
->Pixel
.TextureColorTableScale
;
312 bias
= ctx
->Pixel
.TextureColorTableBias
;
314 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
315 if (!ctx
->Extensions
.SGI_texture_color_table
) {
316 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
319 table
= &(texUnit
->ProxyColorTable
);
322 case GL_POST_CONVOLUTION_COLOR_TABLE
:
323 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
324 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
325 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
327 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
328 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
331 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
332 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
333 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
334 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
336 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
337 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
341 /* try texture targets */
343 struct gl_texture_object
*texobj
344 = _mesa_select_tex_object(ctx
, texUnit
, target
);
346 table
= &texobj
->Palette
;
347 proxy
= _mesa_is_proxy_texture(target
);
350 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
358 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
359 format
== GL_INTENSITY
) {
360 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
364 baseFormat
= base_colortab_format(internalFormat
);
365 if (baseFormat
< 0) {
366 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
370 if (width
< 0 || (width
!= 0 && !_mesa_is_pow_two(width
))) {
374 table
->InternalFormat
= (GLenum
) 0;
375 table
->_BaseFormat
= (GLenum
) 0;
378 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width=%d)", width
);
383 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
386 table
->InternalFormat
= (GLenum
) 0;
387 table
->_BaseFormat
= (GLenum
) 0;
390 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
396 table
->InternalFormat
= internalFormat
;
397 table
->_BaseFormat
= (GLenum
) baseFormat
;
399 comps
= _mesa_components_in_format(table
->_BaseFormat
);
400 assert(comps
> 0); /* error should have been caught sooner */
403 _mesa_free_colortable_data(table
);
406 table
->TableF
= (GLfloat
*) _mesa_malloc(comps
* width
* sizeof(GLfloat
));
407 table
->TableUB
= (GLubyte
*) _mesa_malloc(comps
* width
* sizeof(GLubyte
));
409 if (!table
->TableF
|| !table
->TableUB
) {
410 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
414 store_colortable_entries(ctx
, table
,
415 0, width
, /* start, count */
424 /* do this after the table's Type and Format are set */
425 set_component_sizes(table
);
427 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
428 /* texture object palette, texObj==NULL means the shared palette */
429 if (ctx
->Driver
.UpdateTexturePalette
) {
430 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
434 ctx
->NewState
|= _NEW_PIXEL
;
440 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
441 GLsizei count
, GLenum format
, GLenum type
,
444 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
445 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
446 GET_CURRENT_CONTEXT(ctx
);
447 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
448 struct gl_texture_object
*texObj
= NULL
;
449 struct gl_color_table
*table
= NULL
;
450 const GLfloat
*scale
= one
, *bias
= zero
;
452 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
455 case GL_SHARED_TEXTURE_PALETTE_EXT
:
456 table
= &ctx
->Texture
.Palette
;
459 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
460 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
461 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
463 case GL_TEXTURE_COLOR_TABLE_SGI
:
464 if (!ctx
->Extensions
.SGI_texture_color_table
) {
465 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
468 table
= &(texUnit
->ColorTable
);
469 scale
= ctx
->Pixel
.TextureColorTableScale
;
470 bias
= ctx
->Pixel
.TextureColorTableBias
;
472 case GL_POST_CONVOLUTION_COLOR_TABLE
:
473 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
474 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
475 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
477 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
478 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
479 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
480 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
483 /* try texture targets */
484 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
485 if (texObj
&& !_mesa_is_proxy_texture(target
)) {
486 table
= &texObj
->Palette
;
489 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
496 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
497 format
== GL_INTENSITY
) {
498 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
503 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
507 /* error should have been caught sooner */
508 assert(_mesa_components_in_format(table
->_BaseFormat
) > 0);
510 if (start
+ count
> (GLint
) table
->Size
) {
511 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
515 if (!table
->TableF
|| !table
->TableUB
) {
516 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
520 store_colortable_entries(ctx
, table
, start
, count
,
527 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
528 /* per-texture object palette */
529 if (ctx
->Driver
.UpdateTexturePalette
) {
530 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
534 ctx
->NewState
|= _NEW_PIXEL
;
540 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
541 GLint x
, GLint y
, GLsizei width
)
543 GET_CURRENT_CONTEXT(ctx
);
544 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
546 /* Select buffer to read from */
547 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
553 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
554 GLint x
, GLint y
, GLsizei width
)
556 GET_CURRENT_CONTEXT(ctx
);
557 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
559 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
565 _mesa_GetColorTable( GLenum target
, GLenum format
,
566 GLenum type
, GLvoid
*data
)
568 GET_CURRENT_CONTEXT(ctx
);
569 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
570 struct gl_color_table
*table
= NULL
;
571 GLfloat rgba
[MAX_COLOR_TABLE_SIZE
][4];
572 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
575 _mesa_update_state(ctx
);
579 case GL_SHARED_TEXTURE_PALETTE_EXT
:
580 table
= &ctx
->Texture
.Palette
;
583 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
585 case GL_TEXTURE_COLOR_TABLE_SGI
:
586 if (!ctx
->Extensions
.SGI_texture_color_table
) {
587 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
590 table
= &(texUnit
->ColorTable
);
592 case GL_POST_CONVOLUTION_COLOR_TABLE
:
593 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
595 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
596 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
599 /* try texture targets */
601 struct gl_texture_object
*texobj
602 = _mesa_select_tex_object(ctx
, texUnit
, target
);
603 if (texobj
&& !_mesa_is_proxy_texture(target
)) {
604 table
= &texobj
->Palette
;
607 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
615 if (table
->Size
<= 0) {
619 switch (table
->_BaseFormat
) {
623 for (i
= 0; i
< table
->Size
; i
++) {
627 rgba
[i
][ACOMP
] = table
->TableF
[i
];
634 for (i
= 0; i
< table
->Size
; i
++) {
637 rgba
[i
][BCOMP
] = table
->TableF
[i
];
638 rgba
[i
][ACOMP
] = 1.0F
;
642 case GL_LUMINANCE_ALPHA
:
645 for (i
= 0; i
< table
->Size
; i
++) {
648 rgba
[i
][BCOMP
] = table
->TableF
[i
*2+0];
649 rgba
[i
][ACOMP
] = table
->TableF
[i
*2+1];
656 for (i
= 0; i
< table
->Size
; i
++) {
660 rgba
[i
][ACOMP
] = table
->TableF
[i
];
667 for (i
= 0; i
< table
->Size
; i
++) {
668 rgba
[i
][RCOMP
] = table
->TableF
[i
*3+0];
669 rgba
[i
][GCOMP
] = table
->TableF
[i
*3+1];
670 rgba
[i
][BCOMP
] = table
->TableF
[i
*3+2];
671 rgba
[i
][ACOMP
] = 1.0F
;
676 _mesa_memcpy(rgba
, table
->TableF
, 4 * table
->Size
* sizeof(GLfloat
));
679 _mesa_problem(ctx
, "bad table format in glGetColorTable");
683 data
= _mesa_map_validate_pbo_dest(ctx
,
684 1, &ctx
->Pack
, table
->Size
, 1, 1,
690 _mesa_pack_rgba_span_float(ctx
, table
->Size
, rgba
,
691 format
, type
, data
, &ctx
->Pack
, 0x0);
693 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
699 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
701 GLfloat
*scale
, *bias
;
702 GET_CURRENT_CONTEXT(ctx
);
703 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
706 case GL_COLOR_TABLE_SGI
:
707 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
708 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
710 case GL_TEXTURE_COLOR_TABLE_SGI
:
711 scale
= ctx
->Pixel
.TextureColorTableScale
;
712 bias
= ctx
->Pixel
.TextureColorTableBias
;
714 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
715 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
716 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
718 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
719 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
720 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
723 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
727 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
728 COPY_4V(scale
, params
);
730 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
731 COPY_4V(bias
, params
);
734 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
738 ctx
->NewState
|= _NEW_PIXEL
;
744 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
747 if (pname
== GL_COLOR_TABLE_SGI
||
748 pname
== GL_TEXTURE_COLOR_TABLE_SGI
||
749 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
750 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
752 fparams
[0] = (GLfloat
) params
[0];
753 fparams
[1] = (GLfloat
) params
[1];
754 fparams
[2] = (GLfloat
) params
[2];
755 fparams
[3] = (GLfloat
) params
[3];
759 fparams
[0] = (GLfloat
) params
[0];
761 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
767 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
769 GET_CURRENT_CONTEXT(ctx
);
770 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
771 struct gl_color_table
*table
= NULL
;
772 ASSERT_OUTSIDE_BEGIN_END(ctx
);
775 case GL_SHARED_TEXTURE_PALETTE_EXT
:
776 table
= &ctx
->Texture
.Palette
;
779 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
780 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
781 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
]);
784 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
785 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
]);
789 case GL_PROXY_COLOR_TABLE
:
790 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
792 case GL_TEXTURE_COLOR_TABLE_SGI
:
793 if (!ctx
->Extensions
.SGI_texture_color_table
) {
794 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
797 table
= &(texUnit
->ColorTable
);
798 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
799 COPY_4V(params
, ctx
->Pixel
.TextureColorTableScale
);
802 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
803 COPY_4V(params
, ctx
->Pixel
.TextureColorTableBias
);
807 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
808 if (!ctx
->Extensions
.SGI_texture_color_table
) {
809 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
812 table
= &(texUnit
->ProxyColorTable
);
814 case GL_POST_CONVOLUTION_COLOR_TABLE
:
815 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
816 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
817 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
]);
820 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
821 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
]);
825 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
826 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
828 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
829 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
830 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
831 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
]);
834 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
835 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
]);
839 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
840 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
843 /* try texture targets */
845 struct gl_texture_object
*texobj
846 = _mesa_select_tex_object(ctx
, texUnit
, target
);
848 table
= &texobj
->Palette
;
851 _mesa_error(ctx
, GL_INVALID_ENUM
,
852 "glGetColorTableParameterfv(target)");
861 case GL_COLOR_TABLE_FORMAT
:
862 *params
= (GLfloat
) table
->InternalFormat
;
864 case GL_COLOR_TABLE_WIDTH
:
865 *params
= (GLfloat
) table
->Size
;
867 case GL_COLOR_TABLE_RED_SIZE
:
868 *params
= (GLfloat
) table
->RedSize
;
870 case GL_COLOR_TABLE_GREEN_SIZE
:
871 *params
= (GLfloat
) table
->GreenSize
;
873 case GL_COLOR_TABLE_BLUE_SIZE
:
874 *params
= (GLfloat
) table
->BlueSize
;
876 case GL_COLOR_TABLE_ALPHA_SIZE
:
877 *params
= (GLfloat
) table
->AlphaSize
;
879 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
880 *params
= (GLfloat
) table
->LuminanceSize
;
882 case GL_COLOR_TABLE_INTENSITY_SIZE
:
883 *params
= (GLfloat
) table
->IntensitySize
;
886 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
894 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
896 GET_CURRENT_CONTEXT(ctx
);
897 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
898 struct gl_color_table
*table
= NULL
;
899 ASSERT_OUTSIDE_BEGIN_END(ctx
);
902 case GL_SHARED_TEXTURE_PALETTE_EXT
:
903 table
= &ctx
->Texture
.Palette
;
906 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
907 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
908 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
909 params
[0] = (GLint
) scale
[0];
910 params
[1] = (GLint
) scale
[1];
911 params
[2] = (GLint
) scale
[2];
912 params
[3] = (GLint
) scale
[3];
915 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
916 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
917 params
[0] = (GLint
) bias
[0];
918 params
[1] = (GLint
) bias
[1];
919 params
[2] = (GLint
) bias
[2];
920 params
[3] = (GLint
) bias
[3];
924 case GL_PROXY_COLOR_TABLE
:
925 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
927 case GL_TEXTURE_COLOR_TABLE_SGI
:
928 if (!ctx
->Extensions
.SGI_texture_color_table
) {
929 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
932 table
= &(texUnit
->ColorTable
);
933 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
934 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[0];
935 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[1];
936 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[2];
937 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[3];
940 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
941 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[0];
942 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[1];
943 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[2];
944 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[3];
948 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
949 if (!ctx
->Extensions
.SGI_texture_color_table
) {
950 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
953 table
= &(texUnit
->ProxyColorTable
);
955 case GL_POST_CONVOLUTION_COLOR_TABLE
:
956 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
957 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
958 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
959 params
[0] = (GLint
) scale
[0];
960 params
[1] = (GLint
) scale
[1];
961 params
[2] = (GLint
) scale
[2];
962 params
[3] = (GLint
) scale
[3];
965 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
966 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
967 params
[0] = (GLint
) bias
[0];
968 params
[1] = (GLint
) bias
[1];
969 params
[2] = (GLint
) bias
[2];
970 params
[3] = (GLint
) bias
[3];
974 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
975 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
977 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
978 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
979 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
980 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
981 params
[0] = (GLint
) scale
[0];
982 params
[0] = (GLint
) scale
[1];
983 params
[0] = (GLint
) scale
[2];
984 params
[0] = (GLint
) scale
[3];
987 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
988 GLfloat
*bias
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
989 params
[0] = (GLint
) bias
[0];
990 params
[1] = (GLint
) bias
[1];
991 params
[2] = (GLint
) bias
[2];
992 params
[3] = (GLint
) bias
[3];
996 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
997 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1000 /* Try texture targets */
1002 struct gl_texture_object
*texobj
1003 = _mesa_select_tex_object(ctx
, texUnit
, target
);
1005 table
= &texobj
->Palette
;
1008 _mesa_error(ctx
, GL_INVALID_ENUM
,
1009 "glGetColorTableParameteriv(target)");
1018 case GL_COLOR_TABLE_FORMAT
:
1019 *params
= table
->InternalFormat
;
1021 case GL_COLOR_TABLE_WIDTH
:
1022 *params
= table
->Size
;
1024 case GL_COLOR_TABLE_RED_SIZE
:
1025 *params
= table
->RedSize
;
1027 case GL_COLOR_TABLE_GREEN_SIZE
:
1028 *params
= table
->GreenSize
;
1030 case GL_COLOR_TABLE_BLUE_SIZE
:
1031 *params
= table
->BlueSize
;
1033 case GL_COLOR_TABLE_ALPHA_SIZE
:
1034 *params
= table
->AlphaSize
;
1036 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1037 *params
= table
->LuminanceSize
;
1039 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1040 *params
= table
->IntensitySize
;
1043 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );
1048 /**********************************************************************/
1049 /***** Initialization *****/
1050 /**********************************************************************/
1054 _mesa_init_colortable( struct gl_color_table
*p
)
1059 p
->InternalFormat
= GL_RGBA
;
1065 _mesa_free_colortable_data( struct gl_color_table
*p
)
1068 _mesa_free(p
->TableF
);
1072 _mesa_free(p
->TableUB
);
1079 * Initialize all colortables for a context.
1082 _mesa_init_colortables( GLcontext
* ctx
)
1085 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1086 _mesa_init_colortable(&ctx
->ColorTable
[i
]);
1087 _mesa_init_colortable(&ctx
->ProxyColorTable
[i
]);
1093 * Free all colortable data for a context
1096 _mesa_free_colortables_data( GLcontext
*ctx
)
1099 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1100 _mesa_free_colortable_data(&ctx
->ColorTable
[i
]);
1101 _mesa_free_colortable_data(&ctx
->ProxyColorTable
[i
]);