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