Move the fp_machine struct into s_nvfragmprog.c since (except for program
[mesa.git] / src / mesa / main / colortab.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 6.5
4 *
5 * Copyright (C) 1999-2005 Brian Paul All Rights Reserved.
6 *
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
13 *
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25
26 #include "glheader.h"
27 #include "bufferobj.h"
28 #include "colortab.h"
29 #include "context.h"
30 #include "image.h"
31 #include "macros.h"
32 #include "state.h"
33
34
35 /*
36 * Given an internalFormat token passed to glColorTable,
37 * return the corresponding base format.
38 * Return -1 if invalid token.
39 */
40 static GLint
41 base_colortab_format( GLenum format )
42 {
43 switch (format) {
44 case GL_ALPHA:
45 case GL_ALPHA4:
46 case GL_ALPHA8:
47 case GL_ALPHA12:
48 case GL_ALPHA16:
49 return GL_ALPHA;
50 case GL_LUMINANCE:
51 case GL_LUMINANCE4:
52 case GL_LUMINANCE8:
53 case GL_LUMINANCE12:
54 case GL_LUMINANCE16:
55 return GL_LUMINANCE;
56 case GL_LUMINANCE_ALPHA:
57 case GL_LUMINANCE4_ALPHA4:
58 case GL_LUMINANCE6_ALPHA2:
59 case GL_LUMINANCE8_ALPHA8:
60 case GL_LUMINANCE12_ALPHA4:
61 case GL_LUMINANCE12_ALPHA12:
62 case GL_LUMINANCE16_ALPHA16:
63 return GL_LUMINANCE_ALPHA;
64 case GL_INTENSITY:
65 case GL_INTENSITY4:
66 case GL_INTENSITY8:
67 case GL_INTENSITY12:
68 case GL_INTENSITY16:
69 return GL_INTENSITY;
70 case GL_RGB:
71 case GL_R3_G3_B2:
72 case GL_RGB4:
73 case GL_RGB5:
74 case GL_RGB8:
75 case GL_RGB10:
76 case GL_RGB12:
77 case GL_RGB16:
78 return GL_RGB;
79 case GL_RGBA:
80 case GL_RGBA2:
81 case GL_RGBA4:
82 case GL_RGB5_A1:
83 case GL_RGBA8:
84 case GL_RGB10_A2:
85 case GL_RGBA12:
86 case GL_RGBA16:
87 return GL_RGBA;
88 default:
89 return -1; /* error */
90 }
91 }
92
93
94
95 /*
96 * Examine table's format and set the component sizes accordingly.
97 */
98 static void
99 set_component_sizes( struct gl_color_table *table )
100 {
101 GLubyte sz;
102
103 switch (table->Type) {
104 case GL_UNSIGNED_BYTE:
105 sz = 8 * sizeof(GLubyte);
106 break;
107 case GL_UNSIGNED_SHORT:
108 sz = 8 * sizeof(GLushort);
109 break;
110 case GL_FLOAT:
111 /* Don't actually return 32 here since that causes the conformance
112 * tests to blow up. Conform thinks the component is an integer,
113 * not a float.
114 */
115 sz = 8; /** 8 * sizeof(GLfloat); **/
116 break;
117 default:
118 _mesa_problem(NULL, "bad color table type in set_component_sizes 0x%x", table->Type);
119 return;
120 }
121
122 switch (table->_BaseFormat) {
123 case GL_ALPHA:
124 table->RedSize = 0;
125 table->GreenSize = 0;
126 table->BlueSize = 0;
127 table->AlphaSize = sz;
128 table->IntensitySize = 0;
129 table->LuminanceSize = 0;
130 break;
131 case GL_LUMINANCE:
132 table->RedSize = 0;
133 table->GreenSize = 0;
134 table->BlueSize = 0;
135 table->AlphaSize = 0;
136 table->IntensitySize = 0;
137 table->LuminanceSize = sz;
138 break;
139 case GL_LUMINANCE_ALPHA:
140 table->RedSize = 0;
141 table->GreenSize = 0;
142 table->BlueSize = 0;
143 table->AlphaSize = sz;
144 table->IntensitySize = 0;
145 table->LuminanceSize = sz;
146 break;
147 case GL_INTENSITY:
148 table->RedSize = 0;
149 table->GreenSize = 0;
150 table->BlueSize = 0;
151 table->AlphaSize = 0;
152 table->IntensitySize = sz;
153 table->LuminanceSize = 0;
154 break;
155 case GL_RGB:
156 table->RedSize = sz;
157 table->GreenSize = sz;
158 table->BlueSize = sz;
159 table->AlphaSize = 0;
160 table->IntensitySize = 0;
161 table->LuminanceSize = 0;
162 break;
163 case GL_RGBA:
164 table->RedSize = sz;
165 table->GreenSize = sz;
166 table->BlueSize = sz;
167 table->AlphaSize = sz;
168 table->IntensitySize = 0;
169 table->LuminanceSize = 0;
170 break;
171 default:
172 _mesa_problem(NULL, "unexpected format in set_component_sizes");
173 }
174 }
175
176
177
178 /**
179 * Update/replace all or part of a color table. Helper function
180 * used by _mesa_ColorTable() and _mesa_ColorSubTable().
181 * The table->Table buffer should already be allocated.
182 * \param start first entry to update
183 * \param count number of entries to update
184 * \param format format of user-provided table data
185 * \param type datatype of user-provided table data
186 * \param data user-provided table data
187 * \param [rgba]Scale - RGBA scale factors
188 * \param [rgba]Bias - RGBA bias factors
189 */
190 static void
191 store_colortable_entries(GLcontext *ctx, struct gl_color_table *table,
192 GLsizei start, GLsizei count,
193 GLenum format, GLenum type, const GLvoid *data,
194 GLfloat rScale, GLfloat rBias,
195 GLfloat gScale, GLfloat gBias,
196 GLfloat bScale, GLfloat bBias,
197 GLfloat aScale, GLfloat aBias)
198 {
199 if (ctx->Unpack.BufferObj->Name) {
200 /* Get/unpack the color table data from a PBO */
201 GLubyte *buf;
202 if (!_mesa_validate_pbo_access(1, &ctx->Unpack, count, 1, 1,
203 format, type, data)) {
204 _mesa_error(ctx, GL_INVALID_OPERATION,
205 "glColor[Sub]Table(bad PBO access)");
206 return;
207 }
208 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
209 GL_READ_ONLY_ARB,
210 ctx->Unpack.BufferObj);
211 if (!buf) {
212 _mesa_error(ctx, GL_INVALID_OPERATION,
213 "glColor[Sub]Table(PBO mapped)");
214 return;
215 }
216 data = ADD_POINTERS(buf, data);
217 }
218
219
220 if (table->Type == GL_FLOAT) {
221 /* convert user-provided data to GLfloat values */
222 GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4];
223 GLfloat *tableF;
224 GLint i;
225
226 _mesa_unpack_color_span_float(ctx,
227 count, /* number of pixels */
228 table->_BaseFormat, /* dest format */
229 tempTab, /* dest address */
230 format, type, /* src format/type */
231 data, /* src data */
232 &ctx->Unpack,
233 IMAGE_CLAMP_BIT); /* transfer ops */
234
235 /* the destination */
236 tableF = (GLfloat *) table->Table;
237
238 /* Apply scale & bias & clamp now */
239 switch (table->_BaseFormat) {
240 case GL_INTENSITY:
241 for (i = 0; i < count; i++) {
242 GLuint j = start + i;
243 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
244 }
245 break;
246 case GL_LUMINANCE:
247 for (i = 0; i < count; i++) {
248 GLuint j = start + i;
249 tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F);
250 }
251 break;
252 case GL_ALPHA:
253 for (i = 0; i < count; i++) {
254 GLuint j = start + i;
255 tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F);
256 }
257 break;
258 case GL_LUMINANCE_ALPHA:
259 for (i = 0; i < count; i++) {
260 GLuint j = start + i;
261 tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F);
262 tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F);
263 }
264 break;
265 case GL_RGB:
266 for (i = 0; i < count; i++) {
267 GLuint j = start + i;
268 tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F);
269 tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F);
270 tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F);
271 }
272 break;
273 case GL_RGBA:
274 for (i = 0; i < count; i++) {
275 GLuint j = start + i;
276 tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F);
277 tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F);
278 tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F);
279 tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F);
280 }
281 break;
282 default:
283 _mesa_problem(ctx, "Bad format in store_colortable_entries");
284 return;
285 }
286 }
287 else {
288 /* non-float (GLchan) */
289 const GLint comps = _mesa_components_in_format(table->_BaseFormat);
290 GLchan *dest = (GLchan *) table->Table + start * comps;
291 _mesa_unpack_color_span_chan(ctx, count, /* number of entries */
292 table->_BaseFormat, /* dest format */
293 dest, /* dest address */
294 format, type, data, /* src data */
295 &ctx->Unpack,
296 0); /* transfer ops */
297 }
298
299 if (ctx->Unpack.BufferObj->Name) {
300 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_UNPACK_BUFFER_EXT,
301 ctx->Unpack.BufferObj);
302 }
303 }
304
305
306
307 void GLAPIENTRY
308 _mesa_ColorTable( GLenum target, GLenum internalFormat,
309 GLsizei width, GLenum format, GLenum type,
310 const GLvoid *data )
311 {
312 GET_CURRENT_CONTEXT(ctx);
313 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
314 struct gl_texture_object *texObj = NULL;
315 struct gl_color_table *table = NULL;
316 GLboolean proxy = GL_FALSE;
317 GLint baseFormat;
318 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
319 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
320 GLenum tableType = CHAN_TYPE;
321 GLint comps;
322 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */
323
324 switch (target) {
325 case GL_TEXTURE_1D:
326 texObj = texUnit->Current1D;
327 table = &texObj->Palette;
328 break;
329 case GL_TEXTURE_2D:
330 texObj = texUnit->Current2D;
331 table = &texObj->Palette;
332 break;
333 case GL_TEXTURE_3D:
334 texObj = texUnit->Current3D;
335 table = &texObj->Palette;
336 break;
337 case GL_TEXTURE_CUBE_MAP_ARB:
338 if (!ctx->Extensions.ARB_texture_cube_map) {
339 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
340 return;
341 }
342 texObj = texUnit->CurrentCubeMap;
343 table = &texObj->Palette;
344 break;
345 case GL_PROXY_TEXTURE_1D:
346 texObj = ctx->Texture.Proxy1D;
347 table = &texObj->Palette;
348 proxy = GL_TRUE;
349 break;
350 case GL_PROXY_TEXTURE_2D:
351 texObj = ctx->Texture.Proxy2D;
352 table = &texObj->Palette;
353 proxy = GL_TRUE;
354 break;
355 case GL_PROXY_TEXTURE_3D:
356 texObj = ctx->Texture.Proxy3D;
357 table = &texObj->Palette;
358 proxy = GL_TRUE;
359 break;
360 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
361 if (!ctx->Extensions.ARB_texture_cube_map) {
362 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
363 return;
364 }
365 texObj = ctx->Texture.ProxyCubeMap;
366 table = &texObj->Palette;
367 break;
368 case GL_SHARED_TEXTURE_PALETTE_EXT:
369 table = &ctx->Texture.Palette;
370 tableType = GL_FLOAT;
371 break;
372 case GL_COLOR_TABLE:
373 table = &ctx->ColorTable;
374 tableType = GL_FLOAT;
375 rScale = ctx->Pixel.ColorTableScale[0];
376 gScale = ctx->Pixel.ColorTableScale[1];
377 bScale = ctx->Pixel.ColorTableScale[2];
378 aScale = ctx->Pixel.ColorTableScale[3];
379 rBias = ctx->Pixel.ColorTableBias[0];
380 gBias = ctx->Pixel.ColorTableBias[1];
381 bBias = ctx->Pixel.ColorTableBias[2];
382 aBias = ctx->Pixel.ColorTableBias[3];
383 break;
384 case GL_PROXY_COLOR_TABLE:
385 table = &ctx->ProxyColorTable;
386 proxy = GL_TRUE;
387 break;
388 case GL_TEXTURE_COLOR_TABLE_SGI:
389 if (!ctx->Extensions.SGI_texture_color_table) {
390 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
391 return;
392 }
393 table = &(texUnit->ColorTable);
394 tableType = GL_FLOAT;
395 rScale = ctx->Pixel.TextureColorTableScale[0];
396 gScale = ctx->Pixel.TextureColorTableScale[1];
397 bScale = ctx->Pixel.TextureColorTableScale[2];
398 aScale = ctx->Pixel.TextureColorTableScale[3];
399 rBias = ctx->Pixel.TextureColorTableBias[0];
400 gBias = ctx->Pixel.TextureColorTableBias[1];
401 bBias = ctx->Pixel.TextureColorTableBias[2];
402 aBias = ctx->Pixel.TextureColorTableBias[3];
403 break;
404 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
405 if (!ctx->Extensions.SGI_texture_color_table) {
406 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
407 return;
408 }
409 table = &(texUnit->ProxyColorTable);
410 tableType = GL_FLOAT;
411 proxy = GL_TRUE;
412 break;
413 case GL_POST_CONVOLUTION_COLOR_TABLE:
414 table = &ctx->PostConvolutionColorTable;
415 tableType = GL_FLOAT;
416 rScale = ctx->Pixel.PCCTscale[0];
417 gScale = ctx->Pixel.PCCTscale[1];
418 bScale = ctx->Pixel.PCCTscale[2];
419 aScale = ctx->Pixel.PCCTscale[3];
420 rBias = ctx->Pixel.PCCTbias[0];
421 gBias = ctx->Pixel.PCCTbias[1];
422 bBias = ctx->Pixel.PCCTbias[2];
423 aBias = ctx->Pixel.PCCTbias[3];
424 break;
425 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
426 table = &ctx->ProxyPostConvolutionColorTable;
427 tableType = GL_FLOAT;
428 proxy = GL_TRUE;
429 break;
430 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
431 table = &ctx->PostColorMatrixColorTable;
432 tableType = GL_FLOAT;
433 rScale = ctx->Pixel.PCMCTscale[0];
434 gScale = ctx->Pixel.PCMCTscale[1];
435 bScale = ctx->Pixel.PCMCTscale[2];
436 aScale = ctx->Pixel.PCMCTscale[3];
437 rBias = ctx->Pixel.PCMCTbias[0];
438 gBias = ctx->Pixel.PCMCTbias[1];
439 bBias = ctx->Pixel.PCMCTbias[2];
440 aBias = ctx->Pixel.PCMCTbias[3];
441 break;
442 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
443 table = &ctx->ProxyPostColorMatrixColorTable;
444 tableType = GL_FLOAT;
445 proxy = GL_TRUE;
446 break;
447 default:
448 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)");
449 return;
450 }
451
452 assert(table);
453
454 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
455 format == GL_INTENSITY) {
456 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)");
457 return;
458 }
459
460 baseFormat = base_colortab_format(internalFormat);
461 if (baseFormat < 0) {
462 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)");
463 return;
464 }
465
466 if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) {
467 /* error */
468 if (proxy) {
469 table->Size = 0;
470 table->InternalFormat = (GLenum) 0;
471 table->_BaseFormat = (GLenum) 0;
472 }
473 else {
474 _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width);
475 }
476 return;
477 }
478
479 if (width > (GLsizei) ctx->Const.MaxColorTableSize) {
480 if (proxy) {
481 table->Size = 0;
482 table->InternalFormat = (GLenum) 0;
483 table->_BaseFormat = (GLenum) 0;
484 }
485 else {
486 _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)");
487 }
488 return;
489 }
490
491 table->Size = width;
492 table->InternalFormat = internalFormat;
493 table->_BaseFormat = (GLenum) baseFormat;
494 table->Type = (tableType == GL_FLOAT) ? GL_FLOAT : CHAN_TYPE;
495
496 comps = _mesa_components_in_format(table->_BaseFormat);
497 assert(comps > 0); /* error should have been caught sooner */
498
499 if (!proxy) {
500 /* free old table, if any */
501 if (table->Table) {
502 FREE(table->Table);
503 table->Table = NULL;
504 }
505
506 if (width > 0) {
507 if (table->Type == GL_FLOAT) {
508 table->Table = MALLOC(comps * width * sizeof(GLfloat));
509 }
510 else {
511 table->Table = MALLOC(comps * width * sizeof(GLchan));
512 }
513
514 if (!table->Table) {
515 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable");
516 return;
517 }
518
519 store_colortable_entries(ctx, table,
520 0, width, /* start, count */
521 format, type, data,
522 rScale, rBias,
523 gScale, gBias,
524 bScale, bBias,
525 aScale, aBias);
526 }
527 } /* proxy */
528
529 /* do this after the table's Type and Format are set */
530 set_component_sizes(table);
531
532 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
533 /* texture object palette, texObj==NULL means the shared palette */
534 if (ctx->Driver.UpdateTexturePalette) {
535 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
536 }
537 }
538
539 ctx->NewState |= _NEW_PIXEL;
540 }
541
542
543
544 void GLAPIENTRY
545 _mesa_ColorSubTable( GLenum target, GLsizei start,
546 GLsizei count, GLenum format, GLenum type,
547 const GLvoid *data )
548 {
549 GET_CURRENT_CONTEXT(ctx);
550 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
551 struct gl_texture_object *texObj = NULL;
552 struct gl_color_table *table = NULL;
553 GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0;
554 GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0;
555 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
556
557 switch (target) {
558 case GL_TEXTURE_1D:
559 texObj = texUnit->Current1D;
560 table = &texObj->Palette;
561 break;
562 case GL_TEXTURE_2D:
563 texObj = texUnit->Current2D;
564 table = &texObj->Palette;
565 break;
566 case GL_TEXTURE_3D:
567 texObj = texUnit->Current3D;
568 table = &texObj->Palette;
569 break;
570 case GL_TEXTURE_CUBE_MAP_ARB:
571 if (!ctx->Extensions.ARB_texture_cube_map) {
572 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
573 return;
574 }
575 texObj = texUnit->CurrentCubeMap;
576 table = &texObj->Palette;
577 break;
578 case GL_SHARED_TEXTURE_PALETTE_EXT:
579 table = &ctx->Texture.Palette;
580 break;
581 case GL_COLOR_TABLE:
582 table = &ctx->ColorTable;
583 rScale = ctx->Pixel.ColorTableScale[0];
584 gScale = ctx->Pixel.ColorTableScale[1];
585 bScale = ctx->Pixel.ColorTableScale[2];
586 aScale = ctx->Pixel.ColorTableScale[3];
587 rBias = ctx->Pixel.ColorTableBias[0];
588 gBias = ctx->Pixel.ColorTableBias[1];
589 bBias = ctx->Pixel.ColorTableBias[2];
590 aBias = ctx->Pixel.ColorTableBias[3];
591 break;
592 case GL_TEXTURE_COLOR_TABLE_SGI:
593 if (!ctx->Extensions.SGI_texture_color_table) {
594 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
595 return;
596 }
597 table = &(texUnit->ColorTable);
598 rScale = ctx->Pixel.TextureColorTableScale[0];
599 gScale = ctx->Pixel.TextureColorTableScale[1];
600 bScale = ctx->Pixel.TextureColorTableScale[2];
601 aScale = ctx->Pixel.TextureColorTableScale[3];
602 rBias = ctx->Pixel.TextureColorTableBias[0];
603 gBias = ctx->Pixel.TextureColorTableBias[1];
604 bBias = ctx->Pixel.TextureColorTableBias[2];
605 aBias = ctx->Pixel.TextureColorTableBias[3];
606 break;
607 case GL_POST_CONVOLUTION_COLOR_TABLE:
608 table = &ctx->PostConvolutionColorTable;
609 rScale = ctx->Pixel.PCCTscale[0];
610 gScale = ctx->Pixel.PCCTscale[1];
611 bScale = ctx->Pixel.PCCTscale[2];
612 aScale = ctx->Pixel.PCCTscale[3];
613 rBias = ctx->Pixel.PCCTbias[0];
614 gBias = ctx->Pixel.PCCTbias[1];
615 bBias = ctx->Pixel.PCCTbias[2];
616 aBias = ctx->Pixel.PCCTbias[3];
617 break;
618 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
619 table = &ctx->PostColorMatrixColorTable;
620 rScale = ctx->Pixel.PCMCTscale[0];
621 gScale = ctx->Pixel.PCMCTscale[1];
622 bScale = ctx->Pixel.PCMCTscale[2];
623 aScale = ctx->Pixel.PCMCTscale[3];
624 rBias = ctx->Pixel.PCMCTbias[0];
625 gBias = ctx->Pixel.PCMCTbias[1];
626 bBias = ctx->Pixel.PCMCTbias[2];
627 aBias = ctx->Pixel.PCMCTbias[3];
628 break;
629 default:
630 _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)");
631 return;
632 }
633
634 assert(table);
635
636 if (!_mesa_is_legal_format_and_type(ctx, format, type) ||
637 format == GL_INTENSITY) {
638 _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)");
639 return;
640 }
641
642 if (count < 1) {
643 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
644 return;
645 }
646
647 /* error should have been caught sooner */
648 assert(_mesa_components_in_format(table->_BaseFormat) > 0);
649
650 if (start + count > (GLint) table->Size) {
651 _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)");
652 return;
653 }
654
655 if (!table->Table) {
656 _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable");
657 return;
658 }
659
660 store_colortable_entries(ctx, table, start, count,
661 format, type, data,
662 rScale, rBias,
663 gScale, gBias,
664 bScale, bBias,
665 aScale, aBias);
666
667 if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) {
668 /* per-texture object palette */
669 if (ctx->Driver.UpdateTexturePalette) {
670 (*ctx->Driver.UpdateTexturePalette)( ctx, texObj );
671 }
672 }
673
674 ctx->NewState |= _NEW_PIXEL;
675 }
676
677
678
679 void GLAPIENTRY
680 _mesa_CopyColorTable(GLenum target, GLenum internalformat,
681 GLint x, GLint y, GLsizei width)
682 {
683 GET_CURRENT_CONTEXT(ctx);
684 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
685
686 /* Select buffer to read from */
687 ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width );
688 }
689
690
691
692 void GLAPIENTRY
693 _mesa_CopyColorSubTable(GLenum target, GLsizei start,
694 GLint x, GLint y, GLsizei width)
695 {
696 GET_CURRENT_CONTEXT(ctx);
697 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
698
699 ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width );
700 }
701
702
703
704 void GLAPIENTRY
705 _mesa_GetColorTable( GLenum target, GLenum format,
706 GLenum type, GLvoid *data )
707 {
708 GET_CURRENT_CONTEXT(ctx);
709 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
710 struct gl_color_table *table = NULL;
711 GLchan rgba[MAX_COLOR_TABLE_SIZE][4];
712 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
713
714 if (ctx->NewState) {
715 _mesa_update_state(ctx);
716 }
717
718 switch (target) {
719 case GL_TEXTURE_1D:
720 table = &texUnit->Current1D->Palette;
721 break;
722 case GL_TEXTURE_2D:
723 table = &texUnit->Current2D->Palette;
724 break;
725 case GL_TEXTURE_3D:
726 table = &texUnit->Current3D->Palette;
727 break;
728 case GL_TEXTURE_CUBE_MAP_ARB:
729 if (!ctx->Extensions.ARB_texture_cube_map) {
730 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
731 return;
732 }
733 table = &texUnit->CurrentCubeMap->Palette;
734 break;
735 case GL_SHARED_TEXTURE_PALETTE_EXT:
736 table = &ctx->Texture.Palette;
737 break;
738 case GL_COLOR_TABLE:
739 table = &ctx->ColorTable;
740 break;
741 case GL_TEXTURE_COLOR_TABLE_SGI:
742 if (!ctx->Extensions.SGI_texture_color_table) {
743 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
744 return;
745 }
746 table = &(texUnit->ColorTable);
747 break;
748 case GL_POST_CONVOLUTION_COLOR_TABLE:
749 table = &ctx->PostConvolutionColorTable;
750 break;
751 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
752 table = &ctx->PostColorMatrixColorTable;
753 break;
754 default:
755 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)");
756 return;
757 }
758
759 ASSERT(table);
760
761 switch (table->_BaseFormat) {
762 case GL_ALPHA:
763 if (table->Type == GL_FLOAT) {
764 const GLfloat *tableF = (const GLfloat *) table->Table;
765 GLuint i;
766 for (i = 0; i < table->Size; i++) {
767 rgba[i][RCOMP] = 0;
768 rgba[i][GCOMP] = 0;
769 rgba[i][BCOMP] = 0;
770 #if CHAN_BITS==32
771 rgba[i][ACOMP] = tableF[i];
772 #else
773 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
774 #endif
775 }
776 }
777 else {
778 const GLchan *tableUB = (const GLchan *) table->Table;
779 GLuint i;
780 for (i = 0; i < table->Size; i++) {
781 rgba[i][RCOMP] = 0;
782 rgba[i][GCOMP] = 0;
783 rgba[i][BCOMP] = 0;
784 rgba[i][ACOMP] = tableUB[i];
785 }
786 }
787 break;
788 case GL_LUMINANCE:
789 if (table->Type == GL_FLOAT) {
790 const GLfloat *tableF = (const GLfloat *) table->Table;
791 GLuint i;
792 for (i = 0; i < table->Size; i++) {
793 #if CHAN_BITS==32
794 rgba[i][RCOMP] =
795 rgba[i][GCOMP] =
796 rgba[i][BCOMP] = tableF[i];
797 rgba[i][ACOMP] = CHAN_MAX;
798 #else
799 rgba[i][RCOMP] =
800 rgba[i][GCOMP] =
801 rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
802 rgba[i][ACOMP] = CHAN_MAX;
803 #endif
804 }
805 }
806 else {
807 const GLchan *tableUB = (const GLchan *) table->Table;
808 GLuint i;
809 for (i = 0; i < table->Size; i++) {
810 rgba[i][RCOMP] =
811 rgba[i][GCOMP] =
812 rgba[i][BCOMP] = tableUB[i];
813 rgba[i][ACOMP] = CHAN_MAX;
814 }
815 }
816 break;
817 case GL_LUMINANCE_ALPHA:
818 if (table->Type == GL_FLOAT) {
819 const GLfloat *tableF = (const GLfloat *) table->Table;
820 GLuint i;
821 for (i = 0; i < table->Size; i++) {
822 #if CHAN_BITS==32
823 rgba[i][RCOMP] =
824 rgba[i][GCOMP] =
825 rgba[i][BCOMP] = tableF[i*2+0];
826 rgba[i][ACOMP] = tableF[i*2+1];
827 #else
828 rgba[i][RCOMP] =
829 rgba[i][GCOMP] =
830 rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF);
831 rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF);
832 #endif
833 }
834 }
835 else {
836 const GLchan *tableUB = (const GLchan *) table->Table;
837 GLuint i;
838 for (i = 0; i < table->Size; i++) {
839 rgba[i][RCOMP] =
840 rgba[i][GCOMP] =
841 rgba[i][BCOMP] = tableUB[i*2+0];
842 rgba[i][ACOMP] = tableUB[i*2+1];
843 }
844 }
845 break;
846 case GL_INTENSITY:
847 if (table->Type == GL_FLOAT) {
848 const GLfloat *tableF = (const GLfloat *) table->Table;
849 GLuint i;
850 for (i = 0; i < table->Size; i++) {
851 #if CHAN_BITS==32
852 rgba[i][RCOMP] =
853 rgba[i][GCOMP] =
854 rgba[i][BCOMP] =
855 rgba[i][ACOMP] = tableF[i];
856 #else
857 rgba[i][RCOMP] =
858 rgba[i][GCOMP] =
859 rgba[i][BCOMP] =
860 rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF);
861 #endif
862 }
863 }
864 else {
865 const GLchan *tableUB = (const GLchan *) table->Table;
866 GLuint i;
867 for (i = 0; i < table->Size; i++) {
868 rgba[i][RCOMP] =
869 rgba[i][GCOMP] =
870 rgba[i][BCOMP] =
871 rgba[i][ACOMP] = tableUB[i];
872 }
873 }
874 break;
875 case GL_RGB:
876 if (table->Type == GL_FLOAT) {
877 const GLfloat *tableF = (const GLfloat *) table->Table;
878 GLuint i;
879 for (i = 0; i < table->Size; i++) {
880 #if CHAN_BITS==32
881 rgba[i][RCOMP] = tableF[i*3+0];
882 rgba[i][GCOMP] = tableF[i*3+1];
883 rgba[i][BCOMP] = tableF[i*3+2];
884 rgba[i][ACOMP] = CHAN_MAX;
885 #else
886 rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF);
887 rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF);
888 rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF);
889 rgba[i][ACOMP] = CHAN_MAX;
890 #endif
891 }
892 }
893 else {
894 const GLchan *tableUB = (const GLchan *) table->Table;
895 GLuint i;
896 for (i = 0; i < table->Size; i++) {
897 rgba[i][RCOMP] = tableUB[i*3+0];
898 rgba[i][GCOMP] = tableUB[i*3+1];
899 rgba[i][BCOMP] = tableUB[i*3+2];
900 rgba[i][ACOMP] = CHAN_MAX;
901 }
902 }
903 break;
904 case GL_RGBA:
905 if (table->Type == GL_FLOAT) {
906 const GLfloat *tableF = (const GLfloat *) table->Table;
907 #if CHAN_BITS==32
908 _mesa_memcpy(rgba, tableF, 4 * table->Size * sizeof(GLfloat));
909 #else
910 GLuint i;
911 for (i = 0; i < table->Size; i++) {
912 rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF);
913 rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF);
914 rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF);
915 rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF);
916 }
917 #endif
918 }
919 else {
920 const GLchan *tableUB = (const GLchan *) table->Table;
921 GLuint i;
922 for (i = 0; i < table->Size; i++) {
923 rgba[i][RCOMP] = tableUB[i*4+0];
924 rgba[i][GCOMP] = tableUB[i*4+1];
925 rgba[i][BCOMP] = tableUB[i*4+2];
926 rgba[i][ACOMP] = tableUB[i*4+3];
927 }
928 }
929 break;
930 default:
931 _mesa_problem(ctx, "bad table format in glGetColorTable");
932 return;
933 }
934
935 if (ctx->Pack.BufferObj->Name) {
936 /* pack color table into PBO */
937 GLubyte *buf;
938 if (!_mesa_validate_pbo_access(1, &ctx->Pack, table->Size, 1, 1,
939 format, type, data)) {
940 _mesa_error(ctx, GL_INVALID_OPERATION,
941 "glGetColorTable(invalid PBO access)");
942 return;
943 }
944 buf = (GLubyte *) ctx->Driver.MapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
945 GL_WRITE_ONLY_ARB,
946 ctx->Pack.BufferObj);
947 if (!buf) {
948 /* buffer is already mapped - that's an error */
949 _mesa_error(ctx, GL_INVALID_OPERATION,
950 "glGetColorTable(PBO is mapped)");
951 return;
952 }
953 data = ADD_POINTERS(buf, data);
954 }
955
956 _mesa_pack_rgba_span_chan(ctx, table->Size, (const GLchan (*)[4]) rgba,
957 format, type, data, &ctx->Pack, GL_FALSE);
958
959 if (ctx->Pack.BufferObj->Name) {
960 ctx->Driver.UnmapBuffer(ctx, GL_PIXEL_PACK_BUFFER_EXT,
961 ctx->Pack.BufferObj);
962 }
963 }
964
965
966
967 void GLAPIENTRY
968 _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params)
969 {
970 GET_CURRENT_CONTEXT(ctx);
971 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx);
972
973 switch (target) {
974 case GL_COLOR_TABLE_SGI:
975 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
976 ctx->Pixel.ColorTableScale[0] = params[0];
977 ctx->Pixel.ColorTableScale[1] = params[1];
978 ctx->Pixel.ColorTableScale[2] = params[2];
979 ctx->Pixel.ColorTableScale[3] = params[3];
980 }
981 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
982 ctx->Pixel.ColorTableBias[0] = params[0];
983 ctx->Pixel.ColorTableBias[1] = params[1];
984 ctx->Pixel.ColorTableBias[2] = params[2];
985 ctx->Pixel.ColorTableBias[3] = params[3];
986 }
987 else {
988 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
989 return;
990 }
991 break;
992 case GL_TEXTURE_COLOR_TABLE_SGI:
993 if (!ctx->Extensions.SGI_texture_color_table) {
994 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
995 return;
996 }
997 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
998 ctx->Pixel.TextureColorTableScale[0] = params[0];
999 ctx->Pixel.TextureColorTableScale[1] = params[1];
1000 ctx->Pixel.TextureColorTableScale[2] = params[2];
1001 ctx->Pixel.TextureColorTableScale[3] = params[3];
1002 }
1003 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1004 ctx->Pixel.TextureColorTableBias[0] = params[0];
1005 ctx->Pixel.TextureColorTableBias[1] = params[1];
1006 ctx->Pixel.TextureColorTableBias[2] = params[2];
1007 ctx->Pixel.TextureColorTableBias[3] = params[3];
1008 }
1009 else {
1010 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
1011 return;
1012 }
1013 break;
1014 case GL_POST_CONVOLUTION_COLOR_TABLE_SGI:
1015 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1016 ctx->Pixel.PCCTscale[0] = params[0];
1017 ctx->Pixel.PCCTscale[1] = params[1];
1018 ctx->Pixel.PCCTscale[2] = params[2];
1019 ctx->Pixel.PCCTscale[3] = params[3];
1020 }
1021 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1022 ctx->Pixel.PCCTbias[0] = params[0];
1023 ctx->Pixel.PCCTbias[1] = params[1];
1024 ctx->Pixel.PCCTbias[2] = params[2];
1025 ctx->Pixel.PCCTbias[3] = params[3];
1026 }
1027 else {
1028 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
1029 return;
1030 }
1031 break;
1032 case GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI:
1033 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1034 ctx->Pixel.PCMCTscale[0] = params[0];
1035 ctx->Pixel.PCMCTscale[1] = params[1];
1036 ctx->Pixel.PCMCTscale[2] = params[2];
1037 ctx->Pixel.PCMCTscale[3] = params[3];
1038 }
1039 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1040 ctx->Pixel.PCMCTbias[0] = params[0];
1041 ctx->Pixel.PCMCTbias[1] = params[1];
1042 ctx->Pixel.PCMCTbias[2] = params[2];
1043 ctx->Pixel.PCMCTbias[3] = params[3];
1044 }
1045 else {
1046 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameterfv(pname)");
1047 return;
1048 }
1049 break;
1050 default:
1051 _mesa_error(ctx, GL_INVALID_ENUM, "glColorTableParameter(target)");
1052 return;
1053 }
1054
1055 ctx->NewState |= _NEW_PIXEL;
1056 }
1057
1058
1059
1060 void GLAPIENTRY
1061 _mesa_ColorTableParameteriv(GLenum target, GLenum pname, const GLint *params)
1062 {
1063 GLfloat fparams[4];
1064 if (pname == GL_COLOR_TABLE_SGI ||
1065 pname == GL_TEXTURE_COLOR_TABLE_SGI ||
1066 pname == GL_POST_CONVOLUTION_COLOR_TABLE_SGI ||
1067 pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) {
1068 /* four values */
1069 fparams[0] = (GLfloat) params[0];
1070 fparams[1] = (GLfloat) params[1];
1071 fparams[2] = (GLfloat) params[2];
1072 fparams[3] = (GLfloat) params[3];
1073 }
1074 else {
1075 /* one values */
1076 fparams[0] = (GLfloat) params[0];
1077 }
1078 _mesa_ColorTableParameterfv(target, pname, fparams);
1079 }
1080
1081
1082
1083 void GLAPIENTRY
1084 _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params )
1085 {
1086 GET_CURRENT_CONTEXT(ctx);
1087 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1088 struct gl_color_table *table = NULL;
1089 ASSERT_OUTSIDE_BEGIN_END(ctx);
1090
1091 switch (target) {
1092 case GL_TEXTURE_1D:
1093 table = &texUnit->Current1D->Palette;
1094 break;
1095 case GL_TEXTURE_2D:
1096 table = &texUnit->Current2D->Palette;
1097 break;
1098 case GL_TEXTURE_3D:
1099 table = &texUnit->Current3D->Palette;
1100 break;
1101 case GL_TEXTURE_CUBE_MAP_ARB:
1102 if (!ctx->Extensions.ARB_texture_cube_map) {
1103 _mesa_error(ctx, GL_INVALID_ENUM,
1104 "glGetColorTableParameterfv(target)");
1105 return;
1106 }
1107 table = &texUnit->CurrentCubeMap->Palette;
1108 break;
1109 case GL_PROXY_TEXTURE_1D:
1110 table = &ctx->Texture.Proxy1D->Palette;
1111 break;
1112 case GL_PROXY_TEXTURE_2D:
1113 table = &ctx->Texture.Proxy2D->Palette;
1114 break;
1115 case GL_PROXY_TEXTURE_3D:
1116 table = &ctx->Texture.Proxy3D->Palette;
1117 break;
1118 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1119 if (!ctx->Extensions.ARB_texture_cube_map) {
1120 _mesa_error(ctx, GL_INVALID_ENUM,
1121 "glGetColorTableParameterfv(target)");
1122 return;
1123 }
1124 table = &ctx->Texture.ProxyCubeMap->Palette;
1125 break;
1126 case GL_SHARED_TEXTURE_PALETTE_EXT:
1127 table = &ctx->Texture.Palette;
1128 break;
1129 case GL_COLOR_TABLE:
1130 table = &ctx->ColorTable;
1131 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1132 params[0] = ctx->Pixel.ColorTableScale[0];
1133 params[1] = ctx->Pixel.ColorTableScale[1];
1134 params[2] = ctx->Pixel.ColorTableScale[2];
1135 params[3] = ctx->Pixel.ColorTableScale[3];
1136 return;
1137 }
1138 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1139 params[0] = ctx->Pixel.ColorTableBias[0];
1140 params[1] = ctx->Pixel.ColorTableBias[1];
1141 params[2] = ctx->Pixel.ColorTableBias[2];
1142 params[3] = ctx->Pixel.ColorTableBias[3];
1143 return;
1144 }
1145 break;
1146 case GL_PROXY_COLOR_TABLE:
1147 table = &ctx->ProxyColorTable;
1148 break;
1149 case GL_TEXTURE_COLOR_TABLE_SGI:
1150 if (!ctx->Extensions.SGI_texture_color_table) {
1151 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1152 return;
1153 }
1154 table = &(texUnit->ColorTable);
1155 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1156 params[0] = ctx->Pixel.TextureColorTableScale[0];
1157 params[1] = ctx->Pixel.TextureColorTableScale[1];
1158 params[2] = ctx->Pixel.TextureColorTableScale[2];
1159 params[3] = ctx->Pixel.TextureColorTableScale[3];
1160 return;
1161 }
1162 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1163 params[0] = ctx->Pixel.TextureColorTableBias[0];
1164 params[1] = ctx->Pixel.TextureColorTableBias[1];
1165 params[2] = ctx->Pixel.TextureColorTableBias[2];
1166 params[3] = ctx->Pixel.TextureColorTableBias[3];
1167 return;
1168 }
1169 break;
1170 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1171 if (!ctx->Extensions.SGI_texture_color_table) {
1172 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1173 return;
1174 }
1175 table = &(texUnit->ProxyColorTable);
1176 break;
1177 case GL_POST_CONVOLUTION_COLOR_TABLE:
1178 table = &ctx->PostConvolutionColorTable;
1179 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1180 params[0] = ctx->Pixel.PCCTscale[0];
1181 params[1] = ctx->Pixel.PCCTscale[1];
1182 params[2] = ctx->Pixel.PCCTscale[2];
1183 params[3] = ctx->Pixel.PCCTscale[3];
1184 return;
1185 }
1186 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1187 params[0] = ctx->Pixel.PCCTbias[0];
1188 params[1] = ctx->Pixel.PCCTbias[1];
1189 params[2] = ctx->Pixel.PCCTbias[2];
1190 params[3] = ctx->Pixel.PCCTbias[3];
1191 return;
1192 }
1193 break;
1194 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1195 table = &ctx->ProxyPostConvolutionColorTable;
1196 break;
1197 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1198 table = &ctx->PostColorMatrixColorTable;
1199 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1200 params[0] = ctx->Pixel.PCMCTscale[0];
1201 params[1] = ctx->Pixel.PCMCTscale[1];
1202 params[2] = ctx->Pixel.PCMCTscale[2];
1203 params[3] = ctx->Pixel.PCMCTscale[3];
1204 return;
1205 }
1206 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1207 params[0] = ctx->Pixel.PCMCTbias[0];
1208 params[1] = ctx->Pixel.PCMCTbias[1];
1209 params[2] = ctx->Pixel.PCMCTbias[2];
1210 params[3] = ctx->Pixel.PCMCTbias[3];
1211 return;
1212 }
1213 break;
1214 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1215 table = &ctx->ProxyPostColorMatrixColorTable;
1216 break;
1217 default:
1218 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)");
1219 return;
1220 }
1221
1222 assert(table);
1223
1224 switch (pname) {
1225 case GL_COLOR_TABLE_FORMAT:
1226 *params = (GLfloat) table->InternalFormat;
1227 break;
1228 case GL_COLOR_TABLE_WIDTH:
1229 *params = (GLfloat) table->Size;
1230 break;
1231 case GL_COLOR_TABLE_RED_SIZE:
1232 *params = (GLfloat) table->RedSize;
1233 break;
1234 case GL_COLOR_TABLE_GREEN_SIZE:
1235 *params = (GLfloat) table->GreenSize;
1236 break;
1237 case GL_COLOR_TABLE_BLUE_SIZE:
1238 *params = (GLfloat) table->BlueSize;
1239 break;
1240 case GL_COLOR_TABLE_ALPHA_SIZE:
1241 *params = (GLfloat) table->AlphaSize;
1242 break;
1243 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1244 *params = (GLfloat) table->LuminanceSize;
1245 break;
1246 case GL_COLOR_TABLE_INTENSITY_SIZE:
1247 *params = (GLfloat) table->IntensitySize;
1248 break;
1249 default:
1250 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" );
1251 return;
1252 }
1253 }
1254
1255
1256
1257 void GLAPIENTRY
1258 _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params )
1259 {
1260 GET_CURRENT_CONTEXT(ctx);
1261 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1262 struct gl_color_table *table = NULL;
1263 ASSERT_OUTSIDE_BEGIN_END(ctx);
1264
1265 switch (target) {
1266 case GL_TEXTURE_1D:
1267 table = &texUnit->Current1D->Palette;
1268 break;
1269 case GL_TEXTURE_2D:
1270 table = &texUnit->Current2D->Palette;
1271 break;
1272 case GL_TEXTURE_3D:
1273 table = &texUnit->Current3D->Palette;
1274 break;
1275 case GL_TEXTURE_CUBE_MAP_ARB:
1276 if (!ctx->Extensions.ARB_texture_cube_map) {
1277 _mesa_error(ctx, GL_INVALID_ENUM,
1278 "glGetColorTableParameteriv(target)");
1279 return;
1280 }
1281 table = &texUnit->CurrentCubeMap->Palette;
1282 break;
1283 case GL_PROXY_TEXTURE_1D:
1284 table = &ctx->Texture.Proxy1D->Palette;
1285 break;
1286 case GL_PROXY_TEXTURE_2D:
1287 table = &ctx->Texture.Proxy2D->Palette;
1288 break;
1289 case GL_PROXY_TEXTURE_3D:
1290 table = &ctx->Texture.Proxy3D->Palette;
1291 break;
1292 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1293 if (!ctx->Extensions.ARB_texture_cube_map) {
1294 _mesa_error(ctx, GL_INVALID_ENUM,
1295 "glGetColorTableParameteriv(target)");
1296 return;
1297 }
1298 table = &ctx->Texture.ProxyCubeMap->Palette;
1299 break;
1300 case GL_SHARED_TEXTURE_PALETTE_EXT:
1301 table = &ctx->Texture.Palette;
1302 break;
1303 case GL_COLOR_TABLE:
1304 table = &ctx->ColorTable;
1305 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1306 params[0] = (GLint) ctx->Pixel.ColorTableScale[0];
1307 params[1] = (GLint) ctx->Pixel.ColorTableScale[1];
1308 params[2] = (GLint) ctx->Pixel.ColorTableScale[2];
1309 params[3] = (GLint) ctx->Pixel.ColorTableScale[3];
1310 return;
1311 }
1312 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1313 params[0] = (GLint) ctx->Pixel.ColorTableBias[0];
1314 params[1] = (GLint) ctx->Pixel.ColorTableBias[1];
1315 params[2] = (GLint) ctx->Pixel.ColorTableBias[2];
1316 params[3] = (GLint) ctx->Pixel.ColorTableBias[3];
1317 return;
1318 }
1319 break;
1320 case GL_PROXY_COLOR_TABLE:
1321 table = &ctx->ProxyColorTable;
1322 break;
1323 case GL_TEXTURE_COLOR_TABLE_SGI:
1324 if (!ctx->Extensions.SGI_texture_color_table) {
1325 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1326 return;
1327 }
1328 table = &(texUnit->ColorTable);
1329 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1330 params[0] = (GLint) ctx->Pixel.TextureColorTableScale[0];
1331 params[1] = (GLint) ctx->Pixel.TextureColorTableScale[1];
1332 params[2] = (GLint) ctx->Pixel.TextureColorTableScale[2];
1333 params[3] = (GLint) ctx->Pixel.TextureColorTableScale[3];
1334 return;
1335 }
1336 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1337 params[0] = (GLint) ctx->Pixel.TextureColorTableBias[0];
1338 params[1] = (GLint) ctx->Pixel.TextureColorTableBias[1];
1339 params[2] = (GLint) ctx->Pixel.TextureColorTableBias[2];
1340 params[3] = (GLint) ctx->Pixel.TextureColorTableBias[3];
1341 return;
1342 }
1343 break;
1344 case GL_PROXY_TEXTURE_COLOR_TABLE_SGI:
1345 if (!ctx->Extensions.SGI_texture_color_table) {
1346 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameter(target)");
1347 return;
1348 }
1349 table = &(texUnit->ProxyColorTable);
1350 break;
1351 case GL_POST_CONVOLUTION_COLOR_TABLE:
1352 table = &ctx->PostConvolutionColorTable;
1353 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1354 params[0] = (GLint) ctx->Pixel.PCCTscale[0];
1355 params[1] = (GLint) ctx->Pixel.PCCTscale[1];
1356 params[2] = (GLint) ctx->Pixel.PCCTscale[2];
1357 params[3] = (GLint) ctx->Pixel.PCCTscale[3];
1358 return;
1359 }
1360 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1361 params[0] = (GLint) ctx->Pixel.PCCTbias[0];
1362 params[1] = (GLint) ctx->Pixel.PCCTbias[1];
1363 params[2] = (GLint) ctx->Pixel.PCCTbias[2];
1364 params[3] = (GLint) ctx->Pixel.PCCTbias[3];
1365 return;
1366 }
1367 break;
1368 case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE:
1369 table = &ctx->ProxyPostConvolutionColorTable;
1370 break;
1371 case GL_POST_COLOR_MATRIX_COLOR_TABLE:
1372 table = &ctx->PostColorMatrixColorTable;
1373 if (pname == GL_COLOR_TABLE_SCALE_SGI) {
1374 params[0] = (GLint) ctx->Pixel.PCMCTscale[0];
1375 params[1] = (GLint) ctx->Pixel.PCMCTscale[1];
1376 params[2] = (GLint) ctx->Pixel.PCMCTscale[2];
1377 params[3] = (GLint) ctx->Pixel.PCMCTscale[3];
1378 return;
1379 }
1380 else if (pname == GL_COLOR_TABLE_BIAS_SGI) {
1381 params[0] = (GLint) ctx->Pixel.PCMCTbias[0];
1382 params[1] = (GLint) ctx->Pixel.PCMCTbias[1];
1383 params[2] = (GLint) ctx->Pixel.PCMCTbias[2];
1384 params[3] = (GLint) ctx->Pixel.PCMCTbias[3];
1385 return;
1386 }
1387 break;
1388 case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE:
1389 table = &ctx->ProxyPostColorMatrixColorTable;
1390 break;
1391 default:
1392 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)");
1393 return;
1394 }
1395
1396 assert(table);
1397
1398 switch (pname) {
1399 case GL_COLOR_TABLE_FORMAT:
1400 *params = table->InternalFormat;
1401 break;
1402 case GL_COLOR_TABLE_WIDTH:
1403 *params = table->Size;
1404 break;
1405 case GL_COLOR_TABLE_RED_SIZE:
1406 *params = table->RedSize;
1407 break;
1408 case GL_COLOR_TABLE_GREEN_SIZE:
1409 *params = table->GreenSize;
1410 break;
1411 case GL_COLOR_TABLE_BLUE_SIZE:
1412 *params = table->BlueSize;
1413 break;
1414 case GL_COLOR_TABLE_ALPHA_SIZE:
1415 *params = table->AlphaSize;
1416 break;
1417 case GL_COLOR_TABLE_LUMINANCE_SIZE:
1418 *params = table->LuminanceSize;
1419 break;
1420 case GL_COLOR_TABLE_INTENSITY_SIZE:
1421 *params = table->IntensitySize;
1422 break;
1423 default:
1424 _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" );
1425 return;
1426 }
1427 }
1428
1429 /**********************************************************************/
1430 /***** Initialization *****/
1431 /**********************************************************************/
1432
1433
1434 void
1435 _mesa_init_colortable( struct gl_color_table *p )
1436 {
1437 p->Type = CHAN_TYPE;
1438 p->Table = NULL;
1439 p->Size = 0;
1440 p->InternalFormat = GL_RGBA;
1441 }
1442
1443
1444
1445 void
1446 _mesa_free_colortable_data( struct gl_color_table *p )
1447 {
1448 if (p->Table) {
1449 FREE(p->Table);
1450 p->Table = NULL;
1451 }
1452 }
1453
1454
1455 /*
1456 * Initialize all colortables for a context.
1457 */
1458 void _mesa_init_colortables( GLcontext * ctx )
1459 {
1460 /* Color tables */
1461 _mesa_init_colortable(&ctx->ColorTable);
1462 _mesa_init_colortable(&ctx->ProxyColorTable);
1463 _mesa_init_colortable(&ctx->PostConvolutionColorTable);
1464 _mesa_init_colortable(&ctx->ProxyPostConvolutionColorTable);
1465 _mesa_init_colortable(&ctx->PostColorMatrixColorTable);
1466 _mesa_init_colortable(&ctx->ProxyPostColorMatrixColorTable);
1467 }
1468
1469
1470 /*
1471 * Free all colortable data for a context
1472 */
1473 void _mesa_free_colortables_data( GLcontext *ctx )
1474 {
1475 _mesa_free_colortable_data(&ctx->ColorTable);
1476 _mesa_free_colortable_data(&ctx->ProxyColorTable);
1477 _mesa_free_colortable_data(&ctx->PostConvolutionColorTable);
1478 _mesa_free_colortable_data(&ctx->ProxyPostConvolutionColorTable);
1479 _mesa_free_colortable_data(&ctx->PostColorMatrixColorTable);
1480 _mesa_free_colortable_data(&ctx->ProxyPostColorMatrixColorTable);
1481 }