in _mesa_GetColorTable, return silently if table size is 0
[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 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 = (GLfloat *) _mesa_malloc(comps * width * sizeof(GLfloat));
476 table->TableUB = (GLubyte *) _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 if (table->Size <= 0) {
726 return;
727 }
728
729 switch (table->_BaseFormat) {
730 case GL_ALPHA:
731 {
732 GLuint i;
733 for (i = 0; i < table->Size; i++) {
734 rgba[i][RCOMP] = 0;
735 rgba[i][GCOMP] = 0;
736 rgba[i][BCOMP] = 0;
737 rgba[i][ACOMP] = table->TableF[i];
738 }
739 }
740 break;
741 case GL_LUMINANCE:
742 {
743 GLuint i;
744 for (i = 0; i < table->Size; i++) {
745 rgba[i][RCOMP] =
746 rgba[i][GCOMP] =
747 rgba[i][BCOMP] = table->TableF[i];
748 rgba[i][ACOMP] = 1.0F;
749 }
750 }
751 break;
752 case GL_LUMINANCE_ALPHA:
753 {
754 GLuint i;
755 for (i = 0; i < table->Size; i++) {
756 rgba[i][RCOMP] =
757 rgba[i][GCOMP] =
758 rgba[i][BCOMP] = table->TableF[i*2+0];
759 rgba[i][ACOMP] = table->TableF[i*2+1];
760 }
761 }
762 break;
763 case GL_INTENSITY:
764 {
765 GLuint i;
766 for (i = 0; i < table->Size; i++) {
767 rgba[i][RCOMP] =
768 rgba[i][GCOMP] =
769 rgba[i][BCOMP] =
770 rgba[i][ACOMP] = table->TableF[i];
771 }
772 }
773 break;
774 case GL_RGB:
775 {
776 GLuint i;
777 for (i = 0; i < table->Size; i++) {
778 rgba[i][RCOMP] = table->TableF[i*3+0];
779 rgba[i][GCOMP] = table->TableF[i*3+1];
780 rgba[i][BCOMP] = table->TableF[i*3+2];
781 rgba[i][ACOMP] = 1.0F;
782 }
783 }
784 break;
785 case GL_RGBA:
786 _mesa_memcpy(rgba, table->TableF, 4 * table->Size * sizeof(GLfloat));
787 break;
788 default:
789 _mesa_problem(ctx, "bad table format in glGetColorTable");
790 return;
791 }
792
793 if (ctx->Pack.BufferObj->Name) {
794 /* pack color table into PBO */
795 GLubyte *buf;
796 if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
797 format, type, data)) {
798 _mesa_error(ctx, GL_INVALID_OPERATION,
799 "glGetColorTable(invalid PBO access)");
800 return;
801 }
802 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
803 GL_WRITE_ONLY_ARB,
804 ctx->Pack.BufferObj);
805 if (!buf) {
806 /* buffer is already mapped - that's an error */
807 _mesa_error(ctx, GL_INVALID_OPERATION,
808 "glGetColorTable(PBO is mapped)");
809 return;
810 }
811 data = ADD_POINTERS(buf, data);
812 }
813
814 _mesa_pack_rgba_span_float(ctx, table->Size, rgba,
815 format, type, data, &ctx->Pack, 0x0);
816
817 if (ctx->Pack.BufferObj->Name) {
818 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
819 ctx->Pack.BufferObj);
820 }
821 }
822
823
824
825 void GLAPIENTRY
826 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
827 {
828 GET_CURRENT_CONTEXT(ctx);
829 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
830
831 switch (target) {
832 case GL_COLOR_TABLE_SGI:
833 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
834 ctx->Pixel.ColorTableScale[0] = params[0];
835 ctx->Pixel.ColorTableScale[1] = params[1];
836 ctx->Pixel.ColorTableScale[2] = params[2];
837 ctx->Pixel.ColorTableScale[3] = params[3];
838 }
839 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
840 ctx->Pixel.ColorTableBias[0] = params[0];
841 ctx->Pixel.ColorTableBias[1] = params[1];
842 ctx->Pixel.ColorTableBias[2] = params[2];
843 ctx->Pixel.ColorTableBias[3] = params[3];
844 }
845 else {
846 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
847 return;
848 }
849 break;
850 case GL_TEXTURE_COLOR_TABLE_SGI:
851 if (!ctx->Extensions.SGI_texture_color_table) {
852 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
853 return;
854 }
855 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
856 ctx->Pixel.TextureColorTableScale[0] = params[0];
857 ctx->Pixel.TextureColorTableScale[1] = params[1];
858 ctx->Pixel.TextureColorTableScale[2] = params[2];
859 ctx->Pixel.TextureColorTableScale[3] = params[3];
860 }
861 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
862 ctx->Pixel.TextureColorTableBias[0] = params[0];
863 ctx->Pixel.TextureColorTableBias[1] = params[1];
864 ctx->Pixel.TextureColorTableBias[2] = params[2];
865 ctx->Pixel.TextureColorTableBias[3] = params[3];
866 }
867 else {
868 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
869 return;
870 }
871 break;
872 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
873 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
874 ctx->Pixel.PCCTscale[0] = params[0];
875 ctx->Pixel.PCCTscale[1] = params[1];
876 ctx->Pixel.PCCTscale[2] = params[2];
877 ctx->Pixel.PCCTscale[3] = params[3];
878 }
879 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
880 ctx->Pixel.PCCTbias[0] = params[0];
881 ctx->Pixel.PCCTbias[1] = params[1];
882 ctx->Pixel.PCCTbias[2] = params[2];
883 ctx->Pixel.PCCTbias[3] = params[3];
884 }
885 else {
886 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
887 return;
888 }
889 break;
890 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
891 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
892 ctx->Pixel.PCMCTscale[0] = params[0];
893 ctx->Pixel.PCMCTscale[1] = params[1];
894 ctx->Pixel.PCMCTscale[2] = params[2];
895 ctx->Pixel.PCMCTscale[3] = params[3];
896 }
897 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
898 ctx->Pixel.PCMCTbias[0] = params[0];
899 ctx->Pixel.PCMCTbias[1] = params[1];
900 ctx->Pixel.PCMCTbias[2] = params[2];
901 ctx->Pixel.PCMCTbias[3] = params[3];
902 }
903 else {
904 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
905 return;
906 }
907 break;
908 default:
909 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
910 return;
911 }
912
913 ctx->NewState |= _NEW_PIXEL;
914 }
915
916
917
918 void GLAPIENTRY
919 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
920 {
921 GLfloat fparams[4];
922 if (pname == GL_COLOR_TABLE_SGI ||
923 pname == GL_TEXTURE_COLOR_TABLE_SGI ||
924 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
925 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
926 /* four values */
927 fparams[0] = (GLfloat) params[0];
928 fparams[1] = (GLfloat) params[1];
929 fparams[2] = (GLfloat) params[2];
930 fparams[3] = (GLfloat) params[3];
931 }
932 else {
933 /* one values */
934 fparams[0] = (GLfloat) params[0];
935 }
936 _mesa_ColorTableParameterfv(target, pname, fparams);
937 }
938
939
940
941 void GLAPIENTRY
942 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
943 {
944 GET_CURRENT_CONTEXT(ctx);
945 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
946 struct gl_color_table *table = NULL;
947 ASSERT_OUTSIDE_BEGIN_END(ctx);
948
949 switch (target) {
950 case GL_TEXTURE_1D:
951 table = &texUnit->Current1D->Palette;
952 break;
953 case GL_TEXTURE_2D:
954 table = &texUnit->Current2D->Palette;
955 break;
956 case GL_TEXTURE_3D:
957 table = &texUnit->Current3D->Palette;
958 break;
959 case GL_TEXTURE_CUBE_MAP_ARB:
960 if (!ctx->Extensions.ARB_texture_cube_map) {
961 _mesa_error(ctx, GL_INVALID_ENUM,
962 "glGetColorTableParameterfv(target)");
963 return;
964 }
965 table = &texUnit->CurrentCubeMap->Palette;
966 break;
967 case GL_PROXY_TEXTURE_1D:
968 table = &ctx->Texture.Proxy1D->Palette;
969 break;
970 case GL_PROXY_TEXTURE_2D:
971 table = &ctx->Texture.Proxy2D->Palette;
972 break;
973 case GL_PROXY_TEXTURE_3D:
974 table = &ctx->Texture.Proxy3D->Palette;
975 break;
976 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
977 if (!ctx->Extensions.ARB_texture_cube_map) {
978 _mesa_error(ctx, GL_INVALID_ENUM,
979 "glGetColorTableParameterfv(target)");
980 return;
981 }
982 table = &ctx->Texture.ProxyCubeMap->Palette;
983 break;
984 case GL_SHARED_TEXTURE_PALETTE_EXT:
985 table = &ctx->Texture.Palette;
986 break;
987 case GL_COLOR_TABLE:
988 table = &ctx->ColorTable;
989 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
990 params[0] = ctx->Pixel.ColorTableScale[0];
991 params[1] = ctx->Pixel.ColorTableScale[1];
992 params[2] = ctx->Pixel.ColorTableScale[2];
993 params[3] = ctx->Pixel.ColorTableScale[3];
994 return;
995 }
996 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
997 params[0] = ctx->Pixel.ColorTableBias[0];
998 params[1] = ctx->Pixel.ColorTableBias[1];
999 params[2] = ctx->Pixel.ColorTableBias[2];
1000 params[3] = ctx->Pixel.ColorTableBias[3];
1001 return;
1002 }
1003 break;
1004 case GL_PROXY_COLOR_TABLE:
1005 table = &ctx->ProxyColorTable;
1006 break;
1007 case GL_TEXTURE_COLOR_TABLE_SGI:
1008 if (!ctx->Extensions.SGI_texture_color_table) {
1009 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1010 return;
1011 }
1012 table = &(texUnit->ColorTable);
1013 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1014 params[0] = ctx->Pixel.TextureColorTableScale[0];
1015 params[1] = ctx->Pixel.TextureColorTableScale[1];
1016 params[2] = ctx->Pixel.TextureColorTableScale[2];
1017 params[3] = ctx->Pixel.TextureColorTableScale[3];
1018 return;
1019 }
1020 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1021 params[0] = ctx->Pixel.TextureColorTableBias[0];
1022 params[1] = ctx->Pixel.TextureColorTableBias[1];
1023 params[2] = ctx->Pixel.TextureColorTableBias[2];
1024 params[3] = ctx->Pixel.TextureColorTableBias[3];
1025 return;
1026 }
1027 break;
1028 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1029 if (!ctx->Extensions.SGI_texture_color_table) {
1030 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1031 return;
1032 }
1033 table = &(texUnit->ProxyColorTable);
1034 break;
1035 case GL_POST_CONVOLUTION_COLOR_TABLE:
1036 table = &ctx->PostConvolutionColorTable;
1037 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1038 params[0] = ctx->Pixel.PCCTscale[0];
1039 params[1] = ctx->Pixel.PCCTscale[1];
1040 params[2] = ctx->Pixel.PCCTscale[2];
1041 params[3] = ctx->Pixel.PCCTscale[3];
1042 return;
1043 }
1044 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1045 params[0] = ctx->Pixel.PCCTbias[0];
1046 params[1] = ctx->Pixel.PCCTbias[1];
1047 params[2] = ctx->Pixel.PCCTbias[2];
1048 params[3] = ctx->Pixel.PCCTbias[3];
1049 return;
1050 }
1051 break;
1052 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1053 table = &ctx->ProxyPostConvolutionColorTable;
1054 break;
1055 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1056 table = &ctx->PostColorMatrixColorTable;
1057 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1058 params[0] = ctx->Pixel.PCMCTscale[0];
1059 params[1] = ctx->Pixel.PCMCTscale[1];
1060 params[2] = ctx->Pixel.PCMCTscale[2];
1061 params[3] = ctx->Pixel.PCMCTscale[3];
1062 return;
1063 }
1064 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1065 params[0] = ctx->Pixel.PCMCTbias[0];
1066 params[1] = ctx->Pixel.PCMCTbias[1];
1067 params[2] = ctx->Pixel.PCMCTbias[2];
1068 params[3] = ctx->Pixel.PCMCTbias[3];
1069 return;
1070 }
1071 break;
1072 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1073 table = &ctx->ProxyPostColorMatrixColorTable;
1074 break;
1075 default:
1076 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
1077 return;
1078 }
1079
1080 assert(table);
1081
1082 switch (pname) {
1083 case GL_COLOR_TABLE_FORMAT:
1084 *params = (GLfloat) table->InternalFormat;
1085 break;
1086 case GL_COLOR_TABLE_WIDTH:
1087 *params = (GLfloat) table->Size;
1088 break;
1089 case GL_COLOR_TABLE_RED_SIZE:
1090 *params = (GLfloat) table->RedSize;
1091 break;
1092 case GL_COLOR_TABLE_GREEN_SIZE:
1093 *params = (GLfloat) table->GreenSize;
1094 break;
1095 case GL_COLOR_TABLE_BLUE_SIZE:
1096 *params = (GLfloat) table->BlueSize;
1097 break;
1098 case GL_COLOR_TABLE_ALPHA_SIZE:
1099 *params = (GLfloat) table->AlphaSize;
1100 break;
1101 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1102 *params = (GLfloat) table->LuminanceSize;
1103 break;
1104 case GL_COLOR_TABLE_INTENSITY_SIZE:
1105 *params = (GLfloat) table->IntensitySize;
1106 break;
1107 default:
1108 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
1109 return;
1110 }
1111 }
1112
1113
1114
1115 void GLAPIENTRY
1116 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
1117 {
1118 GET_CURRENT_CONTEXT(ctx);
1119 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1120 struct gl_color_table *table = NULL;
1121 ASSERT_OUTSIDE_BEGIN_END(ctx);
1122
1123 switch (target) {
1124 case GL_TEXTURE_1D:
1125 table = &texUnit->Current1D->Palette;
1126 break;
1127 case GL_TEXTURE_2D:
1128 table = &texUnit->Current2D->Palette;
1129 break;
1130 case GL_TEXTURE_3D:
1131 table = &texUnit->Current3D->Palette;
1132 break;
1133 case GL_TEXTURE_CUBE_MAP_ARB:
1134 if (!ctx->Extensions.ARB_texture_cube_map) {
1135 _mesa_error(ctx, GL_INVALID_ENUM,
1136 "glGetColorTableParameteriv(target)");
1137 return;
1138 }
1139 table = &texUnit->CurrentCubeMap->Palette;
1140 break;
1141 case GL_PROXY_TEXTURE_1D:
1142 table = &ctx->Texture.Proxy1D->Palette;
1143 break;
1144 case GL_PROXY_TEXTURE_2D:
1145 table = &ctx->Texture.Proxy2D->Palette;
1146 break;
1147 case GL_PROXY_TEXTURE_3D:
1148 table = &ctx->Texture.Proxy3D->Palette;
1149 break;
1150 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1151 if (!ctx->Extensions.ARB_texture_cube_map) {
1152 _mesa_error(ctx, GL_INVALID_ENUM,
1153 "glGetColorTableParameteriv(target)");
1154 return;
1155 }
1156 table = &ctx->Texture.ProxyCubeMap->Palette;
1157 break;
1158 case GL_SHARED_TEXTURE_PALETTE_EXT:
1159 table = &ctx->Texture.Palette;
1160 break;
1161 case GL_COLOR_TABLE:
1162 table = &ctx->ColorTable;
1163 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1164 params[0] = (GLint) ctx->Pixel.ColorTableScale[0];
1165 params[1] = (GLint) ctx->Pixel.ColorTableScale[1];
1166 params[2] = (GLint) ctx->Pixel.ColorTableScale[2];
1167 params[3] = (GLint) ctx->Pixel.ColorTableScale[3];
1168 return;
1169 }
1170 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1171 params[0] = (GLint) ctx->Pixel.ColorTableBias[0];
1172 params[1] = (GLint) ctx->Pixel.ColorTableBias[1];
1173 params[2] = (GLint) ctx->Pixel.ColorTableBias[2];
1174 params[3] = (GLint) ctx->Pixel.ColorTableBias[3];
1175 return;
1176 }
1177 break;
1178 case GL_PROXY_COLOR_TABLE:
1179 table = &ctx->ProxyColorTable;
1180 break;
1181 case GL_TEXTURE_COLOR_TABLE_SGI:
1182 if (!ctx->Extensions.SGI_texture_color_table) {
1183 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1184 return;
1185 }
1186 table = &(texUnit->ColorTable);
1187 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1188 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
1189 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
1190 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
1191 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
1192 return;
1193 }
1194 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1195 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
1196 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
1197 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
1198 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
1199 return;
1200 }
1201 break;
1202 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1203 if (!ctx->Extensions.SGI_texture_color_table) {
1204 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1205 return;
1206 }
1207 table = &(texUnit->ProxyColorTable);
1208 break;
1209 case GL_POST_CONVOLUTION_COLOR_TABLE:
1210 table = &ctx->PostConvolutionColorTable;
1211 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1212 params[0] = (GLint) ctx->Pixel.PCCTscale[0];
1213 params[1] = (GLint) ctx->Pixel.PCCTscale[1];
1214 params[2] = (GLint) ctx->Pixel.PCCTscale[2];
1215 params[3] = (GLint) ctx->Pixel.PCCTscale[3];
1216 return;
1217 }
1218 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1219 params[0] = (GLint) ctx->Pixel.PCCTbias[0];
1220 params[1] = (GLint) ctx->Pixel.PCCTbias[1];
1221 params[2] = (GLint) ctx->Pixel.PCCTbias[2];
1222 params[3] = (GLint) ctx->Pixel.PCCTbias[3];
1223 return;
1224 }
1225 break;
1226 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1227 table = &ctx->ProxyPostConvolutionColorTable;
1228 break;
1229 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1230 table = &ctx->PostColorMatrixColorTable;
1231 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1232 params[0] = (GLint) ctx->Pixel.PCMCTscale[0];
1233 params[1] = (GLint) ctx->Pixel.PCMCTscale[1];
1234 params[2] = (GLint) ctx->Pixel.PCMCTscale[2];
1235 params[3] = (GLint) ctx->Pixel.PCMCTscale[3];
1236 return;
1237 }
1238 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1239 params[0] = (GLint) ctx->Pixel.PCMCTbias[0];
1240 params[1] = (GLint) ctx->Pixel.PCMCTbias[1];
1241 params[2] = (GLint) ctx->Pixel.PCMCTbias[2];
1242 params[3] = (GLint) ctx->Pixel.PCMCTbias[3];
1243 return;
1244 }
1245 break;
1246 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1247 table = &ctx->ProxyPostColorMatrixColorTable;
1248 break;
1249 default:
1250 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1251 return;
1252 }
1253
1254 assert(table);
1255
1256 switch (pname) {
1257 case GL_COLOR_TABLE_FORMAT:
1258 *params = table->InternalFormat;
1259 break;
1260 case GL_COLOR_TABLE_WIDTH:
1261 *params = table->Size;
1262 break;
1263 case GL_COLOR_TABLE_RED_SIZE:
1264 *params = table->RedSize;
1265 break;
1266 case GL_COLOR_TABLE_GREEN_SIZE:
1267 *params = table->GreenSize;
1268 break;
1269 case GL_COLOR_TABLE_BLUE_SIZE:
1270 *params = table->BlueSize;
1271 break;
1272 case GL_COLOR_TABLE_ALPHA_SIZE:
1273 *params = table->AlphaSize;
1274 break;
1275 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1276 *params = table->LuminanceSize;
1277 break;
1278 case GL_COLOR_TABLE_INTENSITY_SIZE:
1279 *params = table->IntensitySize;
1280 break;
1281 default:
1282 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1283 return;
1284 }
1285 }
1286
1287 /**********************************************************************/
1288 /***** Initialization *****/
1289 /**********************************************************************/
1290
1291
1292 void
1293 _mesa_init_colortable( struct gl_color_table *p )
1294 {
1295 p->TableF = NULL;
1296 p->TableUB = NULL;
1297 p->Size = 0;
1298 p->InternalFormat = GL_RGBA;
1299 }
1300
1301
1302
1303 void
1304 _mesa_free_colortable_data( struct gl_color_table *p )
1305 {
1306 if (p->TableF) {
1307 _mesa_free(p->TableF);
1308 p->TableF = NULL;
1309 }
1310 if (p->TableUB) {
1311 _mesa_free(p->TableUB);
1312 p->TableUB = NULL;
1313 }
1314 }
1315
1316
1317 /*
1318 * Initialize all colortables for a context.
1319 */
1320 void
1321 _mesa_init_colortables( GLcontext * ctx )
1322 {
1323 /* Color tables */
1324 _mesa_init_colortable(&ctx->ColorTable);
1325 _mesa_init_colortable(&ctx->ProxyColorTable);
1326 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1327 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1328 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1329 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
1330 }
1331
1332
1333 /*
1334 * Free all colortable data for a context
1335 */
1336 void
1337 _mesa_free_colortables_data( GLcontext *ctx )
1338 {
1339 _mesa_free_colortable_data(&ctx->ColorTable);
1340 _mesa_free_colortable_data(&ctx->ProxyColorTable);
1341 _mesa_free_colortable_data(&ctx->PostConvolutionColorTable);
1342 _mesa_free_colortable_data(&ctx->ProxyPostConvolutionColorTable);
1343 _mesa_free_colortable_data(&ctx->PostColorMatrixColorTable);
1344 _mesa_free_colortable_data(&ctx->ProxyPostColorMatrixColorTable);
1345 }