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