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