- struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
- struct gl_texture_object *texObj = NULL;
- struct gl_color_table *table = NULL;
- GLboolean proxy = GL_FALSE;
- GLint baseFormat;
- GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
- GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
- GLint comps;
- ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
-
- switch (target) {
- case GL_TEXTURE_1D:
- texObj = texUnit->Current1D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_2D:
- texObj = texUnit->Current2D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_3D:
- texObj = texUnit->Current3D;
- table = &texObj->Palette;
- break;
- case GL_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- texObj = texUnit->CurrentCubeMap;
- table = &texObj->Palette;
- break;
- case GL_PROXY_TEXTURE_1D:
- texObj = ctx->Texture.Proxy1D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_2D:
- texObj = ctx->Texture.Proxy2D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_3D:
- texObj = ctx->Texture.Proxy3D;
- table = &texObj->Palette;
- proxy = GL_TRUE;
- break;
- case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
- if (!ctx->Extensions.ARB_texture_cube_map) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- texObj = ctx->Texture.ProxyCubeMap;
- table = &texObj->Palette;
- break;
- case GL_SHARED_TEXTURE_PALETTE_EXT:
- table = &ctx->Texture.Palette;
- break;
- case GL_COLOR_TABLE:
- table = &ctx->ColorTable;
- rScale = ctx->Pixel.ColorTableScale[0];
- gScale = ctx->Pixel.ColorTableScale[1];
- bScale = ctx->Pixel.ColorTableScale[2];
- aScale = ctx->Pixel.ColorTableScale[3];
- rBias = ctx->Pixel.ColorTableBias[0];
- gBias = ctx->Pixel.ColorTableBias[1];
- bBias = ctx->Pixel.ColorTableBias[2];
- aBias = ctx->Pixel.ColorTableBias[3];
- break;
- case GL_PROXY_COLOR_TABLE:
- table = &ctx->ProxyColorTable;
- proxy = GL_TRUE;
- break;
- case GL_TEXTURE_COLOR_TABLE_SGI:
- if (!ctx->Extensions.SGI_texture_color_table) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- table = &(texUnit->ColorTable);
- rScale = ctx->Pixel.TextureColorTableScale[0];
- gScale = ctx->Pixel.TextureColorTableScale[1];
- bScale = ctx->Pixel.TextureColorTableScale[2];
- aScale = ctx->Pixel.TextureColorTableScale[3];
- rBias = ctx->Pixel.TextureColorTableBias[0];
- gBias = ctx->Pixel.TextureColorTableBias[1];
- bBias = ctx->Pixel.TextureColorTableBias[2];
- aBias = ctx->Pixel.TextureColorTableBias[3];
- break;
- case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
- if (!ctx->Extensions.SGI_texture_color_table) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
- table = &(texUnit->ProxyColorTable);
- proxy = GL_TRUE;
- break;
- case GL_POST_CONVOLUTION_COLOR_TABLE:
- table = &ctx->PostConvolutionColorTable;
- rScale = ctx->Pixel.PCCTscale[0];
- gScale = ctx->Pixel.PCCTscale[1];
- bScale = ctx->Pixel.PCCTscale[2];
- aScale = ctx->Pixel.PCCTscale[3];
- rBias = ctx->Pixel.PCCTbias[0];
- gBias = ctx->Pixel.PCCTbias[1];
- bBias = ctx->Pixel.PCCTbias[2];
- aBias = ctx->Pixel.PCCTbias[3];
- break;
- case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
- table = &ctx->ProxyPostConvolutionColorTable;
- proxy = GL_TRUE;
- break;
- case GL_POST_COLOR_MATRIX_COLOR_TABLE:
- table = &ctx->PostColorMatrixColorTable;
- rScale = ctx->Pixel.PCMCTscale[0];
- gScale = ctx->Pixel.PCMCTscale[1];
- bScale = ctx->Pixel.PCMCTscale[2];
- aScale = ctx->Pixel.PCMCTscale[3];
- rBias = ctx->Pixel.PCMCTbias[0];
- gBias = ctx->Pixel.PCMCTbias[1];
- bBias = ctx->Pixel.PCMCTbias[2];
- aBias = ctx->Pixel.PCMCTbias[3];
- break;
- case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
- table = &ctx->ProxyPostColorMatrixColorTable;
- proxy = GL_TRUE;
- break;
- default:
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
- return;
- }
-
- assert(table);
-
- if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
- format == GL_INTENSITY) {
- _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
- return;
- }
-
- baseFormat = base_colortab_format(internalFormat);
- if (baseFormat < 0) {
- _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
- return;
- }
-
- if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) {
- /* error */
- if (proxy) {
- table->Size = 0;
- table->InternalFormat = (GLenum) 0;
- table->_BaseFormat = (GLenum) 0;
- }
- else {
- _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
- }
- return;
- }
-
- if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
- if (proxy) {
- table->Size = 0;
- table->InternalFormat = (GLenum) 0;
- table->_BaseFormat = (GLenum) 0;
- }
- else {
- _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
- }
- return;
- }
-
- table->Size = width;
- table->InternalFormat = internalFormat;
- table->_BaseFormat = (GLenum) baseFormat;
-
- comps = _mesa_components_in_format(table->_BaseFormat);
- assert(comps > 0); /* error should have been caught sooner */
-
- if (!proxy) {
- _mesa_free_colortable_data(table);
-
- if (width > 0) {
- table->TableF = (GLfloat *) _mesa_malloc(comps * width * sizeof(GLfloat));
- table->TableUB = (GLubyte *) _mesa_malloc(comps * width * sizeof(GLubyte));
-
- if (!table->TableF || !table->TableUB) {
- _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
- return;
- }
-
- store_colortable_entries(ctx, table,
- 0, width, /* start, count */
- format, type, data,
- rScale, rBias,
- gScale, gBias,
- bScale, bBias,
- aScale, aBias);
- }
- } /* proxy */
-
- /* do this after the table's Type and Format are set */
- set_component_sizes(table);
-
- if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
- /* texture object palette, texObj==NULL means the shared palette */
- if (ctx->Driver.UpdateTexturePalette) {
- (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
- }
- }
-
- ctx->NewState |= _NEW_PIXEL;