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