Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
55 | pj | 1 | /* $Id: colortab.c,v 1.1 2003-02-28 11:41:58 pj Exp $ */ |
2 | |||
3 | /* |
||
4 | * Mesa 3-D graphics library |
||
5 | * Version: 4.1 |
||
6 | * |
||
7 | * Copyright (C) 1999-2002 Brian Paul All Rights Reserved. |
||
8 | * |
||
9 | * Permission is hereby granted, free of charge, to any person obtaining a |
||
10 | * copy of this software and associated documentation files (the "Software"), |
||
11 | * to deal in the Software without restriction, including without limitation |
||
12 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
||
13 | * and/or sell copies of the Software, and to permit persons to whom the |
||
14 | * Software is furnished to do so, subject to the following conditions: |
||
15 | * |
||
16 | * The above copyright notice and this permission notice shall be included |
||
17 | * in all copies or substantial portions of the Software. |
||
18 | * |
||
19 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
||
20 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
||
21 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
||
22 | * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN |
||
23 | * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN |
||
24 | * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
||
25 | */ |
||
26 | |||
27 | |||
28 | #include "glheader.h" |
||
29 | #include "imports.h" |
||
30 | #include "colortab.h" |
||
31 | #include "context.h" |
||
32 | #include "image.h" |
||
33 | #include "macros.h" |
||
34 | #include "mmath.h" |
||
35 | #include "state.h" |
||
36 | |||
37 | |||
38 | /* |
||
39 | * Given an internalFormat token passed to glColorTable, |
||
40 | * return the corresponding base format. |
||
41 | * Return -1 if invalid token. |
||
42 | */ |
||
43 | static GLint |
||
44 | base_colortab_format( GLenum format ) |
||
45 | { |
||
46 | switch (format) { |
||
47 | case GL_ALPHA: |
||
48 | case GL_ALPHA4: |
||
49 | case GL_ALPHA8: |
||
50 | case GL_ALPHA12: |
||
51 | case GL_ALPHA16: |
||
52 | return GL_ALPHA; |
||
53 | case GL_LUMINANCE: |
||
54 | case GL_LUMINANCE4: |
||
55 | case GL_LUMINANCE8: |
||
56 | case GL_LUMINANCE12: |
||
57 | case GL_LUMINANCE16: |
||
58 | return GL_LUMINANCE; |
||
59 | case GL_LUMINANCE_ALPHA: |
||
60 | case GL_LUMINANCE4_ALPHA4: |
||
61 | case GL_LUMINANCE6_ALPHA2: |
||
62 | case GL_LUMINANCE8_ALPHA8: |
||
63 | case GL_LUMINANCE12_ALPHA4: |
||
64 | case GL_LUMINANCE12_ALPHA12: |
||
65 | case GL_LUMINANCE16_ALPHA16: |
||
66 | return GL_LUMINANCE_ALPHA; |
||
67 | case GL_INTENSITY: |
||
68 | case GL_INTENSITY4: |
||
69 | case GL_INTENSITY8: |
||
70 | case GL_INTENSITY12: |
||
71 | case GL_INTENSITY16: |
||
72 | return GL_INTENSITY; |
||
73 | case GL_RGB: |
||
74 | case GL_R3_G3_B2: |
||
75 | case GL_RGB4: |
||
76 | case GL_RGB5: |
||
77 | case GL_RGB8: |
||
78 | case GL_RGB10: |
||
79 | case GL_RGB12: |
||
80 | case GL_RGB16: |
||
81 | return GL_RGB; |
||
82 | case GL_RGBA: |
||
83 | case GL_RGBA2: |
||
84 | case GL_RGBA4: |
||
85 | case GL_RGB5_A1: |
||
86 | case GL_RGBA8: |
||
87 | case GL_RGB10_A2: |
||
88 | case GL_RGBA12: |
||
89 | case GL_RGBA16: |
||
90 | return GL_RGBA; |
||
91 | default: |
||
92 | return -1; /* error */ |
||
93 | } |
||
94 | } |
||
95 | |||
96 | |||
97 | void |
||
98 | _mesa_init_colortable( struct gl_color_table *p ) |
||
99 | { |
||
100 | p->FloatTable = GL_FALSE; |
||
101 | p->Table = NULL; |
||
102 | p->Size = 0; |
||
103 | p->IntFormat = GL_RGBA; |
||
104 | } |
||
105 | |||
106 | |||
107 | |||
108 | void |
||
109 | _mesa_free_colortable_data( struct gl_color_table *p ) |
||
110 | { |
||
111 | if (p->Table) { |
||
112 | FREE(p->Table); |
||
113 | p->Table = NULL; |
||
114 | } |
||
115 | } |
||
116 | |||
117 | |||
118 | /* |
||
119 | * Examine table's format and set the component sizes accordingly. |
||
120 | */ |
||
121 | static void |
||
122 | set_component_sizes( struct gl_color_table *table ) |
||
123 | { |
||
124 | switch (table->Format) { |
||
125 | case GL_ALPHA: |
||
126 | table->RedSize = 0; |
||
127 | table->GreenSize = 0; |
||
128 | table->BlueSize = 0; |
||
129 | table->AlphaSize = CHAN_BITS; |
||
130 | table->IntensitySize = 0; |
||
131 | table->LuminanceSize = 0; |
||
132 | break; |
||
133 | case GL_LUMINANCE: |
||
134 | table->RedSize = 0; |
||
135 | table->GreenSize = 0; |
||
136 | table->BlueSize = 0; |
||
137 | table->AlphaSize = 0; |
||
138 | table->IntensitySize = 0; |
||
139 | table->LuminanceSize = CHAN_BITS; |
||
140 | break; |
||
141 | case GL_LUMINANCE_ALPHA: |
||
142 | table->RedSize = 0; |
||
143 | table->GreenSize = 0; |
||
144 | table->BlueSize = 0; |
||
145 | table->AlphaSize = CHAN_BITS; |
||
146 | table->IntensitySize = 0; |
||
147 | table->LuminanceSize = CHAN_BITS; |
||
148 | break; |
||
149 | case GL_INTENSITY: |
||
150 | table->RedSize = 0; |
||
151 | table->GreenSize = 0; |
||
152 | table->BlueSize = 0; |
||
153 | table->AlphaSize = 0; |
||
154 | table->IntensitySize = CHAN_BITS; |
||
155 | table->LuminanceSize = 0; |
||
156 | break; |
||
157 | case GL_RGB: |
||
158 | table->RedSize = CHAN_BITS; |
||
159 | table->GreenSize = CHAN_BITS; |
||
160 | table->BlueSize = CHAN_BITS; |
||
161 | table->AlphaSize = 0; |
||
162 | table->IntensitySize = 0; |
||
163 | table->LuminanceSize = 0; |
||
164 | break; |
||
165 | case GL_RGBA: |
||
166 | table->RedSize = CHAN_BITS; |
||
167 | table->GreenSize = CHAN_BITS; |
||
168 | table->BlueSize = CHAN_BITS; |
||
169 | table->AlphaSize = CHAN_BITS; |
||
170 | table->IntensitySize = 0; |
||
171 | table->LuminanceSize = 0; |
||
172 | break; |
||
173 | default: |
||
174 | _mesa_problem(NULL, "unexpected format in set_component_sizes"); |
||
175 | } |
||
176 | } |
||
177 | |||
178 | |||
179 | |||
180 | void |
||
181 | _mesa_ColorTable( GLenum target, GLenum internalFormat, |
||
182 | GLsizei width, GLenum format, GLenum type, |
||
183 | const GLvoid *data ) |
||
184 | { |
||
185 | GET_CURRENT_CONTEXT(ctx); |
||
186 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
||
187 | struct gl_texture_object *texObj = NULL; |
||
188 | struct gl_color_table *table = NULL; |
||
189 | GLboolean proxy = GL_FALSE; |
||
190 | GLint baseFormat; |
||
191 | GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; |
||
192 | GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; |
||
193 | GLboolean floatTable = GL_FALSE; |
||
194 | GLint comps; |
||
195 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); /* too complex */ |
||
196 | |||
197 | switch (target) { |
||
198 | case GL_TEXTURE_1D: |
||
199 | texObj = texUnit->Current1D; |
||
200 | table = &texObj->Palette; |
||
201 | break; |
||
202 | case GL_TEXTURE_2D: |
||
203 | texObj = texUnit->Current2D; |
||
204 | table = &texObj->Palette; |
||
205 | break; |
||
206 | case GL_TEXTURE_3D: |
||
207 | texObj = texUnit->Current3D; |
||
208 | table = &texObj->Palette; |
||
209 | break; |
||
210 | case GL_TEXTURE_CUBE_MAP_ARB: |
||
211 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
212 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); |
||
213 | return; |
||
214 | } |
||
215 | texObj = texUnit->CurrentCubeMap; |
||
216 | table = &texObj->Palette; |
||
217 | break; |
||
218 | case GL_PROXY_TEXTURE_1D: |
||
219 | texObj = ctx->Texture.Proxy1D; |
||
220 | table = &texObj->Palette; |
||
221 | proxy = GL_TRUE; |
||
222 | break; |
||
223 | case GL_PROXY_TEXTURE_2D: |
||
224 | texObj = ctx->Texture.Proxy2D; |
||
225 | table = &texObj->Palette; |
||
226 | proxy = GL_TRUE; |
||
227 | break; |
||
228 | case GL_PROXY_TEXTURE_3D: |
||
229 | texObj = ctx->Texture.Proxy3D; |
||
230 | table = &texObj->Palette; |
||
231 | proxy = GL_TRUE; |
||
232 | break; |
||
233 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
||
234 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
235 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); |
||
236 | return; |
||
237 | } |
||
238 | texObj = ctx->Texture.ProxyCubeMap; |
||
239 | table = &texObj->Palette; |
||
240 | break; |
||
241 | case GL_SHARED_TEXTURE_PALETTE_EXT: |
||
242 | table = &ctx->Texture.Palette; |
||
243 | break; |
||
244 | case GL_COLOR_TABLE: |
||
245 | table = &ctx->ColorTable; |
||
246 | floatTable = GL_TRUE; |
||
247 | rScale = ctx->Pixel.ColorTableScale[0]; |
||
248 | gScale = ctx->Pixel.ColorTableScale[1]; |
||
249 | bScale = ctx->Pixel.ColorTableScale[2]; |
||
250 | aScale = ctx->Pixel.ColorTableScale[3]; |
||
251 | rBias = ctx->Pixel.ColorTableBias[0]; |
||
252 | gBias = ctx->Pixel.ColorTableBias[1]; |
||
253 | bBias = ctx->Pixel.ColorTableBias[2]; |
||
254 | aBias = ctx->Pixel.ColorTableBias[3]; |
||
255 | break; |
||
256 | case GL_PROXY_COLOR_TABLE: |
||
257 | table = &ctx->ProxyColorTable; |
||
258 | proxy = GL_TRUE; |
||
259 | break; |
||
260 | case GL_POST_CONVOLUTION_COLOR_TABLE: |
||
261 | table = &ctx->PostConvolutionColorTable; |
||
262 | floatTable = GL_TRUE; |
||
263 | rScale = ctx->Pixel.PCCTscale[0]; |
||
264 | gScale = ctx->Pixel.PCCTscale[1]; |
||
265 | bScale = ctx->Pixel.PCCTscale[2]; |
||
266 | aScale = ctx->Pixel.PCCTscale[3]; |
||
267 | rBias = ctx->Pixel.PCCTbias[0]; |
||
268 | gBias = ctx->Pixel.PCCTbias[1]; |
||
269 | bBias = ctx->Pixel.PCCTbias[2]; |
||
270 | aBias = ctx->Pixel.PCCTbias[3]; |
||
271 | break; |
||
272 | case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: |
||
273 | table = &ctx->ProxyPostConvolutionColorTable; |
||
274 | proxy = GL_TRUE; |
||
275 | break; |
||
276 | case GL_POST_COLOR_MATRIX_COLOR_TABLE: |
||
277 | table = &ctx->PostColorMatrixColorTable; |
||
278 | floatTable = GL_TRUE; |
||
279 | rScale = ctx->Pixel.PCMCTscale[0]; |
||
280 | gScale = ctx->Pixel.PCMCTscale[1]; |
||
281 | bScale = ctx->Pixel.PCMCTscale[2]; |
||
282 | aScale = ctx->Pixel.PCMCTscale[3]; |
||
283 | rBias = ctx->Pixel.PCMCTbias[0]; |
||
284 | gBias = ctx->Pixel.PCMCTbias[1]; |
||
285 | bBias = ctx->Pixel.PCMCTbias[2]; |
||
286 | aBias = ctx->Pixel.PCMCTbias[3]; |
||
287 | break; |
||
288 | case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: |
||
289 | table = &ctx->ProxyPostColorMatrixColorTable; |
||
290 | proxy = GL_TRUE; |
||
291 | break; |
||
292 | default: |
||
293 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(target)"); |
||
294 | return; |
||
295 | } |
||
296 | |||
297 | assert(table); |
||
298 | |||
299 | if (!_mesa_is_legal_format_and_type(format, type) || |
||
300 | format == GL_INTENSITY) { |
||
301 | _mesa_error(ctx, GL_INVALID_OPERATION, "glColorTable(format or type)"); |
||
302 | return; |
||
303 | } |
||
304 | |||
305 | baseFormat = base_colortab_format(internalFormat); |
||
306 | if (baseFormat < 0 || baseFormat == GL_COLOR_INDEX) { |
||
307 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorTable(internalFormat)"); |
||
308 | return; |
||
309 | } |
||
310 | |||
311 | if (width < 0 || (width != 0 && _mesa_bitcount(width) != 1)) { |
||
312 | /* error */ |
||
313 | if (proxy) { |
||
314 | table->Size = 0; |
||
315 | table->IntFormat = (GLenum) 0; |
||
316 | table->Format = (GLenum) 0; |
||
317 | } |
||
318 | else { |
||
319 | _mesa_error(ctx, GL_INVALID_VALUE, "glColorTable(width=%d)", width); |
||
320 | } |
||
321 | return; |
||
322 | } |
||
323 | |||
324 | if (width > (GLsizei) ctx->Const.MaxColorTableSize) { |
||
325 | if (proxy) { |
||
326 | table->Size = 0; |
||
327 | table->IntFormat = (GLenum) 0; |
||
328 | table->Format = (GLenum) 0; |
||
329 | } |
||
330 | else { |
||
331 | _mesa_error(ctx, GL_TABLE_TOO_LARGE, "glColorTable(width)"); |
||
332 | } |
||
333 | return; |
||
334 | } |
||
335 | |||
336 | table->Size = width; |
||
337 | table->IntFormat = internalFormat; |
||
338 | table->Format = (GLenum) baseFormat; |
||
339 | set_component_sizes(table); |
||
340 | |||
341 | comps = _mesa_components_in_format(table->Format); |
||
342 | assert(comps > 0); /* error should have been caught sooner */ |
||
343 | |||
344 | if (!proxy) { |
||
345 | /* free old table, if any */ |
||
346 | if (table->Table) { |
||
347 | FREE(table->Table); |
||
348 | table->Table = NULL; |
||
349 | } |
||
350 | if (width > 0) { |
||
351 | if (floatTable) { |
||
352 | GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; |
||
353 | GLfloat *tableF; |
||
354 | GLint i; |
||
355 | |||
356 | _mesa_unpack_float_color_span(ctx, width, table->Format, |
||
357 | tempTab, /* dest */ |
||
358 | format, type, data, &ctx->Unpack, |
||
359 | 0, GL_FALSE); |
||
360 | |||
361 | table->FloatTable = GL_TRUE; |
||
362 | table->Table = MALLOC(comps * width * sizeof(GLfloat)); |
||
363 | if (!table->Table) { |
||
364 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); |
||
365 | return; |
||
366 | } |
||
367 | |||
368 | tableF = (GLfloat *) table->Table; |
||
369 | |||
370 | switch (table->Format) { |
||
371 | case GL_INTENSITY: |
||
372 | for (i = 0; i < width; i++) { |
||
373 | tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); |
||
374 | } |
||
375 | break; |
||
376 | case GL_LUMINANCE: |
||
377 | for (i = 0; i < width; i++) { |
||
378 | tableF[i] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); |
||
379 | } |
||
380 | break; |
||
381 | case GL_ALPHA: |
||
382 | for (i = 0; i < width; i++) { |
||
383 | tableF[i] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); |
||
384 | } |
||
385 | break; |
||
386 | case GL_LUMINANCE_ALPHA: |
||
387 | for (i = 0; i < width; i++) { |
||
388 | tableF[i*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); |
||
389 | tableF[i*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); |
||
390 | } |
||
391 | break; |
||
392 | case GL_RGB: |
||
393 | for (i = 0; i < width; i++) { |
||
394 | tableF[i*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); |
||
395 | tableF[i*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); |
||
396 | tableF[i*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); |
||
397 | } |
||
398 | break; |
||
399 | case GL_RGBA: |
||
400 | for (i = 0; i < width; i++) { |
||
401 | tableF[i*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); |
||
402 | tableF[i*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); |
||
403 | tableF[i*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); |
||
404 | tableF[i*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); |
||
405 | } |
||
406 | break; |
||
407 | default: |
||
408 | _mesa_problem(ctx, "Bad format in _mesa_ColorTable"); |
||
409 | return; |
||
410 | } |
||
411 | } |
||
412 | else { |
||
413 | /* store GLchan table */ |
||
414 | table->FloatTable = GL_FALSE; |
||
415 | table->Table = MALLOC(comps * width * sizeof(GLchan)); |
||
416 | if (!table->Table) { |
||
417 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorTable"); |
||
418 | return; |
||
419 | } |
||
420 | _mesa_unpack_chan_color_span(ctx, width, table->Format, |
||
421 | (GLchan *) table->Table, /* dest */ |
||
422 | format, type, data, |
||
423 | &ctx->Unpack, 0); |
||
424 | } /* floatTable */ |
||
425 | } /* width > 0 */ |
||
426 | } /* proxy */ |
||
427 | |||
428 | if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { |
||
429 | /* texture object palette, texObj==NULL means the shared palette */ |
||
430 | if (ctx->Driver.UpdateTexturePalette) { |
||
431 | (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); |
||
432 | } |
||
433 | } |
||
434 | |||
435 | ctx->NewState |= _NEW_PIXEL; |
||
436 | } |
||
437 | |||
438 | |||
439 | |||
440 | void |
||
441 | _mesa_ColorSubTable( GLenum target, GLsizei start, |
||
442 | GLsizei count, GLenum format, GLenum type, |
||
443 | const GLvoid *data ) |
||
444 | { |
||
445 | GET_CURRENT_CONTEXT(ctx); |
||
446 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
||
447 | struct gl_texture_object *texObj = NULL; |
||
448 | struct gl_color_table *table = NULL; |
||
449 | GLfloat rScale = 1.0, gScale = 1.0, bScale = 1.0, aScale = 1.0; |
||
450 | GLfloat rBias = 0.0, gBias = 0.0, bBias = 0.0, aBias = 0.0; |
||
451 | GLint comps; |
||
452 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
||
453 | |||
454 | switch (target) { |
||
455 | case GL_TEXTURE_1D: |
||
456 | texObj = texUnit->Current1D; |
||
457 | table = &texObj->Palette; |
||
458 | break; |
||
459 | case GL_TEXTURE_2D: |
||
460 | texObj = texUnit->Current2D; |
||
461 | table = &texObj->Palette; |
||
462 | break; |
||
463 | case GL_TEXTURE_3D: |
||
464 | texObj = texUnit->Current3D; |
||
465 | table = &texObj->Palette; |
||
466 | break; |
||
467 | case GL_TEXTURE_CUBE_MAP_ARB: |
||
468 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
469 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); |
||
470 | return; |
||
471 | } |
||
472 | texObj = texUnit->CurrentCubeMap; |
||
473 | table = &texObj->Palette; |
||
474 | break; |
||
475 | case GL_SHARED_TEXTURE_PALETTE_EXT: |
||
476 | table = &ctx->Texture.Palette; |
||
477 | break; |
||
478 | case GL_COLOR_TABLE: |
||
479 | table = &ctx->ColorTable; |
||
480 | rScale = ctx->Pixel.ColorTableScale[0]; |
||
481 | gScale = ctx->Pixel.ColorTableScale[1]; |
||
482 | bScale = ctx->Pixel.ColorTableScale[2]; |
||
483 | aScale = ctx->Pixel.ColorTableScale[3]; |
||
484 | rBias = ctx->Pixel.ColorTableBias[0]; |
||
485 | gBias = ctx->Pixel.ColorTableBias[1]; |
||
486 | bBias = ctx->Pixel.ColorTableBias[2]; |
||
487 | aBias = ctx->Pixel.ColorTableBias[3]; |
||
488 | break; |
||
489 | case GL_POST_CONVOLUTION_COLOR_TABLE: |
||
490 | table = &ctx->PostConvolutionColorTable; |
||
491 | rScale = ctx->Pixel.PCCTscale[0]; |
||
492 | gScale = ctx->Pixel.PCCTscale[1]; |
||
493 | bScale = ctx->Pixel.PCCTscale[2]; |
||
494 | aScale = ctx->Pixel.PCCTscale[3]; |
||
495 | rBias = ctx->Pixel.PCCTbias[0]; |
||
496 | gBias = ctx->Pixel.PCCTbias[1]; |
||
497 | bBias = ctx->Pixel.PCCTbias[2]; |
||
498 | aBias = ctx->Pixel.PCCTbias[3]; |
||
499 | break; |
||
500 | case GL_POST_COLOR_MATRIX_COLOR_TABLE: |
||
501 | table = &ctx->PostColorMatrixColorTable; |
||
502 | rScale = ctx->Pixel.PCMCTscale[0]; |
||
503 | gScale = ctx->Pixel.PCMCTscale[1]; |
||
504 | bScale = ctx->Pixel.PCMCTscale[2]; |
||
505 | aScale = ctx->Pixel.PCMCTscale[3]; |
||
506 | rBias = ctx->Pixel.PCMCTbias[0]; |
||
507 | gBias = ctx->Pixel.PCMCTbias[1]; |
||
508 | bBias = ctx->Pixel.PCMCTbias[2]; |
||
509 | aBias = ctx->Pixel.PCMCTbias[3]; |
||
510 | break; |
||
511 | default: |
||
512 | _mesa_error(ctx, GL_INVALID_ENUM, "glColorSubTable(target)"); |
||
513 | return; |
||
514 | } |
||
515 | |||
516 | assert(table); |
||
517 | |||
518 | if (!_mesa_is_legal_format_and_type(format, type) || |
||
519 | format == GL_INTENSITY) { |
||
520 | _mesa_error(ctx, GL_INVALID_OPERATION, "glColorSubTable(format or type)"); |
||
521 | return; |
||
522 | } |
||
523 | |||
524 | if (count < 1) { |
||
525 | _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); |
||
526 | return; |
||
527 | } |
||
528 | |||
529 | comps = _mesa_components_in_format(table->Format); |
||
530 | assert(comps > 0); /* error should have been caught sooner */ |
||
531 | |||
532 | if (start + count > (GLint) table->Size) { |
||
533 | _mesa_error(ctx, GL_INVALID_VALUE, "glColorSubTable(count)"); |
||
534 | return; |
||
535 | } |
||
536 | |||
537 | if (!table->Table) { |
||
538 | _mesa_error(ctx, GL_OUT_OF_MEMORY, "glColorSubTable"); |
||
539 | return; |
||
540 | } |
||
541 | |||
542 | if (!table->FloatTable) { |
||
543 | GLchan *dest = (GLchan *) table->Table + start * comps * sizeof(GLchan); |
||
544 | _mesa_unpack_chan_color_span(ctx, count, table->Format, dest, |
||
545 | format, type, data, &ctx->Unpack, 0); |
||
546 | } |
||
547 | else { |
||
548 | GLfloat tempTab[MAX_COLOR_TABLE_SIZE * 4]; |
||
549 | GLfloat *tableF; |
||
550 | GLint i; |
||
551 | |||
552 | ASSERT(table->FloatTable); |
||
553 | |||
554 | _mesa_unpack_float_color_span(ctx, count, table->Format, |
||
555 | tempTab, /* dest */ |
||
556 | format, type, data, &ctx->Unpack, |
||
557 | 0, GL_FALSE); |
||
558 | |||
559 | tableF = (GLfloat *) table->Table; |
||
560 | |||
561 | switch (table->Format) { |
||
562 | case GL_INTENSITY: |
||
563 | for (i = 0; i < count; i++) { |
||
564 | GLuint j = start + i; |
||
565 | tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); |
||
566 | } |
||
567 | break; |
||
568 | case GL_LUMINANCE: |
||
569 | for (i = 0; i < count; i++) { |
||
570 | GLuint j = start + i; |
||
571 | tableF[j] = CLAMP(tempTab[i] * rScale + rBias, 0.0F, 1.0F); |
||
572 | } |
||
573 | break; |
||
574 | case GL_ALPHA: |
||
575 | for (i = 0; i < count; i++) { |
||
576 | GLuint j = start + i; |
||
577 | tableF[j] = CLAMP(tempTab[i] * aScale + aBias, 0.0F, 1.0F); |
||
578 | } |
||
579 | break; |
||
580 | case GL_LUMINANCE_ALPHA: |
||
581 | for (i = 0; i < count; i++) { |
||
582 | GLuint j = start + i; |
||
583 | tableF[j*2+0] = CLAMP(tempTab[i*2+0] * rScale + rBias, 0.0F, 1.0F); |
||
584 | tableF[j*2+1] = CLAMP(tempTab[i*2+1] * aScale + aBias, 0.0F, 1.0F); |
||
585 | } |
||
586 | break; |
||
587 | case GL_RGB: |
||
588 | for (i = 0; i < count; i++) { |
||
589 | GLuint j = start + i; |
||
590 | tableF[j*3+0] = CLAMP(tempTab[i*3+0] * rScale + rBias, 0.0F, 1.0F); |
||
591 | tableF[j*3+1] = CLAMP(tempTab[i*3+1] * gScale + gBias, 0.0F, 1.0F); |
||
592 | tableF[j*3+2] = CLAMP(tempTab[i*3+2] * bScale + bBias, 0.0F, 1.0F); |
||
593 | } |
||
594 | break; |
||
595 | case GL_RGBA: |
||
596 | for (i = 0; i < count; i++) { |
||
597 | GLuint j = start + i; |
||
598 | tableF[j*4+0] = CLAMP(tempTab[i*4+0] * rScale + rBias, 0.0F, 1.0F); |
||
599 | tableF[j*4+1] = CLAMP(tempTab[i*4+1] * gScale + gBias, 0.0F, 1.0F); |
||
600 | tableF[j*4+2] = CLAMP(tempTab[i*4+2] * bScale + bBias, 0.0F, 1.0F); |
||
601 | tableF[j*4+3] = CLAMP(tempTab[i*4+3] * aScale + aBias, 0.0F, 1.0F); |
||
602 | } |
||
603 | break; |
||
604 | default: |
||
605 | _mesa_problem(ctx, "Bad format in _mesa_ColorSubTable"); |
||
606 | return; |
||
607 | } |
||
608 | } |
||
609 | |||
610 | if (texObj || target == GL_SHARED_TEXTURE_PALETTE_EXT) { |
||
611 | /* per-texture object palette */ |
||
612 | if (ctx->Driver.UpdateTexturePalette) { |
||
613 | (*ctx->Driver.UpdateTexturePalette)( ctx, texObj ); |
||
614 | } |
||
615 | } |
||
616 | |||
617 | ctx->NewState |= _NEW_PIXEL; |
||
618 | } |
||
619 | |||
620 | |||
621 | |||
622 | /* XXX not tested */ |
||
623 | void |
||
624 | _mesa_CopyColorTable(GLenum target, GLenum internalformat, |
||
625 | GLint x, GLint y, GLsizei width) |
||
626 | { |
||
627 | GET_CURRENT_CONTEXT(ctx); |
||
628 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
||
629 | |||
630 | /* Select buffer to read from */ |
||
631 | ctx->Driver.CopyColorTable( ctx, target, internalformat, x, y, width ); |
||
632 | } |
||
633 | |||
634 | |||
635 | |||
636 | /* XXX not tested */ |
||
637 | void |
||
638 | _mesa_CopyColorSubTable(GLenum target, GLsizei start, |
||
639 | GLint x, GLint y, GLsizei width) |
||
640 | { |
||
641 | GET_CURRENT_CONTEXT(ctx); |
||
642 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
||
643 | |||
644 | ctx->Driver.CopyColorSubTable( ctx, target, start, x, y, width ); |
||
645 | } |
||
646 | |||
647 | |||
648 | |||
649 | void |
||
650 | _mesa_GetColorTable( GLenum target, GLenum format, |
||
651 | GLenum type, GLvoid *data ) |
||
652 | { |
||
653 | GET_CURRENT_CONTEXT(ctx); |
||
654 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
||
655 | struct gl_color_table *table = NULL; |
||
656 | GLchan rgba[MAX_COLOR_TABLE_SIZE][4]; |
||
657 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
||
658 | |||
659 | if (ctx->NewState) { |
||
660 | _mesa_update_state(ctx); |
||
661 | } |
||
662 | |||
663 | switch (target) { |
||
664 | case GL_TEXTURE_1D: |
||
665 | table = &texUnit->Current1D->Palette; |
||
666 | break; |
||
667 | case GL_TEXTURE_2D: |
||
668 | table = &texUnit->Current2D->Palette; |
||
669 | break; |
||
670 | case GL_TEXTURE_3D: |
||
671 | table = &texUnit->Current3D->Palette; |
||
672 | break; |
||
673 | case GL_TEXTURE_CUBE_MAP_ARB: |
||
674 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
675 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); |
||
676 | return; |
||
677 | } |
||
678 | table = &texUnit->CurrentCubeMap->Palette; |
||
679 | break; |
||
680 | case GL_SHARED_TEXTURE_PALETTE_EXT: |
||
681 | table = &ctx->Texture.Palette; |
||
682 | break; |
||
683 | case GL_COLOR_TABLE: |
||
684 | table = &ctx->ColorTable; |
||
685 | break; |
||
686 | case GL_POST_CONVOLUTION_COLOR_TABLE: |
||
687 | table = &ctx->PostConvolutionColorTable; |
||
688 | break; |
||
689 | case GL_POST_COLOR_MATRIX_COLOR_TABLE: |
||
690 | table = &ctx->PostColorMatrixColorTable; |
||
691 | break; |
||
692 | default: |
||
693 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTable(target)"); |
||
694 | return; |
||
695 | } |
||
696 | |||
697 | assert(table); |
||
698 | |||
699 | switch (table->Format) { |
||
700 | case GL_ALPHA: |
||
701 | if (table->FloatTable) { |
||
702 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
703 | GLuint i; |
||
704 | for (i = 0; i < table->Size; i++) { |
||
705 | rgba[i][RCOMP] = 0; |
||
706 | rgba[i][GCOMP] = 0; |
||
707 | rgba[i][BCOMP] = 0; |
||
708 | rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
709 | } |
||
710 | } |
||
711 | else { |
||
712 | const GLchan *tableUB = (const GLchan *) table->Table; |
||
713 | GLuint i; |
||
714 | for (i = 0; i < table->Size; i++) { |
||
715 | rgba[i][RCOMP] = 0; |
||
716 | rgba[i][GCOMP] = 0; |
||
717 | rgba[i][BCOMP] = 0; |
||
718 | rgba[i][ACOMP] = tableUB[i]; |
||
719 | } |
||
720 | } |
||
721 | break; |
||
722 | case GL_LUMINANCE: |
||
723 | if (table->FloatTable) { |
||
724 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
725 | GLuint i; |
||
726 | for (i = 0; i < table->Size; i++) { |
||
727 | rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
728 | rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
729 | rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
730 | rgba[i][ACOMP] = CHAN_MAX; |
||
731 | } |
||
732 | } |
||
733 | else { |
||
734 | const GLchan *tableUB = (const GLchan *) table->Table; |
||
735 | GLuint i; |
||
736 | for (i = 0; i < table->Size; i++) { |
||
737 | rgba[i][RCOMP] = tableUB[i]; |
||
738 | rgba[i][GCOMP] = tableUB[i]; |
||
739 | rgba[i][BCOMP] = tableUB[i]; |
||
740 | rgba[i][ACOMP] = CHAN_MAX; |
||
741 | } |
||
742 | } |
||
743 | break; |
||
744 | case GL_LUMINANCE_ALPHA: |
||
745 | if (table->FloatTable) { |
||
746 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
747 | GLuint i; |
||
748 | for (i = 0; i < table->Size; i++) { |
||
749 | rgba[i][RCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); |
||
750 | rgba[i][GCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); |
||
751 | rgba[i][BCOMP] = IROUND_POS(tableF[i*2+0] * CHAN_MAXF); |
||
752 | rgba[i][ACOMP] = IROUND_POS(tableF[i*2+1] * CHAN_MAXF); |
||
753 | } |
||
754 | } |
||
755 | else { |
||
756 | const GLchan *tableUB = (const GLchan *) table->Table; |
||
757 | GLuint i; |
||
758 | for (i = 0; i < table->Size; i++) { |
||
759 | rgba[i][RCOMP] = tableUB[i*2+0]; |
||
760 | rgba[i][GCOMP] = tableUB[i*2+0]; |
||
761 | rgba[i][BCOMP] = tableUB[i*2+0]; |
||
762 | rgba[i][ACOMP] = tableUB[i*2+1]; |
||
763 | } |
||
764 | } |
||
765 | break; |
||
766 | case GL_INTENSITY: |
||
767 | if (table->FloatTable) { |
||
768 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
769 | GLuint i; |
||
770 | for (i = 0; i < table->Size; i++) { |
||
771 | rgba[i][RCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
772 | rgba[i][GCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
773 | rgba[i][BCOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
774 | rgba[i][ACOMP] = IROUND_POS(tableF[i] * CHAN_MAXF); |
||
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] = tableUB[i]; |
||
782 | rgba[i][GCOMP] = tableUB[i]; |
||
783 | rgba[i][BCOMP] = tableUB[i]; |
||
784 | rgba[i][ACOMP] = tableUB[i]; |
||
785 | } |
||
786 | } |
||
787 | break; |
||
788 | case GL_RGB: |
||
789 | if (table->FloatTable) { |
||
790 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
791 | GLuint i; |
||
792 | for (i = 0; i < table->Size; i++) { |
||
793 | rgba[i][RCOMP] = IROUND_POS(tableF[i*3+0] * CHAN_MAXF); |
||
794 | rgba[i][GCOMP] = IROUND_POS(tableF[i*3+1] * CHAN_MAXF); |
||
795 | rgba[i][BCOMP] = IROUND_POS(tableF[i*3+2] * CHAN_MAXF); |
||
796 | rgba[i][ACOMP] = CHAN_MAX; |
||
797 | } |
||
798 | } |
||
799 | else { |
||
800 | const GLchan *tableUB = (const GLchan *) table->Table; |
||
801 | GLuint i; |
||
802 | for (i = 0; i < table->Size; i++) { |
||
803 | rgba[i][RCOMP] = tableUB[i*3+0]; |
||
804 | rgba[i][GCOMP] = tableUB[i*3+1]; |
||
805 | rgba[i][BCOMP] = tableUB[i*3+2]; |
||
806 | rgba[i][ACOMP] = CHAN_MAX; |
||
807 | } |
||
808 | } |
||
809 | break; |
||
810 | case GL_RGBA: |
||
811 | if (table->FloatTable) { |
||
812 | const GLfloat *tableF = (const GLfloat *) table->Table; |
||
813 | GLuint i; |
||
814 | for (i = 0; i < table->Size; i++) { |
||
815 | rgba[i][RCOMP] = IROUND_POS(tableF[i*4+0] * CHAN_MAXF); |
||
816 | rgba[i][GCOMP] = IROUND_POS(tableF[i*4+1] * CHAN_MAXF); |
||
817 | rgba[i][BCOMP] = IROUND_POS(tableF[i*4+2] * CHAN_MAXF); |
||
818 | rgba[i][ACOMP] = IROUND_POS(tableF[i*4+3] * CHAN_MAXF); |
||
819 | } |
||
820 | } |
||
821 | else { |
||
822 | const GLchan *tableUB = (const GLchan *) table->Table; |
||
823 | GLuint i; |
||
824 | for (i = 0; i < table->Size; i++) { |
||
825 | rgba[i][RCOMP] = tableUB[i*4+0]; |
||
826 | rgba[i][GCOMP] = tableUB[i*4+1]; |
||
827 | rgba[i][BCOMP] = tableUB[i*4+2]; |
||
828 | rgba[i][ACOMP] = tableUB[i*4+3]; |
||
829 | } |
||
830 | } |
||
831 | break; |
||
832 | default: |
||
833 | _mesa_problem(ctx, "bad table format in glGetColorTable"); |
||
834 | return; |
||
835 | } |
||
836 | |||
837 | _mesa_pack_rgba_span(ctx, table->Size, (const GLchan (*)[4]) rgba, |
||
838 | format, type, data, &ctx->Pack, GL_FALSE); |
||
839 | } |
||
840 | |||
841 | |||
842 | |||
843 | void |
||
844 | _mesa_ColorTableParameterfv(GLenum target, GLenum pname, const GLfloat *params) |
||
845 | { |
||
846 | GET_CURRENT_CONTEXT(ctx); |
||
847 | ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx); |
||
848 | |||
849 | switch (target) { |
||
850 | case GL_COLOR_TABLE_SGI: |
||
851 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
852 | ctx->Pixel.ColorTableScale[0] = params[0]; |
||
853 | ctx->Pixel.ColorTableScale[1] = params[1]; |
||
854 | ctx->Pixel.ColorTableScale[2] = params[2]; |
||
855 | ctx->Pixel.ColorTableScale[3] = params[3]; |
||
856 | } |
||
857 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
858 | ctx->Pixel.ColorTableBias[0] = params[0]; |
||
859 | ctx->Pixel.ColorTableBias[1] = params[1]; |
||
860 | ctx->Pixel.ColorTableBias[2] = params[2]; |
||
861 | ctx->Pixel.ColorTableBias[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 |
||
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_POST_CONVOLUTION_COLOR_TABLE_SGI || |
||
920 | pname == GL_POST_COLOR_MATRIX_COLOR_TABLE_SGI) { |
||
921 | /* four values */ |
||
922 | fparams[0] = (GLfloat) params[0]; |
||
923 | fparams[1] = (GLfloat) params[1]; |
||
924 | fparams[2] = (GLfloat) params[2]; |
||
925 | fparams[3] = (GLfloat) params[3]; |
||
926 | } |
||
927 | else { |
||
928 | /* one values */ |
||
929 | fparams[0] = (GLfloat) params[0]; |
||
930 | } |
||
931 | _mesa_ColorTableParameterfv(target, pname, fparams); |
||
932 | } |
||
933 | |||
934 | |||
935 | |||
936 | void |
||
937 | _mesa_GetColorTableParameterfv( GLenum target, GLenum pname, GLfloat *params ) |
||
938 | { |
||
939 | GET_CURRENT_CONTEXT(ctx); |
||
940 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
||
941 | struct gl_color_table *table = NULL; |
||
942 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
||
943 | |||
944 | switch (target) { |
||
945 | case GL_TEXTURE_1D: |
||
946 | table = &texUnit->Current1D->Palette; |
||
947 | break; |
||
948 | case GL_TEXTURE_2D: |
||
949 | table = &texUnit->Current2D->Palette; |
||
950 | break; |
||
951 | case GL_TEXTURE_3D: |
||
952 | table = &texUnit->Current3D->Palette; |
||
953 | break; |
||
954 | case GL_TEXTURE_CUBE_MAP_ARB: |
||
955 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
956 | _mesa_error(ctx, GL_INVALID_ENUM, |
||
957 | "glGetColorTableParameterfv(target)"); |
||
958 | return; |
||
959 | } |
||
960 | table = &texUnit->CurrentCubeMap->Palette; |
||
961 | break; |
||
962 | case GL_PROXY_TEXTURE_1D: |
||
963 | table = &ctx->Texture.Proxy1D->Palette; |
||
964 | break; |
||
965 | case GL_PROXY_TEXTURE_2D: |
||
966 | table = &ctx->Texture.Proxy2D->Palette; |
||
967 | break; |
||
968 | case GL_PROXY_TEXTURE_3D: |
||
969 | table = &ctx->Texture.Proxy3D->Palette; |
||
970 | break; |
||
971 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
||
972 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
973 | _mesa_error(ctx, GL_INVALID_ENUM, |
||
974 | "glGetColorTableParameterfv(target)"); |
||
975 | return; |
||
976 | } |
||
977 | table = &ctx->Texture.ProxyCubeMap->Palette; |
||
978 | break; |
||
979 | case GL_SHARED_TEXTURE_PALETTE_EXT: |
||
980 | table = &ctx->Texture.Palette; |
||
981 | break; |
||
982 | case GL_COLOR_TABLE: |
||
983 | table = &ctx->ColorTable; |
||
984 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
985 | params[0] = ctx->Pixel.ColorTableScale[0]; |
||
986 | params[1] = ctx->Pixel.ColorTableScale[1]; |
||
987 | params[2] = ctx->Pixel.ColorTableScale[2]; |
||
988 | params[3] = ctx->Pixel.ColorTableScale[3]; |
||
989 | return; |
||
990 | } |
||
991 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
992 | params[0] = ctx->Pixel.ColorTableBias[0]; |
||
993 | params[1] = ctx->Pixel.ColorTableBias[1]; |
||
994 | params[2] = ctx->Pixel.ColorTableBias[2]; |
||
995 | params[3] = ctx->Pixel.ColorTableBias[3]; |
||
996 | return; |
||
997 | } |
||
998 | break; |
||
999 | case GL_PROXY_COLOR_TABLE: |
||
1000 | table = &ctx->ProxyColorTable; |
||
1001 | break; |
||
1002 | case GL_POST_CONVOLUTION_COLOR_TABLE: |
||
1003 | table = &ctx->PostConvolutionColorTable; |
||
1004 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
1005 | params[0] = ctx->Pixel.PCCTscale[0]; |
||
1006 | params[1] = ctx->Pixel.PCCTscale[1]; |
||
1007 | params[2] = ctx->Pixel.PCCTscale[2]; |
||
1008 | params[3] = ctx->Pixel.PCCTscale[3]; |
||
1009 | return; |
||
1010 | } |
||
1011 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
1012 | params[0] = ctx->Pixel.PCCTbias[0]; |
||
1013 | params[1] = ctx->Pixel.PCCTbias[1]; |
||
1014 | params[2] = ctx->Pixel.PCCTbias[2]; |
||
1015 | params[3] = ctx->Pixel.PCCTbias[3]; |
||
1016 | return; |
||
1017 | } |
||
1018 | break; |
||
1019 | case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: |
||
1020 | table = &ctx->ProxyPostConvolutionColorTable; |
||
1021 | break; |
||
1022 | case GL_POST_COLOR_MATRIX_COLOR_TABLE: |
||
1023 | table = &ctx->PostColorMatrixColorTable; |
||
1024 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
1025 | params[0] = ctx->Pixel.PCMCTscale[0]; |
||
1026 | params[1] = ctx->Pixel.PCMCTscale[1]; |
||
1027 | params[2] = ctx->Pixel.PCMCTscale[2]; |
||
1028 | params[3] = ctx->Pixel.PCMCTscale[3]; |
||
1029 | return; |
||
1030 | } |
||
1031 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
1032 | params[0] = ctx->Pixel.PCMCTbias[0]; |
||
1033 | params[1] = ctx->Pixel.PCMCTbias[1]; |
||
1034 | params[2] = ctx->Pixel.PCMCTbias[2]; |
||
1035 | params[3] = ctx->Pixel.PCMCTbias[3]; |
||
1036 | return; |
||
1037 | } |
||
1038 | break; |
||
1039 | case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: |
||
1040 | table = &ctx->ProxyPostColorMatrixColorTable; |
||
1041 | break; |
||
1042 | default: |
||
1043 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(target)"); |
||
1044 | return; |
||
1045 | } |
||
1046 | |||
1047 | assert(table); |
||
1048 | |||
1049 | switch (pname) { |
||
1050 | case GL_COLOR_TABLE_FORMAT: |
||
1051 | *params = (GLfloat) table->IntFormat; |
||
1052 | break; |
||
1053 | case GL_COLOR_TABLE_WIDTH: |
||
1054 | *params = (GLfloat) table->Size; |
||
1055 | break; |
||
1056 | case GL_COLOR_TABLE_RED_SIZE: |
||
1057 | *params = table->RedSize; |
||
1058 | break; |
||
1059 | case GL_COLOR_TABLE_GREEN_SIZE: |
||
1060 | *params = table->GreenSize; |
||
1061 | break; |
||
1062 | case GL_COLOR_TABLE_BLUE_SIZE: |
||
1063 | *params = table->BlueSize; |
||
1064 | break; |
||
1065 | case GL_COLOR_TABLE_ALPHA_SIZE: |
||
1066 | *params = table->AlphaSize; |
||
1067 | break; |
||
1068 | case GL_COLOR_TABLE_LUMINANCE_SIZE: |
||
1069 | *params = table->LuminanceSize; |
||
1070 | break; |
||
1071 | case GL_COLOR_TABLE_INTENSITY_SIZE: |
||
1072 | *params = table->IntensitySize; |
||
1073 | break; |
||
1074 | default: |
||
1075 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameterfv(pname)" ); |
||
1076 | return; |
||
1077 | } |
||
1078 | } |
||
1079 | |||
1080 | |||
1081 | |||
1082 | void |
||
1083 | _mesa_GetColorTableParameteriv( GLenum target, GLenum pname, GLint *params ) |
||
1084 | { |
||
1085 | GET_CURRENT_CONTEXT(ctx); |
||
1086 | struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit]; |
||
1087 | struct gl_color_table *table = NULL; |
||
1088 | ASSERT_OUTSIDE_BEGIN_END(ctx); |
||
1089 | |||
1090 | switch (target) { |
||
1091 | case GL_TEXTURE_1D: |
||
1092 | table = &texUnit->Current1D->Palette; |
||
1093 | break; |
||
1094 | case GL_TEXTURE_2D: |
||
1095 | table = &texUnit->Current2D->Palette; |
||
1096 | break; |
||
1097 | case GL_TEXTURE_3D: |
||
1098 | table = &texUnit->Current3D->Palette; |
||
1099 | break; |
||
1100 | case GL_TEXTURE_CUBE_MAP_ARB: |
||
1101 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
1102 | _mesa_error(ctx, GL_INVALID_ENUM, |
||
1103 | "glGetColorTableParameteriv(target)"); |
||
1104 | return; |
||
1105 | } |
||
1106 | table = &texUnit->CurrentCubeMap->Palette; |
||
1107 | break; |
||
1108 | case GL_PROXY_TEXTURE_1D: |
||
1109 | table = &ctx->Texture.Proxy1D->Palette; |
||
1110 | break; |
||
1111 | case GL_PROXY_TEXTURE_2D: |
||
1112 | table = &ctx->Texture.Proxy2D->Palette; |
||
1113 | break; |
||
1114 | case GL_PROXY_TEXTURE_3D: |
||
1115 | table = &ctx->Texture.Proxy3D->Palette; |
||
1116 | break; |
||
1117 | case GL_PROXY_TEXTURE_CUBE_MAP_ARB: |
||
1118 | if (!ctx->Extensions.ARB_texture_cube_map) { |
||
1119 | _mesa_error(ctx, GL_INVALID_ENUM, |
||
1120 | "glGetColorTableParameteriv(target)"); |
||
1121 | return; |
||
1122 | } |
||
1123 | table = &ctx->Texture.ProxyCubeMap->Palette; |
||
1124 | break; |
||
1125 | case GL_SHARED_TEXTURE_PALETTE_EXT: |
||
1126 | table = &ctx->Texture.Palette; |
||
1127 | break; |
||
1128 | case GL_COLOR_TABLE: |
||
1129 | table = &ctx->ColorTable; |
||
1130 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
1131 | params[0] = (GLint) ctx->Pixel.ColorTableScale[0]; |
||
1132 | params[1] = (GLint) ctx->Pixel.ColorTableScale[1]; |
||
1133 | params[2] = (GLint) ctx->Pixel.ColorTableScale[2]; |
||
1134 | params[3] = (GLint) ctx->Pixel.ColorTableScale[3]; |
||
1135 | return; |
||
1136 | } |
||
1137 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
1138 | params[0] = (GLint) ctx->Pixel.ColorTableBias[0]; |
||
1139 | params[1] = (GLint) ctx->Pixel.ColorTableBias[1]; |
||
1140 | params[2] = (GLint) ctx->Pixel.ColorTableBias[2]; |
||
1141 | params[3] = (GLint) ctx->Pixel.ColorTableBias[3]; |
||
1142 | return; |
||
1143 | } |
||
1144 | break; |
||
1145 | case GL_PROXY_COLOR_TABLE: |
||
1146 | table = &ctx->ProxyColorTable; |
||
1147 | break; |
||
1148 | case GL_POST_CONVOLUTION_COLOR_TABLE: |
||
1149 | table = &ctx->PostConvolutionColorTable; |
||
1150 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
1151 | params[0] = (GLint) ctx->Pixel.PCCTscale[0]; |
||
1152 | params[1] = (GLint) ctx->Pixel.PCCTscale[1]; |
||
1153 | params[2] = (GLint) ctx->Pixel.PCCTscale[2]; |
||
1154 | params[3] = (GLint) ctx->Pixel.PCCTscale[3]; |
||
1155 | return; |
||
1156 | } |
||
1157 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
1158 | params[0] = (GLint) ctx->Pixel.PCCTbias[0]; |
||
1159 | params[1] = (GLint) ctx->Pixel.PCCTbias[1]; |
||
1160 | params[2] = (GLint) ctx->Pixel.PCCTbias[2]; |
||
1161 | params[3] = (GLint) ctx->Pixel.PCCTbias[3]; |
||
1162 | return; |
||
1163 | } |
||
1164 | break; |
||
1165 | case GL_PROXY_POST_CONVOLUTION_COLOR_TABLE: |
||
1166 | table = &ctx->ProxyPostConvolutionColorTable; |
||
1167 | break; |
||
1168 | case GL_POST_COLOR_MATRIX_COLOR_TABLE: |
||
1169 | table = &ctx->PostColorMatrixColorTable; |
||
1170 | if (pname == GL_COLOR_TABLE_SCALE_SGI) { |
||
1171 | params[0] = (GLint) ctx->Pixel.PCMCTscale[0]; |
||
1172 | params[1] = (GLint) ctx->Pixel.PCMCTscale[1]; |
||
1173 | params[2] = (GLint) ctx->Pixel.PCMCTscale[2]; |
||
1174 | params[3] = (GLint) ctx->Pixel.PCMCTscale[3]; |
||
1175 | return; |
||
1176 | } |
||
1177 | else if (pname == GL_COLOR_TABLE_BIAS_SGI) { |
||
1178 | params[0] = (GLint) ctx->Pixel.PCMCTbias[0]; |
||
1179 | params[1] = (GLint) ctx->Pixel.PCMCTbias[1]; |
||
1180 | params[2] = (GLint) ctx->Pixel.PCMCTbias[2]; |
||
1181 | params[3] = (GLint) ctx->Pixel.PCMCTbias[3]; |
||
1182 | return; |
||
1183 | } |
||
1184 | break; |
||
1185 | case GL_PROXY_POST_COLOR_MATRIX_COLOR_TABLE: |
||
1186 | table = &ctx->ProxyPostColorMatrixColorTable; |
||
1187 | break; |
||
1188 | default: |
||
1189 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(target)"); |
||
1190 | return; |
||
1191 | } |
||
1192 | |||
1193 | assert(table); |
||
1194 | |||
1195 | switch (pname) { |
||
1196 | case GL_COLOR_TABLE_FORMAT: |
||
1197 | *params = table->IntFormat; |
||
1198 | break; |
||
1199 | case GL_COLOR_TABLE_WIDTH: |
||
1200 | *params = table->Size; |
||
1201 | break; |
||
1202 | case GL_COLOR_TABLE_RED_SIZE: |
||
1203 | *params = table->RedSize; |
||
1204 | break; |
||
1205 | case GL_COLOR_TABLE_GREEN_SIZE: |
||
1206 | *params = table->GreenSize; |
||
1207 | break; |
||
1208 | case GL_COLOR_TABLE_BLUE_SIZE: |
||
1209 | *params = table->BlueSize; |
||
1210 | break; |
||
1211 | case GL_COLOR_TABLE_ALPHA_SIZE: |
||
1212 | *params = table->AlphaSize; |
||
1213 | break; |
||
1214 | case GL_COLOR_TABLE_LUMINANCE_SIZE: |
||
1215 | *params = table->LuminanceSize; |
||
1216 | break; |
||
1217 | case GL_COLOR_TABLE_INTENSITY_SIZE: |
||
1218 | *params = table->IntensitySize; |
||
1219 | break; |
||
1220 | default: |
||
1221 | _mesa_error(ctx, GL_INVALID_ENUM, "glGetColorTableParameteriv(pname)" ); |
||
1222 | return; |
||
1223 | } |
||
1224 | } |