merge from master
[mesa.git] / src / mesa / main / colortab.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5.3
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 "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 /* assuming the ubyte table */
102 const GLubyte sz = 8;
103
104 switch (table->_BaseFormat) {
105 case GL_ALPHA:
106 table->RedSize = 0;
107 table->GreenSize = 0;
108 table->BlueSize = 0;
109 table->AlphaSize = sz;
110 table->IntensitySize = 0;
111 table->LuminanceSize = 0;
112 break;
113 case GL_LUMINANCE:
114 table->RedSize = 0;
115 table->GreenSize = 0;
116 table->BlueSize = 0;
117 table->AlphaSize = 0;
118 table->IntensitySize = 0;
119 table->LuminanceSize = sz;
120 break;
121 case GL_LUMINANCE_ALPHA:
122 table->RedSize = 0;
123 table->GreenSize = 0;
124 table->BlueSize = 0;
125 table->AlphaSize = sz;
126 table->IntensitySize = 0;
127 table->LuminanceSize = sz;
128 break;
129 case GL_INTENSITY:
130 table->RedSize = 0;
131 table->GreenSize = 0;
132 table->BlueSize = 0;
133 table->AlphaSize = 0;
134 table->IntensitySize = sz;
135 table->LuminanceSize = 0;
136 break;
137 case GL_RGB:
138 table->RedSize = sz;
139 table->GreenSize = sz;
140 table->BlueSize = sz;
141 table->AlphaSize = 0;
142 table->IntensitySize = 0;
143 table->LuminanceSize = 0;
144 break;
145 case GL_RGBA:
146 table->RedSize = sz;
147 table->GreenSize = sz;
148 table->BlueSize = sz;
149 table->AlphaSize = sz;
150 table->IntensitySize = 0;
151 table->LuminanceSize = 0;
152 break;
153 default:
154 _mesa_problem(NULL, "unexpected format in set_component_sizes");
155 }
156 }
157
158
159
160 /**
161 * Update/replace all or part of a color table. Helper function
162 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
163 * The table->Table buffer should already be allocated.
164 * \param start first entry to update
165 * \param count number of entries to update
166 * \param format format of user-provided table data
167 * \param type datatype of user-provided table data
168 * \param data user-provided table data
169 * \param [rgba]Scale - RGBA scale factors
170 * \param [rgba]Bias - RGBA bias factors
171 */
172 static void
173 store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
174 GLsizei start, GLsizei count,
175 GLenum format, GLenum type, const GLvoid *data,
176 GLfloat rScale, GLfloat rBias,
177 GLfloat gScale, GLfloat gBias,
178 GLfloat bScale, GLfloat bBias,
179 GLfloat aScale, GLfloat aBias)
180 {
181 if (ctx->Unpack.BufferObj->Name) {
182 /* Get/unpack the color table data from a PBO */
183 GLubyte *buf;
184 if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
185 format, type, data)) {
186 _mesa_error(ctx, GL_INVALID_OPERATION,
187 "glColor[Sub]Table(bad PBO access)");
188 return;
189 }
190 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
191 GL_READ_ONLY_ARB,
192 ctx->Unpack.BufferObj);
193 if (!buf) {
194 _mesa_error(ctx, GL_INVALID_OPERATION,
195 "glColor[Sub]Table(PBO mapped)");
196 return;
197 }
198 data = ADD_POINTERS(buf, data);
199 }
200
201
202 {
203 /* convert user-provided data to GLfloat values */
204 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
205 GLfloat *tableF;
206 GLint i;
207
208 _mesa_unpack_color_span_float(ctx,
209 count, /* number of pixels */
210 table->_BaseFormat, /* dest format */
211 tempTab, /* dest address */
212 format, type, /* src format/type */
213 data, /* src data */
214 &ctx->Unpack,
215 IMAGE_CLAMP_BIT); /* transfer ops */
216
217 /* the destination */
218 tableF = table->TableF;
219
220 /* Apply scale & bias & clamp now */
221 switch (table->_BaseFormat) {
222 case GL_INTENSITY:
223 for (i = 0; i < count; i++) {
224 GLuint j = start + i;
225 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
226 }
227 break;
228 case GL_LUMINANCE:
229 for (i = 0; i < count; i++) {
230 GLuint j = start + i;
231 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
232 }
233 break;
234 case GL_ALPHA:
235 for (i = 0; i < count; i++) {
236 GLuint j = start + i;
237 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
238 }
239 break;
240 case GL_LUMINANCE_ALPHA:
241 for (i = 0; i < count; i++) {
242 GLuint j = start + i;
243 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
244 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
245 }
246 break;
247 case GL_RGB:
248 for (i = 0; i < count; i++) {
249 GLuint j = start + i;
250 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
251 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
252 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
253 }
254 break;
255 case GL_RGBA:
256 for (i = 0; i < count; i++) {
257 GLuint j = start + i;
258 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
259 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
260 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
261 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
262 }
263 break;
264 default:
265 _mesa_problem(ctx, "Bad format in store_colortable_entries");
266 return;
267 }
268 }
269
270 /* update the ubyte table */
271 {
272 const GLint comps = _mesa_components_in_format(table->_BaseFormat);
273 const GLfloat *tableF = table->TableF + start * comps;
274 GLubyte *tableUB = table->TableUB + start * comps;
275 GLint i;
276 for (i = 0; i < count * comps; i++) {
277 CLAMPED_FLOAT_TO_UBYTE(tableUB[i], tableF[i]);
278 }
279 }
280
281 if (ctx->Unpack.BufferObj->Name) {
282 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
283 ctx->Unpack.BufferObj);
284 }
285 }
286
287
288
289 void GLAPIENTRY
290 _mesa_ColorTable( GLenum target, GLenum internalFormat,
291 GLsizei width, GLenum format, GLenum type,
292 const GLvoid *data )
293 {
294 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
295 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
296 GET_CURRENT_CONTEXT(ctx);
297 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
298 struct gl_texture_object *texObj = NULL;
299 struct gl_color_table *table = NULL;
300 GLboolean proxy = GL_FALSE;
301 GLint baseFormat;
302 const GLfloat *scale = one, *bias = zero;
303 GLint comps;
304
305 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
306
307 switch (target) {
308 case GL_TEXTURE_1D:
309 texObj = texUnit->Current1D;
310 table = &texObj->Palette;
311 break;
312 case GL_TEXTURE_2D:
313 texObj = texUnit->Current2D;
314 table = &texObj->Palette;
315 break;
316 case GL_TEXTURE_3D:
317 texObj = texUnit->Current3D;
318 table = &texObj->Palette;
319 break;
320 case GL_TEXTURE_CUBE_MAP_ARB:
321 if (!ctx->Extensions.ARB_texture_cube_map) {
322 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
323 return;
324 }
325 texObj = texUnit->CurrentCubeMap;
326 table = &texObj->Palette;
327 break;
328 case GL_PROXY_TEXTURE_1D:
329 texObj = ctx->Texture.Proxy1D;
330 table = &texObj->Palette;
331 proxy = GL_TRUE;
332 break;
333 case GL_PROXY_TEXTURE_2D:
334 texObj = ctx->Texture.Proxy2D;
335 table = &texObj->Palette;
336 proxy = GL_TRUE;
337 break;
338 case GL_PROXY_TEXTURE_3D:
339 texObj = ctx->Texture.Proxy3D;
340 table = &texObj->Palette;
341 proxy = GL_TRUE;
342 break;
343 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
344 if (!ctx->Extensions.ARB_texture_cube_map) {
345 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
346 return;
347 }
348 texObj = ctx->Texture.ProxyCubeMap;
349 table = &texObj->Palette;
350 break;
351 case GL_SHARED_TEXTURE_PALETTE_EXT:
352 table = &ctx->Texture.Palette;
353 break;
354 case GL_COLOR_TABLE:
355 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];
356 scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];
357 bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];
358 break;
359 case GL_PROXY_COLOR_TABLE:
360 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION];
361 proxy = GL_TRUE;
362 break;
363 case GL_TEXTURE_COLOR_TABLE_SGI:
364 if (!ctx->Extensions.SGI_texture_color_table) {
365 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
366 return;
367 }
368 table = &(texUnit->ColorTable);
369 scale = ctx->Pixel.TextureColorTableScale;
370 bias = ctx->Pixel.TextureColorTableBias;
371 break;
372 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
373 if (!ctx->Extensions.SGI_texture_color_table) {
374 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
375 return;
376 }
377 table = &(texUnit->ProxyColorTable);
378 proxy = GL_TRUE;
379 break;
380 case GL_POST_CONVOLUTION_COLOR_TABLE:
381 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];
382 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];
383 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];
384 break;
385 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
386 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION];
387 proxy = GL_TRUE;
388 break;
389 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
390 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
391 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
392 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
393 break;
394 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
395 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
396 proxy = GL_TRUE;
397 break;
398 default:
399 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
400 return;
401 }
402
403 assert(table);
404
405 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
406 format == GL_INTENSITY) {
407 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
408 return;
409 }
410
411 baseFormat = base_colortab_format(internalFormat);
412 if (baseFormat < 0) {
413 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
414 return;
415 }
416
417 if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) {
418 /* error */
419 if (proxy) {
420 table->Size = 0;
421 table->InternalFormat = (GLenum) 0;
422 table->_BaseFormat = (GLenum) 0;
423 }
424 else {
425 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
426 }
427 return;
428 }
429
430 if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
431 if (proxy) {
432 table->Size = 0;
433 table->InternalFormat = (GLenum) 0;
434 table->_BaseFormat = (GLenum) 0;
435 }
436 else {
437 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
438 }
439 return;
440 }
441
442 table->Size = width;
443 table->InternalFormat = internalFormat;
444 table->_BaseFormat = (GLenum) baseFormat;
445
446 comps = _mesa_components_in_format(table->_BaseFormat);
447 assert(comps > 0); /* error should have been caught sooner */
448
449 if (!proxy) {
450 _mesa_free_colortable_data(table);
451
452 if (width > 0) {
453 table->TableF = (GLfloat *) _mesa_malloc(comps * width * sizeof(GLfloat));
454 table->TableUB = (GLubyte *) _mesa_malloc(comps * width * sizeof(GLubyte));
455
456 if (!table->TableF || !table->TableUB) {
457 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
458 return;
459 }
460
461 store_colortable_entries(ctx, table,
462 0, width, /* start, count */
463 format, type, data,
464 scale[0], bias[0],
465 scale[1], bias[1],
466 scale[2], bias[2],
467 scale[3], bias[3]);
468 }
469 } /* proxy */
470
471 /* do this after the table's Type and Format are set */
472 set_component_sizes(table);
473
474 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
475 /* texture object palette, texObj==NULL means the shared palette */
476 if (ctx->Driver.UpdateTexturePalette) {
477 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
478 }
479 }
480
481 ctx->NewState |= _NEW_PIXEL;
482 }
483
484
485
486 void GLAPIENTRY
487 _mesa_ColorSubTable( GLenum target, GLsizei start,
488 GLsizei count, GLenum format, GLenum type,
489 const GLvoid *data )
490 {
491 static const GLfloat one[4] = { 1.0, 1.0, 1.0, 1.0 };
492 static const GLfloat zero[4] = { 0.0, 0.0, 0.0, 0.0 };
493 GET_CURRENT_CONTEXT(ctx);
494 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
495 struct gl_texture_object *texObj = NULL;
496 struct gl_color_table *table = NULL;
497 const GLfloat *scale = one, *bias = zero;
498
499 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
500
501 switch (target) {
502 case GL_TEXTURE_1D:
503 texObj = texUnit->Current1D;
504 table = &texObj->Palette;
505 break;
506 case GL_TEXTURE_2D:
507 texObj = texUnit->Current2D;
508 table = &texObj->Palette;
509 break;
510 case GL_TEXTURE_3D:
511 texObj = texUnit->Current3D;
512 table = &texObj->Palette;
513 break;
514 case GL_TEXTURE_CUBE_MAP_ARB:
515 if (!ctx->Extensions.ARB_texture_cube_map) {
516 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
517 return;
518 }
519 texObj = texUnit->CurrentCubeMap;
520 table = &texObj->Palette;
521 break;
522 case GL_SHARED_TEXTURE_PALETTE_EXT:
523 table = &ctx->Texture.Palette;
524 break;
525 case GL_COLOR_TABLE:
526 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];
527 scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];
528 bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];
529 break;
530 case GL_TEXTURE_COLOR_TABLE_SGI:
531 if (!ctx->Extensions.SGI_texture_color_table) {
532 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
533 return;
534 }
535 table = &(texUnit->ColorTable);
536 scale = ctx->Pixel.TextureColorTableScale;
537 bias = ctx->Pixel.TextureColorTableBias;
538 break;
539 case GL_POST_CONVOLUTION_COLOR_TABLE:
540 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];
541 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];
542 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];
543 break;
544 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
545 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
546 scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
547 bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX];
548 break;
549 default:
550 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
551 return;
552 }
553
554 assert(table);
555
556 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
557 format == GL_INTENSITY) {
558 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
559 return;
560 }
561
562 if (count < 1) {
563 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
564 return;
565 }
566
567 /* error should have been caught sooner */
568 assert(_mesa_components_in_format(table->_BaseFormat) > 0);
569
570 if (start + count > (GLint) table->Size) {
571 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
572 return;
573 }
574
575 if (!table->TableF || !table->TableUB) {
576 /* a GL_OUT_OF_MEMORY error would have been recorded previously */
577 return;
578 }
579
580 store_colortable_entries(ctx, table, start, count,
581 format, type, data,
582 scale[0], bias[0],
583 scale[1], bias[1],
584 scale[2], bias[2],
585 scale[3], bias[3]);
586
587 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
588 /* per-texture object palette */
589 if (ctx->Driver.UpdateTexturePalette) {
590 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
591 }
592 }
593
594 ctx->NewState |= _NEW_PIXEL;
595 }
596
597
598
599 void GLAPIENTRY
600 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
601 GLint x, GLint y, GLsizei width)
602 {
603 GET_CURRENT_CONTEXT(ctx);
604 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
605
606 /* Select buffer to read from */
607 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
608 }
609
610
611
612 void GLAPIENTRY
613 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
614 GLint x, GLint y, GLsizei width)
615 {
616 GET_CURRENT_CONTEXT(ctx);
617 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
618
619 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
620 }
621
622
623
624 void GLAPIENTRY
625 _mesa_GetColorTable( GLenum target, GLenum format,
626 GLenum type, GLvoid *data )
627 {
628 GET_CURRENT_CONTEXT(ctx);
629 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
630 struct gl_color_table *table = NULL;
631 GLfloat rgba[MAX_COLOR_TABLE_SIZE][4];
632 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
633
634 if (ctx->NewState) {
635 _mesa_update_state(ctx);
636 }
637
638 switch (target) {
639 case GL_TEXTURE_1D:
640 table = &texUnit->Current1D->Palette;
641 break;
642 case GL_TEXTURE_2D:
643 table = &texUnit->Current2D->Palette;
644 break;
645 case GL_TEXTURE_3D:
646 table = &texUnit->Current3D->Palette;
647 break;
648 case GL_TEXTURE_CUBE_MAP_ARB:
649 if (!ctx->Extensions.ARB_texture_cube_map) {
650 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
651 return;
652 }
653 table = &texUnit->CurrentCubeMap->Palette;
654 break;
655 case GL_SHARED_TEXTURE_PALETTE_EXT:
656 table = &ctx->Texture.Palette;
657 break;
658 case GL_COLOR_TABLE:
659 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];
660 break;
661 case GL_TEXTURE_COLOR_TABLE_SGI:
662 if (!ctx->Extensions.SGI_texture_color_table) {
663 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
664 return;
665 }
666 table = &(texUnit->ColorTable);
667 break;
668 case GL_POST_CONVOLUTION_COLOR_TABLE:
669 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];
670 break;
671 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
672 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
673 break;
674 default:
675 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
676 return;
677 }
678
679 ASSERT(table);
680
681 if (table->Size <= 0) {
682 return;
683 }
684
685 switch (table->_BaseFormat) {
686 case GL_ALPHA:
687 {
688 GLuint i;
689 for (i = 0; i < table->Size; i++) {
690 rgba[i][RCOMP] = 0;
691 rgba[i][GCOMP] = 0;
692 rgba[i][BCOMP] = 0;
693 rgba[i][ACOMP] = table->TableF[i];
694 }
695 }
696 break;
697 case GL_LUMINANCE:
698 {
699 GLuint i;
700 for (i = 0; i < table->Size; i++) {
701 rgba[i][RCOMP] =
702 rgba[i][GCOMP] =
703 rgba[i][BCOMP] = table->TableF[i];
704 rgba[i][ACOMP] = 1.0F;
705 }
706 }
707 break;
708 case GL_LUMINANCE_ALPHA:
709 {
710 GLuint i;
711 for (i = 0; i < table->Size; i++) {
712 rgba[i][RCOMP] =
713 rgba[i][GCOMP] =
714 rgba[i][BCOMP] = table->TableF[i*2+0];
715 rgba[i][ACOMP] = table->TableF[i*2+1];
716 }
717 }
718 break;
719 case GL_INTENSITY:
720 {
721 GLuint i;
722 for (i = 0; i < table->Size; i++) {
723 rgba[i][RCOMP] =
724 rgba[i][GCOMP] =
725 rgba[i][BCOMP] =
726 rgba[i][ACOMP] = table->TableF[i];
727 }
728 }
729 break;
730 case GL_RGB:
731 {
732 GLuint i;
733 for (i = 0; i < table->Size; i++) {
734 rgba[i][RCOMP] = table->TableF[i*3+0];
735 rgba[i][GCOMP] = table->TableF[i*3+1];
736 rgba[i][BCOMP] = table->TableF[i*3+2];
737 rgba[i][ACOMP] = 1.0F;
738 }
739 }
740 break;
741 case GL_RGBA:
742 _mesa_memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat));
743 break;
744 default:
745 _mesa_problem(ctx, "bad table format in glGetColorTable");
746 return;
747 }
748
749 if (ctx->Pack.BufferObj->Name) {
750 /* pack color table into PBO */
751 GLubyte *buf;
752 if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
753 format, type, data)) {
754 _mesa_error(ctx, GL_INVALID_OPERATION,
755 "glGetColorTable(invalid PBO access)");
756 return;
757 }
758 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
759 GL_WRITE_ONLY_ARB,
760 ctx->Pack.BufferObj);
761 if (!buf) {
762 /* buffer is already mapped - that's an error */
763 _mesa_error(ctx, GL_INVALID_OPERATION,
764 "glGetColorTable(PBO is mapped)");
765 return;
766 }
767 data = ADD_POINTERS(buf, data);
768 }
769
770 _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
771 format, type, data, &ctx->Pack, 0x0);
772
773 if (ctx->Pack.BufferObj->Name) {
774 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
775 ctx->Pack.BufferObj);
776 }
777 }
778
779
780
781 void GLAPIENTRY
782 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
783 {
784 GET_CURRENT_CONTEXT(ctx);
785 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
786
787 switch (target) {
788 case GL_COLOR_TABLE_SGI:
789 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
790 COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION], params);
791 }
792 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
793 COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION], params);
794 }
795 else {
796 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
797 return;
798 }
799 break;
800 case GL_TEXTURE_COLOR_TABLE_SGI:
801 if (!ctx->Extensions.SGI_texture_color_table) {
802 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
803 return;
804 }
805 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
806 COPY_4V(ctx->Pixel.TextureColorTableScale, params);
807 }
808 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
809 COPY_4V(ctx->Pixel.TextureColorTableBias, params);
810 }
811 else {
812 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
813 return;
814 }
815 break;
816 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
817 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
818 COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION], params);
819 }
820 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
821 COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION], params);
822 }
823 else {
824 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
825 return;
826 }
827 break;
828 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
829 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
830 COPY_4V(ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX], params);
831 }
832 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
833 COPY_4V(ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX], params);
834 }
835 else {
836 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
837 return;
838 }
839 break;
840 default:
841 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
842 return;
843 }
844
845 ctx->NewState |= _NEW_PIXEL;
846 }
847
848
849
850 void GLAPIENTRY
851 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
852 {
853 GLfloat fparams[4];
854 if (pname == GL_COLOR_TABLE_SGI ||
855 pname == GL_TEXTURE_COLOR_TABLE_SGI ||
856 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
857 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
858 /* four values */
859 fparams[0] = (GLfloat) params[0];
860 fparams[1] = (GLfloat) params[1];
861 fparams[2] = (GLfloat) params[2];
862 fparams[3] = (GLfloat) params[3];
863 }
864 else {
865 /* one values */
866 fparams[0] = (GLfloat) params[0];
867 }
868 _mesa_ColorTableParameterfv(target, pname, fparams);
869 }
870
871
872
873 void GLAPIENTRY
874 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
875 {
876 GET_CURRENT_CONTEXT(ctx);
877 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
878 struct gl_color_table *table = NULL;
879 ASSERT_OUTSIDE_BEGIN_END(ctx);
880
881 switch (target) {
882 case GL_TEXTURE_1D:
883 table = &texUnit->Current1D->Palette;
884 break;
885 case GL_TEXTURE_2D:
886 table = &texUnit->Current2D->Palette;
887 break;
888 case GL_TEXTURE_3D:
889 table = &texUnit->Current3D->Palette;
890 break;
891 case GL_TEXTURE_CUBE_MAP_ARB:
892 if (!ctx->Extensions.ARB_texture_cube_map) {
893 _mesa_error(ctx, GL_INVALID_ENUM,
894 "glGetColorTableParameterfv(target)");
895 return;
896 }
897 table = &texUnit->CurrentCubeMap->Palette;
898 break;
899 case GL_PROXY_TEXTURE_1D:
900 table = &ctx->Texture.Proxy1D->Palette;
901 break;
902 case GL_PROXY_TEXTURE_2D:
903 table = &ctx->Texture.Proxy2D->Palette;
904 break;
905 case GL_PROXY_TEXTURE_3D:
906 table = &ctx->Texture.Proxy3D->Palette;
907 break;
908 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
909 if (!ctx->Extensions.ARB_texture_cube_map) {
910 _mesa_error(ctx, GL_INVALID_ENUM,
911 "glGetColorTableParameterfv(target)");
912 return;
913 }
914 table = &ctx->Texture.ProxyCubeMap->Palette;
915 break;
916 case GL_SHARED_TEXTURE_PALETTE_EXT:
917 table = &ctx->Texture.Palette;
918 break;
919 case GL_COLOR_TABLE:
920 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];
921 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
922 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION]);
923 return;
924 }
925 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
926 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION]);
927 return;
928 }
929 break;
930 case GL_PROXY_COLOR_TABLE:
931 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION];
932 break;
933 case GL_TEXTURE_COLOR_TABLE_SGI:
934 if (!ctx->Extensions.SGI_texture_color_table) {
935 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
936 return;
937 }
938 table = &(texUnit->ColorTable);
939 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
940 COPY_4V(params, ctx->Pixel.TextureColorTableScale);
941 return;
942 }
943 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
944 COPY_4V(params, ctx->Pixel.TextureColorTableBias);
945 return;
946 }
947 break;
948 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
949 if (!ctx->Extensions.SGI_texture_color_table) {
950 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
951 return;
952 }
953 table = &(texUnit->ProxyColorTable);
954 break;
955 case GL_POST_CONVOLUTION_COLOR_TABLE:
956 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];
957 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
958 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION]);
959 return;
960 }
961 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
962 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION]);
963 return;
964 }
965 break;
966 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
967 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION];
968 break;
969 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
970 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
971 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
972 COPY_4V(params, ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX]);
973 return;
974 }
975 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
976 COPY_4V(params, ctx->Pixel.ColorTableBias[COLORTABLE_POSTCOLORMATRIX]);
977 return;
978 }
979 break;
980 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
981 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
982 break;
983 default:
984 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
985 return;
986 }
987
988 assert(table);
989
990 switch (pname) {
991 case GL_COLOR_TABLE_FORMAT:
992 *params = (GLfloat) table->InternalFormat;
993 break;
994 case GL_COLOR_TABLE_WIDTH:
995 *params = (GLfloat) table->Size;
996 break;
997 case GL_COLOR_TABLE_RED_SIZE:
998 *params = (GLfloat) table->RedSize;
999 break;
1000 case GL_COLOR_TABLE_GREEN_SIZE:
1001 *params = (GLfloat) table->GreenSize;
1002 break;
1003 case GL_COLOR_TABLE_BLUE_SIZE:
1004 *params = (GLfloat) table->BlueSize;
1005 break;
1006 case GL_COLOR_TABLE_ALPHA_SIZE:
1007 *params = (GLfloat) table->AlphaSize;
1008 break;
1009 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1010 *params = (GLfloat) table->LuminanceSize;
1011 break;
1012 case GL_COLOR_TABLE_INTENSITY_SIZE:
1013 *params = (GLfloat) table->IntensitySize;
1014 break;
1015 default:
1016 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
1017 return;
1018 }
1019 }
1020
1021
1022
1023 void GLAPIENTRY
1024 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
1025 {
1026 GET_CURRENT_CONTEXT(ctx);
1027 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1028 struct gl_color_table *table = NULL;
1029 ASSERT_OUTSIDE_BEGIN_END(ctx);
1030
1031 switch (target) {
1032 case GL_TEXTURE_1D:
1033 table = &texUnit->Current1D->Palette;
1034 break;
1035 case GL_TEXTURE_2D:
1036 table = &texUnit->Current2D->Palette;
1037 break;
1038 case GL_TEXTURE_3D:
1039 table = &texUnit->Current3D->Palette;
1040 break;
1041 case GL_TEXTURE_CUBE_MAP_ARB:
1042 if (!ctx->Extensions.ARB_texture_cube_map) {
1043 _mesa_error(ctx, GL_INVALID_ENUM,
1044 "glGetColorTableParameteriv(target)");
1045 return;
1046 }
1047 table = &texUnit->CurrentCubeMap->Palette;
1048 break;
1049 case GL_PROXY_TEXTURE_1D:
1050 table = &ctx->Texture.Proxy1D->Palette;
1051 break;
1052 case GL_PROXY_TEXTURE_2D:
1053 table = &ctx->Texture.Proxy2D->Palette;
1054 break;
1055 case GL_PROXY_TEXTURE_3D:
1056 table = &ctx->Texture.Proxy3D->Palette;
1057 break;
1058 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1059 if (!ctx->Extensions.ARB_texture_cube_map) {
1060 _mesa_error(ctx, GL_INVALID_ENUM,
1061 "glGetColorTableParameteriv(target)");
1062 return;
1063 }
1064 table = &ctx->Texture.ProxyCubeMap->Palette;
1065 break;
1066 case GL_SHARED_TEXTURE_PALETTE_EXT:
1067 table = &ctx->Texture.Palette;
1068 break;
1069 case GL_COLOR_TABLE:
1070 table = &ctx->ColorTable[COLORTABLE_PRECONVOLUTION];
1071 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1072 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_PRECONVOLUTION];
1073 params[0] = (GLint) scale[0];
1074 params[1] = (GLint) scale[1];
1075 params[2] = (GLint) scale[2];
1076 params[3] = (GLint) scale[3];
1077 return;
1078 }
1079 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1080 GLfloat *bias = ctx->Pixel.ColorTableBias[COLORTABLE_PRECONVOLUTION];
1081 params[0] = (GLint) bias[0];
1082 params[1] = (GLint) bias[1];
1083 params[2] = (GLint) bias[2];
1084 params[3] = (GLint) bias[3];
1085 return;
1086 }
1087 break;
1088 case GL_PROXY_COLOR_TABLE:
1089 table = &ctx->ProxyColorTable[COLORTABLE_PRECONVOLUTION];
1090 break;
1091 case GL_TEXTURE_COLOR_TABLE_SGI:
1092 if (!ctx->Extensions.SGI_texture_color_table) {
1093 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1094 return;
1095 }
1096 table = &(texUnit->ColorTable);
1097 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1098 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
1099 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
1100 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
1101 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
1102 return;
1103 }
1104 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1105 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
1106 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
1107 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
1108 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
1109 return;
1110 }
1111 break;
1112 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1113 if (!ctx->Extensions.SGI_texture_color_table) {
1114 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1115 return;
1116 }
1117 table = &(texUnit->ProxyColorTable);
1118 break;
1119 case GL_POST_CONVOLUTION_COLOR_TABLE:
1120 table = &ctx->ColorTable[COLORTABLE_POSTCONVOLUTION];
1121 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1122 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCONVOLUTION];
1123 params[0] = (GLint) scale[0];
1124 params[1] = (GLint) scale[1];
1125 params[2] = (GLint) scale[2];
1126 params[3] = (GLint) scale[3];
1127 return;
1128 }
1129 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1130 GLfloat *bias = ctx->Pixel.ColorTableBias[COLORTABLE_POSTCONVOLUTION];
1131 params[0] = (GLint) bias[0];
1132 params[1] = (GLint) bias[1];
1133 params[2] = (GLint) bias[2];
1134 params[3] = (GLint) bias[3];
1135 return;
1136 }
1137 break;
1138 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1139 table = &ctx->ProxyColorTable[COLORTABLE_POSTCONVOLUTION];
1140 break;
1141 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1142 table = &ctx->ColorTable[COLORTABLE_POSTCOLORMATRIX];
1143 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1144 GLfloat *scale = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
1145 params[0] = (GLint) scale[0];
1146 params[0] = (GLint) scale[1];
1147 params[0] = (GLint) scale[2];
1148 params[0] = (GLint) scale[3];
1149 return;
1150 }
1151 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1152 GLfloat *bias = ctx->Pixel.ColorTableScale[COLORTABLE_POSTCOLORMATRIX];
1153 params[0] = (GLint) bias[0];
1154 params[1] = (GLint) bias[1];
1155 params[2] = (GLint) bias[2];
1156 params[3] = (GLint) bias[3];
1157 return;
1158 }
1159 break;
1160 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1161 table = &ctx->ProxyColorTable[COLORTABLE_POSTCOLORMATRIX];
1162 break;
1163 default:
1164 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1165 return;
1166 }
1167
1168 assert(table);
1169
1170 switch (pname) {
1171 case GL_COLOR_TABLE_FORMAT:
1172 *params = table->InternalFormat;
1173 break;
1174 case GL_COLOR_TABLE_WIDTH:
1175 *params = table->Size;
1176 break;
1177 case GL_COLOR_TABLE_RED_SIZE:
1178 *params = table->RedSize;
1179 break;
1180 case GL_COLOR_TABLE_GREEN_SIZE:
1181 *params = table->GreenSize;
1182 break;
1183 case GL_COLOR_TABLE_BLUE_SIZE:
1184 *params = table->BlueSize;
1185 break;
1186 case GL_COLOR_TABLE_ALPHA_SIZE:
1187 *params = table->AlphaSize;
1188 break;
1189 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1190 *params = table->LuminanceSize;
1191 break;
1192 case GL_COLOR_TABLE_INTENSITY_SIZE:
1193 *params = table->IntensitySize;
1194 break;
1195 default:
1196 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1197 return;
1198 }
1199 }
1200
1201 /**********************************************************************/
1202 /***** Initialization *****/
1203 /**********************************************************************/
1204
1205
1206 void
1207 _mesa_init_colortable( struct gl_color_table *p )
1208 {
1209 p->TableF = NULL;
1210 p->TableUB = NULL;
1211 p->Size = 0;
1212 p->InternalFormat = GL_RGBA;
1213 }
1214
1215
1216
1217 void
1218 _mesa_free_colortable_data( struct gl_color_table *p )
1219 {
1220 if (p->TableF) {
1221 _mesa_free(p->TableF);
1222 p->TableF = NULL;
1223 }
1224 if (p->TableUB) {
1225 _mesa_free(p->TableUB);
1226 p->TableUB = NULL;
1227 }
1228 }
1229
1230
1231 /*
1232 * Initialize all colortables for a context.
1233 */
1234 void
1235 _mesa_init_colortables( GLcontext * ctx )
1236 {
1237 GLuint i;
1238 for (i = 0; i < COLORTABLE_MAX; i++) {
1239 _mesa_init_colortable(&ctx->ColorTable[i]);
1240 _mesa_init_colortable(&ctx->ProxyColorTable[i]);
1241 }
1242 }
1243
1244
1245 /*
1246 * Free all colortable data for a context
1247 */
1248 void
1249 _mesa_free_colortables_data( GLcontext *ctx )
1250 {
1251 GLuint i;
1252 for (i = 0; i < COLORTABLE_MAX; i++) {
1253 _mesa_free_colortable_data(&ctx->ColorTable[i]);
1254 _mesa_free_colortable_data(&ctx->ProxyColorTable[i]);
1255 }
1256 }