colortab.c revision f959f6e1dc27c71fc0ccc56e09b29101b3bf3b97
1/* 2 * Mesa 3-D graphics library 3 * Version: 6.1 4 * 5 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved. 6 * 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: 13 * 14 * The above copyright notice and this permission notice shall be included 15 * in all copies or substantial portions of the Software. 16 * 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. 23 */ 24 25 26#include "glheader.h" 27#include "imports.h" 28#include "colortab.h" 29#include "context.h" 30#include "image.h" 31#include "macros.h" 32#include "state.h" 33 34 35/* 36 * Given an internalFormat token passed to glColorTable, 37 * return the corresponding base format. 38 * Return -1 if invalid token. 39 */ 40static GLint 41base_colortab_format( GLenum format ) 42{ 43 switch (format) { 44 case GL_ALPHA: 45 case GL_ALPHA4: 46 case GL_ALPHA8: 47 case GL_ALPHA12: 48 case GL_ALPHA16: 49 return GL_ALPHA; 50 case GL_LUMINANCE: 51 case GL_LUMINANCE4: 52 case GL_LUMINANCE8: 53 case GL_LUMINANCE12: 54 case GL_LUMINANCE16: 55 return GL_LUMINANCE; 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; 64 case GL_INTENSITY: 65 case GL_INTENSITY4: 66 case GL_INTENSITY8: 67 case GL_INTENSITY12: 68 case GL_INTENSITY16: 69 return GL_INTENSITY; 70 case GL_RGB: 71 case GL_R3_G3_B2: 72 case GL_RGB4: 73 case GL_RGB5: 74 case GL_RGB8: 75 case GL_RGB10: 76 case GL_RGB12: 77 case GL_RGB16: 78 return GL_RGB; 79 case GL_RGBA: 80 case GL_RGBA2: 81 case GL_RGBA4: 82 case GL_RGB5_A1: 83 case GL_RGBA8: 84 case GL_RGB10_A2: 85 case GL_RGBA12: 86 case GL_RGBA16: 87 return GL_RGBA; 88 default: 89 return -1; /* error */ 90 } 91} 92 93 94 95/* 96 * Examine table's format and set the component sizes accordingly. 97 */ 98static void 99set_component_sizes( struct gl_color_table *table ) 100{ 101 GLubyte sz; 102 103 switch (table->Type) { 104 case GL_UNSIGNED_BYTE: 105 sz = sizeof(GLubyte); 106 break; 107 case GL_UNSIGNED_SHORT: 108 sz = sizeof(GLushort); 109 break; 110 case GL_FLOAT: 111 sz = sizeof(GLfloat); 112 break; 113 default: 114 _mesa_problem(NULL, "bad color table type in set_component_sizes 0x%x", table->Type); 115 return; 116 } 117 118 switch (table->Format) { 119 case GL_ALPHA: 120 table->RedSize = 0; 121 table->GreenSize = 0; 122 table->BlueSize = 0; 123 table->AlphaSize = sz; 124 table->IntensitySize = 0; 125 table->LuminanceSize = 0; 126 break; 127 case GL_LUMINANCE: 128 table->RedSize = 0; 129 table->GreenSize = 0; 130 table->BlueSize = 0; 131 table->AlphaSize = 0; 132 table->IntensitySize = 0; 133 table->LuminanceSize = sz; 134 break; 135 case GL_LUMINANCE_ALPHA: 136 table->RedSize = 0; 137 table->GreenSize = 0; 138 table->BlueSize = 0; 139 table->AlphaSize = sz; 140 table->IntensitySize = 0; 141 table->LuminanceSize = sz; 142 break; 143 case GL_INTENSITY: 144 table->RedSize = 0; 145 table->GreenSize = 0; 146 table->BlueSize = 0; 147 table->AlphaSize = 0; 148 table->IntensitySize = sz; 149 table->LuminanceSize = 0; 150 break; 151 case GL_RGB: 152 table->RedSize = sz; 153 table->GreenSize = sz; 154 table->BlueSize = sz; 155 table->AlphaSize = 0; 156 table->IntensitySize = 0; 157 table->LuminanceSize = 0; 158 break; 159 case GL_RGBA: 160 table->RedSize = sz; 161 table->GreenSize = sz; 162 table->BlueSize = sz; 163 table->AlphaSize = sz; 164 table->IntensitySize = 0; 165 table->LuminanceSize = 0; 166 break; 167 default: 168 _mesa_problem(NULL, "unexpected format in set_component_sizes"); 169 } 170} 171 172 173 174/** 175 * Update/replace all or part of a color table. Helper function 176 * used by _mesa_ColorTable() and _mesa_ColorSubTable(). 177 * The table->Table buffer should already be allocated. 178 * \param start - first entry to update 179 * \param count - number of entries to update 180 * \param format - format of user-provided table data 181 * \param type - datatype of user-provided table data 182 * \param data - user-provided table data 183 * \param [rgba]Scale - RGBA scale factors 184 * \param [rgba]Bias - RGBA bias factors 185 */ 186static void 187store_colortable_entries(GLcontext *ctx, struct gl_color_table *table, 188 GLsizei start, GLsizei count, 189 GLenum format, GLenum type, const GLvoid *data, 190 GLfloat rScale, GLfloat rBias, 191 GLfloat gScale, GLfloat gBias, 192 GLfloat bScale, GLfloat bBias, 193 GLfloat aScale, GLfloat aBias) 194{ 195 if (table->Type == GL_FLOAT) { 196 /* convert user-provided data to GLfloat values */ 197 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; 198 GLfloat *tableF; 199 GLint i; 200 201 _mesa_unpack_color_span_float(ctx, 202 count, /* number of pixels */ 203 table->Format, /* dest format */ 204 tempTab, /* dest address */ 205 format, type, data, /* src data */ 206 &ctx->Unpack, 207 IMAGE_CLAMP_BIT); /* transfer ops */ 208 209 tableF = (GLfloat *) table->Table; 210 211 switch (table->Format) { 212 case GL_INTENSITY: 213 for (i = 0; i < count; i++) { 214 GLuint j = start + i; 215 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); 216 } 217 break; 218 case GL_LUMINANCE: 219 for (i = 0; i < count; i++) { 220 GLuint j = start + i; 221 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); 222 } 223 break; 224 case GL_ALPHA: 225 for (i = 0; i < count; i++) { 226 GLuint j = start + i; 227 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); 228 } 229 break; 230 case GL_LUMINANCE_ALPHA: 231 for (i = 0; i < count; i++) { 232 GLuint j = start + i; 233 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); 234 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); 235 } 236 break; 237 case GL_RGB: 238 for (i = 0; i < count; i++) { 239 GLuint j = start + i; 240 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); 241 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); 242 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); 243 } 244 break; 245 case GL_RGBA: 246 for (i = 0; i < count; i++) { 247 GLuint j = start + i; 248 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); 249 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); 250 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); 251 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); 252 } 253 break; 254 default: 255 _mesa_problem(ctx, "Bad format in store_colortable_entries"); 256 return; 257 } 258 } 259 else { 260 /* non-float (GLchan) */ 261 const GLint comps = _mesa_components_in_format(table->Format); 262 GLchan *dest = (GLchan *) table->Table + start * comps; 263 _mesa_unpack_color_span_chan(ctx, count, /* number of entries */ 264 table->Format, /* dest format */ 265 dest, /* dest address */ 266 format, type, data, /* src data */ 267 &ctx->Unpack, 268 0); /* transfer ops */ 269 } 270} 271 272 273 274void GLAPIENTRY 275_mesa_ColorTable( GLenum target, GLenum internalFormat, 276 GLsizei width, GLenum format, GLenum type, 277 const GLvoid *data ) 278{ 279 GET_CURRENT_CONTEXT(ctx); 280 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 281 struct gl_texture_object *texObj = NULL; 282 struct gl_color_table *table = NULL; 283 GLboolean proxy = GL_FALSE; 284 GLint baseFormat; 285 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; 286 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; 287 GLenum tableType = CHAN_TYPE; 288 GLint comps; 289 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ 290 291 switch (target) { 292 case GL_TEXTURE_1D: 293 texObj = texUnit->Current1D; 294 table = &texObj->Palette; 295 break; 296 case GL_TEXTURE_2D: 297 texObj = texUnit->Current2D; 298 table = &texObj->Palette; 299 break; 300 case GL_TEXTURE_3D: 301 texObj = texUnit->Current3D; 302 table = &texObj->Palette; 303 break; 304 case GL_TEXTURE_CUBE_MAP_ARB: 305 if (!ctx->Extensions.ARB_texture_cube_map) { 306 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 307 return; 308 } 309 texObj = texUnit->CurrentCubeMap; 310 table = &texObj->Palette; 311 break; 312 case GL_PROXY_TEXTURE_1D: 313 texObj = ctx->Texture.Proxy1D; 314 table = &texObj->Palette; 315 proxy = GL_TRUE; 316 break; 317 case GL_PROXY_TEXTURE_2D: 318 texObj = ctx->Texture.Proxy2D; 319 table = &texObj->Palette; 320 proxy = GL_TRUE; 321 break; 322 case GL_PROXY_TEXTURE_3D: 323 texObj = ctx->Texture.Proxy3D; 324 table = &texObj->Palette; 325 proxy = GL_TRUE; 326 break; 327 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 328 if (!ctx->Extensions.ARB_texture_cube_map) { 329 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 330 return; 331 } 332 texObj = ctx->Texture.ProxyCubeMap; 333 table = &texObj->Palette; 334 break; 335 case GL_SHARED_TEXTURE_PALETTE_EXT: 336 table = &ctx->Texture.Palette; 337 break; 338 case GL_COLOR_TABLE: 339 table = &ctx->ColorTable; 340 tableType = GL_FLOAT; 341 rScale = ctx->Pixel.ColorTableScale[0]; 342 gScale = ctx->Pixel.ColorTableScale[1]; 343 bScale = ctx->Pixel.ColorTableScale[2]; 344 aScale = ctx->Pixel.ColorTableScale[3]; 345 rBias = ctx->Pixel.ColorTableBias[0]; 346 gBias = ctx->Pixel.ColorTableBias[1]; 347 bBias = ctx->Pixel.ColorTableBias[2]; 348 aBias = ctx->Pixel.ColorTableBias[3]; 349 break; 350 case GL_PROXY_COLOR_TABLE: 351 table = &ctx->ProxyColorTable; 352 proxy = GL_TRUE; 353 break; 354 case GL_TEXTURE_COLOR_TABLE_SGI: 355 if (!ctx->Extensions.SGI_texture_color_table) { 356 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 357 return; 358 } 359 table = &(texUnit->ColorTable); 360 tableType = GL_FLOAT; 361 rScale = ctx->Pixel.TextureColorTableScale[0]; 362 gScale = ctx->Pixel.TextureColorTableScale[1]; 363 bScale = ctx->Pixel.TextureColorTableScale[2]; 364 aScale = ctx->Pixel.TextureColorTableScale[3]; 365 rBias = ctx->Pixel.TextureColorTableBias[0]; 366 gBias = ctx->Pixel.TextureColorTableBias[1]; 367 bBias = ctx->Pixel.TextureColorTableBias[2]; 368 aBias = ctx->Pixel.TextureColorTableBias[3]; 369 break; 370 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 371 if (!ctx->Extensions.SGI_texture_color_table) { 372 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 373 return; 374 } 375 table = &(texUnit->ProxyColorTable); 376 proxy = GL_TRUE; 377 break; 378 case GL_POST_CONVOLUTION_COLOR_TABLE: 379 table = &ctx->PostConvolutionColorTable; 380 tableType = GL_FLOAT; 381 rScale = ctx->Pixel.PCCTscale[0]; 382 gScale = ctx->Pixel.PCCTscale[1]; 383 bScale = ctx->Pixel.PCCTscale[2]; 384 aScale = ctx->Pixel.PCCTscale[3]; 385 rBias = ctx->Pixel.PCCTbias[0]; 386 gBias = ctx->Pixel.PCCTbias[1]; 387 bBias = ctx->Pixel.PCCTbias[2]; 388 aBias = ctx->Pixel.PCCTbias[3]; 389 break; 390 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 391 table = &ctx->ProxyPostConvolutionColorTable; 392 proxy = GL_TRUE; 393 break; 394 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 395 table = &ctx->PostColorMatrixColorTable; 396 tableType = GL_FLOAT; 397 rScale = ctx->Pixel.PCMCTscale[0]; 398 gScale = ctx->Pixel.PCMCTscale[1]; 399 bScale = ctx->Pixel.PCMCTscale[2]; 400 aScale = ctx->Pixel.PCMCTscale[3]; 401 rBias = ctx->Pixel.PCMCTbias[0]; 402 gBias = ctx->Pixel.PCMCTbias[1]; 403 bBias = ctx->Pixel.PCMCTbias[2]; 404 aBias = ctx->Pixel.PCMCTbias[3]; 405 break; 406 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 407 table = &ctx->ProxyPostColorMatrixColorTable; 408 proxy = GL_TRUE; 409 break; 410 default: 411 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 412 return; 413 } 414 415 assert(table); 416 417 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 418 format == GL_INTENSITY) { 419 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)"); 420 return; 421 } 422 423 baseFormat = base_colortab_format(internalFormat); 424 if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) { 425 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)"); 426 return; 427 } 428 429 if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) { 430 /* error */ 431 if (proxy) { 432 table->Size = 0; 433 table->IntFormat = (GLenum) 0; 434 table->Format = (GLenum) 0; 435 } 436 else { 437 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width); 438 } 439 return; 440 } 441 442 if (width > (GLsizei) ctx->Const.MaxColorTableSize) { 443 if (proxy) { 444 table->Size = 0; 445 table->IntFormat = (GLenum) 0; 446 table->Format = (GLenum) 0; 447 } 448 else { 449 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); 450 } 451 return; 452 } 453 454 table->Size = width; 455 table->IntFormat = internalFormat; 456 table->Format = (GLenum) baseFormat; 457 set_component_sizes(table); 458 459 comps = _mesa_components_in_format(table->Format); 460 assert(comps > 0); /* error should have been caught sooner */ 461 462 if (!proxy) { 463 /* free old table, if any */ 464 if (table->Table) { 465 FREE(table->Table); 466 table->Table = NULL; 467 } 468 469 if (width > 0) { 470 if (tableType == GL_FLOAT) { 471 table->Type = GL_FLOAT; 472 table->Table = MALLOC(comps * width * sizeof(GLfloat)); 473 } 474 else { 475 table->Type = CHAN_TYPE; 476 table->Table = MALLOC(comps * width * sizeof(GLchan)); 477 } 478 479 if (!table->Table) { 480 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); 481 return; 482 } 483 484 store_colortable_entries(ctx, table, 485 0, width, /* start, count */ 486 format, type, data, 487 rScale, rBias, 488 gScale, gBias, 489 bScale, bBias, 490 aScale, aBias); 491 } 492 } /* proxy */ 493 494 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 495 /* texture object palette, texObj==NULL means the shared palette */ 496 if (ctx->Driver.UpdateTexturePalette) { 497 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 498 } 499 } 500 501 ctx->NewState |= _NEW_PIXEL; 502} 503 504 505 506void GLAPIENTRY 507_mesa_ColorSubTable( GLenum target, GLsizei start, 508 GLsizei count, GLenum format, GLenum type, 509 const GLvoid *data ) 510{ 511 GET_CURRENT_CONTEXT(ctx); 512 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 513 struct gl_texture_object *texObj = NULL; 514 struct gl_color_table *table = NULL; 515 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; 516 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; 517 GLint comps; 518 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 519 520 switch (target) { 521 case GL_TEXTURE_1D: 522 texObj = texUnit->Current1D; 523 table = &texObj->Palette; 524 break; 525 case GL_TEXTURE_2D: 526 texObj = texUnit->Current2D; 527 table = &texObj->Palette; 528 break; 529 case GL_TEXTURE_3D: 530 texObj = texUnit->Current3D; 531 table = &texObj->Palette; 532 break; 533 case GL_TEXTURE_CUBE_MAP_ARB: 534 if (!ctx->Extensions.ARB_texture_cube_map) { 535 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 536 return; 537 } 538 texObj = texUnit->CurrentCubeMap; 539 table = &texObj->Palette; 540 break; 541 case GL_SHARED_TEXTURE_PALETTE_EXT: 542 table = &ctx->Texture.Palette; 543 break; 544 case GL_COLOR_TABLE: 545 table = &ctx->ColorTable; 546 rScale = ctx->Pixel.ColorTableScale[0]; 547 gScale = ctx->Pixel.ColorTableScale[1]; 548 bScale = ctx->Pixel.ColorTableScale[2]; 549 aScale = ctx->Pixel.ColorTableScale[3]; 550 rBias = ctx->Pixel.ColorTableBias[0]; 551 gBias = ctx->Pixel.ColorTableBias[1]; 552 bBias = ctx->Pixel.ColorTableBias[2]; 553 aBias = ctx->Pixel.ColorTableBias[3]; 554 break; 555 case GL_TEXTURE_COLOR_TABLE_SGI: 556 if (!ctx->Extensions.SGI_texture_color_table) { 557 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 558 return; 559 } 560 table = &(texUnit->ColorTable); 561 rScale = ctx->Pixel.TextureColorTableScale[0]; 562 gScale = ctx->Pixel.TextureColorTableScale[1]; 563 bScale = ctx->Pixel.TextureColorTableScale[2]; 564 aScale = ctx->Pixel.TextureColorTableScale[3]; 565 rBias = ctx->Pixel.TextureColorTableBias[0]; 566 gBias = ctx->Pixel.TextureColorTableBias[1]; 567 bBias = ctx->Pixel.TextureColorTableBias[2]; 568 aBias = ctx->Pixel.TextureColorTableBias[3]; 569 break; 570 case GL_POST_CONVOLUTION_COLOR_TABLE: 571 table = &ctx->PostConvolutionColorTable; 572 rScale = ctx->Pixel.PCCTscale[0]; 573 gScale = ctx->Pixel.PCCTscale[1]; 574 bScale = ctx->Pixel.PCCTscale[2]; 575 aScale = ctx->Pixel.PCCTscale[3]; 576 rBias = ctx->Pixel.PCCTbias[0]; 577 gBias = ctx->Pixel.PCCTbias[1]; 578 bBias = ctx->Pixel.PCCTbias[2]; 579 aBias = ctx->Pixel.PCCTbias[3]; 580 break; 581 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 582 table = &ctx->PostColorMatrixColorTable; 583 rScale = ctx->Pixel.PCMCTscale[0]; 584 gScale = ctx->Pixel.PCMCTscale[1]; 585 bScale = ctx->Pixel.PCMCTscale[2]; 586 aScale = ctx->Pixel.PCMCTscale[3]; 587 rBias = ctx->Pixel.PCMCTbias[0]; 588 gBias = ctx->Pixel.PCMCTbias[1]; 589 bBias = ctx->Pixel.PCMCTbias[2]; 590 aBias = ctx->Pixel.PCMCTbias[3]; 591 break; 592 default: 593 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 594 return; 595 } 596 597 assert(table); 598 599 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 600 format == GL_INTENSITY) { 601 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)"); 602 return; 603 } 604 605 if (count < 1) { 606 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 607 return; 608 } 609 610 comps = _mesa_components_in_format(table->Format); 611 assert(comps > 0); /* error should have been caught sooner */ 612 613 if (start + count > (GLint) table->Size) { 614 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 615 return; 616 } 617 618 if (!table->Table) { 619 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable"); 620 return; 621 } 622 623 store_colortable_entries(ctx, table, start, count, 624 format, type, data, 625 rScale, rBias, 626 gScale, gBias, 627 bScale, bBias, 628 aScale, aBias); 629 630 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 631 /* per-texture object palette */ 632 if (ctx->Driver.UpdateTexturePalette) { 633 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 634 } 635 } 636 637 ctx->NewState |= _NEW_PIXEL; 638} 639 640 641 642/* XXX not tested */ 643void GLAPIENTRY 644_mesa_CopyColorTable(GLenum target, GLenum internalformat, 645 GLint x, GLint y, GLsizei width) 646{ 647 GET_CURRENT_CONTEXT(ctx); 648 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 649 650 /* Select buffer to read from */ 651 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width ); 652} 653 654 655 656/* XXX not tested */ 657void GLAPIENTRY 658_mesa_CopyColorSubTable(GLenum target, GLsizei start, 659 GLint x, GLint y, GLsizei width) 660{ 661 GET_CURRENT_CONTEXT(ctx); 662 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 663 664 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width ); 665} 666 667 668 669void GLAPIENTRY 670_mesa_GetColorTable( GLenum target, GLenum format, 671 GLenum type, GLvoid *data ) 672{ 673 GET_CURRENT_CONTEXT(ctx); 674 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 675 struct gl_color_table *table = NULL; 676 GLchan rgba[MAX_COLOR_TABLE_SIZE][4]; 677 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 678 679 if (ctx->NewState) { 680 _mesa_update_state(ctx); 681 } 682 683 switch (target) { 684 case GL_TEXTURE_1D: 685 table = &texUnit->Current1D->Palette; 686 break; 687 case GL_TEXTURE_2D: 688 table = &texUnit->Current2D->Palette; 689 break; 690 case GL_TEXTURE_3D: 691 table = &texUnit->Current3D->Palette; 692 break; 693 case GL_TEXTURE_CUBE_MAP_ARB: 694 if (!ctx->Extensions.ARB_texture_cube_map) { 695 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 696 return; 697 } 698 table = &texUnit->CurrentCubeMap->Palette; 699 break; 700 case GL_SHARED_TEXTURE_PALETTE_EXT: 701 table = &ctx->Texture.Palette; 702 break; 703 case GL_COLOR_TABLE: 704 table = &ctx->ColorTable; 705 break; 706 case GL_TEXTURE_COLOR_TABLE_SGI: 707 if (!ctx->Extensions.SGI_texture_color_table) { 708 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 709 return; 710 } 711 table = &(texUnit->ColorTable); 712 break; 713 case GL_POST_CONVOLUTION_COLOR_TABLE: 714 table = &ctx->PostConvolutionColorTable; 715 break; 716 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 717 table = &ctx->PostColorMatrixColorTable; 718 break; 719 default: 720 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 721 return; 722 } 723 724 ASSERT(table); 725 726 switch (table->Format) { 727 case GL_ALPHA: 728 if (table->Type == GL_FLOAT) { 729 const GLfloat *tableF = (const GLfloat *) table->Table; 730 GLuint i; 731 for (i = 0; i < table->Size; i++) { 732 rgba[i][RCOMP] = 0; 733 rgba[i][GCOMP] = 0; 734 rgba[i][BCOMP] = 0; 735 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 736 } 737 } 738 else { 739 const GLchan *tableUB = (const GLchan *) table->Table; 740 GLuint i; 741 for (i = 0; i < table->Size; i++) { 742 rgba[i][RCOMP] = 0; 743 rgba[i][GCOMP] = 0; 744 rgba[i][BCOMP] = 0; 745 rgba[i][ACOMP] = tableUB[i]; 746 } 747 } 748 break; 749 case GL_LUMINANCE: 750 if (table->Type == GL_FLOAT) { 751 const GLfloat *tableF = (const GLfloat *) table->Table; 752 GLuint i; 753 for (i = 0; i < table->Size; i++) { 754 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 755 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 756 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 757 rgba[i][ACOMP] = CHAN_MAX; 758 } 759 } 760 else { 761 const GLchan *tableUB = (const GLchan *) table->Table; 762 GLuint i; 763 for (i = 0; i < table->Size; i++) { 764 rgba[i][RCOMP] = tableUB[i]; 765 rgba[i][GCOMP] = tableUB[i]; 766 rgba[i][BCOMP] = tableUB[i]; 767 rgba[i][ACOMP] = CHAN_MAX; 768 } 769 } 770 break; 771 case GL_LUMINANCE_ALPHA: 772 if (table->Type == GL_FLOAT) { 773 const GLfloat *tableF = (const GLfloat *) table->Table; 774 GLuint i; 775 for (i = 0; i < table->Size; i++) { 776 rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); 777 rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); 778 rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); 779 rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF); 780 } 781 } 782 else { 783 const GLchan *tableUB = (const GLchan *) table->Table; 784 GLuint i; 785 for (i = 0; i < table->Size; i++) { 786 rgba[i][RCOMP] = tableUB[i*2+0]; 787 rgba[i][GCOMP] = tableUB[i*2+0]; 788 rgba[i][BCOMP] = tableUB[i*2+0]; 789 rgba[i][ACOMP] = tableUB[i*2+1]; 790 } 791 } 792 break; 793 case GL_INTENSITY: 794 if (table->Type == GL_FLOAT) { 795 const GLfloat *tableF = (const GLfloat *) table->Table; 796 GLuint i; 797 for (i = 0; i < table->Size; i++) { 798 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 799 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 800 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 801 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); 802 } 803 } 804 else { 805 const GLchan *tableUB = (const GLchan *) table->Table; 806 GLuint i; 807 for (i = 0; i < table->Size; i++) { 808 rgba[i][RCOMP] = tableUB[i]; 809 rgba[i][GCOMP] = tableUB[i]; 810 rgba[i][BCOMP] = tableUB[i]; 811 rgba[i][ACOMP] = tableUB[i]; 812 } 813 } 814 break; 815 case GL_RGB: 816 if (table->Type == GL_FLOAT) { 817 const GLfloat *tableF = (const GLfloat *) table->Table; 818 GLuint i; 819 for (i = 0; i < table->Size; i++) { 820 rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF); 821 rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF); 822 rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF); 823 rgba[i][ACOMP] = CHAN_MAX; 824 } 825 } 826 else { 827 const GLchan *tableUB = (const GLchan *) table->Table; 828 GLuint i; 829 for (i = 0; i < table->Size; i++) { 830 rgba[i][RCOMP] = tableUB[i*3+0]; 831 rgba[i][GCOMP] = tableUB[i*3+1]; 832 rgba[i][BCOMP] = tableUB[i*3+2]; 833 rgba[i][ACOMP] = CHAN_MAX; 834 } 835 } 836 break; 837 case GL_RGBA: 838 if (table->Type == GL_FLOAT) { 839 const GLfloat *tableF = (const GLfloat *) table->Table; 840 GLuint i; 841 for (i = 0; i < table->Size; i++) { 842 rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF); 843 rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF); 844 rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF); 845 rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF); 846 } 847 } 848 else { 849 const GLchan *tableUB = (const GLchan *) table->Table; 850 GLuint i; 851 for (i = 0; i < table->Size; i++) { 852 rgba[i][RCOMP] = tableUB[i*4+0]; 853 rgba[i][GCOMP] = tableUB[i*4+1]; 854 rgba[i][BCOMP] = tableUB[i*4+2]; 855 rgba[i][ACOMP] = tableUB[i*4+3]; 856 } 857 } 858 break; 859 default: 860 _mesa_problem(ctx, "bad table format in glGetColorTable"); 861 return; 862 } 863 864 _mesa_pack_rgba_span_chan(ctx, table->Size, (const GLchan (*)[4]) rgba, 865 format, type, data, &ctx->Pack, GL_FALSE); 866} 867 868 869 870void GLAPIENTRY 871_mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) 872{ 873 GET_CURRENT_CONTEXT(ctx); 874 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 875 876 switch (target) { 877 case GL_COLOR_TABLE_SGI: 878 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 879 ctx->Pixel.ColorTableScale[0] = params[0]; 880 ctx->Pixel.ColorTableScale[1] = params[1]; 881 ctx->Pixel.ColorTableScale[2] = params[2]; 882 ctx->Pixel.ColorTableScale[3] = params[3]; 883 } 884 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 885 ctx->Pixel.ColorTableBias[0] = params[0]; 886 ctx->Pixel.ColorTableBias[1] = params[1]; 887 ctx->Pixel.ColorTableBias[2] = params[2]; 888 ctx->Pixel.ColorTableBias[3] = params[3]; 889 } 890 else { 891 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); 892 return; 893 } 894 break; 895 case GL_TEXTURE_COLOR_TABLE_SGI: 896 if (!ctx->Extensions.SGI_texture_color_table) { 897 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); 898 return; 899 } 900 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 901 ctx->Pixel.TextureColorTableScale[0] = params[0]; 902 ctx->Pixel.TextureColorTableScale[1] = params[1]; 903 ctx->Pixel.TextureColorTableScale[2] = params[2]; 904 ctx->Pixel.TextureColorTableScale[3] = params[3]; 905 } 906 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 907 ctx->Pixel.TextureColorTableBias[0] = params[0]; 908 ctx->Pixel.TextureColorTableBias[1] = params[1]; 909 ctx->Pixel.TextureColorTableBias[2] = params[2]; 910 ctx->Pixel.TextureColorTableBias[3] = params[3]; 911 } 912 else { 913 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); 914 return; 915 } 916 break; 917 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI: 918 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 919 ctx->Pixel.PCCTscale[0] = params[0]; 920 ctx->Pixel.PCCTscale[1] = params[1]; 921 ctx->Pixel.PCCTscale[2] = params[2]; 922 ctx->Pixel.PCCTscale[3] = params[3]; 923 } 924 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 925 ctx->Pixel.PCCTbias[0] = params[0]; 926 ctx->Pixel.PCCTbias[1] = params[1]; 927 ctx->Pixel.PCCTbias[2] = params[2]; 928 ctx->Pixel.PCCTbias[3] = params[3]; 929 } 930 else { 931 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); 932 return; 933 } 934 break; 935 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI: 936 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 937 ctx->Pixel.PCMCTscale[0] = params[0]; 938 ctx->Pixel.PCMCTscale[1] = params[1]; 939 ctx->Pixel.PCMCTscale[2] = params[2]; 940 ctx->Pixel.PCMCTscale[3] = params[3]; 941 } 942 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 943 ctx->Pixel.PCMCTbias[0] = params[0]; 944 ctx->Pixel.PCMCTbias[1] = params[1]; 945 ctx->Pixel.PCMCTbias[2] = params[2]; 946 ctx->Pixel.PCMCTbias[3] = params[3]; 947 } 948 else { 949 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); 950 return; 951 } 952 break; 953 default: 954 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); 955 return; 956 } 957 958 ctx->NewState |= _NEW_PIXEL; 959} 960 961 962 963void GLAPIENTRY 964_mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params) 965{ 966 GLfloat fparams[4]; 967 if (pname == GL_COLOR_TABLE_SGI || 968 pname == GL_TEXTURE_COLOR_TABLE_SGI || 969 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI || 970 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) { 971 /* four values */ 972 fparams[0] = (GLfloat) params[0]; 973 fparams[1] = (GLfloat) params[1]; 974 fparams[2] = (GLfloat) params[2]; 975 fparams[3] = (GLfloat) params[3]; 976 } 977 else { 978 /* one values */ 979 fparams[0] = (GLfloat) params[0]; 980 } 981 _mesa_ColorTableParameterfv(target, pname, fparams); 982} 983 984 985 986void GLAPIENTRY 987_mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) 988{ 989 GET_CURRENT_CONTEXT(ctx); 990 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 991 struct gl_color_table *table = NULL; 992 ASSERT_OUTSIDE_BEGIN_END(ctx); 993 994 switch (target) { 995 case GL_TEXTURE_1D: 996 table = &texUnit->Current1D->Palette; 997 break; 998 case GL_TEXTURE_2D: 999 table = &texUnit->Current2D->Palette; 1000 break; 1001 case GL_TEXTURE_3D: 1002 table = &texUnit->Current3D->Palette; 1003 break; 1004 case GL_TEXTURE_CUBE_MAP_ARB: 1005 if (!ctx->Extensions.ARB_texture_cube_map) { 1006 _mesa_error(ctx, GL_INVALID_ENUM, 1007 "glGetColorTableParameterfv(target)"); 1008 return; 1009 } 1010 table = &texUnit->CurrentCubeMap->Palette; 1011 break; 1012 case GL_PROXY_TEXTURE_1D: 1013 table = &ctx->Texture.Proxy1D->Palette; 1014 break; 1015 case GL_PROXY_TEXTURE_2D: 1016 table = &ctx->Texture.Proxy2D->Palette; 1017 break; 1018 case GL_PROXY_TEXTURE_3D: 1019 table = &ctx->Texture.Proxy3D->Palette; 1020 break; 1021 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1022 if (!ctx->Extensions.ARB_texture_cube_map) { 1023 _mesa_error(ctx, GL_INVALID_ENUM, 1024 "glGetColorTableParameterfv(target)"); 1025 return; 1026 } 1027 table = &ctx->Texture.ProxyCubeMap->Palette; 1028 break; 1029 case GL_SHARED_TEXTURE_PALETTE_EXT: 1030 table = &ctx->Texture.Palette; 1031 break; 1032 case GL_COLOR_TABLE: 1033 table = &ctx->ColorTable; 1034 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1035 params[0] = ctx->Pixel.ColorTableScale[0]; 1036 params[1] = ctx->Pixel.ColorTableScale[1]; 1037 params[2] = ctx->Pixel.ColorTableScale[2]; 1038 params[3] = ctx->Pixel.ColorTableScale[3]; 1039 return; 1040 } 1041 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1042 params[0] = ctx->Pixel.ColorTableBias[0]; 1043 params[1] = ctx->Pixel.ColorTableBias[1]; 1044 params[2] = ctx->Pixel.ColorTableBias[2]; 1045 params[3] = ctx->Pixel.ColorTableBias[3]; 1046 return; 1047 } 1048 break; 1049 case GL_PROXY_COLOR_TABLE: 1050 table = &ctx->ProxyColorTable; 1051 break; 1052 case GL_TEXTURE_COLOR_TABLE_SGI: 1053 if (!ctx->Extensions.SGI_texture_color_table) { 1054 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 1055 return; 1056 } 1057 table = &(texUnit->ColorTable); 1058 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1059 params[0] = ctx->Pixel.TextureColorTableScale[0]; 1060 params[1] = ctx->Pixel.TextureColorTableScale[1]; 1061 params[2] = ctx->Pixel.TextureColorTableScale[2]; 1062 params[3] = ctx->Pixel.TextureColorTableScale[3]; 1063 return; 1064 } 1065 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1066 params[0] = ctx->Pixel.TextureColorTableBias[0]; 1067 params[1] = ctx->Pixel.TextureColorTableBias[1]; 1068 params[2] = ctx->Pixel.TextureColorTableBias[2]; 1069 params[3] = ctx->Pixel.TextureColorTableBias[3]; 1070 return; 1071 } 1072 break; 1073 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 1074 if (!ctx->Extensions.SGI_texture_color_table) { 1075 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 1076 return; 1077 } 1078 table = &(texUnit->ProxyColorTable); 1079 break; 1080 case GL_POST_CONVOLUTION_COLOR_TABLE: 1081 table = &ctx->PostConvolutionColorTable; 1082 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1083 params[0] = ctx->Pixel.PCCTscale[0]; 1084 params[1] = ctx->Pixel.PCCTscale[1]; 1085 params[2] = ctx->Pixel.PCCTscale[2]; 1086 params[3] = ctx->Pixel.PCCTscale[3]; 1087 return; 1088 } 1089 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1090 params[0] = ctx->Pixel.PCCTbias[0]; 1091 params[1] = ctx->Pixel.PCCTbias[1]; 1092 params[2] = ctx->Pixel.PCCTbias[2]; 1093 params[3] = ctx->Pixel.PCCTbias[3]; 1094 return; 1095 } 1096 break; 1097 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 1098 table = &ctx->ProxyPostConvolutionColorTable; 1099 break; 1100 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 1101 table = &ctx->PostColorMatrixColorTable; 1102 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1103 params[0] = ctx->Pixel.PCMCTscale[0]; 1104 params[1] = ctx->Pixel.PCMCTscale[1]; 1105 params[2] = ctx->Pixel.PCMCTscale[2]; 1106 params[3] = ctx->Pixel.PCMCTscale[3]; 1107 return; 1108 } 1109 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1110 params[0] = ctx->Pixel.PCMCTbias[0]; 1111 params[1] = ctx->Pixel.PCMCTbias[1]; 1112 params[2] = ctx->Pixel.PCMCTbias[2]; 1113 params[3] = ctx->Pixel.PCMCTbias[3]; 1114 return; 1115 } 1116 break; 1117 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 1118 table = &ctx->ProxyPostColorMatrixColorTable; 1119 break; 1120 default: 1121 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)"); 1122 return; 1123 } 1124 1125 assert(table); 1126 1127 switch (pname) { 1128 case GL_COLOR_TABLE_FORMAT: 1129 *params = (GLfloat) table->IntFormat; 1130 break; 1131 case GL_COLOR_TABLE_WIDTH: 1132 *params = (GLfloat) table->Size; 1133 break; 1134 case GL_COLOR_TABLE_RED_SIZE: 1135 *params = (GLfloat) table->RedSize; 1136 break; 1137 case GL_COLOR_TABLE_GREEN_SIZE: 1138 *params = (GLfloat) table->GreenSize; 1139 break; 1140 case GL_COLOR_TABLE_BLUE_SIZE: 1141 *params = (GLfloat) table->BlueSize; 1142 break; 1143 case GL_COLOR_TABLE_ALPHA_SIZE: 1144 *params = (GLfloat) table->AlphaSize; 1145 break; 1146 case GL_COLOR_TABLE_LUMINANCE_SIZE: 1147 *params = (GLfloat) table->LuminanceSize; 1148 break; 1149 case GL_COLOR_TABLE_INTENSITY_SIZE: 1150 *params = (GLfloat) table->IntensitySize; 1151 break; 1152 default: 1153 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" ); 1154 return; 1155 } 1156} 1157 1158 1159 1160void GLAPIENTRY 1161_mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) 1162{ 1163 GET_CURRENT_CONTEXT(ctx); 1164 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 1165 struct gl_color_table *table = NULL; 1166 ASSERT_OUTSIDE_BEGIN_END(ctx); 1167 1168 switch (target) { 1169 case GL_TEXTURE_1D: 1170 table = &texUnit->Current1D->Palette; 1171 break; 1172 case GL_TEXTURE_2D: 1173 table = &texUnit->Current2D->Palette; 1174 break; 1175 case GL_TEXTURE_3D: 1176 table = &texUnit->Current3D->Palette; 1177 break; 1178 case GL_TEXTURE_CUBE_MAP_ARB: 1179 if (!ctx->Extensions.ARB_texture_cube_map) { 1180 _mesa_error(ctx, GL_INVALID_ENUM, 1181 "glGetColorTableParameteriv(target)"); 1182 return; 1183 } 1184 table = &texUnit->CurrentCubeMap->Palette; 1185 break; 1186 case GL_PROXY_TEXTURE_1D: 1187 table = &ctx->Texture.Proxy1D->Palette; 1188 break; 1189 case GL_PROXY_TEXTURE_2D: 1190 table = &ctx->Texture.Proxy2D->Palette; 1191 break; 1192 case GL_PROXY_TEXTURE_3D: 1193 table = &ctx->Texture.Proxy3D->Palette; 1194 break; 1195 case GL_PROXY_TEXTURE_CUBE_MAP_ARB: 1196 if (!ctx->Extensions.ARB_texture_cube_map) { 1197 _mesa_error(ctx, GL_INVALID_ENUM, 1198 "glGetColorTableParameteriv(target)"); 1199 return; 1200 } 1201 table = &ctx->Texture.ProxyCubeMap->Palette; 1202 break; 1203 case GL_SHARED_TEXTURE_PALETTE_EXT: 1204 table = &ctx->Texture.Palette; 1205 break; 1206 case GL_COLOR_TABLE: 1207 table = &ctx->ColorTable; 1208 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1209 params[0] = (GLint) ctx->Pixel.ColorTableScale[0]; 1210 params[1] = (GLint) ctx->Pixel.ColorTableScale[1]; 1211 params[2] = (GLint) ctx->Pixel.ColorTableScale[2]; 1212 params[3] = (GLint) ctx->Pixel.ColorTableScale[3]; 1213 return; 1214 } 1215 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1216 params[0] = (GLint) ctx->Pixel.ColorTableBias[0]; 1217 params[1] = (GLint) ctx->Pixel.ColorTableBias[1]; 1218 params[2] = (GLint) ctx->Pixel.ColorTableBias[2]; 1219 params[3] = (GLint) ctx->Pixel.ColorTableBias[3]; 1220 return; 1221 } 1222 break; 1223 case GL_PROXY_COLOR_TABLE: 1224 table = &ctx->ProxyColorTable; 1225 break; 1226 case GL_TEXTURE_COLOR_TABLE_SGI: 1227 if (!ctx->Extensions.SGI_texture_color_table) { 1228 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 1229 return; 1230 } 1231 table = &(texUnit->ColorTable); 1232 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1233 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0]; 1234 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1]; 1235 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2]; 1236 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3]; 1237 return; 1238 } 1239 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1240 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0]; 1241 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1]; 1242 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2]; 1243 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3]; 1244 return; 1245 } 1246 break; 1247 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 1248 if (!ctx->Extensions.SGI_texture_color_table) { 1249 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 1250 return; 1251 } 1252 table = &(texUnit->ProxyColorTable); 1253 break; 1254 case GL_POST_CONVOLUTION_COLOR_TABLE: 1255 table = &ctx->PostConvolutionColorTable; 1256 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1257 params[0] = (GLint) ctx->Pixel.PCCTscale[0]; 1258 params[1] = (GLint) ctx->Pixel.PCCTscale[1]; 1259 params[2] = (GLint) ctx->Pixel.PCCTscale[2]; 1260 params[3] = (GLint) ctx->Pixel.PCCTscale[3]; 1261 return; 1262 } 1263 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1264 params[0] = (GLint) ctx->Pixel.PCCTbias[0]; 1265 params[1] = (GLint) ctx->Pixel.PCCTbias[1]; 1266 params[2] = (GLint) ctx->Pixel.PCCTbias[2]; 1267 params[3] = (GLint) ctx->Pixel.PCCTbias[3]; 1268 return; 1269 } 1270 break; 1271 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 1272 table = &ctx->ProxyPostConvolutionColorTable; 1273 break; 1274 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 1275 table = &ctx->PostColorMatrixColorTable; 1276 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 1277 params[0] = (GLint) ctx->Pixel.PCMCTscale[0]; 1278 params[1] = (GLint) ctx->Pixel.PCMCTscale[1]; 1279 params[2] = (GLint) ctx->Pixel.PCMCTscale[2]; 1280 params[3] = (GLint) ctx->Pixel.PCMCTscale[3]; 1281 return; 1282 } 1283 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 1284 params[0] = (GLint) ctx->Pixel.PCMCTbias[0]; 1285 params[1] = (GLint) ctx->Pixel.PCMCTbias[1]; 1286 params[2] = (GLint) ctx->Pixel.PCMCTbias[2]; 1287 params[3] = (GLint) ctx->Pixel.PCMCTbias[3]; 1288 return; 1289 } 1290 break; 1291 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 1292 table = &ctx->ProxyPostColorMatrixColorTable; 1293 break; 1294 default: 1295 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)"); 1296 return; 1297 } 1298 1299 assert(table); 1300 1301 switch (pname) { 1302 case GL_COLOR_TABLE_FORMAT: 1303 *params = table->IntFormat; 1304 break; 1305 case GL_COLOR_TABLE_WIDTH: 1306 *params = table->Size; 1307 break; 1308 case GL_COLOR_TABLE_RED_SIZE: 1309 *params = table->RedSize; 1310 break; 1311 case GL_COLOR_TABLE_GREEN_SIZE: 1312 *params = table->GreenSize; 1313 break; 1314 case GL_COLOR_TABLE_BLUE_SIZE: 1315 *params = table->BlueSize; 1316 break; 1317 case GL_COLOR_TABLE_ALPHA_SIZE: 1318 *params = table->AlphaSize; 1319 break; 1320 case GL_COLOR_TABLE_LUMINANCE_SIZE: 1321 *params = table->LuminanceSize; 1322 break; 1323 case GL_COLOR_TABLE_INTENSITY_SIZE: 1324 *params = table->IntensitySize; 1325 break; 1326 default: 1327 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" ); 1328 return; 1329 } 1330} 1331 1332/**********************************************************************/ 1333/***** Initialization *****/ 1334/**********************************************************************/ 1335 1336 1337void 1338_mesa_init_colortable( struct gl_color_table *p ) 1339{ 1340 p->Type = CHAN_TYPE; 1341 p->Table = NULL; 1342 p->Size = 0; 1343 p->IntFormat = GL_RGBA; 1344} 1345 1346 1347 1348void 1349_mesa_free_colortable_data( struct gl_color_table *p ) 1350{ 1351 if (p->Table) { 1352 FREE(p->Table); 1353 p->Table = NULL; 1354 } 1355} 1356 1357 1358/* 1359 * Initialize all colortables for a context. 1360 */ 1361void _mesa_init_colortables( GLcontext * ctx ) 1362{ 1363 /* Color tables */ 1364 _mesa_init_colortable(&ctx->ColorTable); 1365 _mesa_init_colortable(&ctx->ProxyColorTable); 1366 _mesa_init_colortable(&ctx->PostConvolutionColorTable); 1367 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable); 1368 _mesa_init_colortable(&ctx->PostColorMatrixColorTable); 1369 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable); 1370} 1371 1372 1373/* 1374 * Free all colortable data for a context 1375 */ 1376void _mesa_free_colortables_data( GLcontext *ctx ) 1377{ 1378 _mesa_free_colortable_data(&ctx->ColorTable); 1379 _mesa_free_colortable_data(&ctx->ProxyColorTable); 1380 _mesa_free_colortable_data(&ctx->PostConvolutionColorTable); 1381 _mesa_free_colortable_data(&ctx->ProxyPostConvolutionColorTable); 1382 _mesa_free_colortable_data(&ctx->PostColorMatrixColorTable); 1383 _mesa_free_colortable_data(&ctx->ProxyPostColorMatrixColorTable); 1384} 1385