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