026fa48786dc89c3e3f2cda64741133bfbed9fcd
[mesa.git] / src / mesa / main / colortab.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.1
4 *
5 * Copyright (C) 1999-2007 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 "mfeatures.h"
33 #include "mtypes.h"
34 #include "pack.h"
35 #include "state.h"
36 #include "teximage.h"
37 #include "texstate.h"
38 #include "main/dispatch.h"
39
40
41 #if FEATURE_colortable
42
43
44 /**
45 * Given an internalFormat token passed to glColorTable,
46 * return the corresponding base format.
47 * Return -1 if invalid token.
48 */
49 static GLint
50 base_colortab_format( GLenum format )
51 {
52 switch (format) {
53 case GL_ALPHA:
54 case GL_ALPHA4:
55 case GL_ALPHA8:
56 case GL_ALPHA12:
57 case GL_ALPHA16:
58 return GL_ALPHA;
59 case GL_LUMINANCE:
60 case GL_LUMINANCE4:
61 case GL_LUMINANCE8:
62 case GL_LUMINANCE12:
63 case GL_LUMINANCE16:
64 return GL_LUMINANCE;
65 case GL_LUMINANCE_ALPHA:
66 case GL_LUMINANCE4_ALPHA4:
67 case GL_LUMINANCE6_ALPHA2:
68 case GL_LUMINANCE8_ALPHA8:
69 case GL_LUMINANCE12_ALPHA4:
70 case GL_LUMINANCE12_ALPHA12:
71 case GL_LUMINANCE16_ALPHA16:
72 return GL_LUMINANCE_ALPHA;
73 case GL_INTENSITY:
74 case GL_INTENSITY4:
75 case GL_INTENSITY8:
76 case GL_INTENSITY12:
77 case GL_INTENSITY16:
78 return GL_INTENSITY;
79 case GL_RGB:
80 case GL_R3_G3_B2:
81 case GL_RGB4:
82 case GL_RGB5:
83 case GL_RGB8:
84 case GL_RGB10:
85 case GL_RGB12:
86 case GL_RGB16:
87 return GL_RGB;
88 case GL_RGBA:
89 case GL_RGBA2:
90 case GL_RGBA4:
91 case GL_RGB5_A1:
92 case GL_RGBA8:
93 case GL_RGB10_A2:
94 case GL_RGBA12:
95 case GL_RGBA16:
96 return GL_RGBA;
97 default:
98 return -1; /* error */
99 }
100 }
101
102
103
104 /**
105 * Examine table's format and set the component sizes accordingly.
106 */
107 static void
108 set_component_sizes( struct gl_color_table *table )
109 {
110 /* assuming the ubyte table */
111 const GLubyte sz = 8;
112
113 switch (table->_BaseFormat) {
114 case GL_ALPHA:
115 table->RedSize = 0;
116 table->GreenSize = 0;
117 table->BlueSize = 0;
118 table->AlphaSize = sz;
119 table->IntensitySize = 0;
120 table->LuminanceSize = 0;
121 break;
122 case GL_LUMINANCE:
123 table->RedSize = 0;
124 table->GreenSize = 0;
125 table->BlueSize = 0;
126 table->AlphaSize = 0;
127 table->IntensitySize = 0;
128 table->LuminanceSize = sz;
129 break;
130 case GL_LUMINANCE_ALPHA:
131 table->RedSize = 0;
132 table->GreenSize = 0;
133 table->BlueSize = 0;
134 table->AlphaSize = sz;
135 table->IntensitySize = 0;
136 table->LuminanceSize = sz;
137 break;
138 case GL_INTENSITY:
139 table->RedSize = 0;
140 table->GreenSize = 0;
141 table->BlueSize = 0;
142 table->AlphaSize = 0;
143 table->IntensitySize = sz;
144 table->LuminanceSize = 0;
145 break;
146 case GL_RGB:
147 table->RedSize = sz;
148 table->GreenSize = sz;
149 table->BlueSize = sz;
150 table->AlphaSize = 0;
151 table->IntensitySize = 0;
152 table->LuminanceSize = 0;
153 break;
154 case GL_RGBA:
155 table->RedSize = sz;
156 table->GreenSize = sz;
157 table->BlueSize = sz;
158 table->AlphaSize = sz;
159 table->IntensitySize = 0;
160 table->LuminanceSize = 0;
161 break;
162 default:
163 _mesa_problem(NULL, "unexpected format in set_component_sizes");
164 }
165 }
166
167
168
169 /**
170 * Update/replace all or part of a color table. Helper function
171 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
172 * The table->Table buffer should already be allocated.
173 * \param start first entry to update
174 * \param count number of entries to update
175 * \param format format of user-provided table data
176 * \param type datatype of user-provided table data
177 * \param data user-provided table data
178 * \param [rgba]Scale - RGBA scale factors
179 * \param [rgba]Bias - RGBA bias factors
180 */
181 static void
182 store_colortable_entries(struct gl_context *ctx, struct gl_color_table *table,
183 GLsizei start, GLsizei count,
184 GLenum format, GLenum type, const GLvoid *data,
185 GLfloat rScale, GLfloat rBias,
186 GLfloat gScale, GLfloat gBias,
187 GLfloat bScale, GLfloat bBias,
188 GLfloat aScale, GLfloat aBias)
189 {
190 data = _mesa_map_validate_pbo_source(ctx,
191 1, &ctx->Unpack, count, 1, 1,
192 format, type, data,
193 "glColor[Sub]Table");
194 if (!data)
195 return;
196
197 {
198 /* convert user-provided data to GLfloat values */
199 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
200 GLfloat *tableF;
201 GLint i;
202
203 _mesa_unpack_color_span_float(ctx,
204 count, /* number of pixels */
205 table->_BaseFormat, /* dest format */
206 tempTab, /* dest address */
207 format, type, /* src format/type */
208 data, /* src data */
209 &ctx->Unpack,
210 IMAGE_CLAMP_BIT); /* transfer ops */
211
212 /* the destination */
213 tableF = table->TableF;
214
215 /* Apply scale & bias & clamp now */
216 switch (table->_BaseFormat) {
217 case GL_INTENSITY:
218 for (i = 0; i < count; i++) {
219 GLuint j = start + i;
220 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
221 }
222 break;
223 case GL_LUMINANCE:
224 for (i = 0; i < count; i++) {
225 GLuint j = start + i;
226 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
227 }
228 break;
229 case GL_ALPHA:
230 for (i = 0; i < count; i++) {
231 GLuint j = start + i;
232 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
233 }
234 break;
235 case GL_LUMINANCE_ALPHA:
236 for (i = 0; i < count; i++) {
237 GLuint j = start + i;
238 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
239 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
240 }
241 break;
242 case GL_RGB:
243 for (i = 0; i < count; i++) {
244 GLuint j = start + i;
245 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
246 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
247 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
248 }
249 break;
250 case GL_RGBA:
251 for (i = 0; i < count; i++) {
252 GLuint j = start + i;
253 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
254 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
255 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
256 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
257 }
258 break;
259 default:
260 _mesa_problem(ctx, "Bad format in store_colortable_entries");
261 return;
262 }
263 }
264
265 /* update the ubyte table */
266 {
267 const GLint comps = _mesa_components_in_format(table->_BaseFormat);
268 const GLfloat *tableF = table->TableF + start * comps;
269 GLubyte *tableUB = table->TableUB + start * comps;
270 GLint i;
271 for (i = 0; i < count * comps; i++) {
272 CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]);
273 }
274 }
275
276 _mesa_unmap_pbo_source(ctx, &ctx->Unpack);
277 }
278
279
280
281 void GLAPIENTRY
282 _mesa_ColorTable( GLenum target, GLenum internalFormat,
283 GLsizei width, GLenum format, GLenum type,
284 const GLvoid *data )
285 {
286 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
287 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
288 GET_CURRENT_CONTEXT(ctx);
289 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
290 struct gl_texture_object *texObj = NULL;
291 struct gl_color_table *table = NULL;
292 GLboolean proxy = GL_FALSE;
293 GLint baseFormat;
294 const GLfloat *scale = one, *bias = zero;
295 GLint comps;
296
297 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
298
299 switch (target) {
300 case GL_SHARED_TEXTURE_PALETTE_EXT:
301 table = &ctx->Texture.Palette;
302 break;
303 default:
304 /* try texture targets */
305 {
306 struct gl_texture_object *texobj
307 = _mesa_select_tex_object(ctx, texUnit, target);
308 if (texobj) {
309 table = &texobj->Palette;
310 proxy = _mesa_is_proxy_texture(target);
311 }
312 else {
313 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
314 return;
315 }
316 }
317 }
318
319 assert(table);
320
321 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
322 format == GL_INTENSITY) {
323 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
324 return;
325 }
326
327 baseFormat = base_colortab_format(internalFormat);
328 if (baseFormat < 0) {
329 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
330 return;
331 }
332
333 if (width < 0 || (width != 0 && !_mesa_is_pow_two(width))) {
334 /* error */
335 if (proxy) {
336 table->Size = 0;
337 table->InternalFormat = (GLenum) 0;
338 table->_BaseFormat = (GLenum) 0;
339 }
340 else {
341 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
342 }
343 return;
344 }
345
346 if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
347 if (proxy) {
348 table->Size = 0;
349 table->InternalFormat = (GLenum) 0;
350 table->_BaseFormat = (GLenum) 0;
351 }
352 else {
353 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
354 }
355 return;
356 }
357
358 table->Size = width;
359 table->InternalFormat = internalFormat;
360 table->_BaseFormat = (GLenum) baseFormat;
361
362 comps = _mesa_components_in_format(table->_BaseFormat);
363 assert(comps > 0); /* error should have been caught sooner */
364
365 if (!proxy) {
366 _mesa_free_colortable_data(table);
367
368 if (width > 0) {
369 table->TableF = (GLfloat *) malloc(comps * width * sizeof(GLfloat));
370 table->TableUB = (GLubyte *) malloc(comps * width * sizeof(GLubyte));
371
372 if (!table->TableF || !table->TableUB) {
373 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
374 return;
375 }
376
377 store_colortable_entries(ctx, table,
378 0, width, /* start, count */
379 format, type, data,
380 scale[0], bias[0],
381 scale[1], bias[1],
382 scale[2], bias[2],
383 scale[3], bias[3]);
384 }
385 } /* proxy */
386
387 /* do this after the table's Type and Format are set */
388 set_component_sizes(table);
389
390 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
391 /* texture object palette, texObj==NULL means the shared palette */
392 if (ctx->Driver.UpdateTexturePalette) {
393 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
394 }
395 }
396
397 ctx->NewState |= _NEW_PIXEL;
398 }
399
400
401
402 void GLAPIENTRY
403 _mesa_ColorSubTable( GLenum target, GLsizei start,
404 GLsizei count, GLenum format, GLenum type,
405 const GLvoid *data )
406 {
407 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
408 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
409 GET_CURRENT_CONTEXT(ctx);
410 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
411 struct gl_texture_object *texObj = NULL;
412 struct gl_color_table *table = NULL;
413 const GLfloat *scale = one, *bias = zero;
414
415 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
416
417 switch (target) {
418 case GL_SHARED_TEXTURE_PALETTE_EXT:
419 table = &ctx->Texture.Palette;
420 break;
421 default:
422 /* try texture targets */
423 texObj = _mesa_select_tex_object(ctx, texUnit, target);
424 if (texObj && !_mesa_is_proxy_texture(target)) {
425 table = &texObj->Palette;
426 }
427 else {
428 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
429 return;
430 }
431 }
432
433 assert(table);
434
435 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
436 format == GL_INTENSITY) {
437 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
438 return;
439 }
440
441 if (count < 1) {
442 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
443 return;
444 }
445
446 /* error should have been caught sooner */
447 assert(_mesa_components_in_format(table->_BaseFormat) > 0);
448
449 if (start + count > (GLint) table->Size) {
450 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
451 return;
452 }
453
454 if (!table->TableF || !table->TableUB) {
455 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
456 return;
457 }
458
459 store_colortable_entries(ctx, table, start, count,
460 format, type, data,
461 scale[0], bias[0],
462 scale[1], bias[1],
463 scale[2], bias[2],
464 scale[3], bias[3]);
465
466 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
467 /* per-texture object palette */
468 if (ctx->Driver.UpdateTexturePalette) {
469 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
470 }
471 }
472
473 ctx->NewState |= _NEW_PIXEL;
474 }
475
476
477
478 static void GLAPIENTRY
479 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
480 GLint x, GLint y, GLsizei width)
481 {
482 GET_CURRENT_CONTEXT(ctx);
483 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
484
485 if (!ctx->ReadBuffer->_ColorReadBuffer) {
486 return; /* no readbuffer - OK */
487 }
488
489 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
490 }
491
492
493
494 static void GLAPIENTRY
495 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
496 GLint x, GLint y, GLsizei width)
497 {
498 GET_CURRENT_CONTEXT(ctx);
499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
500
501 if (!ctx->ReadBuffer->_ColorReadBuffer) {
502 return; /* no readbuffer - OK */
503 }
504
505 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
506 }
507
508
509
510 static void GLAPIENTRY
511 _mesa_GetColorTable( GLenum target, GLenum format,
512 GLenum type, GLvoid *data )
513 {
514 GET_CURRENT_CONTEXT(ctx);
515 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
516 struct gl_color_table *table = NULL;
517 GLfloat rgba[MAX_COLOR_TABLE_SIZE][4];
518 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
519
520 if (ctx->NewState) {
521 _mesa_update_state(ctx);
522 }
523
524 switch (target) {
525 case GL_SHARED_TEXTURE_PALETTE_EXT:
526 table = &ctx->Texture.Palette;
527 break;
528 default:
529 /* try texture targets */
530 {
531 struct gl_texture_object *texobj
532 = _mesa_select_tex_object(ctx, texUnit, target);
533 if (texobj && !_mesa_is_proxy_texture(target)) {
534 table = &texobj->Palette;
535 }
536 else {
537 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
538 return;
539 }
540 }
541 }
542
543 ASSERT(table);
544
545 if (table->Size <= 0) {
546 return;
547 }
548
549 switch (table->_BaseFormat) {
550 case GL_ALPHA:
551 {
552 GLuint i;
553 for (i = 0; i < table->Size; i++) {
554 rgba[i][RCOMP] = 0;
555 rgba[i][GCOMP] = 0;
556 rgba[i][BCOMP] = 0;
557 rgba[i][ACOMP] = table->TableF[i];
558 }
559 }
560 break;
561 case GL_LUMINANCE:
562 {
563 GLuint i;
564 for (i = 0; i < table->Size; i++) {
565 rgba[i][RCOMP] =
566 rgba[i][GCOMP] =
567 rgba[i][BCOMP] = table->TableF[i];
568 rgba[i][ACOMP] = 1.0F;
569 }
570 }
571 break;
572 case GL_LUMINANCE_ALPHA:
573 {
574 GLuint i;
575 for (i = 0; i < table->Size; i++) {
576 rgba[i][RCOMP] =
577 rgba[i][GCOMP] =
578 rgba[i][BCOMP] = table->TableF[i*2+0];
579 rgba[i][ACOMP] = table->TableF[i*2+1];
580 }
581 }
582 break;
583 case GL_INTENSITY:
584 {
585 GLuint i;
586 for (i = 0; i < table->Size; i++) {
587 rgba[i][RCOMP] =
588 rgba[i][GCOMP] =
589 rgba[i][BCOMP] =
590 rgba[i][ACOMP] = table->TableF[i];
591 }
592 }
593 break;
594 case GL_RGB:
595 {
596 GLuint i;
597 for (i = 0; i < table->Size; i++) {
598 rgba[i][RCOMP] = table->TableF[i*3+0];
599 rgba[i][GCOMP] = table->TableF[i*3+1];
600 rgba[i][BCOMP] = table->TableF[i*3+2];
601 rgba[i][ACOMP] = 1.0F;
602 }
603 }
604 break;
605 case GL_RGBA:
606 memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat));
607 break;
608 default:
609 _mesa_problem(ctx, "bad table format in glGetColorTable");
610 return;
611 }
612
613 data = _mesa_map_validate_pbo_dest(ctx,
614 1, &ctx->Pack, table->Size, 1, 1,
615 format, type, data,
616 "glGetColorTable");
617 if (!data)
618 return;
619
620 _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
621 format, type, data, &ctx->Pack, 0x0);
622
623 _mesa_unmap_pbo_dest(ctx, &ctx->Pack);
624 }
625
626
627
628 static void GLAPIENTRY
629 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
630 {
631 GLfloat *scale, *bias;
632 GET_CURRENT_CONTEXT(ctx);
633 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
634
635 switch (target) {
636 default:
637 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
638 return;
639 }
640
641 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
642 COPY_4V(scale, params);
643 }
644 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
645 COPY_4V(bias, params);
646 }
647 else {
648 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
649 return;
650 }
651
652 ctx->NewState |= _NEW_PIXEL;
653 }
654
655
656
657 static void GLAPIENTRY
658 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
659 {
660 GLfloat fparams[4];
661 fparams[0] = (GLfloat) params[0];
662 _mesa_ColorTableParameterfv(target, pname, fparams);
663 }
664
665
666
667 static void GLAPIENTRY
668 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
669 {
670 GET_CURRENT_CONTEXT(ctx);
671 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
672 struct gl_color_table *table = NULL;
673 ASSERT_OUTSIDE_BEGIN_END(ctx);
674
675 switch (target) {
676 case GL_SHARED_TEXTURE_PALETTE_EXT:
677 table = &ctx->Texture.Palette;
678 break;
679 default:
680 /* try texture targets */
681 {
682 struct gl_texture_object *texobj
683 = _mesa_select_tex_object(ctx, texUnit, target);
684 if (texobj) {
685 table = &texobj->Palette;
686 }
687 else {
688 _mesa_error(ctx, GL_INVALID_ENUM,
689 "glGetColorTableParameterfv(target)");
690 return;
691 }
692 }
693 }
694
695 assert(table);
696
697 switch (pname) {
698 case GL_COLOR_TABLE_FORMAT:
699 *params = (GLfloat) table->InternalFormat;
700 break;
701 case GL_COLOR_TABLE_WIDTH:
702 *params = (GLfloat) table->Size;
703 break;
704 case GL_COLOR_TABLE_RED_SIZE:
705 *params = (GLfloat) table->RedSize;
706 break;
707 case GL_COLOR_TABLE_GREEN_SIZE:
708 *params = (GLfloat) table->GreenSize;
709 break;
710 case GL_COLOR_TABLE_BLUE_SIZE:
711 *params = (GLfloat) table->BlueSize;
712 break;
713 case GL_COLOR_TABLE_ALPHA_SIZE:
714 *params = (GLfloat) table->AlphaSize;
715 break;
716 case GL_COLOR_TABLE_LUMINANCE_SIZE:
717 *params = (GLfloat) table->LuminanceSize;
718 break;
719 case GL_COLOR_TABLE_INTENSITY_SIZE:
720 *params = (GLfloat) table->IntensitySize;
721 break;
722 default:
723 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
724 return;
725 }
726 }
727
728
729
730 static void GLAPIENTRY
731 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
732 {
733 GET_CURRENT_CONTEXT(ctx);
734 struct gl_texture_unit *texUnit = _mesa_get_current_tex_unit(ctx);
735 struct gl_color_table *table = NULL;
736 ASSERT_OUTSIDE_BEGIN_END(ctx);
737
738 switch (target) {
739 case GL_SHARED_TEXTURE_PALETTE_EXT:
740 table = &ctx->Texture.Palette;
741 break;
742 default:
743 /* Try texture targets */
744 {
745 struct gl_texture_object *texobj
746 = _mesa_select_tex_object(ctx, texUnit, target);
747 if (texobj) {
748 table = &texobj->Palette;
749 }
750 else {
751 _mesa_error(ctx, GL_INVALID_ENUM,
752 "glGetColorTableParameteriv(target)");
753 return;
754 }
755 }
756 }
757
758 assert(table);
759
760 switch (pname) {
761 case GL_COLOR_TABLE_FORMAT:
762 *params = table->InternalFormat;
763 break;
764 case GL_COLOR_TABLE_WIDTH:
765 *params = table->Size;
766 break;
767 case GL_COLOR_TABLE_RED_SIZE:
768 *params = table->RedSize;
769 break;
770 case GL_COLOR_TABLE_GREEN_SIZE:
771 *params = table->GreenSize;
772 break;
773 case GL_COLOR_TABLE_BLUE_SIZE:
774 *params = table->BlueSize;
775 break;
776 case GL_COLOR_TABLE_ALPHA_SIZE:
777 *params = table->AlphaSize;
778 break;
779 case GL_COLOR_TABLE_LUMINANCE_SIZE:
780 *params = table->LuminanceSize;
781 break;
782 case GL_COLOR_TABLE_INTENSITY_SIZE:
783 *params = table->IntensitySize;
784 break;
785 default:
786 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
787 return;
788 }
789 }
790
791
792 void
793 _mesa_init_colortable_dispatch(struct _glapi_table *disp)
794 {
795 SET_ColorSubTable(disp, _mesa_ColorSubTable);
796 SET_ColorTable(disp, _mesa_ColorTable);
797 SET_ColorTableParameterfv(disp, _mesa_ColorTableParameterfv);
798 SET_ColorTableParameteriv(disp, _mesa_ColorTableParameteriv);
799 SET_CopyColorSubTable(disp, _mesa_CopyColorSubTable);
800 SET_CopyColorTable(disp, _mesa_CopyColorTable);
801 SET_GetColorTable(disp, _mesa_GetColorTable);
802 SET_GetColorTableParameterfv(disp, _mesa_GetColorTableParameterfv);
803 SET_GetColorTableParameteriv(disp, _mesa_GetColorTableParameteriv);
804 }
805
806
807 #endif /* FEATURE_colortable */
808
809
810 /**********************************************************************/
811 /***** Initialization *****/
812 /**********************************************************************/
813
814
815 void
816 _mesa_init_colortable( struct gl_color_table *p )
817 {
818 p->TableF = NULL;
819 p->TableUB = NULL;
820 p->Size = 0;
821 p->InternalFormat = GL_RGBA;
822 }
823
824
825
826 void
827 _mesa_free_colortable_data( struct gl_color_table *p )
828 {
829 if (p->TableF) {
830 free(p->TableF);
831 p->TableF = NULL;
832 }
833 if (p->TableUB) {
834 free(p->TableUB);
835 p->TableUB = NULL;
836 }
837 }