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"
36 * Given an internalFormat token passed to glColorTable,
37 * return the corresponding base format.
38 * Return -1 if invalid token.
41 base_colortab_format( GLenum format
)
56 case GL_LUMINANCE_ALPHA
:
57 case GL_LUMINANCE4_ALPHA4
:
58 case GL_LUMINANCE6_ALPHA2
:
59 case GL_LUMINANCE8_ALPHA8
:
60 case GL_LUMINANCE12_ALPHA4
:
61 case GL_LUMINANCE12_ALPHA12
:
62 case GL_LUMINANCE16_ALPHA16
:
63 return GL_LUMINANCE_ALPHA
;
89 return -1; /* error */
96 * Examine table's format and set the component sizes accordingly.
99 set_component_sizes( struct gl_color_table
*table
)
101 /* assuming the ubyte table */
102 const GLubyte sz
= 8;
104 switch (table
->_BaseFormat
) {
107 table
->GreenSize
= 0;
109 table
->AlphaSize
= sz
;
110 table
->IntensitySize
= 0;
111 table
->LuminanceSize
= 0;
115 table
->GreenSize
= 0;
117 table
->AlphaSize
= 0;
118 table
->IntensitySize
= 0;
119 table
->LuminanceSize
= sz
;
121 case GL_LUMINANCE_ALPHA
:
123 table
->GreenSize
= 0;
125 table
->AlphaSize
= sz
;
126 table
->IntensitySize
= 0;
127 table
->LuminanceSize
= sz
;
131 table
->GreenSize
= 0;
133 table
->AlphaSize
= 0;
134 table
->IntensitySize
= sz
;
135 table
->LuminanceSize
= 0;
139 table
->GreenSize
= sz
;
140 table
->BlueSize
= sz
;
141 table
->AlphaSize
= 0;
142 table
->IntensitySize
= 0;
143 table
->LuminanceSize
= 0;
147 table
->GreenSize
= sz
;
148 table
->BlueSize
= sz
;
149 table
->AlphaSize
= sz
;
150 table
->IntensitySize
= 0;
151 table
->LuminanceSize
= 0;
154 _mesa_problem(NULL
, "unexpected format in set_component_sizes");
161 * Update/replace all or part of a color table. Helper function
162 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
163 * The table->Table buffer should already be allocated.
164 * \param start first entry to update
165 * \param count number of entries to update
166 * \param format format of user-provided table data
167 * \param type datatype of user-provided table data
168 * \param data user-provided table data
169 * \param [rgba]Scale - RGBA scale factors
170 * \param [rgba]Bias - RGBA bias factors
173 store_colortable_entries(GLcontext
*ctx
, struct gl_color_table
*table
,
174 GLsizei start
, GLsizei count
,
175 GLenum format
, GLenum type
, const GLvoid
*data
,
176 GLfloat rScale
, GLfloat rBias
,
177 GLfloat gScale
, GLfloat gBias
,
178 GLfloat bScale
, GLfloat bBias
,
179 GLfloat aScale
, GLfloat aBias
)
181 if (ctx
->Unpack
.BufferObj
->Name
) {
182 /* Get/unpack the color table data from a PBO */
184 if (!_mesa_validate_pbo_access(1, &ctx
->Unpack
, count
, 1, 1,
185 format
, type
, data
)) {
186 _mesa_error(ctx
, GL_INVALID_OPERATION
,
187 "glColor[Sub]Table(bad PBO access)");
190 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
192 ctx
->Unpack
.BufferObj
);
194 _mesa_error(ctx
, GL_INVALID_OPERATION
,
195 "glColor[Sub]Table(PBO mapped)");
198 data
= ADD_POINTERS(buf
, data
);
203 /* convert user-provided data to GLfloat values */
204 GLfloat tempTab
[MAX_COLOR_TABLE_SIZE
* 4];
208 _mesa_unpack_color_span_float(ctx
,
209 count
, /* number of pixels */
210 table
->_BaseFormat
, /* dest format */
211 tempTab
, /* dest address */
212 format
, type
, /* src format/type */
215 IMAGE_CLAMP_BIT
); /* transfer ops */
217 /* the destination */
218 tableF
= table
->TableF
;
220 /* Apply scale & bias & clamp now */
221 switch (table
->_BaseFormat
) {
223 for (i
= 0; i
< count
; i
++) {
224 GLuint j
= start
+ i
;
225 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
229 for (i
= 0; i
< count
; i
++) {
230 GLuint j
= start
+ i
;
231 tableF
[j
] = CLAMP(tempTab
[i
] * rScale
+ rBias
, 0.0F
, 1.0F
);
235 for (i
= 0; i
< count
; i
++) {
236 GLuint j
= start
+ i
;
237 tableF
[j
] = CLAMP(tempTab
[i
] * aScale
+ aBias
, 0.0F
, 1.0F
);
240 case GL_LUMINANCE_ALPHA
:
241 for (i
= 0; i
< count
; i
++) {
242 GLuint j
= start
+ i
;
243 tableF
[j
*2+0] = CLAMP(tempTab
[i
*2+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
244 tableF
[j
*2+1] = CLAMP(tempTab
[i
*2+1] * aScale
+ aBias
, 0.0F
, 1.0F
);
248 for (i
= 0; i
< count
; i
++) {
249 GLuint j
= start
+ i
;
250 tableF
[j
*3+0] = CLAMP(tempTab
[i
*3+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
251 tableF
[j
*3+1] = CLAMP(tempTab
[i
*3+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
252 tableF
[j
*3+2] = CLAMP(tempTab
[i
*3+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
256 for (i
= 0; i
< count
; i
++) {
257 GLuint j
= start
+ i
;
258 tableF
[j
*4+0] = CLAMP(tempTab
[i
*4+0] * rScale
+ rBias
, 0.0F
, 1.0F
);
259 tableF
[j
*4+1] = CLAMP(tempTab
[i
*4+1] * gScale
+ gBias
, 0.0F
, 1.0F
);
260 tableF
[j
*4+2] = CLAMP(tempTab
[i
*4+2] * bScale
+ bBias
, 0.0F
, 1.0F
);
261 tableF
[j
*4+3] = CLAMP(tempTab
[i
*4+3] * aScale
+ aBias
, 0.0F
, 1.0F
);
265 _mesa_problem(ctx
, "Bad format in store_colortable_entries");
270 /* update the ubyte table */
272 const GLint comps
= _mesa_components_in_format(table
->_BaseFormat
);
273 const GLfloat
*tableF
= table
->TableF
+ start
* comps
;
274 GLubyte
*tableUB
= table
->TableUB
+ start
* comps
;
276 for (i
= 0; i
< count
* comps
; i
++) {
277 CLAMPED_FLOAT_TO_UBYTE(tableUB
[i
], tableF
[i
]);
281 if (ctx
->Unpack
.BufferObj
->Name
) {
282 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_UNPACK_BUFFER_EXT
,
283 ctx
->Unpack
.BufferObj
);
290 _mesa_ColorTable( GLenum target
, GLenum internalFormat
,
291 GLsizei width
, GLenum format
, GLenum type
,
294 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
295 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
296 GET_CURRENT_CONTEXT(ctx
);
297 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
298 struct gl_texture_object
*texObj
= NULL
;
299 struct gl_color_table
*table
= NULL
;
300 GLboolean proxy
= GL_FALSE
;
302 const GLfloat
*scale
= one
, *bias
= zero
;
305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
); /* too complex */
309 texObj
= texUnit
->Current1D
;
310 table
= &texObj
->Palette
;
313 texObj
= texUnit
->Current2D
;
314 table
= &texObj
->Palette
;
317 texObj
= texUnit
->Current3D
;
318 table
= &texObj
->Palette
;
320 case GL_TEXTURE_CUBE_MAP_ARB
:
321 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
322 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
325 texObj
= texUnit
->CurrentCubeMap
;
326 table
= &texObj
->Palette
;
328 case GL_PROXY_TEXTURE_1D
:
329 texObj
= ctx
->Texture
.Proxy1D
;
330 table
= &texObj
->Palette
;
333 case GL_PROXY_TEXTURE_2D
:
334 texObj
= ctx
->Texture
.Proxy2D
;
335 table
= &texObj
->Palette
;
338 case GL_PROXY_TEXTURE_3D
:
339 texObj
= ctx
->Texture
.Proxy3D
;
340 table
= &texObj
->Palette
;
343 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
344 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
345 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
348 texObj
= ctx
->Texture
.ProxyCubeMap
;
349 table
= &texObj
->Palette
;
351 case GL_SHARED_TEXTURE_PALETTE_EXT
:
352 table
= &ctx
->Texture
.Palette
;
355 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
356 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
357 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
359 case GL_PROXY_COLOR_TABLE
:
360 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
363 case GL_TEXTURE_COLOR_TABLE_SGI
:
364 if (!ctx
->Extensions
.SGI_texture_color_table
) {
365 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
368 table
= &(texUnit
->ColorTable
);
369 scale
= ctx
->Pixel
.TextureColorTableScale
;
370 bias
= ctx
->Pixel
.TextureColorTableBias
;
372 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
373 if (!ctx
->Extensions
.SGI_texture_color_table
) {
374 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
377 table
= &(texUnit
->ProxyColorTable
);
380 case GL_POST_CONVOLUTION_COLOR_TABLE
:
381 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
382 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
383 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
385 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
386 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
389 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
390 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
391 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
392 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
394 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
395 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
399 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(target)");
405 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
406 format
== GL_INTENSITY
) {
407 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorTable(format or type)");
411 baseFormat
= base_colortab_format(internalFormat
);
412 if (baseFormat
< 0) {
413 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTable(internalFormat)");
417 if (width
< 0 || (width
!= 0 && _mesa_bitcount(width
) != 1)) {
421 table
->InternalFormat
= (GLenum
) 0;
422 table
->_BaseFormat
= (GLenum
) 0;
425 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorTable(width=%d)", width
);
430 if (width
> (GLsizei
) ctx
->Const
.MaxColorTableSize
) {
433 table
->InternalFormat
= (GLenum
) 0;
434 table
->_BaseFormat
= (GLenum
) 0;
437 _mesa_error(ctx
, GL_TABLE_TOO_LARGE
, "glColorTable(width)");
443 table
->InternalFormat
= internalFormat
;
444 table
->_BaseFormat
= (GLenum
) baseFormat
;
446 comps
= _mesa_components_in_format(table
->_BaseFormat
);
447 assert(comps
> 0); /* error should have been caught sooner */
450 _mesa_free_colortable_data(table
);
453 table
->TableF
= (GLfloat
*) _mesa_malloc(comps
* width
* sizeof(GLfloat
));
454 table
->TableUB
= (GLubyte
*) _mesa_malloc(comps
* width
* sizeof(GLubyte
));
456 if (!table
->TableF
|| !table
->TableUB
) {
457 _mesa_error(ctx
, GL_OUT_OF_MEMORY
, "glColorTable");
461 store_colortable_entries(ctx
, table
,
462 0, width
, /* start, count */
471 /* do this after the table's Type and Format are set */
472 set_component_sizes(table
);
474 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
475 /* texture object palette, texObj==NULL means the shared palette */
476 if (ctx
->Driver
.UpdateTexturePalette
) {
477 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
481 ctx
->NewState
|= _NEW_PIXEL
;
487 _mesa_ColorSubTable( GLenum target
, GLsizei start
,
488 GLsizei count
, GLenum format
, GLenum type
,
491 static const GLfloat one
[4] = { 1.0, 1.0, 1.0, 1.0 };
492 static const GLfloat zero
[4] = { 0.0, 0.0, 0.0, 0.0 };
493 GET_CURRENT_CONTEXT(ctx
);
494 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
495 struct gl_texture_object
*texObj
= NULL
;
496 struct gl_color_table
*table
= NULL
;
497 const GLfloat
*scale
= one
, *bias
= zero
;
499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
503 texObj
= texUnit
->Current1D
;
504 table
= &texObj
->Palette
;
507 texObj
= texUnit
->Current2D
;
508 table
= &texObj
->Palette
;
511 texObj
= texUnit
->Current3D
;
512 table
= &texObj
->Palette
;
514 case GL_TEXTURE_CUBE_MAP_ARB
:
515 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
516 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
519 texObj
= texUnit
->CurrentCubeMap
;
520 table
= &texObj
->Palette
;
522 case GL_SHARED_TEXTURE_PALETTE_EXT
:
523 table
= &ctx
->Texture
.Palette
;
526 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
527 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
528 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
530 case GL_TEXTURE_COLOR_TABLE_SGI
:
531 if (!ctx
->Extensions
.SGI_texture_color_table
) {
532 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
535 table
= &(texUnit
->ColorTable
);
536 scale
= ctx
->Pixel
.TextureColorTableScale
;
537 bias
= ctx
->Pixel
.TextureColorTableBias
;
539 case GL_POST_CONVOLUTION_COLOR_TABLE
:
540 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
541 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
542 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
544 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
545 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
546 scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
547 bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
];
550 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorSubTable(target)");
556 if (!_mesa_is_legal_format_and_type(ctx
, format
, type
) ||
557 format
== GL_INTENSITY
) {
558 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glColorSubTable(format or type)");
563 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
567 /* error should have been caught sooner */
568 assert(_mesa_components_in_format(table
->_BaseFormat
) > 0);
570 if (start
+ count
> (GLint
) table
->Size
) {
571 _mesa_error(ctx
, GL_INVALID_VALUE
, "glColorSubTable(count)");
575 if (!table
->TableF
|| !table
->TableUB
) {
576 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
580 store_colortable_entries(ctx
, table
, start
, count
,
587 if (texObj
|| target
== GL_SHARED_TEXTURE_PALETTE_EXT
) {
588 /* per-texture object palette */
589 if (ctx
->Driver
.UpdateTexturePalette
) {
590 (*ctx
->Driver
.UpdateTexturePalette
)( ctx
, texObj
);
594 ctx
->NewState
|= _NEW_PIXEL
;
600 _mesa_CopyColorTable(GLenum target
, GLenum internalformat
,
601 GLint x
, GLint y
, GLsizei width
)
603 GET_CURRENT_CONTEXT(ctx
);
604 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
606 /* Select buffer to read from */
607 ctx
->Driver
.CopyColorTable( ctx
, target
, internalformat
, x
, y
, width
);
613 _mesa_CopyColorSubTable(GLenum target
, GLsizei start
,
614 GLint x
, GLint y
, GLsizei width
)
616 GET_CURRENT_CONTEXT(ctx
);
617 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
619 ctx
->Driver
.CopyColorSubTable( ctx
, target
, start
, x
, y
, width
);
625 _mesa_GetColorTable( GLenum target
, GLenum format
,
626 GLenum type
, GLvoid
*data
)
628 GET_CURRENT_CONTEXT(ctx
);
629 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
630 struct gl_color_table
*table
= NULL
;
631 GLfloat rgba
[MAX_COLOR_TABLE_SIZE
][4];
632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
635 _mesa_update_state(ctx
);
640 table
= &texUnit
->Current1D
->Palette
;
643 table
= &texUnit
->Current2D
->Palette
;
646 table
= &texUnit
->Current3D
->Palette
;
648 case GL_TEXTURE_CUBE_MAP_ARB
:
649 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
650 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
653 table
= &texUnit
->CurrentCubeMap
->Palette
;
655 case GL_SHARED_TEXTURE_PALETTE_EXT
:
656 table
= &ctx
->Texture
.Palette
;
659 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
661 case GL_TEXTURE_COLOR_TABLE_SGI
:
662 if (!ctx
->Extensions
.SGI_texture_color_table
) {
663 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
666 table
= &(texUnit
->ColorTable
);
668 case GL_POST_CONVOLUTION_COLOR_TABLE
:
669 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
671 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
672 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
675 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTable(target)");
681 if (table
->Size
<= 0) {
685 switch (table
->_BaseFormat
) {
689 for (i
= 0; i
< table
->Size
; i
++) {
693 rgba
[i
][ACOMP
] = table
->TableF
[i
];
700 for (i
= 0; i
< table
->Size
; i
++) {
703 rgba
[i
][BCOMP
] = table
->TableF
[i
];
704 rgba
[i
][ACOMP
] = 1.0F
;
708 case GL_LUMINANCE_ALPHA
:
711 for (i
= 0; i
< table
->Size
; i
++) {
714 rgba
[i
][BCOMP
] = table
->TableF
[i
*2+0];
715 rgba
[i
][ACOMP
] = table
->TableF
[i
*2+1];
722 for (i
= 0; i
< table
->Size
; i
++) {
726 rgba
[i
][ACOMP
] = table
->TableF
[i
];
733 for (i
= 0; i
< table
->Size
; i
++) {
734 rgba
[i
][RCOMP
] = table
->TableF
[i
*3+0];
735 rgba
[i
][GCOMP
] = table
->TableF
[i
*3+1];
736 rgba
[i
][BCOMP
] = table
->TableF
[i
*3+2];
737 rgba
[i
][ACOMP
] = 1.0F
;
742 _mesa_memcpy(rgba
, table
->TableF
, 4 * table
->Size
* sizeof(GLfloat
));
745 _mesa_problem(ctx
, "bad table format in glGetColorTable");
749 if (ctx
->Pack
.BufferObj
->Name
) {
750 /* pack color table into PBO */
752 if (!_mesa_validate_pbo_access(1, &ctx
->Pack
, table
->Size
, 1, 1,
753 format
, type
, data
)) {
754 _mesa_error(ctx
, GL_INVALID_OPERATION
,
755 "glGetColorTable(invalid PBO access)");
758 buf
= (GLubyte
*) ctx
->Driver
.MapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
760 ctx
->Pack
.BufferObj
);
762 /* buffer is already mapped - that's an error */
763 _mesa_error(ctx
, GL_INVALID_OPERATION
,
764 "glGetColorTable(PBO is mapped)");
767 data
= ADD_POINTERS(buf
, data
);
770 _mesa_pack_rgba_span_float(ctx
, table
->Size
, rgba
,
771 format
, type
, data
, &ctx
->Pack
, 0x0);
773 if (ctx
->Pack
.BufferObj
->Name
) {
774 ctx
->Driver
.UnmapBuffer(ctx
, GL_PIXEL_PACK_BUFFER_EXT
,
775 ctx
->Pack
.BufferObj
);
782 _mesa_ColorTableParameterfv(GLenum target
, GLenum pname
, const GLfloat
*params
)
784 GET_CURRENT_CONTEXT(ctx
);
785 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx
);
788 case GL_COLOR_TABLE_SGI
:
789 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
790 COPY_4V(ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
], params
);
792 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
793 COPY_4V(ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
], params
);
796 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
800 case GL_TEXTURE_COLOR_TABLE_SGI
:
801 if (!ctx
->Extensions
.SGI_texture_color_table
) {
802 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
805 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
806 COPY_4V(ctx
->Pixel
.TextureColorTableScale
, params
);
808 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
809 COPY_4V(ctx
->Pixel
.TextureColorTableBias
, params
);
812 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
816 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI
:
817 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
818 COPY_4V(ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
], params
);
820 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
821 COPY_4V(ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
], params
);
824 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
828 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
:
829 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
830 COPY_4V(ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
], params
);
832 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
833 COPY_4V(ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
], params
);
836 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameterfv(pname)");
841 _mesa_error(ctx
, GL_INVALID_ENUM
, "glColorTableParameter(target)");
845 ctx
->NewState
|= _NEW_PIXEL
;
851 _mesa_ColorTableParameteriv(GLenum target
, GLenum pname
, const GLint
*params
)
854 if (pname
== GL_COLOR_TABLE_SGI
||
855 pname
== GL_TEXTURE_COLOR_TABLE_SGI
||
856 pname
== GL_POST_CONVOLUTION_COLOR_TABLE_SGI
||
857 pname
== GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI
) {
859 fparams
[0] = (GLfloat
) params
[0];
860 fparams
[1] = (GLfloat
) params
[1];
861 fparams
[2] = (GLfloat
) params
[2];
862 fparams
[3] = (GLfloat
) params
[3];
866 fparams
[0] = (GLfloat
) params
[0];
868 _mesa_ColorTableParameterfv(target
, pname
, fparams
);
874 _mesa_GetColorTableParameterfv( GLenum target
, GLenum pname
, GLfloat
*params
)
876 GET_CURRENT_CONTEXT(ctx
);
877 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
878 struct gl_color_table
*table
= NULL
;
879 ASSERT_OUTSIDE_BEGIN_END(ctx
);
883 table
= &texUnit
->Current1D
->Palette
;
886 table
= &texUnit
->Current2D
->Palette
;
889 table
= &texUnit
->Current3D
->Palette
;
891 case GL_TEXTURE_CUBE_MAP_ARB
:
892 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
893 _mesa_error(ctx
, GL_INVALID_ENUM
,
894 "glGetColorTableParameterfv(target)");
897 table
= &texUnit
->CurrentCubeMap
->Palette
;
899 case GL_PROXY_TEXTURE_1D
:
900 table
= &ctx
->Texture
.Proxy1D
->Palette
;
902 case GL_PROXY_TEXTURE_2D
:
903 table
= &ctx
->Texture
.Proxy2D
->Palette
;
905 case GL_PROXY_TEXTURE_3D
:
906 table
= &ctx
->Texture
.Proxy3D
->Palette
;
908 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
909 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
910 _mesa_error(ctx
, GL_INVALID_ENUM
,
911 "glGetColorTableParameterfv(target)");
914 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
916 case GL_SHARED_TEXTURE_PALETTE_EXT
:
917 table
= &ctx
->Texture
.Palette
;
920 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
921 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
922 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
]);
925 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
926 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
]);
930 case GL_PROXY_COLOR_TABLE
:
931 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
933 case GL_TEXTURE_COLOR_TABLE_SGI
:
934 if (!ctx
->Extensions
.SGI_texture_color_table
) {
935 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
938 table
= &(texUnit
->ColorTable
);
939 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
940 COPY_4V(params
, ctx
->Pixel
.TextureColorTableScale
);
943 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
944 COPY_4V(params
, ctx
->Pixel
.TextureColorTableBias
);
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 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
]);
961 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
962 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
]);
966 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
967 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
969 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
970 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
971 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
972 COPY_4V(params
, ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
]);
975 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
976 COPY_4V(params
, ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCOLORMATRIX
]);
980 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
981 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
984 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(target)");
991 case GL_COLOR_TABLE_FORMAT
:
992 *params
= (GLfloat
) table
->InternalFormat
;
994 case GL_COLOR_TABLE_WIDTH
:
995 *params
= (GLfloat
) table
->Size
;
997 case GL_COLOR_TABLE_RED_SIZE
:
998 *params
= (GLfloat
) table
->RedSize
;
1000 case GL_COLOR_TABLE_GREEN_SIZE
:
1001 *params
= (GLfloat
) table
->GreenSize
;
1003 case GL_COLOR_TABLE_BLUE_SIZE
:
1004 *params
= (GLfloat
) table
->BlueSize
;
1006 case GL_COLOR_TABLE_ALPHA_SIZE
:
1007 *params
= (GLfloat
) table
->AlphaSize
;
1009 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1010 *params
= (GLfloat
) table
->LuminanceSize
;
1012 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1013 *params
= (GLfloat
) table
->IntensitySize
;
1016 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameterfv(pname)" );
1024 _mesa_GetColorTableParameteriv( GLenum target
, GLenum pname
, GLint
*params
)
1026 GET_CURRENT_CONTEXT(ctx
);
1027 struct gl_texture_unit
*texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
1028 struct gl_color_table
*table
= NULL
;
1029 ASSERT_OUTSIDE_BEGIN_END(ctx
);
1033 table
= &texUnit
->Current1D
->Palette
;
1036 table
= &texUnit
->Current2D
->Palette
;
1039 table
= &texUnit
->Current3D
->Palette
;
1041 case GL_TEXTURE_CUBE_MAP_ARB
:
1042 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1043 _mesa_error(ctx
, GL_INVALID_ENUM
,
1044 "glGetColorTableParameteriv(target)");
1047 table
= &texUnit
->CurrentCubeMap
->Palette
;
1049 case GL_PROXY_TEXTURE_1D
:
1050 table
= &ctx
->Texture
.Proxy1D
->Palette
;
1052 case GL_PROXY_TEXTURE_2D
:
1053 table
= &ctx
->Texture
.Proxy2D
->Palette
;
1055 case GL_PROXY_TEXTURE_3D
:
1056 table
= &ctx
->Texture
.Proxy3D
->Palette
;
1058 case GL_PROXY_TEXTURE_CUBE_MAP_ARB
:
1059 if (!ctx
->Extensions
.ARB_texture_cube_map
) {
1060 _mesa_error(ctx
, GL_INVALID_ENUM
,
1061 "glGetColorTableParameteriv(target)");
1064 table
= &ctx
->Texture
.ProxyCubeMap
->Palette
;
1066 case GL_SHARED_TEXTURE_PALETTE_EXT
:
1067 table
= &ctx
->Texture
.Palette
;
1069 case GL_COLOR_TABLE
:
1070 table
= &ctx
->ColorTable
[COLORTABLE_PRECONVOLUTION
];
1071 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1072 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_PRECONVOLUTION
];
1073 params
[0] = (GLint
) scale
[0];
1074 params
[1] = (GLint
) scale
[1];
1075 params
[2] = (GLint
) scale
[2];
1076 params
[3] = (GLint
) scale
[3];
1079 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1080 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_PRECONVOLUTION
];
1081 params
[0] = (GLint
) bias
[0];
1082 params
[1] = (GLint
) bias
[1];
1083 params
[2] = (GLint
) bias
[2];
1084 params
[3] = (GLint
) bias
[3];
1088 case GL_PROXY_COLOR_TABLE
:
1089 table
= &ctx
->ProxyColorTable
[COLORTABLE_PRECONVOLUTION
];
1091 case GL_TEXTURE_COLOR_TABLE_SGI
:
1092 if (!ctx
->Extensions
.SGI_texture_color_table
) {
1093 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
1096 table
= &(texUnit
->ColorTable
);
1097 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1098 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[0];
1099 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[1];
1100 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[2];
1101 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableScale
[3];
1104 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1105 params
[0] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[0];
1106 params
[1] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[1];
1107 params
[2] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[2];
1108 params
[3] = (GLint
) ctx
->Pixel
.TextureColorTableBias
[3];
1112 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI
:
1113 if (!ctx
->Extensions
.SGI_texture_color_table
) {
1114 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameter(target)");
1117 table
= &(texUnit
->ProxyColorTable
);
1119 case GL_POST_CONVOLUTION_COLOR_TABLE
:
1120 table
= &ctx
->ColorTable
[COLORTABLE_POSTCONVOLUTION
];
1121 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1122 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCONVOLUTION
];
1123 params
[0] = (GLint
) scale
[0];
1124 params
[1] = (GLint
) scale
[1];
1125 params
[2] = (GLint
) scale
[2];
1126 params
[3] = (GLint
) scale
[3];
1129 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1130 GLfloat
*bias
= ctx
->Pixel
.ColorTableBias
[COLORTABLE_POSTCONVOLUTION
];
1131 params
[0] = (GLint
) bias
[0];
1132 params
[1] = (GLint
) bias
[1];
1133 params
[2] = (GLint
) bias
[2];
1134 params
[3] = (GLint
) bias
[3];
1138 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE
:
1139 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCONVOLUTION
];
1141 case GL_POST_COLOR_MATRIX_COLOR_TABLE
:
1142 table
= &ctx
->ColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1143 if (pname
== GL_COLOR_TABLE_SCALE_SGI
) {
1144 GLfloat
*scale
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
1145 params
[0] = (GLint
) scale
[0];
1146 params
[0] = (GLint
) scale
[1];
1147 params
[0] = (GLint
) scale
[2];
1148 params
[0] = (GLint
) scale
[3];
1151 else if (pname
== GL_COLOR_TABLE_BIAS_SGI
) {
1152 GLfloat
*bias
= ctx
->Pixel
.ColorTableScale
[COLORTABLE_POSTCOLORMATRIX
];
1153 params
[0] = (GLint
) bias
[0];
1154 params
[1] = (GLint
) bias
[1];
1155 params
[2] = (GLint
) bias
[2];
1156 params
[3] = (GLint
) bias
[3];
1160 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE
:
1161 table
= &ctx
->ProxyColorTable
[COLORTABLE_POSTCOLORMATRIX
];
1164 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(target)");
1171 case GL_COLOR_TABLE_FORMAT
:
1172 *params
= table
->InternalFormat
;
1174 case GL_COLOR_TABLE_WIDTH
:
1175 *params
= table
->Size
;
1177 case GL_COLOR_TABLE_RED_SIZE
:
1178 *params
= table
->RedSize
;
1180 case GL_COLOR_TABLE_GREEN_SIZE
:
1181 *params
= table
->GreenSize
;
1183 case GL_COLOR_TABLE_BLUE_SIZE
:
1184 *params
= table
->BlueSize
;
1186 case GL_COLOR_TABLE_ALPHA_SIZE
:
1187 *params
= table
->AlphaSize
;
1189 case GL_COLOR_TABLE_LUMINANCE_SIZE
:
1190 *params
= table
->LuminanceSize
;
1192 case GL_COLOR_TABLE_INTENSITY_SIZE
:
1193 *params
= table
->IntensitySize
;
1196 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetColorTableParameteriv(pname)" );
1201 /**********************************************************************/
1202 /***** Initialization *****/
1203 /**********************************************************************/
1207 _mesa_init_colortable( struct gl_color_table
*p
)
1212 p
->InternalFormat
= GL_RGBA
;
1218 _mesa_free_colortable_data( struct gl_color_table
*p
)
1221 _mesa_free(p
->TableF
);
1225 _mesa_free(p
->TableUB
);
1232 * Initialize all colortables for a context.
1235 _mesa_init_colortables( GLcontext
* ctx
)
1238 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1239 _mesa_init_colortable(&ctx
->ColorTable
[i
]);
1240 _mesa_init_colortable(&ctx
->ProxyColorTable
[i
]);
1246 * Free all colortable data for a context
1249 _mesa_free_colortables_data( GLcontext
*ctx
)
1252 for (i
= 0; i
< COLORTABLE_MAX
; i
++) {
1253 _mesa_free_colortable_data(&ctx
->ColorTable
[i
]);
1254 _mesa_free_colortable_data(&ctx
->ProxyColorTable
[i
]);