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