4eafe3e899fcfecba3f804169d06e2fca5809984
[mesa.git] / src / mesa / main / colortab.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.3
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 "bufferobj.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 (ctx->Unpack.BufferObj->Name) {
196 /* Get/unpack the color table data from a PBO */
197 GLubyte *buf;
198 if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
199 format, type, data)) {
200 _mesa_error(ctx, GL_INVALID_OPERATION,
201 "glColor[Sub]Table(bad PBO access)");
202 return;
203 }
204 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
205 GL_READ_ONLY_ARB,
206 ctx->Unpack.BufferObj);
207 if (!buf) {
208 _mesa_error(ctx, GL_INVALID_OPERATION,
209 "glColor[Sub]Table(PBO mapped)");
210 return;
211 }
212 data = ADD_POINTERS(buf, data);
213 }
214
215
216 if (table->Type == GL_FLOAT) {
217 /* convert user-provided data to GLfloat values */
218 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
219 GLfloat *tableF;
220 GLint i;
221
222 _mesa_unpack_color_span_float(ctx,
223 count, /* number of pixels */
224 table->Format, /* dest format */
225 tempTab, /* dest address */
226 format, type, /* src format/type */
227 data, /* src data */
228 &ctx->Unpack,
229 IMAGE_CLAMP_BIT); /* transfer ops */
230
231 /* the destination */
232 tableF = (GLfloat *) table->Table;
233
234 /* Apply scale & bias & clamp now */
235 switch (table->Format) {
236 case GL_INTENSITY:
237 for (i = 0; i < count; i++) {
238 GLuint j = start + i;
239 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
240 }
241 break;
242 case GL_LUMINANCE:
243 for (i = 0; i < count; i++) {
244 GLuint j = start + i;
245 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
246 }
247 break;
248 case GL_ALPHA:
249 for (i = 0; i < count; i++) {
250 GLuint j = start + i;
251 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
252 }
253 break;
254 case GL_LUMINANCE_ALPHA:
255 for (i = 0; i < count; i++) {
256 GLuint j = start + i;
257 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
258 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
259 }
260 break;
261 case GL_RGB:
262 for (i = 0; i < count; i++) {
263 GLuint j = start + i;
264 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
265 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
266 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
267 }
268 break;
269 case GL_RGBA:
270 for (i = 0; i < count; i++) {
271 GLuint j = start + i;
272 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
273 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
274 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
275 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
276 }
277 break;
278 default:
279 _mesa_problem(ctx, "Bad format in store_colortable_entries");
280 return;
281 }
282 }
283 else {
284 /* non-float (GLchan) */
285 const GLint comps = _mesa_components_in_format(table->Format);
286 GLchan *dest = (GLchan *) table->Table + start * comps;
287 _mesa_unpack_color_span_chan(ctx, count, /* number of entries */
288 table->Format, /* dest format */
289 dest, /* dest address */
290 format, type, data, /* src data */
291 &ctx->Unpack,
292 0); /* transfer ops */
293 }
294
295 if (ctx->Unpack.BufferObj->Name) {
296 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
297 ctx->Unpack.BufferObj);
298 }
299 }
300
301
302
303 void GLAPIENTRY
304 _mesa_ColorTable( GLenum target, GLenum internalFormat,
305 GLsizei width, GLenum format, GLenum type,
306 const GLvoid *data )
307 {
308 GET_CURRENT_CONTEXT(ctx);
309 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
310 struct gl_texture_object *texObj = NULL;
311 struct gl_color_table *table = NULL;
312 GLboolean proxy = GL_FALSE;
313 GLint baseFormat;
314 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
315 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
316 GLenum tableType = CHAN_TYPE;
317 GLint comps;
318 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
319
320 switch (target) {
321 case GL_TEXTURE_1D:
322 texObj = texUnit->Current1D;
323 table = &texObj->Palette;
324 break;
325 case GL_TEXTURE_2D:
326 texObj = texUnit->Current2D;
327 table = &texObj->Palette;
328 break;
329 case GL_TEXTURE_3D:
330 texObj = texUnit->Current3D;
331 table = &texObj->Palette;
332 break;
333 case GL_TEXTURE_CUBE_MAP_ARB:
334 if (!ctx->Extensions.ARB_texture_cube_map) {
335 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
336 return;
337 }
338 texObj = texUnit->CurrentCubeMap;
339 table = &texObj->Palette;
340 break;
341 case GL_PROXY_TEXTURE_1D:
342 texObj = ctx->Texture.Proxy1D;
343 table = &texObj->Palette;
344 proxy = GL_TRUE;
345 break;
346 case GL_PROXY_TEXTURE_2D:
347 texObj = ctx->Texture.Proxy2D;
348 table = &texObj->Palette;
349 proxy = GL_TRUE;
350 break;
351 case GL_PROXY_TEXTURE_3D:
352 texObj = ctx->Texture.Proxy3D;
353 table = &texObj->Palette;
354 proxy = GL_TRUE;
355 break;
356 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
357 if (!ctx->Extensions.ARB_texture_cube_map) {
358 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
359 return;
360 }
361 texObj = ctx->Texture.ProxyCubeMap;
362 table = &texObj->Palette;
363 break;
364 case GL_SHARED_TEXTURE_PALETTE_EXT:
365 table = &ctx->Texture.Palette;
366 break;
367 case GL_COLOR_TABLE:
368 table = &ctx->ColorTable;
369 tableType = GL_FLOAT;
370 rScale = ctx->Pixel.ColorTableScale[0];
371 gScale = ctx->Pixel.ColorTableScale[1];
372 bScale = ctx->Pixel.ColorTableScale[2];
373 aScale = ctx->Pixel.ColorTableScale[3];
374 rBias = ctx->Pixel.ColorTableBias[0];
375 gBias = ctx->Pixel.ColorTableBias[1];
376 bBias = ctx->Pixel.ColorTableBias[2];
377 aBias = ctx->Pixel.ColorTableBias[3];
378 break;
379 case GL_PROXY_COLOR_TABLE:
380 table = &ctx->ProxyColorTable;
381 proxy = GL_TRUE;
382 break;
383 case GL_TEXTURE_COLOR_TABLE_SGI:
384 if (!ctx->Extensions.SGI_texture_color_table) {
385 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
386 return;
387 }
388 table = &(texUnit->ColorTable);
389 tableType = GL_FLOAT;
390 rScale = ctx->Pixel.TextureColorTableScale[0];
391 gScale = ctx->Pixel.TextureColorTableScale[1];
392 bScale = ctx->Pixel.TextureColorTableScale[2];
393 aScale = ctx->Pixel.TextureColorTableScale[3];
394 rBias = ctx->Pixel.TextureColorTableBias[0];
395 gBias = ctx->Pixel.TextureColorTableBias[1];
396 bBias = ctx->Pixel.TextureColorTableBias[2];
397 aBias = ctx->Pixel.TextureColorTableBias[3];
398 break;
399 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
400 if (!ctx->Extensions.SGI_texture_color_table) {
401 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
402 return;
403 }
404 table = &(texUnit->ProxyColorTable);
405 proxy = GL_TRUE;
406 break;
407 case GL_POST_CONVOLUTION_COLOR_TABLE:
408 table = &ctx->PostConvolutionColorTable;
409 tableType = GL_FLOAT;
410 rScale = ctx->Pixel.PCCTscale[0];
411 gScale = ctx->Pixel.PCCTscale[1];
412 bScale = ctx->Pixel.PCCTscale[2];
413 aScale = ctx->Pixel.PCCTscale[3];
414 rBias = ctx->Pixel.PCCTbias[0];
415 gBias = ctx->Pixel.PCCTbias[1];
416 bBias = ctx->Pixel.PCCTbias[2];
417 aBias = ctx->Pixel.PCCTbias[3];
418 break;
419 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
420 table = &ctx->ProxyPostConvolutionColorTable;
421 proxy = GL_TRUE;
422 break;
423 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
424 table = &ctx->PostColorMatrixColorTable;
425 tableType = GL_FLOAT;
426 rScale = ctx->Pixel.PCMCTscale[0];
427 gScale = ctx->Pixel.PCMCTscale[1];
428 bScale = ctx->Pixel.PCMCTscale[2];
429 aScale = ctx->Pixel.PCMCTscale[3];
430 rBias = ctx->Pixel.PCMCTbias[0];
431 gBias = ctx->Pixel.PCMCTbias[1];
432 bBias = ctx->Pixel.PCMCTbias[2];
433 aBias = ctx->Pixel.PCMCTbias[3];
434 break;
435 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
436 table = &ctx->ProxyPostColorMatrixColorTable;
437 proxy = GL_TRUE;
438 break;
439 default:
440 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
441 return;
442 }
443
444 assert(table);
445
446 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
447 format == GL_INTENSITY) {
448 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
449 return;
450 }
451
452 baseFormat = base_colortab_format(internalFormat);
453 if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) {
454 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
455 return;
456 }
457
458 if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) {
459 /* error */
460 if (proxy) {
461 table->Size = 0;
462 table->IntFormat = (GLenum) 0;
463 table->Format = (GLenum) 0;
464 }
465 else {
466 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
467 }
468 return;
469 }
470
471 if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
472 if (proxy) {
473 table->Size = 0;
474 table->IntFormat = (GLenum) 0;
475 table->Format = (GLenum) 0;
476 }
477 else {
478 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
479 }
480 return;
481 }
482
483 table->Size = width;
484 table->IntFormat = internalFormat;
485 table->Format = (GLenum) baseFormat;
486 set_component_sizes(table);
487
488 comps = _mesa_components_in_format(table->Format);
489 assert(comps > 0); /* error should have been caught sooner */
490
491 if (!proxy) {
492 /* free old table, if any */
493 if (table->Table) {
494 FREE(table->Table);
495 table->Table = NULL;
496 }
497
498 if (width > 0) {
499 if (tableType == GL_FLOAT) {
500 table->Type = GL_FLOAT;
501 table->Table = MALLOC(comps * width * sizeof(GLfloat));
502 }
503 else {
504 table->Type = CHAN_TYPE;
505 table->Table = MALLOC(comps * width * sizeof(GLchan));
506 }
507
508 if (!table->Table) {
509 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
510 return;
511 }
512
513 store_colortable_entries(ctx, table,
514 0, width, /* start, count */
515 format, type, data,
516 rScale, rBias,
517 gScale, gBias,
518 bScale, bBias,
519 aScale, aBias);
520 }
521 } /* proxy */
522
523 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
524 /* texture object palette, texObj==NULL means the shared palette */
525 if (ctx->Driver.UpdateTexturePalette) {
526 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
527 }
528 }
529
530 ctx->NewState |= _NEW_PIXEL;
531 }
532
533
534
535 void GLAPIENTRY
536 _mesa_ColorSubTable( GLenum target, GLsizei start,
537 GLsizei count, GLenum format, GLenum type,
538 const GLvoid *data )
539 {
540 GET_CURRENT_CONTEXT(ctx);
541 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
542 struct gl_texture_object *texObj = NULL;
543 struct gl_color_table *table = NULL;
544 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
545 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
546 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
547
548 switch (target) {
549 case GL_TEXTURE_1D:
550 texObj = texUnit->Current1D;
551 table = &texObj->Palette;
552 break;
553 case GL_TEXTURE_2D:
554 texObj = texUnit->Current2D;
555 table = &texObj->Palette;
556 break;
557 case GL_TEXTURE_3D:
558 texObj = texUnit->Current3D;
559 table = &texObj->Palette;
560 break;
561 case GL_TEXTURE_CUBE_MAP_ARB:
562 if (!ctx->Extensions.ARB_texture_cube_map) {
563 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
564 return;
565 }
566 texObj = texUnit->CurrentCubeMap;
567 table = &texObj->Palette;
568 break;
569 case GL_SHARED_TEXTURE_PALETTE_EXT:
570 table = &ctx->Texture.Palette;
571 break;
572 case GL_COLOR_TABLE:
573 table = &ctx->ColorTable;
574 rScale = ctx->Pixel.ColorTableScale[0];
575 gScale = ctx->Pixel.ColorTableScale[1];
576 bScale = ctx->Pixel.ColorTableScale[2];
577 aScale = ctx->Pixel.ColorTableScale[3];
578 rBias = ctx->Pixel.ColorTableBias[0];
579 gBias = ctx->Pixel.ColorTableBias[1];
580 bBias = ctx->Pixel.ColorTableBias[2];
581 aBias = ctx->Pixel.ColorTableBias[3];
582 break;
583 case GL_TEXTURE_COLOR_TABLE_SGI:
584 if (!ctx->Extensions.SGI_texture_color_table) {
585 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
586 return;
587 }
588 table = &(texUnit->ColorTable);
589 rScale = ctx->Pixel.TextureColorTableScale[0];
590 gScale = ctx->Pixel.TextureColorTableScale[1];
591 bScale = ctx->Pixel.TextureColorTableScale[2];
592 aScale = ctx->Pixel.TextureColorTableScale[3];
593 rBias = ctx->Pixel.TextureColorTableBias[0];
594 gBias = ctx->Pixel.TextureColorTableBias[1];
595 bBias = ctx->Pixel.TextureColorTableBias[2];
596 aBias = ctx->Pixel.TextureColorTableBias[3];
597 break;
598 case GL_POST_CONVOLUTION_COLOR_TABLE:
599 table = &ctx->PostConvolutionColorTable;
600 rScale = ctx->Pixel.PCCTscale[0];
601 gScale = ctx->Pixel.PCCTscale[1];
602 bScale = ctx->Pixel.PCCTscale[2];
603 aScale = ctx->Pixel.PCCTscale[3];
604 rBias = ctx->Pixel.PCCTbias[0];
605 gBias = ctx->Pixel.PCCTbias[1];
606 bBias = ctx->Pixel.PCCTbias[2];
607 aBias = ctx->Pixel.PCCTbias[3];
608 break;
609 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
610 table = &ctx->PostColorMatrixColorTable;
611 rScale = ctx->Pixel.PCMCTscale[0];
612 gScale = ctx->Pixel.PCMCTscale[1];
613 bScale = ctx->Pixel.PCMCTscale[2];
614 aScale = ctx->Pixel.PCMCTscale[3];
615 rBias = ctx->Pixel.PCMCTbias[0];
616 gBias = ctx->Pixel.PCMCTbias[1];
617 bBias = ctx->Pixel.PCMCTbias[2];
618 aBias = ctx->Pixel.PCMCTbias[3];
619 break;
620 default:
621 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
622 return;
623 }
624
625 assert(table);
626
627 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
628 format == GL_INTENSITY) {
629 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
630 return;
631 }
632
633 if (count < 1) {
634 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
635 return;
636 }
637
638 /* error should have been caught sooner */
639 assert(_mesa_components_in_format(table->Format) > 0);
640
641 if (start + count > (GLint) table->Size) {
642 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
643 return;
644 }
645
646 if (!table->Table) {
647 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable");
648 return;
649 }
650
651 store_colortable_entries(ctx, table, start, count,
652 format, type, data,
653 rScale, rBias,
654 gScale, gBias,
655 bScale, bBias,
656 aScale, aBias);
657
658 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
659 /* per-texture object palette */
660 if (ctx->Driver.UpdateTexturePalette) {
661 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
662 }
663 }
664
665 ctx->NewState |= _NEW_PIXEL;
666 }
667
668
669
670 void GLAPIENTRY
671 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
672 GLint x, GLint y, GLsizei width)
673 {
674 GET_CURRENT_CONTEXT(ctx);
675 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
676
677 /* Select buffer to read from */
678 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
679 }
680
681
682
683 void GLAPIENTRY
684 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
685 GLint x, GLint y, GLsizei width)
686 {
687 GET_CURRENT_CONTEXT(ctx);
688 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
689
690 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
691 }
692
693
694
695 void GLAPIENTRY
696 _mesa_GetColorTable( GLenum target, GLenum format,
697 GLenum type, GLvoid *data )
698 {
699 GET_CURRENT_CONTEXT(ctx);
700 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
701 struct gl_color_table *table = NULL;
702 GLchan rgba[MAX_COLOR_TABLE_SIZE][4];
703 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
704
705 if (ctx->NewState) {
706 _mesa_update_state(ctx);
707 }
708
709 switch (target) {
710 case GL_TEXTURE_1D:
711 table = &texUnit->Current1D->Palette;
712 break;
713 case GL_TEXTURE_2D:
714 table = &texUnit->Current2D->Palette;
715 break;
716 case GL_TEXTURE_3D:
717 table = &texUnit->Current3D->Palette;
718 break;
719 case GL_TEXTURE_CUBE_MAP_ARB:
720 if (!ctx->Extensions.ARB_texture_cube_map) {
721 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
722 return;
723 }
724 table = &texUnit->CurrentCubeMap->Palette;
725 break;
726 case GL_SHARED_TEXTURE_PALETTE_EXT:
727 table = &ctx->Texture.Palette;
728 break;
729 case GL_COLOR_TABLE:
730 table = &ctx->ColorTable;
731 break;
732 case GL_TEXTURE_COLOR_TABLE_SGI:
733 if (!ctx->Extensions.SGI_texture_color_table) {
734 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
735 return;
736 }
737 table = &(texUnit->ColorTable);
738 break;
739 case GL_POST_CONVOLUTION_COLOR_TABLE:
740 table = &ctx->PostConvolutionColorTable;
741 break;
742 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
743 table = &ctx->PostColorMatrixColorTable;
744 break;
745 default:
746 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
747 return;
748 }
749
750 ASSERT(table);
751
752 switch (table->Format) {
753 case GL_ALPHA:
754 if (table->Type == GL_FLOAT) {
755 const GLfloat *tableF = (const GLfloat *) table->Table;
756 GLuint i;
757 for (i = 0; i < table->Size; i++) {
758 rgba[i][RCOMP] = 0;
759 rgba[i][GCOMP] = 0;
760 rgba[i][BCOMP] = 0;
761 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
762 }
763 }
764 else {
765 const GLchan *tableUB = (const GLchan *) table->Table;
766 GLuint i;
767 for (i = 0; i < table->Size; i++) {
768 rgba[i][RCOMP] = 0;
769 rgba[i][GCOMP] = 0;
770 rgba[i][BCOMP] = 0;
771 rgba[i][ACOMP] = tableUB[i];
772 }
773 }
774 break;
775 case GL_LUMINANCE:
776 if (table->Type == GL_FLOAT) {
777 const GLfloat *tableF = (const GLfloat *) table->Table;
778 GLuint i;
779 for (i = 0; i < table->Size; i++) {
780 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
781 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
782 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
783 rgba[i][ACOMP] = CHAN_MAX;
784 }
785 }
786 else {
787 const GLchan *tableUB = (const GLchan *) table->Table;
788 GLuint i;
789 for (i = 0; i < table->Size; i++) {
790 rgba[i][RCOMP] = tableUB[i];
791 rgba[i][GCOMP] = tableUB[i];
792 rgba[i][BCOMP] = tableUB[i];
793 rgba[i][ACOMP] = CHAN_MAX;
794 }
795 }
796 break;
797 case GL_LUMINANCE_ALPHA:
798 if (table->Type == GL_FLOAT) {
799 const GLfloat *tableF = (const GLfloat *) table->Table;
800 GLuint i;
801 for (i = 0; i < table->Size; i++) {
802 rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
803 rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
804 rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
805 rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF);
806 }
807 }
808 else {
809 const GLchan *tableUB = (const GLchan *) table->Table;
810 GLuint i;
811 for (i = 0; i < table->Size; i++) {
812 rgba[i][RCOMP] = tableUB[i*2+0];
813 rgba[i][GCOMP] = tableUB[i*2+0];
814 rgba[i][BCOMP] = tableUB[i*2+0];
815 rgba[i][ACOMP] = tableUB[i*2+1];
816 }
817 }
818 break;
819 case GL_INTENSITY:
820 if (table->Type == GL_FLOAT) {
821 const GLfloat *tableF = (const GLfloat *) table->Table;
822 GLuint i;
823 for (i = 0; i < table->Size; i++) {
824 rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
825 rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
826 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
827 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
828 }
829 }
830 else {
831 const GLchan *tableUB = (const GLchan *) table->Table;
832 GLuint i;
833 for (i = 0; i < table->Size; i++) {
834 rgba[i][RCOMP] = tableUB[i];
835 rgba[i][GCOMP] = tableUB[i];
836 rgba[i][BCOMP] = tableUB[i];
837 rgba[i][ACOMP] = tableUB[i];
838 }
839 }
840 break;
841 case GL_RGB:
842 if (table->Type == GL_FLOAT) {
843 const GLfloat *tableF = (const GLfloat *) table->Table;
844 GLuint i;
845 for (i = 0; i < table->Size; i++) {
846 rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF);
847 rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF);
848 rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF);
849 rgba[i][ACOMP] = CHAN_MAX;
850 }
851 }
852 else {
853 const GLchan *tableUB = (const GLchan *) table->Table;
854 GLuint i;
855 for (i = 0; i < table->Size; i++) {
856 rgba[i][RCOMP] = tableUB[i*3+0];
857 rgba[i][GCOMP] = tableUB[i*3+1];
858 rgba[i][BCOMP] = tableUB[i*3+2];
859 rgba[i][ACOMP] = CHAN_MAX;
860 }
861 }
862 break;
863 case GL_RGBA:
864 if (table->Type == GL_FLOAT) {
865 const GLfloat *tableF = (const GLfloat *) table->Table;
866 GLuint i;
867 for (i = 0; i < table->Size; i++) {
868 rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF);
869 rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF);
870 rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF);
871 rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF);
872 }
873 }
874 else {
875 const GLchan *tableUB = (const GLchan *) table->Table;
876 GLuint i;
877 for (i = 0; i < table->Size; i++) {
878 rgba[i][RCOMP] = tableUB[i*4+0];
879 rgba[i][GCOMP] = tableUB[i*4+1];
880 rgba[i][BCOMP] = tableUB[i*4+2];
881 rgba[i][ACOMP] = tableUB[i*4+3];
882 }
883 }
884 break;
885 default:
886 _mesa_problem(ctx, "bad table format in glGetColorTable");
887 return;
888 }
889
890 if (ctx->Pack.BufferObj->Name) {
891 /* pack color table into PBO */
892 GLubyte *buf;
893 if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
894 format, type, data)) {
895 _mesa_error(ctx, GL_INVALID_OPERATION,
896 "glGetColorTable(invalid PBO access)");
897 return;
898 }
899 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
900 GL_WRITE_ONLY_ARB,
901 ctx->Pack.BufferObj);
902 if (!buf) {
903 /* buffer is already mapped - that's an error */
904 _mesa_error(ctx, GL_INVALID_OPERATION,
905 "glGetColorTable(PBO is mapped)");
906 return;
907 }
908 data = ADD_POINTERS(buf, data);
909 }
910
911 _mesa_pack_rgba_span_chan(ctx, table->Size, (const GLchan (*)[4]) rgba,
912 format, type, data, &ctx->Pack, GL_FALSE);
913
914 if (ctx->Pack.BufferObj->Name) {
915 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
916 ctx->Pack.BufferObj);
917 }
918 }
919
920
921
922 void GLAPIENTRY
923 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
924 {
925 GET_CURRENT_CONTEXT(ctx);
926 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
927
928 switch (target) {
929 case GL_COLOR_TABLE_SGI:
930 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
931 ctx->Pixel.ColorTableScale[0] = params[0];
932 ctx->Pixel.ColorTableScale[1] = params[1];
933 ctx->Pixel.ColorTableScale[2] = params[2];
934 ctx->Pixel.ColorTableScale[3] = params[3];
935 }
936 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
937 ctx->Pixel.ColorTableBias[0] = params[0];
938 ctx->Pixel.ColorTableBias[1] = params[1];
939 ctx->Pixel.ColorTableBias[2] = params[2];
940 ctx->Pixel.ColorTableBias[3] = params[3];
941 }
942 else {
943 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
944 return;
945 }
946 break;
947 case GL_TEXTURE_COLOR_TABLE_SGI:
948 if (!ctx->Extensions.SGI_texture_color_table) {
949 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
950 return;
951 }
952 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
953 ctx->Pixel.TextureColorTableScale[0] = params[0];
954 ctx->Pixel.TextureColorTableScale[1] = params[1];
955 ctx->Pixel.TextureColorTableScale[2] = params[2];
956 ctx->Pixel.TextureColorTableScale[3] = params[3];
957 }
958 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
959 ctx->Pixel.TextureColorTableBias[0] = params[0];
960 ctx->Pixel.TextureColorTableBias[1] = params[1];
961 ctx->Pixel.TextureColorTableBias[2] = params[2];
962 ctx->Pixel.TextureColorTableBias[3] = params[3];
963 }
964 else {
965 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
966 return;
967 }
968 break;
969 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
970 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
971 ctx->Pixel.PCCTscale[0] = params[0];
972 ctx->Pixel.PCCTscale[1] = params[1];
973 ctx->Pixel.PCCTscale[2] = params[2];
974 ctx->Pixel.PCCTscale[3] = params[3];
975 }
976 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
977 ctx->Pixel.PCCTbias[0] = params[0];
978 ctx->Pixel.PCCTbias[1] = params[1];
979 ctx->Pixel.PCCTbias[2] = params[2];
980 ctx->Pixel.PCCTbias[3] = params[3];
981 }
982 else {
983 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
984 return;
985 }
986 break;
987 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
988 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
989 ctx->Pixel.PCMCTscale[0] = params[0];
990 ctx->Pixel.PCMCTscale[1] = params[1];
991 ctx->Pixel.PCMCTscale[2] = params[2];
992 ctx->Pixel.PCMCTscale[3] = params[3];
993 }
994 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
995 ctx->Pixel.PCMCTbias[0] = params[0];
996 ctx->Pixel.PCMCTbias[1] = params[1];
997 ctx->Pixel.PCMCTbias[2] = params[2];
998 ctx->Pixel.PCMCTbias[3] = params[3];
999 }
1000 else {
1001 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
1002 return;
1003 }
1004 break;
1005 default:
1006 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
1007 return;
1008 }
1009
1010 ctx->NewState |= _NEW_PIXEL;
1011 }
1012
1013
1014
1015 void GLAPIENTRY
1016 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
1017 {
1018 GLfloat fparams[4];
1019 if (pname == GL_COLOR_TABLE_SGI ||
1020 pname == GL_TEXTURE_COLOR_TABLE_SGI ||
1021 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1022 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
1023 /* four values */
1024 fparams[0] = (GLfloat) params[0];
1025 fparams[1] = (GLfloat) params[1];
1026 fparams[2] = (GLfloat) params[2];
1027 fparams[3] = (GLfloat) params[3];
1028 }
1029 else {
1030 /* one values */
1031 fparams[0] = (GLfloat) params[0];
1032 }
1033 _mesa_ColorTableParameterfv(target, pname, fparams);
1034 }
1035
1036
1037
1038 void GLAPIENTRY
1039 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
1040 {
1041 GET_CURRENT_CONTEXT(ctx);
1042 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1043 struct gl_color_table *table = NULL;
1044 ASSERT_OUTSIDE_BEGIN_END(ctx);
1045
1046 switch (target) {
1047 case GL_TEXTURE_1D:
1048 table = &texUnit->Current1D->Palette;
1049 break;
1050 case GL_TEXTURE_2D:
1051 table = &texUnit->Current2D->Palette;
1052 break;
1053 case GL_TEXTURE_3D:
1054 table = &texUnit->Current3D->Palette;
1055 break;
1056 case GL_TEXTURE_CUBE_MAP_ARB:
1057 if (!ctx->Extensions.ARB_texture_cube_map) {
1058 _mesa_error(ctx, GL_INVALID_ENUM,
1059 "glGetColorTableParameterfv(target)");
1060 return;
1061 }
1062 table = &texUnit->CurrentCubeMap->Palette;
1063 break;
1064 case GL_PROXY_TEXTURE_1D:
1065 table = &ctx->Texture.Proxy1D->Palette;
1066 break;
1067 case GL_PROXY_TEXTURE_2D:
1068 table = &ctx->Texture.Proxy2D->Palette;
1069 break;
1070 case GL_PROXY_TEXTURE_3D:
1071 table = &ctx->Texture.Proxy3D->Palette;
1072 break;
1073 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1074 if (!ctx->Extensions.ARB_texture_cube_map) {
1075 _mesa_error(ctx, GL_INVALID_ENUM,
1076 "glGetColorTableParameterfv(target)");
1077 return;
1078 }
1079 table = &ctx->Texture.ProxyCubeMap->Palette;
1080 break;
1081 case GL_SHARED_TEXTURE_PALETTE_EXT:
1082 table = &ctx->Texture.Palette;
1083 break;
1084 case GL_COLOR_TABLE:
1085 table = &ctx->ColorTable;
1086 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1087 params[0] = ctx->Pixel.ColorTableScale[0];
1088 params[1] = ctx->Pixel.ColorTableScale[1];
1089 params[2] = ctx->Pixel.ColorTableScale[2];
1090 params[3] = ctx->Pixel.ColorTableScale[3];
1091 return;
1092 }
1093 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1094 params[0] = ctx->Pixel.ColorTableBias[0];
1095 params[1] = ctx->Pixel.ColorTableBias[1];
1096 params[2] = ctx->Pixel.ColorTableBias[2];
1097 params[3] = ctx->Pixel.ColorTableBias[3];
1098 return;
1099 }
1100 break;
1101 case GL_PROXY_COLOR_TABLE:
1102 table = &ctx->ProxyColorTable;
1103 break;
1104 case GL_TEXTURE_COLOR_TABLE_SGI:
1105 if (!ctx->Extensions.SGI_texture_color_table) {
1106 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1107 return;
1108 }
1109 table = &(texUnit->ColorTable);
1110 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1111 params[0] = ctx->Pixel.TextureColorTableScale[0];
1112 params[1] = ctx->Pixel.TextureColorTableScale[1];
1113 params[2] = ctx->Pixel.TextureColorTableScale[2];
1114 params[3] = ctx->Pixel.TextureColorTableScale[3];
1115 return;
1116 }
1117 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1118 params[0] = ctx->Pixel.TextureColorTableBias[0];
1119 params[1] = ctx->Pixel.TextureColorTableBias[1];
1120 params[2] = ctx->Pixel.TextureColorTableBias[2];
1121 params[3] = ctx->Pixel.TextureColorTableBias[3];
1122 return;
1123 }
1124 break;
1125 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1126 if (!ctx->Extensions.SGI_texture_color_table) {
1127 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1128 return;
1129 }
1130 table = &(texUnit->ProxyColorTable);
1131 break;
1132 case GL_POST_CONVOLUTION_COLOR_TABLE:
1133 table = &ctx->PostConvolutionColorTable;
1134 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1135 params[0] = ctx->Pixel.PCCTscale[0];
1136 params[1] = ctx->Pixel.PCCTscale[1];
1137 params[2] = ctx->Pixel.PCCTscale[2];
1138 params[3] = ctx->Pixel.PCCTscale[3];
1139 return;
1140 }
1141 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1142 params[0] = ctx->Pixel.PCCTbias[0];
1143 params[1] = ctx->Pixel.PCCTbias[1];
1144 params[2] = ctx->Pixel.PCCTbias[2];
1145 params[3] = ctx->Pixel.PCCTbias[3];
1146 return;
1147 }
1148 break;
1149 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1150 table = &ctx->ProxyPostConvolutionColorTable;
1151 break;
1152 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1153 table = &ctx->PostColorMatrixColorTable;
1154 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1155 params[0] = ctx->Pixel.PCMCTscale[0];
1156 params[1] = ctx->Pixel.PCMCTscale[1];
1157 params[2] = ctx->Pixel.PCMCTscale[2];
1158 params[3] = ctx->Pixel.PCMCTscale[3];
1159 return;
1160 }
1161 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1162 params[0] = ctx->Pixel.PCMCTbias[0];
1163 params[1] = ctx->Pixel.PCMCTbias[1];
1164 params[2] = ctx->Pixel.PCMCTbias[2];
1165 params[3] = ctx->Pixel.PCMCTbias[3];
1166 return;
1167 }
1168 break;
1169 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1170 table = &ctx->ProxyPostColorMatrixColorTable;
1171 break;
1172 default:
1173 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
1174 return;
1175 }
1176
1177 assert(table);
1178
1179 switch (pname) {
1180 case GL_COLOR_TABLE_FORMAT:
1181 *params = (GLfloat) table->IntFormat;
1182 break;
1183 case GL_COLOR_TABLE_WIDTH:
1184 *params = (GLfloat) table->Size;
1185 break;
1186 case GL_COLOR_TABLE_RED_SIZE:
1187 *params = (GLfloat) table->RedSize;
1188 break;
1189 case GL_COLOR_TABLE_GREEN_SIZE:
1190 *params = (GLfloat) table->GreenSize;
1191 break;
1192 case GL_COLOR_TABLE_BLUE_SIZE:
1193 *params = (GLfloat) table->BlueSize;
1194 break;
1195 case GL_COLOR_TABLE_ALPHA_SIZE:
1196 *params = (GLfloat) table->AlphaSize;
1197 break;
1198 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1199 *params = (GLfloat) table->LuminanceSize;
1200 break;
1201 case GL_COLOR_TABLE_INTENSITY_SIZE:
1202 *params = (GLfloat) table->IntensitySize;
1203 break;
1204 default:
1205 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
1206 return;
1207 }
1208 }
1209
1210
1211
1212 void GLAPIENTRY
1213 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
1214 {
1215 GET_CURRENT_CONTEXT(ctx);
1216 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1217 struct gl_color_table *table = NULL;
1218 ASSERT_OUTSIDE_BEGIN_END(ctx);
1219
1220 switch (target) {
1221 case GL_TEXTURE_1D:
1222 table = &texUnit->Current1D->Palette;
1223 break;
1224 case GL_TEXTURE_2D:
1225 table = &texUnit->Current2D->Palette;
1226 break;
1227 case GL_TEXTURE_3D:
1228 table = &texUnit->Current3D->Palette;
1229 break;
1230 case GL_TEXTURE_CUBE_MAP_ARB:
1231 if (!ctx->Extensions.ARB_texture_cube_map) {
1232 _mesa_error(ctx, GL_INVALID_ENUM,
1233 "glGetColorTableParameteriv(target)");
1234 return;
1235 }
1236 table = &texUnit->CurrentCubeMap->Palette;
1237 break;
1238 case GL_PROXY_TEXTURE_1D:
1239 table = &ctx->Texture.Proxy1D->Palette;
1240 break;
1241 case GL_PROXY_TEXTURE_2D:
1242 table = &ctx->Texture.Proxy2D->Palette;
1243 break;
1244 case GL_PROXY_TEXTURE_3D:
1245 table = &ctx->Texture.Proxy3D->Palette;
1246 break;
1247 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1248 if (!ctx->Extensions.ARB_texture_cube_map) {
1249 _mesa_error(ctx, GL_INVALID_ENUM,
1250 "glGetColorTableParameteriv(target)");
1251 return;
1252 }
1253 table = &ctx->Texture.ProxyCubeMap->Palette;
1254 break;
1255 case GL_SHARED_TEXTURE_PALETTE_EXT:
1256 table = &ctx->Texture.Palette;
1257 break;
1258 case GL_COLOR_TABLE:
1259 table = &ctx->ColorTable;
1260 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1261 params[0] = (GLint) ctx->Pixel.ColorTableScale[0];
1262 params[1] = (GLint) ctx->Pixel.ColorTableScale[1];
1263 params[2] = (GLint) ctx->Pixel.ColorTableScale[2];
1264 params[3] = (GLint) ctx->Pixel.ColorTableScale[3];
1265 return;
1266 }
1267 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1268 params[0] = (GLint) ctx->Pixel.ColorTableBias[0];
1269 params[1] = (GLint) ctx->Pixel.ColorTableBias[1];
1270 params[2] = (GLint) ctx->Pixel.ColorTableBias[2];
1271 params[3] = (GLint) ctx->Pixel.ColorTableBias[3];
1272 return;
1273 }
1274 break;
1275 case GL_PROXY_COLOR_TABLE:
1276 table = &ctx->ProxyColorTable;
1277 break;
1278 case GL_TEXTURE_COLOR_TABLE_SGI:
1279 if (!ctx->Extensions.SGI_texture_color_table) {
1280 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1281 return;
1282 }
1283 table = &(texUnit->ColorTable);
1284 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1285 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
1286 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
1287 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
1288 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
1289 return;
1290 }
1291 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1292 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
1293 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
1294 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
1295 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
1296 return;
1297 }
1298 break;
1299 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1300 if (!ctx->Extensions.SGI_texture_color_table) {
1301 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1302 return;
1303 }
1304 table = &(texUnit->ProxyColorTable);
1305 break;
1306 case GL_POST_CONVOLUTION_COLOR_TABLE:
1307 table = &ctx->PostConvolutionColorTable;
1308 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1309 params[0] = (GLint) ctx->Pixel.PCCTscale[0];
1310 params[1] = (GLint) ctx->Pixel.PCCTscale[1];
1311 params[2] = (GLint) ctx->Pixel.PCCTscale[2];
1312 params[3] = (GLint) ctx->Pixel.PCCTscale[3];
1313 return;
1314 }
1315 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1316 params[0] = (GLint) ctx->Pixel.PCCTbias[0];
1317 params[1] = (GLint) ctx->Pixel.PCCTbias[1];
1318 params[2] = (GLint) ctx->Pixel.PCCTbias[2];
1319 params[3] = (GLint) ctx->Pixel.PCCTbias[3];
1320 return;
1321 }
1322 break;
1323 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1324 table = &ctx->ProxyPostConvolutionColorTable;
1325 break;
1326 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1327 table = &ctx->PostColorMatrixColorTable;
1328 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1329 params[0] = (GLint) ctx->Pixel.PCMCTscale[0];
1330 params[1] = (GLint) ctx->Pixel.PCMCTscale[1];
1331 params[2] = (GLint) ctx->Pixel.PCMCTscale[2];
1332 params[3] = (GLint) ctx->Pixel.PCMCTscale[3];
1333 return;
1334 }
1335 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1336 params[0] = (GLint) ctx->Pixel.PCMCTbias[0];
1337 params[1] = (GLint) ctx->Pixel.PCMCTbias[1];
1338 params[2] = (GLint) ctx->Pixel.PCMCTbias[2];
1339 params[3] = (GLint) ctx->Pixel.PCMCTbias[3];
1340 return;
1341 }
1342 break;
1343 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1344 table = &ctx->ProxyPostColorMatrixColorTable;
1345 break;
1346 default:
1347 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1348 return;
1349 }
1350
1351 assert(table);
1352
1353 switch (pname) {
1354 case GL_COLOR_TABLE_FORMAT:
1355 *params = table->IntFormat;
1356 break;
1357 case GL_COLOR_TABLE_WIDTH:
1358 *params = table->Size;
1359 break;
1360 case GL_COLOR_TABLE_RED_SIZE:
1361 *params = table->RedSize;
1362 break;
1363 case GL_COLOR_TABLE_GREEN_SIZE:
1364 *params = table->GreenSize;
1365 break;
1366 case GL_COLOR_TABLE_BLUE_SIZE:
1367 *params = table->BlueSize;
1368 break;
1369 case GL_COLOR_TABLE_ALPHA_SIZE:
1370 *params = table->AlphaSize;
1371 break;
1372 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1373 *params = table->LuminanceSize;
1374 break;
1375 case GL_COLOR_TABLE_INTENSITY_SIZE:
1376 *params = table->IntensitySize;
1377 break;
1378 default:
1379 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1380 return;
1381 }
1382 }
1383
1384 /**********************************************************************/
1385 /***** Initialization *****/
1386 /**********************************************************************/
1387
1388
1389 void
1390 _mesa_init_colortable( struct gl_color_table *p )
1391 {
1392 p->Type = CHAN_TYPE;
1393 p->Table = NULL;
1394 p->Size = 0;
1395 p->IntFormat = GL_RGBA;
1396 }
1397
1398
1399
1400 void
1401 _mesa_free_colortable_data( struct gl_color_table *p )
1402 {
1403 if (p->Table) {
1404 FREE(p->Table);
1405 p->Table = NULL;
1406 }
1407 }
1408
1409
1410 /*
1411 * Initialize all colortables for a context.
1412 */
1413 void _mesa_init_colortables( GLcontext * ctx )
1414 {
1415 /* Color tables */
1416 _mesa_init_colortable(&ctx->ColorTable);
1417 _mesa_init_colortable(&ctx->ProxyColorTable);
1418 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1419 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1420 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1421 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
1422 }
1423
1424
1425 /*
1426 * Free all colortable data for a context
1427 */
1428 void _mesa_free_colortables_data( GLcontext *ctx )
1429 {
1430 _mesa_free_colortable_data(&ctx->ColorTable);
1431 _mesa_free_colortable_data(&ctx->ProxyColorTable);
1432 _mesa_free_colortable_data(&ctx->PostConvolutionColorTable);
1433 _mesa_free_colortable_data(&ctx->ProxyPostConvolutionColorTable);
1434 _mesa_free_colortable_data(&ctx->PostColorMatrixColorTable);
1435 _mesa_free_colortable_data(&ctx->ProxyPostColorMatrixColorTable);
1436 }