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 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
547 return; /* no readbuffer - OK */
550 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
556 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
557 GLint x
, GLint y
, GLsizei width
)
559 GET_CURRENT_CONTEXT(ctx
);
560 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
562 if (!ctx
->ReadBuffer
->_ColorReadBuffer
) {
563 return; /* no readbuffer - OK */
566 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
572 _mesa_GetColorTable( GLenum target
, GLenum format
,
573 GLenum type
, GLvoid
*data
)
575 GET_CURRENT_CONTEXT(ctx
);
576 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
577 struct gl_color_table
*table
= NULL
;
578 GLfloat rgba
[MAX_COLOR_TABLE_SIZE
][4];
579 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
582 _mesa_update_state(ctx
);
586 case GL_SHARED_TEXTURE_PALETTE_EXT
:
587 table
= &ctx
->Texture
.Palette
;
590 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
592 case GL_TEXTURE_COLOR_TABLE_SGI
:
593 if (!ctx
->Extensions
.SGI_texture_color_table
) {
594 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
597 table
= &(texUnit
->ColorTable
);
599 case GL_POST_CONVOLUTION_COLOR_TABLE
:
600 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
602 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
603 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
606 /* try texture targets */
608 struct gl_texture_object
*texobj
609 = _mesa_select_tex_object(ctx
, texUnit
, target
);
610 if (texobj
&& !_mesa_is_proxy_texture(target
)) {
611 table
= &texobj
->Palette
;
614 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
622 if (table
->Size
<= 0) {
626 switch (table
->_BaseFormat
) {
630 for (i
= 0; i
< table
->Size
; i
++) {
634 rgba
[i
][ACOMP
] = table
->TableF
[i
];
641 for (i
= 0; i
< table
->Size
; i
++) {
644 rgba
[i
][BCOMP
] = table
->TableF
[i
];
645 rgba
[i
][ACOMP
] = 1.0F
;
649 case GL_LUMINANCE_ALPHA
:
652 for (i
= 0; i
< table
->Size
; i
++) {
655 rgba
[i
][BCOMP
] = table
->TableF
[i
*2+0];
656 rgba
[i
][ACOMP
] = table
->TableF
[i
*2+1];
663 for (i
= 0; i
< table
->Size
; i
++) {
667 rgba
[i
][ACOMP
] = table
->TableF
[i
];
674 for (i
= 0; i
< table
->Size
; i
++) {
675 rgba
[i
][RCOMP
] = table
->TableF
[i
*3+0];
676 rgba
[i
][GCOMP
] = table
->TableF
[i
*3+1];
677 rgba
[i
][BCOMP
] = table
->TableF
[i
*3+2];
678 rgba
[i
][ACOMP
] = 1.0F
;
683 _mesa_memcpy(rgba
, table
->TableF
, 4 * table
->Size
* sizeof(GLfloat
));
686 _mesa_problem(ctx
, "bad table format in glGetColorTable");
690 data
= _mesa_map_validate_pbo_dest(ctx
,
691 1, &ctx
->Pack
, table
->Size
, 1, 1,
697 _mesa_pack_rgba_span_float(ctx
, table
->Size
, rgba
,
698 format
, type
, data
, &ctx
->Pack
, 0x0);
700 _mesa_unmap_pbo_dest(ctx
, &ctx
->Pack
);
706 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
708 GLfloat
*scale
, *bias
;
709 GET_CURRENT_CONTEXT(ctx
);
710 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
713 case GL_COLOR_TABLE_SGI
:
714 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
715 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
717 case GL_TEXTURE_COLOR_TABLE_SGI
:
718 scale
= ctx
->Pixel
.TextureColorTableScale
;
719 bias
= ctx
->Pixel
.TextureColorTableBias
;
721 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
722 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
723 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
725 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
726 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
727 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
730 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
734 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
735 COPY_4V(scale
, params
);
737 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
738 COPY_4V(bias
, params
);
741 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
745 ctx
->NewState
|= _NEW_PIXEL
;
751 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
754 if (pname
== GL_COLOR_TABLE_SGI
||
755 pname
== GL_TEXTURE_COLOR_TABLE_SGI
||
756 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
757 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
759 fparams
[0] = (GLfloat
) params
[0];
760 fparams
[1] = (GLfloat
) params
[1];
761 fparams
[2] = (GLfloat
) params
[2];
762 fparams
[3] = (GLfloat
) params
[3];
766 fparams
[0] = (GLfloat
) params
[0];
768 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
774 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
776 GET_CURRENT_CONTEXT(ctx
);
777 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
778 struct gl_color_table
*table
= NULL
;
779 ASSERT_OUTSIDE_BEGIN_END(ctx
);
782 case GL_SHARED_TEXTURE_PALETTE_EXT
:
783 table
= &ctx
->Texture
.Palette
;
786 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
787 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
788 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
]);
791 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
792 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
]);
796 case GL_PROXY_COLOR_TABLE
:
797 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
799 case GL_TEXTURE_COLOR_TABLE_SGI
:
800 if (!ctx
->Extensions
.SGI_texture_color_table
) {
801 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
804 table
= &(texUnit
->ColorTable
);
805 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
806 COPY_4V(params
, ctx
->Pixel
.TextureColorTableScale
);
809 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
810 COPY_4V(params
, ctx
->Pixel
.TextureColorTableBias
);
814 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
815 if (!ctx
->Extensions
.SGI_texture_color_table
) {
816 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
819 table
= &(texUnit
->ProxyColorTable
);
821 case GL_POST_CONVOLUTION_COLOR_TABLE
:
822 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
823 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
824 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
]);
827 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
828 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
]);
832 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
833 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
835 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
836 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
837 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
838 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
]);
841 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
842 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
]);
846 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
847 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
850 /* try texture targets */
852 struct gl_texture_object
*texobj
853 = _mesa_select_tex_object(ctx
, texUnit
, target
);
855 table
= &texobj
->Palette
;
858 _mesa_error(ctx
, GL_INVALID_ENUM
,
859 "glGetColorTableParameterfv(target)");
868 case GL_COLOR_TABLE_FORMAT
:
869 *params
= (GLfloat
) table
->InternalFormat
;
871 case GL_COLOR_TABLE_WIDTH
:
872 *params
= (GLfloat
) table
->Size
;
874 case GL_COLOR_TABLE_RED_SIZE
:
875 *params
= (GLfloat
) table
->RedSize
;
877 case GL_COLOR_TABLE_GREEN_SIZE
:
878 *params
= (GLfloat
) table
->GreenSize
;
880 case GL_COLOR_TABLE_BLUE_SIZE
:
881 *params
= (GLfloat
) table
->BlueSize
;
883 case GL_COLOR_TABLE_ALPHA_SIZE
:
884 *params
= (GLfloat
) table
->AlphaSize
;
886 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
887 *params
= (GLfloat
) table
->LuminanceSize
;
889 case GL_COLOR_TABLE_INTENSITY_SIZE
:
890 *params
= (GLfloat
) table
->IntensitySize
;
893 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
901 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
903 GET_CURRENT_CONTEXT(ctx
);
904 struct gl_texture_unit
*texUnit
= _mesa_get_current_tex_unit(ctx
);
905 struct gl_color_table
*table
= NULL
;
906 ASSERT_OUTSIDE_BEGIN_END(ctx
);
909 case GL_SHARED_TEXTURE_PALETTE_EXT
:
910 table
= &ctx
->Texture
.Palette
;
913 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
914 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
915 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
916 params
[0] = (GLint
) scale
[0];
917 params
[1] = (GLint
) scale
[1];
918 params
[2] = (GLint
) scale
[2];
919 params
[3] = (GLint
) scale
[3];
922 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
923 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
924 params
[0] = (GLint
) bias
[0];
925 params
[1] = (GLint
) bias
[1];
926 params
[2] = (GLint
) bias
[2];
927 params
[3] = (GLint
) bias
[3];
931 case GL_PROXY_COLOR_TABLE
:
932 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
934 case GL_TEXTURE_COLOR_TABLE_SGI
:
935 if (!ctx
->Extensions
.SGI_texture_color_table
) {
936 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
939 table
= &(texUnit
->ColorTable
);
940 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
941 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[0];
942 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[1];
943 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[2];
944 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[3];
947 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
948 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[0];
949 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[1];
950 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[2];
951 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[3];
955 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
956 if (!ctx
->Extensions
.SGI_texture_color_table
) {
957 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
960 table
= &(texUnit
->ProxyColorTable
);
962 case GL_POST_CONVOLUTION_COLOR_TABLE
:
963 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
964 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
965 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
966 params
[0] = (GLint
) scale
[0];
967 params
[1] = (GLint
) scale
[1];
968 params
[2] = (GLint
) scale
[2];
969 params
[3] = (GLint
) scale
[3];
972 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
973 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
974 params
[0] = (GLint
) bias
[0];
975 params
[1] = (GLint
) bias
[1];
976 params
[2] = (GLint
) bias
[2];
977 params
[3] = (GLint
) bias
[3];
981 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
982 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
984 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
985 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
986 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
987 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
988 params
[0] = (GLint
) scale
[0];
989 params
[0] = (GLint
) scale
[1];
990 params
[0] = (GLint
) scale
[2];
991 params
[0] = (GLint
) scale
[3];
994 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
995 GLfloat
*bias
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
996 params
[0] = (GLint
) bias
[0];
997 params
[1] = (GLint
) bias
[1];
998 params
[2] = (GLint
) bias
[2];
999 params
[3] = (GLint
) bias
[3];
1003 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1004 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1007 /* Try texture targets */
1009 struct gl_texture_object
*texobj
1010 = _mesa_select_tex_object(ctx
, texUnit
, target
);
1012 table
= &texobj
->Palette
;
1015 _mesa_error(ctx
, GL_INVALID_ENUM
,
1016 "glGetColorTableParameteriv(target)");
1025 case GL_COLOR_TABLE_FORMAT
:
1026 *params
= table
->InternalFormat
;
1028 case GL_COLOR_TABLE_WIDTH
:
1029 *params
= table
->Size
;
1031 case GL_COLOR_TABLE_RED_SIZE
:
1032 *params
= table
->RedSize
;
1034 case GL_COLOR_TABLE_GREEN_SIZE
:
1035 *params
= table
->GreenSize
;
1037 case GL_COLOR_TABLE_BLUE_SIZE
:
1038 *params
= table
->BlueSize
;
1040 case GL_COLOR_TABLE_ALPHA_SIZE
:
1041 *params
= table
->AlphaSize
;
1043 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1044 *params
= table
->LuminanceSize
;
1046 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1047 *params
= table
->IntensitySize
;
1050 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );
1055 /**********************************************************************/
1056 /***** Initialization *****/
1057 /**********************************************************************/
1061 _mesa_init_colortable( struct gl_color_table
*p
)
1066 p
->InternalFormat
= GL_RGBA
;
1072 _mesa_free_colortable_data( struct gl_color_table
*p
)
1075 _mesa_free(p
->TableF
);
1079 _mesa_free(p
->TableUB
);
1086 * Initialize all colortables for a context.
1089 _mesa_init_colortables( GLcontext
* ctx
)
1092 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1093 _mesa_init_colortable(&ctx
->ColorTable
[i
]);
1094 _mesa_init_colortable(&ctx
->ProxyColorTable
[i
]);
1100 * Free all colortable data for a context
1103 _mesa_free_colortables_data( GLcontext
*ctx
)
1106 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1107 _mesa_free_colortable_data(&ctx
->ColorTable
[i
]);
1108 _mesa_free_colortable_data(&ctx
->ProxyColorTable
[i
]);