colortab.c revision e5c6a92a12b5cd7db205d72039f58d302b0be9d5
1/* 2 * Mesa 3-D graphics library 3 * Version: 7.1 4 * 5 * Copyright (C) 1999-2007 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 "mfeatures.h" 33#include "mtypes.h" 34#include "pack.h" 35#include "pbo.h" 36#include "state.h" 37#include "teximage.h" 38#include "texstate.h" 39#include "main/dispatch.h" 40 41 42#if FEATURE_colortable 43 44 45/** 46 * Given an internalFormat token passed to glColorTable, 47 * return the corresponding base format. 48 * Return -1 if invalid token. 49 */ 50static GLint 51base_colortab_format( GLenum format ) 52{ 53 switch (format) { 54 case GL_ALPHA: 55 case GL_ALPHA4: 56 case GL_ALPHA8: 57 case GL_ALPHA12: 58 case GL_ALPHA16: 59 return GL_ALPHA; 60 case GL_LUMINANCE: 61 case GL_LUMINANCE4: 62 case GL_LUMINANCE8: 63 case GL_LUMINANCE12: 64 case GL_LUMINANCE16: 65 return GL_LUMINANCE; 66 case GL_LUMINANCE_ALPHA: 67 case GL_LUMINANCE4_ALPHA4: 68 case GL_LUMINANCE6_ALPHA2: 69 case GL_LUMINANCE8_ALPHA8: 70 case GL_LUMINANCE12_ALPHA4: 71 case GL_LUMINANCE12_ALPHA12: 72 case GL_LUMINANCE16_ALPHA16: 73 return GL_LUMINANCE_ALPHA; 74 case GL_INTENSITY: 75 case GL_INTENSITY4: 76 case GL_INTENSITY8: 77 case GL_INTENSITY12: 78 case GL_INTENSITY16: 79 return GL_INTENSITY; 80 case GL_RGB: 81 case GL_R3_G3_B2: 82 case GL_RGB4: 83 case GL_RGB5: 84 case GL_RGB8: 85 case GL_RGB10: 86 case GL_RGB12: 87 case GL_RGB16: 88 return GL_RGB; 89 case GL_RGBA: 90 case GL_RGBA2: 91 case GL_RGBA4: 92 case GL_RGB5_A1: 93 case GL_RGBA8: 94 case GL_RGB10_A2: 95 case GL_RGBA12: 96 case GL_RGBA16: 97 return GL_RGBA; 98 default: 99 return -1; /* error */ 100 } 101} 102 103 104 105/** 106 * Examine table's format and set the component sizes accordingly. 107 */ 108static void 109set_component_sizes( struct gl_color_table *table ) 110{ 111 /* assuming the ubyte table */ 112 const GLubyte sz = 8; 113 114 switch (table->_BaseFormat) { 115 case GL_ALPHA: 116 table->RedSize = 0; 117 table->GreenSize = 0; 118 table->BlueSize = 0; 119 table->AlphaSize = sz; 120 table->IntensitySize = 0; 121 table->LuminanceSize = 0; 122 break; 123 case GL_LUMINANCE: 124 table->RedSize = 0; 125 table->GreenSize = 0; 126 table->BlueSize = 0; 127 table->AlphaSize = 0; 128 table->IntensitySize = 0; 129 table->LuminanceSize = sz; 130 break; 131 case GL_LUMINANCE_ALPHA: 132 table->RedSize = 0; 133 table->GreenSize = 0; 134 table->BlueSize = 0; 135 table->AlphaSize = sz; 136 table->IntensitySize = 0; 137 table->LuminanceSize = sz; 138 break; 139 case GL_INTENSITY: 140 table->RedSize = 0; 141 table->GreenSize = 0; 142 table->BlueSize = 0; 143 table->AlphaSize = 0; 144 table->IntensitySize = sz; 145 table->LuminanceSize = 0; 146 break; 147 case GL_RGB: 148 table->RedSize = sz; 149 table->GreenSize = sz; 150 table->BlueSize = sz; 151 table->AlphaSize = 0; 152 table->IntensitySize = 0; 153 table->LuminanceSize = 0; 154 break; 155 case GL_RGBA: 156 table->RedSize = sz; 157 table->GreenSize = sz; 158 table->BlueSize = sz; 159 table->AlphaSize = sz; 160 table->IntensitySize = 0; 161 table->LuminanceSize = 0; 162 break; 163 default: 164 _mesa_problem(NULL, "unexpected format in set_component_sizes"); 165 } 166} 167 168 169 170/** 171 * Update/replace all or part of a color table. Helper function 172 * used by _mesa_ColorTable() and _mesa_ColorSubTable(). 173 * The table->Table buffer should already be allocated. 174 * \param start first entry to update 175 * \param count number of entries to update 176 * \param format format of user-provided table data 177 * \param type datatype of user-provided table data 178 * \param data user-provided table data 179 * \param [rgba]Scale - RGBA scale factors 180 * \param [rgba]Bias - RGBA bias factors 181 */ 182static void 183store_colortable_entries(struct gl_context *ctx, struct gl_color_table *table, 184 GLsizei start, GLsizei count, 185 GLenum format, GLenum type, const GLvoid *data, 186 GLfloat rScale, GLfloat rBias, 187 GLfloat gScale, GLfloat gBias, 188 GLfloat bScale, GLfloat bBias, 189 GLfloat aScale, GLfloat aBias) 190{ 191 data = _mesa_map_validate_pbo_source(ctx, 192 1, &ctx->Unpack, count, 1, 1, 193 format, type, data, 194 "glColor[Sub]Table"); 195 if (!data) 196 return; 197 198 { 199 /* convert user-provided data to GLfloat values */ 200 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; 201 GLfloat *tableF; 202 GLint i; 203 204 _mesa_unpack_color_span_float(ctx, 205 count, /* number of pixels */ 206 table->_BaseFormat, /* dest format */ 207 tempTab, /* dest address */ 208 format, type, /* src format/type */ 209 data, /* src data */ 210 &ctx->Unpack, 211 IMAGE_CLAMP_BIT); /* transfer ops */ 212 213 /* the destination */ 214 tableF = table->TableF; 215 216 /* Apply scale & bias & clamp now */ 217 switch (table->_BaseFormat) { 218 case GL_INTENSITY: 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_LUMINANCE: 225 for (i = 0; i < count; i++) { 226 GLuint j = start + i; 227 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); 228 } 229 break; 230 case GL_ALPHA: 231 for (i = 0; i < count; i++) { 232 GLuint j = start + i; 233 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); 234 } 235 break; 236 case GL_LUMINANCE_ALPHA: 237 for (i = 0; i < count; i++) { 238 GLuint j = start + i; 239 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); 240 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); 241 } 242 break; 243 case GL_RGB: 244 for (i = 0; i < count; i++) { 245 GLuint j = start + i; 246 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); 247 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); 248 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); 249 } 250 break; 251 case GL_RGBA: 252 for (i = 0; i < count; i++) { 253 GLuint j = start + i; 254 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); 255 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); 256 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); 257 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); 258 } 259 break; 260 default: 261 _mesa_problem(ctx, "Bad format in store_colortable_entries"); 262 return; 263 } 264 } 265 266 /* update the ubyte table */ 267 { 268 const GLint comps = _mesa_components_in_format(table->_BaseFormat); 269 const GLfloat *tableF = table->TableF + start * comps; 270 GLubyte *tableUB = table->TableUB + start * comps; 271 GLint i; 272 for (i = 0; i < count * comps; i++) { 273 CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]); 274 } 275 } 276 277 _mesa_unmap_pbo_source(ctx, &ctx->Unpack); 278} 279 280 281 282void GLAPIENTRY 283_mesa_ColorTable( GLenum target, GLenum internalFormat, 284 GLsizei width, GLenum format, GLenum type, 285 const GLvoid *data ) 286{ 287 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 }; 288 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 }; 289 GET_CURRENT_CONTEXT(ctx); 290 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 291 struct gl_texture_object *texObj = NULL; 292 struct gl_color_table *table = NULL; 293 GLboolean proxy = GL_FALSE; 294 GLint baseFormat; 295 const GLfloat *scale = one, *bias = zero; 296 GLint comps; 297 298 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ 299 300 switch (target) { 301 case GL_SHARED_TEXTURE_PALETTE_EXT: 302 table = &ctx->Texture.Palette; 303 break; 304 default: 305 /* try texture targets */ 306 { 307 struct gl_texture_object *texobj 308 = _mesa_select_tex_object(ctx, texUnit, target); 309 if (texobj) { 310 table = &texobj->Palette; 311 proxy = _mesa_is_proxy_texture(target); 312 } 313 else { 314 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 315 return; 316 } 317 } 318 } 319 320 assert(table); 321 322 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 323 format == GL_INTENSITY) { 324 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)"); 325 return; 326 } 327 328 baseFormat = base_colortab_format(internalFormat); 329 if (baseFormat < 0) { 330 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)"); 331 return; 332 } 333 334 if (width < 0 || (width != 0 && !_mesa_is_pow_two(width))) { 335 /* error */ 336 if (proxy) { 337 table->Size = 0; 338 table->InternalFormat = (GLenum) 0; 339 table->_BaseFormat = (GLenum) 0; 340 } 341 else { 342 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width); 343 } 344 return; 345 } 346 347 if (width > (GLsizei) ctx->Const.MaxColorTableSize) { 348 if (proxy) { 349 table->Size = 0; 350 table->InternalFormat = (GLenum) 0; 351 table->_BaseFormat = (GLenum) 0; 352 } 353 else { 354 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); 355 } 356 return; 357 } 358 359 table->Size = width; 360 table->InternalFormat = internalFormat; 361 table->_BaseFormat = (GLenum) baseFormat; 362 363 comps = _mesa_components_in_format(table->_BaseFormat); 364 assert(comps > 0); /* error should have been caught sooner */ 365 366 if (!proxy) { 367 _mesa_free_colortable_data(table); 368 369 if (width > 0) { 370 table->TableF = (GLfloat *) malloc(comps * width * sizeof(GLfloat)); 371 table->TableUB = (GLubyte *) malloc(comps * width * sizeof(GLubyte)); 372 373 if (!table->TableF || !table->TableUB) { 374 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); 375 return; 376 } 377 378 store_colortable_entries(ctx, table, 379 0, width, /* start, count */ 380 format, type, data, 381 scale[0], bias[0], 382 scale[1], bias[1], 383 scale[2], bias[2], 384 scale[3], bias[3]); 385 } 386 } /* proxy */ 387 388 /* do this after the table's Type and Format are set */ 389 set_component_sizes(table); 390 391 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 392 /* texture object palette, texObj==NULL means the shared palette */ 393 if (ctx->Driver.UpdateTexturePalette) { 394 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 395 } 396 } 397 398 ctx->NewState |= _NEW_PIXEL; 399} 400 401 402 403void GLAPIENTRY 404_mesa_ColorSubTable( GLenum target, GLsizei start, 405 GLsizei count, GLenum format, GLenum type, 406 const GLvoid *data ) 407{ 408 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 }; 409 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 }; 410 GET_CURRENT_CONTEXT(ctx); 411 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 412 struct gl_texture_object *texObj = NULL; 413 struct gl_color_table *table = NULL; 414 const GLfloat *scale = one, *bias = zero; 415 416 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 417 418 switch (target) { 419 case GL_SHARED_TEXTURE_PALETTE_EXT: 420 table = &ctx->Texture.Palette; 421 break; 422 default: 423 /* try texture targets */ 424 texObj = _mesa_select_tex_object(ctx, texUnit, target); 425 if (texObj && !_mesa_is_proxy_texture(target)) { 426 table = &texObj->Palette; 427 } 428 else { 429 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 430 return; 431 } 432 } 433 434 assert(table); 435 436 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 437 format == GL_INTENSITY) { 438 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)"); 439 return; 440 } 441 442 if (count < 1) { 443 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 444 return; 445 } 446 447 /* error should have been caught sooner */ 448 assert(_mesa_components_in_format(table->_BaseFormat) > 0); 449 450 if (start + count > (GLint) table->Size) { 451 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 452 return; 453 } 454 455 if (!table->TableF || !table->TableUB) { 456 /* a GL_OUT_OF_MEMORY error would have been recorded previously */ 457 return; 458 } 459 460 store_colortable_entries(ctx, table, start, count, 461 format, type, data, 462 scale[0], bias[0], 463 scale[1], bias[1], 464 scale[2], bias[2], 465 scale[3], bias[3]); 466 467 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 468 /* per-texture object palette */ 469 if (ctx->Driver.UpdateTexturePalette) { 470 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 471 } 472 } 473 474 ctx->NewState |= _NEW_PIXEL; 475} 476 477 478 479static void GLAPIENTRY 480_mesa_CopyColorTable(GLenum target, GLenum internalformat, 481 GLint x, GLint y, GLsizei width) 482{ 483 GET_CURRENT_CONTEXT(ctx); 484 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 485 486 if (!ctx->ReadBuffer->_ColorReadBuffer) { 487 return; /* no readbuffer - OK */ 488 } 489 490 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width ); 491} 492 493 494 495static void GLAPIENTRY 496_mesa_CopyColorSubTable(GLenum target, GLsizei start, 497 GLint x, GLint y, GLsizei width) 498{ 499 GET_CURRENT_CONTEXT(ctx); 500 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 501 502 if (!ctx->ReadBuffer->_ColorReadBuffer) { 503 return; /* no readbuffer - OK */ 504 } 505 506 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width ); 507} 508 509 510 511static void GLAPIENTRY 512_mesa_GetColorTable( GLenum target, GLenum format, 513 GLenum type, GLvoid *data ) 514{ 515 GET_CURRENT_CONTEXT(ctx); 516 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 517 struct gl_color_table *table = NULL; 518 GLfloat rgba[MAX_COLOR_TABLE_SIZE][4]; 519 GLbitfield transferOps = 0; 520 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 521 522 if (ctx->NewState) { 523 _mesa_update_state(ctx); 524 } 525 526 switch (target) { 527 case GL_SHARED_TEXTURE_PALETTE_EXT: 528 table = &ctx->Texture.Palette; 529 break; 530 default: 531 /* try texture targets */ 532 { 533 struct gl_texture_object *texobj 534 = _mesa_select_tex_object(ctx, texUnit, target); 535 if (texobj && !_mesa_is_proxy_texture(target)) { 536 table = &texobj->Palette; 537 } 538 else { 539 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 540 return; 541 } 542 } 543 } 544 545 ASSERT(table); 546 547 if (table->Size <= 0) { 548 return; 549 } 550 551 switch (table->_BaseFormat) { 552 case GL_ALPHA: 553 { 554 GLuint i; 555 for (i = 0; i < table->Size; i++) { 556 rgba[i][RCOMP] = 0; 557 rgba[i][GCOMP] = 0; 558 rgba[i][BCOMP] = 0; 559 rgba[i][ACOMP] = table->TableF[i]; 560 } 561 } 562 break; 563 case GL_LUMINANCE: 564 { 565 GLuint i; 566 for (i = 0; i < table->Size; i++) { 567 rgba[i][RCOMP] = 568 rgba[i][GCOMP] = 569 rgba[i][BCOMP] = table->TableF[i]; 570 rgba[i][ACOMP] = 1.0F; 571 } 572 } 573 break; 574 case GL_LUMINANCE_ALPHA: 575 { 576 GLuint i; 577 for (i = 0; i < table->Size; i++) { 578 rgba[i][RCOMP] = 579 rgba[i][GCOMP] = 580 rgba[i][BCOMP] = table->TableF[i*2+0]; 581 rgba[i][ACOMP] = table->TableF[i*2+1]; 582 } 583 } 584 break; 585 case GL_INTENSITY: 586 { 587 GLuint i; 588 for (i = 0; i < table->Size; i++) { 589 rgba[i][RCOMP] = 590 rgba[i][GCOMP] = 591 rgba[i][BCOMP] = 592 rgba[i][ACOMP] = table->TableF[i]; 593 } 594 } 595 break; 596 case GL_RGB: 597 { 598 GLuint i; 599 for (i = 0; i < table->Size; i++) { 600 rgba[i][RCOMP] = table->TableF[i*3+0]; 601 rgba[i][GCOMP] = table->TableF[i*3+1]; 602 rgba[i][BCOMP] = table->TableF[i*3+2]; 603 rgba[i][ACOMP] = 1.0F; 604 } 605 } 606 break; 607 case GL_RGBA: 608 memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat)); 609 break; 610 default: 611 _mesa_problem(ctx, "bad table format in glGetColorTable"); 612 return; 613 } 614 615 data = _mesa_map_validate_pbo_dest(ctx, 616 1, &ctx->Pack, table->Size, 1, 1, 617 format, type, data, 618 "glGetColorTable"); 619 if (!data) 620 return; 621 622 /* TODO: is this correct? */ 623 if(ctx->Color._ClampReadColor) 624 transferOps |= IMAGE_CLAMP_BIT; 625 626 _mesa_pack_rgba_span_float(ctx, table->Size, rgba, 627 format, type, data, &ctx->Pack, transferOps); 628 629 _mesa_unmap_pbo_dest(ctx, &ctx->Pack); 630} 631 632 633 634static void GLAPIENTRY 635_mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) 636{ 637 /* no extensions use this function */ 638 GET_CURRENT_CONTEXT(ctx); 639 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 640 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(target)"); 641} 642 643 644 645static void GLAPIENTRY 646_mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params) 647{ 648 /* no extensions use this function */ 649 GET_CURRENT_CONTEXT(ctx); 650 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 651 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameteriv(target)"); 652} 653 654 655 656static void GLAPIENTRY 657_mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) 658{ 659 GET_CURRENT_CONTEXT(ctx); 660 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 661 struct gl_color_table *table = NULL; 662 ASSERT_OUTSIDE_BEGIN_END(ctx); 663 664 switch (target) { 665 case GL_SHARED_TEXTURE_PALETTE_EXT: 666 table = &ctx->Texture.Palette; 667 break; 668 default: 669 /* try texture targets */ 670 { 671 struct gl_texture_object *texobj 672 = _mesa_select_tex_object(ctx, texUnit, target); 673 if (texobj) { 674 table = &texobj->Palette; 675 } 676 else { 677 _mesa_error(ctx, GL_INVALID_ENUM, 678 "glGetColorTableParameterfv(target)"); 679 return; 680 } 681 } 682 } 683 684 assert(table); 685 686 switch (pname) { 687 case GL_COLOR_TABLE_FORMAT: 688 *params = (GLfloat) table->InternalFormat; 689 break; 690 case GL_COLOR_TABLE_WIDTH: 691 *params = (GLfloat) table->Size; 692 break; 693 case GL_COLOR_TABLE_RED_SIZE: 694 *params = (GLfloat) table->RedSize; 695 break; 696 case GL_COLOR_TABLE_GREEN_SIZE: 697 *params = (GLfloat) table->GreenSize; 698 break; 699 case GL_COLOR_TABLE_BLUE_SIZE: 700 *params = (GLfloat) table->BlueSize; 701 break; 702 case GL_COLOR_TABLE_ALPHA_SIZE: 703 *params = (GLfloat) table->AlphaSize; 704 break; 705 case GL_COLOR_TABLE_LUMINANCE_SIZE: 706 *params = (GLfloat) table->LuminanceSize; 707 break; 708 case GL_COLOR_TABLE_INTENSITY_SIZE: 709 *params = (GLfloat) table->IntensitySize; 710 break; 711 default: 712 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" ); 713 return; 714 } 715} 716 717 718 719static void GLAPIENTRY 720_mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) 721{ 722 GET_CURRENT_CONTEXT(ctx); 723 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx); 724 struct gl_color_table *table = NULL; 725 ASSERT_OUTSIDE_BEGIN_END(ctx); 726 727 switch (target) { 728 case GL_SHARED_TEXTURE_PALETTE_EXT: 729 table = &ctx->Texture.Palette; 730 break; 731 default: 732 /* Try texture targets */ 733 { 734 struct gl_texture_object *texobj 735 = _mesa_select_tex_object(ctx, texUnit, target); 736 if (texobj) { 737 table = &texobj->Palette; 738 } 739 else { 740 _mesa_error(ctx, GL_INVALID_ENUM, 741 "glGetColorTableParameteriv(target)"); 742 return; 743 } 744 } 745 } 746 747 assert(table); 748 749 switch (pname) { 750 case GL_COLOR_TABLE_FORMAT: 751 *params = table->InternalFormat; 752 break; 753 case GL_COLOR_TABLE_WIDTH: 754 *params = table->Size; 755 break; 756 case GL_COLOR_TABLE_RED_SIZE: 757 *params = table->RedSize; 758 break; 759 case GL_COLOR_TABLE_GREEN_SIZE: 760 *params = table->GreenSize; 761 break; 762 case GL_COLOR_TABLE_BLUE_SIZE: 763 *params = table->BlueSize; 764 break; 765 case GL_COLOR_TABLE_ALPHA_SIZE: 766 *params = table->AlphaSize; 767 break; 768 case GL_COLOR_TABLE_LUMINANCE_SIZE: 769 *params = table->LuminanceSize; 770 break; 771 case GL_COLOR_TABLE_INTENSITY_SIZE: 772 *params = table->IntensitySize; 773 break; 774 default: 775 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" ); 776 return; 777 } 778} 779 780 781void 782_mesa_init_colortable_dispatch(struct _glapi_table *disp) 783{ 784 SET_ColorSubTable(disp, _mesa_ColorSubTable); 785 SET_ColorTable(disp, _mesa_ColorTable); 786 SET_ColorTableParameterfv(disp, _mesa_ColorTableParameterfv); 787 SET_ColorTableParameteriv(disp, _mesa_ColorTableParameteriv); 788 SET_CopyColorSubTable(disp, _mesa_CopyColorSubTable); 789 SET_CopyColorTable(disp, _mesa_CopyColorTable); 790 SET_GetColorTable(disp, _mesa_GetColorTable); 791 SET_GetColorTableParameterfv(disp, _mesa_GetColorTableParameterfv); 792 SET_GetColorTableParameteriv(disp, _mesa_GetColorTableParameteriv); 793} 794 795 796#endif /* FEATURE_colortable */ 797 798 799/**********************************************************************/ 800/***** Initialization *****/ 801/**********************************************************************/ 802 803 804void 805_mesa_init_colortable( struct gl_color_table *p ) 806{ 807 p->TableF = NULL; 808 p->TableUB = NULL; 809 p->Size = 0; 810 p->InternalFormat = GL_RGBA; 811} 812 813 814 815void 816_mesa_free_colortable_data( struct gl_color_table *p ) 817{ 818 if (p->TableF) { 819 free(p->TableF); 820 p->TableF = NULL; 821 } 822 if (p->TableUB) { 823 free(p->TableUB); 824 p->TableUB = NULL; 825 } 826} 827