Home | Info | Community | Development | myReactOS | Contact Us
ReactOS Development > Doxygencolortab.c
Go to the documentation of this file.
00001 /* 00002 * Mesa 3-D graphics library 00003 * Version: 7.1 00004 * 00005 * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. 00006 * 00007 * Permission is hereby granted, free of charge, to any person obtaining a 00008 * copy of this software and associated documentation files (the "Software"), 00009 * to deal in the Software without restriction, including without limitation 00010 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00011 * and/or sell copies of the Software, and to permit persons to whom the 00012 * Software is furnished to do so, subject to the following conditions: 00013 * 00014 * The above copyright notice and this permission notice shall be included 00015 * in all copies or substantial portions of the Software. 00016 * 00017 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00018 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 00019 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 00020 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN 00021 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 00022 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 00023 */ 00024 00025 00026 #include "glheader.h" 00027 #include "bufferobj.h" 00028 #include "colortab.h" 00029 #include "context.h" 00030 #include "image.h" 00031 #include "macros.h" 00032 #include "state.h" 00033 #include "teximage.h" 00034 00035 00041 static GLint 00042 base_colortab_format( GLenum format ) 00043 { 00044 switch (format) { 00045 case GL_ALPHA: 00046 case GL_ALPHA4: 00047 case GL_ALPHA8: 00048 case GL_ALPHA12: 00049 case GL_ALPHA16: 00050 return GL_ALPHA; 00051 case GL_LUMINANCE: 00052 case GL_LUMINANCE4: 00053 case GL_LUMINANCE8: 00054 case GL_LUMINANCE12: 00055 case GL_LUMINANCE16: 00056 return GL_LUMINANCE; 00057 case GL_LUMINANCE_ALPHA: 00058 case GL_LUMINANCE4_ALPHA4: 00059 case GL_LUMINANCE6_ALPHA2: 00060 case GL_LUMINANCE8_ALPHA8: 00061 case GL_LUMINANCE12_ALPHA4: 00062 case GL_LUMINANCE12_ALPHA12: 00063 case GL_LUMINANCE16_ALPHA16: 00064 return GL_LUMINANCE_ALPHA; 00065 case GL_INTENSITY: 00066 case GL_INTENSITY4: 00067 case GL_INTENSITY8: 00068 case GL_INTENSITY12: 00069 case GL_INTENSITY16: 00070 return GL_INTENSITY; 00071 case GL_RGB: 00072 case GL_R3_G3_B2: 00073 case GL_RGB4: 00074 case GL_RGB5: 00075 case GL_RGB8: 00076 case GL_RGB10: 00077 case GL_RGB12: 00078 case GL_RGB16: 00079 return GL_RGB; 00080 case GL_RGBA: 00081 case GL_RGBA2: 00082 case GL_RGBA4: 00083 case GL_RGB5_A1: 00084 case GL_RGBA8: 00085 case GL_RGB10_A2: 00086 case GL_RGBA12: 00087 case GL_RGBA16: 00088 return GL_RGBA; 00089 default: 00090 return -1; /* error */ 00091 } 00092 } 00093 00094 00095 00099 static void 00100 set_component_sizes( struct gl_color_table *table ) 00101 { 00102 /* assuming the ubyte table */ 00103 const GLubyte sz = 8; 00104 00105 switch (table->_BaseFormat) { 00106 case GL_ALPHA: 00107 table->RedSize = 0; 00108 table->GreenSize = 0; 00109 table->BlueSize = 0; 00110 table->AlphaSize = sz; 00111 table->IntensitySize = 0; 00112 table->LuminanceSize = 0; 00113 break; 00114 case GL_LUMINANCE: 00115 table->RedSize = 0; 00116 table->GreenSize = 0; 00117 table->BlueSize = 0; 00118 table->AlphaSize = 0; 00119 table->IntensitySize = 0; 00120 table->LuminanceSize = sz; 00121 break; 00122 case GL_LUMINANCE_ALPHA: 00123 table->RedSize = 0; 00124 table->GreenSize = 0; 00125 table->BlueSize = 0; 00126 table->AlphaSize = sz; 00127 table->IntensitySize = 0; 00128 table->LuminanceSize = sz; 00129 break; 00130 case GL_INTENSITY: 00131 table->RedSize = 0; 00132 table->GreenSize = 0; 00133 table->BlueSize = 0; 00134 table->AlphaSize = 0; 00135 table->IntensitySize = sz; 00136 table->LuminanceSize = 0; 00137 break; 00138 case GL_RGB: 00139 table->RedSize = sz; 00140 table->GreenSize = sz; 00141 table->BlueSize = sz; 00142 table->AlphaSize = 0; 00143 table->IntensitySize = 0; 00144 table->LuminanceSize = 0; 00145 break; 00146 case GL_RGBA: 00147 table->RedSize = sz; 00148 table->GreenSize = sz; 00149 table->BlueSize = sz; 00150 table->AlphaSize = sz; 00151 table->IntensitySize = 0; 00152 table->LuminanceSize = 0; 00153 break; 00154 default: 00155 _mesa_problem(NULL, "unexpected format in set_component_sizes"); 00156 } 00157 } 00158 00159 00160 00173 static void 00174 store_colortable_entries(GLcontext *ctx, struct gl_color_table *table, 00175 GLsizei start, GLsizei count, 00176 GLenum format, GLenum type, const GLvoid *data, 00177 GLfloat rScale, GLfloat rBias, 00178 GLfloat gScale, GLfloat gBias, 00179 GLfloat bScale, GLfloat bBias, 00180 GLfloat aScale, GLfloat aBias) 00181 { 00182 if (ctx->Unpack.BufferObj->Name) { 00183 /* Get/unpack the color table data from a PBO */ 00184 GLubyte *buf; 00185 if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1, 00186 format, type, data)) { 00187 _mesa_error(ctx, GL_INVALID_OPERATION, 00188 "glColor[Sub]Table(bad PBO access)"); 00189 return; 00190 } 00191 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, 00192 GL_READ_ONLY_ARB, 00193 ctx->Unpack.BufferObj); 00194 if (!buf) { 00195 _mesa_error(ctx, GL_INVALID_OPERATION, 00196 "glColor[Sub]Table(PBO mapped)"); 00197 return; 00198 } 00199 data = ADD_POINTERS(buf, data); 00200 } 00201 00202 00203 { 00204 /* convert user-provided data to GLfloat values */ 00205 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; 00206 GLfloat *tableF; 00207 GLint i; 00208 00209 _mesa_unpack_color_span_float(ctx, 00210 count, /* number of pixels */ 00211 table->_BaseFormat, /* dest format */ 00212 tempTab, /* dest address */ 00213 format, type, /* src format/type */ 00214 data, /* src data */ 00215 &ctx->Unpack, 00216 IMAGE_CLAMP_BIT); /* transfer ops */ 00217 00218 /* the destination */ 00219 tableF = table->TableF; 00220 00221 /* Apply scale & bias & clamp now */ 00222 switch (table->_BaseFormat) { 00223 case GL_INTENSITY: 00224 for (i = 0; i < count; i++) { 00225 GLuint j = start + i; 00226 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); 00227 } 00228 break; 00229 case GL_LUMINANCE: 00230 for (i = 0; i < count; i++) { 00231 GLuint j = start + i; 00232 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); 00233 } 00234 break; 00235 case GL_ALPHA: 00236 for (i = 0; i < count; i++) { 00237 GLuint j = start + i; 00238 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); 00239 } 00240 break; 00241 case GL_LUMINANCE_ALPHA: 00242 for (i = 0; i < count; i++) { 00243 GLuint j = start + i; 00244 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); 00245 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); 00246 } 00247 break; 00248 case GL_RGB: 00249 for (i = 0; i < count; i++) { 00250 GLuint j = start + i; 00251 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); 00252 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); 00253 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); 00254 } 00255 break; 00256 case GL_RGBA: 00257 for (i = 0; i < count; i++) { 00258 GLuint j = start + i; 00259 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); 00260 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); 00261 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); 00262 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); 00263 } 00264 break; 00265 default: 00266 _mesa_problem(ctx, "Bad format in store_colortable_entries"); 00267 return; 00268 } 00269 } 00270 00271 /* update the ubyte table */ 00272 { 00273 const GLint comps = _mesa_components_in_format(table->_BaseFormat); 00274 const GLfloat *tableF = table->TableF + start * comps; 00275 GLubyte *tableUB = table->TableUB + start * comps; 00276 GLint i; 00277 for (i = 0; i < count * comps; i++) { 00278 CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]); 00279 } 00280 } 00281 00282 if (ctx->Unpack.BufferObj->Name) { 00283 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT, 00284 ctx->Unpack.BufferObj); 00285 } 00286 } 00287 00288 00289 00290 void GLAPIENTRY 00291 _mesa_ColorTable( GLenum target, GLenum internalFormat, 00292 GLsizei width, GLenum format, GLenum type, 00293 const GLvoid *data ) 00294 { 00295 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 }; 00296 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 }; 00297 GET_CURRENT_CONTEXT(ctx); 00298 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00299 struct gl_texture_object *texObj = NULL; 00300 struct gl_color_table *table = NULL; 00301 GLboolean proxy = GL_FALSE; 00302 GLint baseFormat; 00303 const GLfloat *scale = one, *bias = zero; 00304 GLint comps; 00305 00306 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ 00307 00308 switch (target) { 00309 case GL_SHARED_TEXTURE_PALETTE_EXT: 00310 table = &ctx->Texture.Palette; 00311 break; 00312 case GL_COLOR_TABLE: 00313 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION]; 00314 scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]; 00315 bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]; 00316 break; 00317 case GL_PROXY_COLOR_TABLE: 00318 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION]; 00319 proxy = GL_TRUE; 00320 break; 00321 case GL_TEXTURE_COLOR_TABLE_SGI: 00322 if (!ctx->Extensions.SGI_texture_color_table) { 00323 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 00324 return; 00325 } 00326 table = &(texUnit->ColorTable); 00327 scale = ctx->Pixel.TextureColorTableScale; 00328 bias = ctx->Pixel.TextureColorTableBias; 00329 break; 00330 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 00331 if (!ctx->Extensions.SGI_texture_color_table) { 00332 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 00333 return; 00334 } 00335 table = &(texUnit->ProxyColorTable); 00336 proxy = GL_TRUE; 00337 break; 00338 case GL_POST_CONVOLUTION_COLOR_TABLE: 00339 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION]; 00340 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]; 00341 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]; 00342 break; 00343 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 00344 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION]; 00345 proxy = GL_TRUE; 00346 break; 00347 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 00348 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; 00349 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; 00350 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]; 00351 break; 00352 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 00353 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX]; 00354 proxy = GL_TRUE; 00355 break; 00356 default: 00357 /* try texture targets */ 00358 { 00359 struct gl_texture_object *texobj 00360 = _mesa_select_tex_object(ctx, texUnit, target); 00361 if (texobj) { 00362 table = &texobj->Palette; 00363 proxy = _mesa_is_proxy_texture(target); 00364 } 00365 else { 00366 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); 00367 return; 00368 } 00369 } 00370 } 00371 00372 assert(table); 00373 00374 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 00375 format == GL_INTENSITY) { 00376 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)"); 00377 return; 00378 } 00379 00380 baseFormat = base_colortab_format(internalFormat); 00381 if (baseFormat < 0) { 00382 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)"); 00383 return; 00384 } 00385 00386 if (width < 0 || (width != 0 && !_mesa_is_pow_two(width))) { 00387 /* error */ 00388 if (proxy) { 00389 table->Size = 0; 00390 table->InternalFormat = (GLenum) 0; 00391 table->_BaseFormat = (GLenum) 0; 00392 } 00393 else { 00394 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width); 00395 } 00396 return; 00397 } 00398 00399 if (width > (GLsizei) ctx->Const.MaxColorTableSize) { 00400 if (proxy) { 00401 table->Size = 0; 00402 table->InternalFormat = (GLenum) 0; 00403 table->_BaseFormat = (GLenum) 0; 00404 } 00405 else { 00406 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); 00407 } 00408 return; 00409 } 00410 00411 table->Size = width; 00412 table->InternalFormat = internalFormat; 00413 table->_BaseFormat = (GLenum) baseFormat; 00414 00415 comps = _mesa_components_in_format(table->_BaseFormat); 00416 assert(comps > 0); /* error should have been caught sooner */ 00417 00418 if (!proxy) { 00419 _mesa_free_colortable_data(table); 00420 00421 if (width > 0) { 00422 table->TableF = (GLfloat *) _mesa_malloc(comps * width * sizeof(GLfloat)); 00423 table->TableUB = (GLubyte *) _mesa_malloc(comps * width * sizeof(GLubyte)); 00424 00425 if (!table->TableF || !table->TableUB) { 00426 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); 00427 return; 00428 } 00429 00430 store_colortable_entries(ctx, table, 00431 0, width, /* start, count */ 00432 format, type, data, 00433 scale[0], bias[0], 00434 scale[1], bias[1], 00435 scale[2], bias[2], 00436 scale[3], bias[3]); 00437 } 00438 } /* proxy */ 00439 00440 /* do this after the table's Type and Format are set */ 00441 set_component_sizes(table); 00442 00443 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 00444 /* texture object palette, texObj==NULL means the shared palette */ 00445 if (ctx->Driver.UpdateTexturePalette) { 00446 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 00447 } 00448 } 00449 00450 ctx->NewState |= _NEW_PIXEL; 00451 } 00452 00453 00454 00455 void GLAPIENTRY 00456 _mesa_ColorSubTable( GLenum target, GLsizei start, 00457 GLsizei count, GLenum format, GLenum type, 00458 const GLvoid *data ) 00459 { 00460 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 }; 00461 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 }; 00462 GET_CURRENT_CONTEXT(ctx); 00463 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00464 struct gl_texture_object *texObj = NULL; 00465 struct gl_color_table *table = NULL; 00466 const GLfloat *scale = one, *bias = zero; 00467 00468 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 00469 00470 switch (target) { 00471 case GL_SHARED_TEXTURE_PALETTE_EXT: 00472 table = &ctx->Texture.Palette; 00473 break; 00474 case GL_COLOR_TABLE: 00475 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION]; 00476 scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]; 00477 bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]; 00478 break; 00479 case GL_TEXTURE_COLOR_TABLE_SGI: 00480 if (!ctx->Extensions.SGI_texture_color_table) { 00481 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 00482 return; 00483 } 00484 table = &(texUnit->ColorTable); 00485 scale = ctx->Pixel.TextureColorTableScale; 00486 bias = ctx->Pixel.TextureColorTableBias; 00487 break; 00488 case GL_POST_CONVOLUTION_COLOR_TABLE: 00489 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION]; 00490 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]; 00491 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]; 00492 break; 00493 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 00494 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; 00495 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; 00496 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]; 00497 break; 00498 default: 00499 /* try texture targets */ 00500 texObj = _mesa_select_tex_object(ctx, texUnit, target); 00501 if (texObj && !_mesa_is_proxy_texture(target)) { 00502 table = &texObj->Palette; 00503 } 00504 else { 00505 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); 00506 return; 00507 } 00508 } 00509 00510 assert(table); 00511 00512 if (!_mesa_is_legal_format_and_type(ctx, format, type) || 00513 format == GL_INTENSITY) { 00514 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)"); 00515 return; 00516 } 00517 00518 if (count < 1) { 00519 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 00520 return; 00521 } 00522 00523 /* error should have been caught sooner */ 00524 assert(_mesa_components_in_format(table->_BaseFormat) > 0); 00525 00526 if (start + count > (GLint) table->Size) { 00527 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); 00528 return; 00529 } 00530 00531 if (!table->TableF || !table->TableUB) { 00532 /* a GL_OUT_OF_MEMORY error would have been recorded previously */ 00533 return; 00534 } 00535 00536 store_colortable_entries(ctx, table, start, count, 00537 format, type, data, 00538 scale[0], bias[0], 00539 scale[1], bias[1], 00540 scale[2], bias[2], 00541 scale[3], bias[3]); 00542 00543 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { 00544 /* per-texture object palette */ 00545 if (ctx->Driver.UpdateTexturePalette) { 00546 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); 00547 } 00548 } 00549 00550 ctx->NewState |= _NEW_PIXEL; 00551 } 00552 00553 00554 00555 void GLAPIENTRY 00556 _mesa_CopyColorTable(GLenum target, GLenum internalformat, 00557 GLint x, GLint y, GLsizei width) 00558 { 00559 GET_CURRENT_CONTEXT(ctx); 00560 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 00561 00562 /* Select buffer to read from */ 00563 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width ); 00564 } 00565 00566 00567 00568 void GLAPIENTRY 00569 _mesa_CopyColorSubTable(GLenum target, GLsizei start, 00570 GLint x, GLint y, GLsizei width) 00571 { 00572 GET_CURRENT_CONTEXT(ctx); 00573 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 00574 00575 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width ); 00576 } 00577 00578 00579 00580 void GLAPIENTRY 00581 _mesa_GetColorTable( GLenum target, GLenum format, 00582 GLenum type, GLvoid *data ) 00583 { 00584 GET_CURRENT_CONTEXT(ctx); 00585 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00586 struct gl_color_table *table = NULL; 00587 GLfloat rgba[MAX_COLOR_TABLE_SIZE][4]; 00588 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 00589 00590 if (ctx->NewState) { 00591 _mesa_update_state(ctx); 00592 } 00593 00594 switch (target) { 00595 case GL_SHARED_TEXTURE_PALETTE_EXT: 00596 table = &ctx->Texture.Palette; 00597 break; 00598 case GL_COLOR_TABLE: 00599 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION]; 00600 break; 00601 case GL_TEXTURE_COLOR_TABLE_SGI: 00602 if (!ctx->Extensions.SGI_texture_color_table) { 00603 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 00604 return; 00605 } 00606 table = &(texUnit->ColorTable); 00607 break; 00608 case GL_POST_CONVOLUTION_COLOR_TABLE: 00609 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION]; 00610 break; 00611 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 00612 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; 00613 break; 00614 default: 00615 /* try texture targets */ 00616 { 00617 struct gl_texture_object *texobj 00618 = _mesa_select_tex_object(ctx, texUnit, target); 00619 if (texobj && !_mesa_is_proxy_texture(target)) { 00620 table = &texobj->Palette; 00621 } 00622 else { 00623 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); 00624 return; 00625 } 00626 } 00627 } 00628 00629 ASSERT(table); 00630 00631 if (table->Size <= 0) { 00632 return; 00633 } 00634 00635 switch (table->_BaseFormat) { 00636 case GL_ALPHA: 00637 { 00638 GLuint i; 00639 for (i = 0; i < table->Size; i++) { 00640 rgba[i][RCOMP] = 0; 00641 rgba[i][GCOMP] = 0; 00642 rgba[i][BCOMP] = 0; 00643 rgba[i][ACOMP] = table->TableF[i]; 00644 } 00645 } 00646 break; 00647 case GL_LUMINANCE: 00648 { 00649 GLuint i; 00650 for (i = 0; i < table->Size; i++) { 00651 rgba[i][RCOMP] = 00652 rgba[i][GCOMP] = 00653 rgba[i][BCOMP] = table->TableF[i]; 00654 rgba[i][ACOMP] = 1.0F; 00655 } 00656 } 00657 break; 00658 case GL_LUMINANCE_ALPHA: 00659 { 00660 GLuint i; 00661 for (i = 0; i < table->Size; i++) { 00662 rgba[i][RCOMP] = 00663 rgba[i][GCOMP] = 00664 rgba[i][BCOMP] = table->TableF[i*2+0]; 00665 rgba[i][ACOMP] = table->TableF[i*2+1]; 00666 } 00667 } 00668 break; 00669 case GL_INTENSITY: 00670 { 00671 GLuint i; 00672 for (i = 0; i < table->Size; i++) { 00673 rgba[i][RCOMP] = 00674 rgba[i][GCOMP] = 00675 rgba[i][BCOMP] = 00676 rgba[i][ACOMP] = table->TableF[i]; 00677 } 00678 } 00679 break; 00680 case GL_RGB: 00681 { 00682 GLuint i; 00683 for (i = 0; i < table->Size; i++) { 00684 rgba[i][RCOMP] = table->TableF[i*3+0]; 00685 rgba[i][GCOMP] = table->TableF[i*3+1]; 00686 rgba[i][BCOMP] = table->TableF[i*3+2]; 00687 rgba[i][ACOMP] = 1.0F; 00688 } 00689 } 00690 break; 00691 case GL_RGBA: 00692 _mesa_memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat)); 00693 break; 00694 default: 00695 _mesa_problem(ctx, "bad table format in glGetColorTable"); 00696 return; 00697 } 00698 00699 if (ctx->Pack.BufferObj->Name) { 00700 /* pack color table into PBO */ 00701 GLubyte *buf; 00702 if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1, 00703 format, type, data)) { 00704 _mesa_error(ctx, GL_INVALID_OPERATION, 00705 "glGetColorTable(invalid PBO access)"); 00706 return; 00707 } 00708 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, 00709 GL_WRITE_ONLY_ARB, 00710 ctx->Pack.BufferObj); 00711 if (!buf) { 00712 /* buffer is already mapped - that's an error */ 00713 _mesa_error(ctx, GL_INVALID_OPERATION, 00714 "glGetColorTable(PBO is mapped)"); 00715 return; 00716 } 00717 data = ADD_POINTERS(buf, data); 00718 } 00719 00720 _mesa_pack_rgba_span_float(ctx, table->Size, rgba, 00721 format, type, data, &ctx->Pack, 0x0); 00722 00723 if (ctx->Pack.BufferObj->Name) { 00724 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT, 00725 ctx->Pack.BufferObj); 00726 } 00727 } 00728 00729 00730 00731 void GLAPIENTRY 00732 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) 00733 { 00734 GLfloat *scale, *bias; 00735 GET_CURRENT_CONTEXT(ctx); 00736 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); 00737 00738 switch (target) { 00739 case GL_COLOR_TABLE_SGI: 00740 scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]; 00741 bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]; 00742 break; 00743 case GL_TEXTURE_COLOR_TABLE_SGI: 00744 scale = ctx->Pixel.TextureColorTableScale; 00745 bias = ctx->Pixel.TextureColorTableBias; 00746 break; 00747 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI: 00748 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]; 00749 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]; 00750 break; 00751 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI: 00752 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; 00753 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]; 00754 break; 00755 default: 00756 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)"); 00757 return; 00758 } 00759 00760 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00761 COPY_4V(scale, params); 00762 } 00763 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00764 COPY_4V(bias, params); 00765 } 00766 else { 00767 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)"); 00768 return; 00769 } 00770 00771 ctx->NewState |= _NEW_PIXEL; 00772 } 00773 00774 00775 00776 void GLAPIENTRY 00777 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params) 00778 { 00779 GLfloat fparams[4]; 00780 if (pname == GL_COLOR_TABLE_SGI || 00781 pname == GL_TEXTURE_COLOR_TABLE_SGI || 00782 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI || 00783 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) { 00784 /* four values */ 00785 fparams[0] = (GLfloat) params[0]; 00786 fparams[1] = (GLfloat) params[1]; 00787 fparams[2] = (GLfloat) params[2]; 00788 fparams[3] = (GLfloat) params[3]; 00789 } 00790 else { 00791 /* one values */ 00792 fparams[0] = (GLfloat) params[0]; 00793 } 00794 _mesa_ColorTableParameterfv(target, pname, fparams); 00795 } 00796 00797 00798 00799 void GLAPIENTRY 00800 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) 00801 { 00802 GET_CURRENT_CONTEXT(ctx); 00803 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00804 struct gl_color_table *table = NULL; 00805 ASSERT_OUTSIDE_BEGIN_END(ctx); 00806 00807 switch (target) { 00808 case GL_SHARED_TEXTURE_PALETTE_EXT: 00809 table = &ctx->Texture.Palette; 00810 break; 00811 case GL_COLOR_TABLE: 00812 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION]; 00813 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00814 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]); 00815 return; 00816 } 00817 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00818 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]); 00819 return; 00820 } 00821 break; 00822 case GL_PROXY_COLOR_TABLE: 00823 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION]; 00824 break; 00825 case GL_TEXTURE_COLOR_TABLE_SGI: 00826 if (!ctx->Extensions.SGI_texture_color_table) { 00827 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 00828 return; 00829 } 00830 table = &(texUnit->ColorTable); 00831 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00832 COPY_4V(params, ctx->Pixel.TextureColorTableScale); 00833 return; 00834 } 00835 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00836 COPY_4V(params, ctx->Pixel.TextureColorTableBias); 00837 return; 00838 } 00839 break; 00840 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 00841 if (!ctx->Extensions.SGI_texture_color_table) { 00842 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 00843 return; 00844 } 00845 table = &(texUnit->ProxyColorTable); 00846 break; 00847 case GL_POST_CONVOLUTION_COLOR_TABLE: 00848 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION]; 00849 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00850 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]); 00851 return; 00852 } 00853 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00854 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]); 00855 return; 00856 } 00857 break; 00858 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 00859 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION]; 00860 break; 00861 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 00862 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; 00863 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00864 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]); 00865 return; 00866 } 00867 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00868 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]); 00869 return; 00870 } 00871 break; 00872 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 00873 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX]; 00874 break; 00875 default: 00876 /* try texture targets */ 00877 { 00878 struct gl_texture_object *texobj 00879 = _mesa_select_tex_object(ctx, texUnit, target); 00880 if (texobj) { 00881 table = &texobj->Palette; 00882 } 00883 else { 00884 _mesa_error(ctx, GL_INVALID_ENUM, 00885 "glGetColorTableParameterfv(target)"); 00886 return; 00887 } 00888 } 00889 } 00890 00891 assert(table); 00892 00893 switch (pname) { 00894 case GL_COLOR_TABLE_FORMAT: 00895 *params = (GLfloat) table->InternalFormat; 00896 break; 00897 case GL_COLOR_TABLE_WIDTH: 00898 *params = (GLfloat) table->Size; 00899 break; 00900 case GL_COLOR_TABLE_RED_SIZE: 00901 *params = (GLfloat) table->RedSize; 00902 break; 00903 case GL_COLOR_TABLE_GREEN_SIZE: 00904 *params = (GLfloat) table->GreenSize; 00905 break; 00906 case GL_COLOR_TABLE_BLUE_SIZE: 00907 *params = (GLfloat) table->BlueSize; 00908 break; 00909 case GL_COLOR_TABLE_ALPHA_SIZE: 00910 *params = (GLfloat) table->AlphaSize; 00911 break; 00912 case GL_COLOR_TABLE_LUMINANCE_SIZE: 00913 *params = (GLfloat) table->LuminanceSize; 00914 break; 00915 case GL_COLOR_TABLE_INTENSITY_SIZE: 00916 *params = (GLfloat) table->IntensitySize; 00917 break; 00918 default: 00919 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" ); 00920 return; 00921 } 00922 } 00923 00924 00925 00926 void GLAPIENTRY 00927 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) 00928 { 00929 GET_CURRENT_CONTEXT(ctx); 00930 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; 00931 struct gl_color_table *table = NULL; 00932 ASSERT_OUTSIDE_BEGIN_END(ctx); 00933 00934 switch (target) { 00935 case GL_SHARED_TEXTURE_PALETTE_EXT: 00936 table = &ctx->Texture.Palette; 00937 break; 00938 case GL_COLOR_TABLE: 00939 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION]; 00940 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00941 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]; 00942 params[0] = (GLint) scale[0]; 00943 params[1] = (GLint) scale[1]; 00944 params[2] = (GLint) scale[2]; 00945 params[3] = (GLint) scale[3]; 00946 return; 00947 } 00948 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00949 GLfloat *bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]; 00950 params[0] = (GLint) bias[0]; 00951 params[1] = (GLint) bias[1]; 00952 params[2] = (GLint) bias[2]; 00953 params[3] = (GLint) bias[3]; 00954 return; 00955 } 00956 break; 00957 case GL_PROXY_COLOR_TABLE: 00958 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION]; 00959 break; 00960 case GL_TEXTURE_COLOR_TABLE_SGI: 00961 if (!ctx->Extensions.SGI_texture_color_table) { 00962 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 00963 return; 00964 } 00965 table = &(texUnit->ColorTable); 00966 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00967 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0]; 00968 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1]; 00969 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2]; 00970 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3]; 00971 return; 00972 } 00973 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00974 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0]; 00975 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1]; 00976 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2]; 00977 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3]; 00978 return; 00979 } 00980 break; 00981 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI: 00982 if (!ctx->Extensions.SGI_texture_color_table) { 00983 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)"); 00984 return; 00985 } 00986 table = &(texUnit->ProxyColorTable); 00987 break; 00988 case GL_POST_CONVOLUTION_COLOR_TABLE: 00989 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION]; 00990 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 00991 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]; 00992 params[0] = (GLint) scale[0]; 00993 params[1] = (GLint) scale[1]; 00994 params[2] = (GLint) scale[2]; 00995 params[3] = (GLint) scale[3]; 00996 return; 00997 } 00998 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 00999 GLfloat *bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]; 01000 params[0] = (GLint) bias[0]; 01001 params[1] = (GLint) bias[1]; 01002 params[2] = (GLint) bias[2]; 01003 params[3] = (GLint) bias[3]; 01004 return; 01005 } 01006 break; 01007 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: 01008 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION]; 01009 break; 01010 case GL_POST_COLOR_MATRIX_COLOR_TABLE: 01011 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX]; 01012 if (pname == GL_COLOR_TABLE_SCALE_SGI) { 01013 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; 01014 params[0] = (GLint) scale[0]; 01015 params[0] = (GLint) scale[1]; 01016 params[0] = (GLint) scale[2]; 01017 params[0] = (GLint) scale[3]; 01018 return; 01019 } 01020 else if (pname == GL_COLOR_TABLE_BIAS_SGI) { 01021 GLfloat *bias = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]; 01022 params[0] = (GLint) bias[0]; 01023 params[1] = (GLint) bias[1]; 01024 params[2] = (GLint) bias[2]; 01025 params[3] = (GLint) bias[3]; 01026 return; 01027 } 01028 break; 01029 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: 01030 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX]; 01031 break; 01032 default: 01033 /* Try texture targets */ 01034 { 01035 struct gl_texture_object *texobj 01036 = _mesa_select_tex_object(ctx, texUnit, target); 01037 if (texobj) { 01038 table = &texobj->Palette; 01039 } 01040 else { 01041 _mesa_error(ctx, GL_INVALID_ENUM, 01042 "glGetColorTableParameteriv(target)"); 01043 return; 01044 } 01045 } 01046 } 01047 01048 assert(table); 01049 01050 switch (pname) { 01051 case GL_COLOR_TABLE_FORMAT: 01052 *params = table->InternalFormat; 01053 break; 01054 case GL_COLOR_TABLE_WIDTH: 01055 *params = table->Size; 01056 break; 01057 case GL_COLOR_TABLE_RED_SIZE: 01058 *params = table->RedSize; 01059 break; 01060 case GL_COLOR_TABLE_GREEN_SIZE: 01061 *params = table->GreenSize; 01062 break; 01063 case GL_COLOR_TABLE_BLUE_SIZE: 01064 *params = table->BlueSize; 01065 break; 01066 case GL_COLOR_TABLE_ALPHA_SIZE: 01067 *params = table->AlphaSize; 01068 break; 01069 case GL_COLOR_TABLE_LUMINANCE_SIZE: 01070 *params = table->LuminanceSize; 01071 break; 01072 case GL_COLOR_TABLE_INTENSITY_SIZE: 01073 *params = table->IntensitySize; 01074 break; 01075 default: 01076 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" ); 01077 return; 01078 } 01079 } 01080 01081 /**********************************************************************/ 01082 /***** Initialization *****/ 01083 /**********************************************************************/ 01084 01085 01086 void 01087 _mesa_init_colortable( struct gl_color_table *p ) 01088 { 01089 p->TableF = NULL; 01090 p->TableUB = NULL; 01091 p->Size = 0; 01092 p->InternalFormat = GL_RGBA; 01093 } 01094 01095 01096 01097 void 01098 _mesa_free_colortable_data( struct gl_color_table *p ) 01099 { 01100 if (p->TableF) { 01101 _mesa_free(p->TableF); 01102 p->TableF = NULL; 01103 } 01104 if (p->TableUB) { 01105 _mesa_free(p->TableUB); 01106 p->TableUB = NULL; 01107 } 01108 } 01109 01110 01111 /* 01112 * Initialize all colortables for a context. 01113 */ 01114 void 01115 _mesa_init_colortables( GLcontext * ctx ) 01116 { 01117 GLuint i; 01118 for (i = 0; i < COLORTABLE_MAX; i++) { 01119 _mesa_init_colortable(&ctx->ColorTable[i]); 01120 _mesa_init_colortable(&ctx->ProxyColorTable[i]); 01121 } 01122 } 01123 01124 01125 /* 01126 * Free all colortable data for a context 01127 */ 01128 void 01129 _mesa_free_colortables_data( GLcontext *ctx ) 01130 { 01131 GLuint i; 01132 for (i = 0; i < COLORTABLE_MAX; i++) { 01133 _mesa_free_colortable_data(&ctx->ColorTable[i]); 01134 _mesa_free_colortable_data(&ctx->ProxyColorTable[i]); 01135 } 01136 } Generated on Sat May 26 2012 04:18:58 for ReactOS by
1.7.6.1
|