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 if (ctx
->Unpack
.BufferObj
->Name
) {
183 /* Get/unpack the color table data from a PBO */
185 if (!_mesa_validate_pbo_access(1, &ctx
->Unpack
, count
, 1, 1,
186 format
, type
, data
)) {
187 _mesa_error(ctx
, GL_INVALID_OPERATION
,
188 "glColor[Sub]Table(bad PBO access)");
191 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
193 ctx
->Unpack
.BufferObj
);
195 _mesa_error(ctx
, GL_INVALID_OPERATION
,
196 "glColor[Sub]Table(PBO mapped)");
199 data
= ADD_POINTERS(buf
, data
);
204 /* convert user-provided data to GLfloat values */
205 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
209 _mesa_unpack_color_span_float(ctx
,
210 count
, /* number of pixels */
211 table
->_BaseFormat
, /* dest format */
212 tempTab
, /* dest address */
213 format
, type
, /* src format/type */
216 IMAGE_CLAMP_BIT
); /* transfer ops */
218 /* the destination */
219 tableF
= table
->TableF
;
221 /* Apply scale & bias & clamp now */
222 switch (table
->_BaseFormat
) {
224 for (i
= 0; i
< count
; i
++) {
225 GLuint j
= start
+ i
;
226 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
230 for (i
= 0; i
< count
; i
++) {
231 GLuint j
= start
+ i
;
232 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
236 for (i
= 0; i
< count
; i
++) {
237 GLuint j
= start
+ i
;
238 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
241 case GL_LUMINANCE_ALPHA
:
242 for (i
= 0; i
< count
; i
++) {
243 GLuint j
= start
+ i
;
244 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
245 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
249 for (i
= 0; i
< count
; i
++) {
250 GLuint j
= start
+ i
;
251 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
252 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
253 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
257 for (i
= 0; i
< count
; i
++) {
258 GLuint j
= start
+ i
;
259 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
260 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
261 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
262 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
266 _mesa_problem(ctx
, "Bad format in store_colortable_entries");
271 /* update the ubyte table */
273 const GLint comps
= _mesa_components_in_format(table
->_BaseFormat
);
274 const GLfloat
*tableF
= table
->TableF
+ start
* comps
;
275 GLubyte
*tableUB
= table
->TableUB
+ start
* comps
;
277 for (i
= 0; i
< count
* comps
; i
++) {
278 CLAMPED_FLOAT_TO_UBYTE(tableUB
[i
], tableF
[i
]);
282 if (ctx
->Unpack
.BufferObj
->Name
) {
283 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
284 ctx
->Unpack
.BufferObj
);
291 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
292 GLsizei width
, GLenum format
, GLenum type
,
295 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
296 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
297 GET_CURRENT_CONTEXT(ctx
);
298 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
299 struct gl_texture_object
*texObj
= NULL
;
300 struct gl_color_table
*table
= NULL
;
301 GLboolean proxy
= GL_FALSE
;
303 const GLfloat
*scale
= one
, *bias
= zero
;
306 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
309 case GL_SHARED_TEXTURE_PALETTE_EXT
:
310 table
= &ctx
->Texture
.Palette
;
313 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
314 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
315 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
317 case GL_PROXY_COLOR_TABLE
:
318 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
321 case GL_TEXTURE_COLOR_TABLE_SGI
:
322 if (!ctx
->Extensions
.SGI_texture_color_table
) {
323 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
326 table
= &(texUnit
->ColorTable
);
327 scale
= ctx
->Pixel
.TextureColorTableScale
;
328 bias
= ctx
->Pixel
.TextureColorTableBias
;
330 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
331 if (!ctx
->Extensions
.SGI_texture_color_table
) {
332 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
335 table
= &(texUnit
->ProxyColorTable
);
338 case GL_POST_CONVOLUTION_COLOR_TABLE
:
339 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
340 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
341 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
343 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
344 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
347 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
348 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
349 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
350 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
352 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
353 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
357 /* try texture targets */
359 struct gl_texture_object
*texobj
360 = _mesa_select_tex_object(ctx
, texUnit
, target
);
362 table
= &texobj
->Palette
;
363 proxy
= _mesa_is_proxy_texture(target
);
366 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
374 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
375 format
== GL_INTENSITY
) {
376 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
380 baseFormat
= base_colortab_format(internalFormat
);
381 if (baseFormat
< 0) {
382 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
386 if (width
< 0 || (width
!= 0 && _mesa_bitcount(width
) != 1)) {
390 table
->InternalFormat
= (GLenum
) 0;
391 table
->_BaseFormat
= (GLenum
) 0;
394 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width=%d)", width
);
399 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
402 table
->InternalFormat
= (GLenum
) 0;
403 table
->_BaseFormat
= (GLenum
) 0;
406 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
412 table
->InternalFormat
= internalFormat
;
413 table
->_BaseFormat
= (GLenum
) baseFormat
;
415 comps
= _mesa_components_in_format(table
->_BaseFormat
);
416 assert(comps
> 0); /* error should have been caught sooner */
419 _mesa_free_colortable_data(table
);
422 table
->TableF
= (GLfloat
*) _mesa_malloc(comps
* width
* sizeof(GLfloat
));
423 table
->TableUB
= (GLubyte
*) _mesa_malloc(comps
* width
* sizeof(GLubyte
));
425 if (!table
->TableF
|| !table
->TableUB
) {
426 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
430 store_colortable_entries(ctx
, table
,
431 0, width
, /* start, count */
440 /* do this after the table's Type and Format are set */
441 set_component_sizes(table
);
443 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
444 /* texture object palette, texObj==NULL means the shared palette */
445 if (ctx
->Driver
.UpdateTexturePalette
) {
446 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
450 ctx
->NewState
|= _NEW_PIXEL
;
456 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
457 GLsizei count
, GLenum format
, GLenum type
,
460 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
461 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
462 GET_CURRENT_CONTEXT(ctx
);
463 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
464 struct gl_texture_object
*texObj
= NULL
;
465 struct gl_color_table
*table
= NULL
;
466 const GLfloat
*scale
= one
, *bias
= zero
;
468 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
471 case GL_SHARED_TEXTURE_PALETTE_EXT
:
472 table
= &ctx
->Texture
.Palette
;
475 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
476 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
477 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
479 case GL_TEXTURE_COLOR_TABLE_SGI
:
480 if (!ctx
->Extensions
.SGI_texture_color_table
) {
481 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
484 table
= &(texUnit
->ColorTable
);
485 scale
= ctx
->Pixel
.TextureColorTableScale
;
486 bias
= ctx
->Pixel
.TextureColorTableBias
;
488 case GL_POST_CONVOLUTION_COLOR_TABLE
:
489 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
490 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
491 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
493 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
494 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
495 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
496 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
499 /* try texture targets */
500 texObj
= _mesa_select_tex_object(ctx
, texUnit
, target
);
501 if (texObj
&& !_mesa_is_proxy_texture(target
)) {
502 table
= &texObj
->Palette
;
505 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
512 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
513 format
== GL_INTENSITY
) {
514 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
519 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
523 /* error should have been caught sooner */
524 assert(_mesa_components_in_format(table
->_BaseFormat
) > 0);
526 if (start
+ count
> (GLint
) table
->Size
) {
527 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
531 if (!table
->TableF
|| !table
->TableUB
) {
532 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
536 store_colortable_entries(ctx
, table
, start
, count
,
543 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
544 /* per-texture object palette */
545 if (ctx
->Driver
.UpdateTexturePalette
) {
546 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
550 ctx
->NewState
|= _NEW_PIXEL
;
556 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
557 GLint x
, GLint y
, GLsizei width
)
559 GET_CURRENT_CONTEXT(ctx
);
560 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
562 /* Select buffer to read from */
563 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
569 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
570 GLint x
, GLint y
, GLsizei width
)
572 GET_CURRENT_CONTEXT(ctx
);
573 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
575 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
581 _mesa_GetColorTable( GLenum target
, GLenum format
,
582 GLenum type
, GLvoid
*data
)
584 GET_CURRENT_CONTEXT(ctx
);
585 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
586 struct gl_color_table
*table
= NULL
;
587 GLfloat rgba
[MAX_COLOR_TABLE_SIZE
][4];
588 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
591 _mesa_update_state(ctx
);
595 case GL_SHARED_TEXTURE_PALETTE_EXT
:
596 table
= &ctx
->Texture
.Palette
;
599 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
601 case GL_TEXTURE_COLOR_TABLE_SGI
:
602 if (!ctx
->Extensions
.SGI_texture_color_table
) {
603 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
606 table
= &(texUnit
->ColorTable
);
608 case GL_POST_CONVOLUTION_COLOR_TABLE
:
609 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
611 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
612 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
615 /* try texture targets */
617 struct gl_texture_object
*texobj
618 = _mesa_select_tex_object(ctx
, texUnit
, target
);
619 if (texobj
&& !_mesa_is_proxy_texture(target
)) {
620 table
= &texobj
->Palette
;
623 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
631 if (table
->Size
<= 0) {
635 switch (table
->_BaseFormat
) {
639 for (i
= 0; i
< table
->Size
; i
++) {
643 rgba
[i
][ACOMP
] = table
->TableF
[i
];
650 for (i
= 0; i
< table
->Size
; i
++) {
653 rgba
[i
][BCOMP
] = table
->TableF
[i
];
654 rgba
[i
][ACOMP
] = 1.0F
;
658 case GL_LUMINANCE_ALPHA
:
661 for (i
= 0; i
< table
->Size
; i
++) {
664 rgba
[i
][BCOMP
] = table
->TableF
[i
*2+0];
665 rgba
[i
][ACOMP
] = table
->TableF
[i
*2+1];
672 for (i
= 0; i
< table
->Size
; i
++) {
676 rgba
[i
][ACOMP
] = table
->TableF
[i
];
683 for (i
= 0; i
< table
->Size
; i
++) {
684 rgba
[i
][RCOMP
] = table
->TableF
[i
*3+0];
685 rgba
[i
][GCOMP
] = table
->TableF
[i
*3+1];
686 rgba
[i
][BCOMP
] = table
->TableF
[i
*3+2];
687 rgba
[i
][ACOMP
] = 1.0F
;
692 _mesa_memcpy(rgba
, table
->TableF
, 4 * table
->Size
* sizeof(GLfloat
));
695 _mesa_problem(ctx
, "bad table format in glGetColorTable");
699 if (ctx
->Pack
.BufferObj
->Name
) {
700 /* pack color table into PBO */
702 if (!_mesa_validate_pbo_access(1, &ctx
->Pack
, table
->Size
, 1, 1,
703 format
, type
, data
)) {
704 _mesa_error(ctx
, GL_INVALID_OPERATION
,
705 "glGetColorTable(invalid PBO access)");
708 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
710 ctx
->Pack
.BufferObj
);
712 /* buffer is already mapped - that's an error */
713 _mesa_error(ctx
, GL_INVALID_OPERATION
,
714 "glGetColorTable(PBO is mapped)");
717 data
= ADD_POINTERS(buf
, data
);
720 _mesa_pack_rgba_span_float(ctx
, table
->Size
, rgba
,
721 format
, type
, data
, &ctx
->Pack
, 0x0);
723 if (ctx
->Pack
.BufferObj
->Name
) {
724 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
725 ctx
->Pack
.BufferObj
);
732 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
734 GLfloat
*scale
, *bias
;
735 GET_CURRENT_CONTEXT(ctx
);
736 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
739 case GL_COLOR_TABLE_SGI
:
740 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
741 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
743 case GL_TEXTURE_COLOR_TABLE_SGI
:
744 scale
= ctx
->Pixel
.TextureColorTableScale
;
745 bias
= ctx
->Pixel
.TextureColorTableBias
;
747 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
748 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
749 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
751 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
752 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
753 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
756 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
760 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
761 COPY_4V(scale
, params
);
763 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
764 COPY_4V(bias
, params
);
767 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
771 ctx
->NewState
|= _NEW_PIXEL
;
777 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
780 if (pname
== GL_COLOR_TABLE_SGI
||
781 pname
== GL_TEXTURE_COLOR_TABLE_SGI
||
782 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
783 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
785 fparams
[0] = (GLfloat
) params
[0];
786 fparams
[1] = (GLfloat
) params
[1];
787 fparams
[2] = (GLfloat
) params
[2];
788 fparams
[3] = (GLfloat
) params
[3];
792 fparams
[0] = (GLfloat
) params
[0];
794 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
800 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
802 GET_CURRENT_CONTEXT(ctx
);
803 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
804 struct gl_color_table
*table
= NULL
;
805 ASSERT_OUTSIDE_BEGIN_END(ctx
);
808 case GL_SHARED_TEXTURE_PALETTE_EXT
:
809 table
= &ctx
->Texture
.Palette
;
812 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
813 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
814 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
]);
817 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
818 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
]);
822 case GL_PROXY_COLOR_TABLE
:
823 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
825 case GL_TEXTURE_COLOR_TABLE_SGI
:
826 if (!ctx
->Extensions
.SGI_texture_color_table
) {
827 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
830 table
= &(texUnit
->ColorTable
);
831 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
832 COPY_4V(params
, ctx
->Pixel
.TextureColorTableScale
);
835 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
836 COPY_4V(params
, ctx
->Pixel
.TextureColorTableBias
);
840 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
841 if (!ctx
->Extensions
.SGI_texture_color_table
) {
842 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
845 table
= &(texUnit
->ProxyColorTable
);
847 case GL_POST_CONVOLUTION_COLOR_TABLE
:
848 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
849 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
850 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
]);
853 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
854 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
]);
858 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
859 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
861 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
862 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
863 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
864 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
]);
867 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
868 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
]);
872 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
873 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
876 /* try texture targets */
878 struct gl_texture_object
*texobj
879 = _mesa_select_tex_object(ctx
, texUnit
, target
);
881 table
= &texobj
->Palette
;
884 _mesa_error(ctx
, GL_INVALID_ENUM
,
885 "glGetColorTableParameterfv(target)");
894 case GL_COLOR_TABLE_FORMAT
:
895 *params
= (GLfloat
) table
->InternalFormat
;
897 case GL_COLOR_TABLE_WIDTH
:
898 *params
= (GLfloat
) table
->Size
;
900 case GL_COLOR_TABLE_RED_SIZE
:
901 *params
= (GLfloat
) table
->RedSize
;
903 case GL_COLOR_TABLE_GREEN_SIZE
:
904 *params
= (GLfloat
) table
->GreenSize
;
906 case GL_COLOR_TABLE_BLUE_SIZE
:
907 *params
= (GLfloat
) table
->BlueSize
;
909 case GL_COLOR_TABLE_ALPHA_SIZE
:
910 *params
= (GLfloat
) table
->AlphaSize
;
912 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
913 *params
= (GLfloat
) table
->LuminanceSize
;
915 case GL_COLOR_TABLE_INTENSITY_SIZE
:
916 *params
= (GLfloat
) table
->IntensitySize
;
919 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
927 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
929 GET_CURRENT_CONTEXT(ctx
);
930 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
931 struct gl_color_table
*table
= NULL
;
932 ASSERT_OUTSIDE_BEGIN_END(ctx
);
935 case GL_SHARED_TEXTURE_PALETTE_EXT
:
936 table
= &ctx
->Texture
.Palette
;
939 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
940 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
941 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
942 params
[0] = (GLint
) scale
[0];
943 params
[1] = (GLint
) scale
[1];
944 params
[2] = (GLint
) scale
[2];
945 params
[3] = (GLint
) scale
[3];
948 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
949 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
950 params
[0] = (GLint
) bias
[0];
951 params
[1] = (GLint
) bias
[1];
952 params
[2] = (GLint
) bias
[2];
953 params
[3] = (GLint
) bias
[3];
957 case GL_PROXY_COLOR_TABLE
:
958 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
960 case GL_TEXTURE_COLOR_TABLE_SGI
:
961 if (!ctx
->Extensions
.SGI_texture_color_table
) {
962 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
965 table
= &(texUnit
->ColorTable
);
966 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
967 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[0];
968 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[1];
969 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[2];
970 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[3];
973 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
974 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[0];
975 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[1];
976 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[2];
977 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[3];
981 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
982 if (!ctx
->Extensions
.SGI_texture_color_table
) {
983 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
986 table
= &(texUnit
->ProxyColorTable
);
988 case GL_POST_CONVOLUTION_COLOR_TABLE
:
989 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
990 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
991 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
992 params
[0] = (GLint
) scale
[0];
993 params
[1] = (GLint
) scale
[1];
994 params
[2] = (GLint
) scale
[2];
995 params
[3] = (GLint
) scale
[3];
998 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
999 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
1000 params
[0] = (GLint
) bias
[0];
1001 params
[1] = (GLint
) bias
[1];
1002 params
[2] = (GLint
) bias
[2];
1003 params
[3] = (GLint
) bias
[3];
1007 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1008 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
1010 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1011 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1012 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1013 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
1014 params
[0] = (GLint
) scale
[0];
1015 params
[0] = (GLint
) scale
[1];
1016 params
[0] = (GLint
) scale
[2];
1017 params
[0] = (GLint
) scale
[3];
1020 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1021 GLfloat
*bias
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
1022 params
[0] = (GLint
) bias
[0];
1023 params
[1] = (GLint
) bias
[1];
1024 params
[2] = (GLint
) bias
[2];
1025 params
[3] = (GLint
) bias
[3];
1029 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1030 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1033 /* Try texture targets */
1035 struct gl_texture_object
*texobj
1036 = _mesa_select_tex_object(ctx
, texUnit
, target
);
1038 table
= &texobj
->Palette
;
1041 _mesa_error(ctx
, GL_INVALID_ENUM
,
1042 "glGetColorTableParameteriv(target)");
1051 case GL_COLOR_TABLE_FORMAT
:
1052 *params
= table
->InternalFormat
;
1054 case GL_COLOR_TABLE_WIDTH
:
1055 *params
= table
->Size
;
1057 case GL_COLOR_TABLE_RED_SIZE
:
1058 *params
= table
->RedSize
;
1060 case GL_COLOR_TABLE_GREEN_SIZE
:
1061 *params
= table
->GreenSize
;
1063 case GL_COLOR_TABLE_BLUE_SIZE
:
1064 *params
= table
->BlueSize
;
1066 case GL_COLOR_TABLE_ALPHA_SIZE
:
1067 *params
= table
->AlphaSize
;
1069 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1070 *params
= table
->LuminanceSize
;
1072 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1073 *params
= table
->IntensitySize
;
1076 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );
1081 /**********************************************************************/
1082 /***** Initialization *****/
1083 /**********************************************************************/
1087 _mesa_init_colortable( struct gl_color_table
*p
)
1092 p
->InternalFormat
= GL_RGBA
;
1098 _mesa_free_colortable_data( struct gl_color_table
*p
)
1101 _mesa_free(p
->TableF
);
1105 _mesa_free(p
->TableUB
);
1112 * Initialize all colortables for a context.
1115 _mesa_init_colortables( GLcontext
* ctx
)
1118 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1119 _mesa_init_colortable(&ctx
->ColorTable
[i
]);
1120 _mesa_init_colortable(&ctx
->ProxyColorTable
[i
]);
1126 * Free all colortable data for a context
1129 _mesa_free_colortables_data( GLcontext
*ctx
)
1132 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1133 _mesa_free_colortable_data(&ctx
->ColorTable
[i
]);
1134 _mesa_free_colortable_data(&ctx
->ProxyColorTable
[i
]);