043ca3bac386cb3f514b178b0b94131e5f299eb0
[mesa.git] / src / mesa / main / texstate.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 * \file texstate.c
27 *
28 * Texture state handling.
29 */
30
31 #include "glheader.h"
32 #include "colormac.h"
33 #include "colortab.h"
34 #include "context.h"
35 #include "enums.h"
36 #include "macros.h"
37 #include "texobj.h"
38 #include "teximage.h"
39 #include "texstate.h"
40 #include "texenvprogram.h"
41 #include "mtypes.h"
42 #include "math/m_xform.h"
43
44
45
46 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
47 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
48
49
50 /**
51 * Default texture combine environment state. This is used to initialize
52 * a context's texture units and as the basis for converting "classic"
53 * texture environmnets to ARB_texture_env_combine style values.
54 */
55 static const struct gl_tex_env_combine_state default_combine_state = {
56 GL_MODULATE, GL_MODULATE,
57 { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT },
58 { GL_TEXTURE, GL_PREVIOUS, GL_CONSTANT },
59 { GL_SRC_COLOR, GL_SRC_COLOR, GL_SRC_ALPHA },
60 { GL_SRC_ALPHA, GL_SRC_ALPHA, GL_SRC_ALPHA },
61 0, 0,
62 2, 2
63 };
64
65
66 void
67 _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
68 {
69 GLuint i;
70
71 ASSERT(src);
72 ASSERT(dst);
73
74 dst->Texture.CurrentUnit = src->Texture.CurrentUnit;
75 dst->Texture._GenFlags = src->Texture._GenFlags;
76 dst->Texture._TexGenEnabled = src->Texture._TexGenEnabled;
77 dst->Texture._TexMatEnabled = src->Texture._TexMatEnabled;
78 dst->Texture.SharedPalette = src->Texture.SharedPalette;
79
80 /* per-unit state */
81 for (i = 0; i < src->Const.MaxTextureUnits; i++) {
82 dst->Texture.Unit[i].Enabled = src->Texture.Unit[i].Enabled;
83 dst->Texture.Unit[i].EnvMode = src->Texture.Unit[i].EnvMode;
84 COPY_4V(dst->Texture.Unit[i].EnvColor, src->Texture.Unit[i].EnvColor);
85 dst->Texture.Unit[i].TexGenEnabled = src->Texture.Unit[i].TexGenEnabled;
86 dst->Texture.Unit[i].GenModeS = src->Texture.Unit[i].GenModeS;
87 dst->Texture.Unit[i].GenModeT = src->Texture.Unit[i].GenModeT;
88 dst->Texture.Unit[i].GenModeR = src->Texture.Unit[i].GenModeR;
89 dst->Texture.Unit[i].GenModeQ = src->Texture.Unit[i].GenModeQ;
90 dst->Texture.Unit[i]._GenBitS = src->Texture.Unit[i]._GenBitS;
91 dst->Texture.Unit[i]._GenBitT = src->Texture.Unit[i]._GenBitT;
92 dst->Texture.Unit[i]._GenBitR = src->Texture.Unit[i]._GenBitR;
93 dst->Texture.Unit[i]._GenBitQ = src->Texture.Unit[i]._GenBitQ;
94 dst->Texture.Unit[i]._GenFlags = src->Texture.Unit[i]._GenFlags;
95 COPY_4V(dst->Texture.Unit[i].ObjectPlaneS, src->Texture.Unit[i].ObjectPlaneS);
96 COPY_4V(dst->Texture.Unit[i].ObjectPlaneT, src->Texture.Unit[i].ObjectPlaneT);
97 COPY_4V(dst->Texture.Unit[i].ObjectPlaneR, src->Texture.Unit[i].ObjectPlaneR);
98 COPY_4V(dst->Texture.Unit[i].ObjectPlaneQ, src->Texture.Unit[i].ObjectPlaneQ);
99 COPY_4V(dst->Texture.Unit[i].EyePlaneS, src->Texture.Unit[i].EyePlaneS);
100 COPY_4V(dst->Texture.Unit[i].EyePlaneT, src->Texture.Unit[i].EyePlaneT);
101 COPY_4V(dst->Texture.Unit[i].EyePlaneR, src->Texture.Unit[i].EyePlaneR);
102 COPY_4V(dst->Texture.Unit[i].EyePlaneQ, src->Texture.Unit[i].EyePlaneQ);
103 dst->Texture.Unit[i].LodBias = src->Texture.Unit[i].LodBias;
104
105 /* GL_EXT_texture_env_combine */
106 dst->Texture.Unit[i].Combine.ModeRGB = src->Texture.Unit[i].Combine.ModeRGB;
107 dst->Texture.Unit[i].Combine.ModeA = src->Texture.Unit[i].Combine.ModeA;
108 COPY_3V(dst->Texture.Unit[i].Combine.SourceRGB, src->Texture.Unit[i].Combine.SourceRGB);
109 COPY_3V(dst->Texture.Unit[i].Combine.SourceA, src->Texture.Unit[i].Combine.SourceA);
110 COPY_3V(dst->Texture.Unit[i].Combine.OperandRGB, src->Texture.Unit[i].Combine.OperandRGB);
111 COPY_3V(dst->Texture.Unit[i].Combine.OperandA, src->Texture.Unit[i].Combine.OperandA);
112 dst->Texture.Unit[i].Combine.ScaleShiftRGB = src->Texture.Unit[i].Combine.ScaleShiftRGB;
113 dst->Texture.Unit[i].Combine.ScaleShiftA = src->Texture.Unit[i].Combine.ScaleShiftA;
114
115 /* texture object state */
116 _mesa_copy_texture_object(dst->Texture.Unit[i].Current1D,
117 src->Texture.Unit[i].Current1D);
118 _mesa_copy_texture_object(dst->Texture.Unit[i].Current2D,
119 src->Texture.Unit[i].Current2D);
120 _mesa_copy_texture_object(dst->Texture.Unit[i].Current3D,
121 src->Texture.Unit[i].Current3D);
122 _mesa_copy_texture_object(dst->Texture.Unit[i].CurrentCubeMap,
123 src->Texture.Unit[i].CurrentCubeMap);
124 _mesa_copy_texture_object(dst->Texture.Unit[i].CurrentRect,
125 src->Texture.Unit[i].CurrentRect);
126 }
127 }
128
129
130 /*
131 * For debugging
132 */
133 void
134 _mesa_print_texunit_state( GLcontext *ctx, GLuint unit )
135 {
136 const struct gl_texture_unit *texUnit = ctx->Texture.Unit + unit;
137 _mesa_printf("Texture Unit %d\n", unit);
138 _mesa_printf(" GL_TEXTURE_ENV_MODE = %s\n", _mesa_lookup_enum_by_nr(texUnit->EnvMode));
139 _mesa_printf(" GL_COMBINE_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeRGB));
140 _mesa_printf(" GL_COMBINE_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.ModeA));
141 _mesa_printf(" GL_SOURCE0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[0]));
142 _mesa_printf(" GL_SOURCE1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[1]));
143 _mesa_printf(" GL_SOURCE2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceRGB[2]));
144 _mesa_printf(" GL_SOURCE0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[0]));
145 _mesa_printf(" GL_SOURCE1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[1]));
146 _mesa_printf(" GL_SOURCE2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.SourceA[2]));
147 _mesa_printf(" GL_OPERAND0_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[0]));
148 _mesa_printf(" GL_OPERAND1_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[1]));
149 _mesa_printf(" GL_OPERAND2_RGB = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandRGB[2]));
150 _mesa_printf(" GL_OPERAND0_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[0]));
151 _mesa_printf(" GL_OPERAND1_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[1]));
152 _mesa_printf(" GL_OPERAND2_ALPHA = %s\n", _mesa_lookup_enum_by_nr(texUnit->Combine.OperandA[2]));
153 _mesa_printf(" GL_RGB_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftRGB);
154 _mesa_printf(" GL_ALPHA_SCALE = %d\n", 1 << texUnit->Combine.ScaleShiftA);
155 _mesa_printf(" GL_TEXTURE_ENV_COLOR = (%f, %f, %f, %f)\n", texUnit->EnvColor[0], texUnit->EnvColor[1], texUnit->EnvColor[2], texUnit->EnvColor[3]);
156 }
157
158
159
160 /**********************************************************************/
161 /* Texture Environment */
162 /**********************************************************************/
163
164 /**
165 * Convert "classic" texture environment to ARB_texture_env_combine style
166 * environments.
167 *
168 * \param state texture_env_combine state vector to be filled-in.
169 * \param mode Classic texture environment mode (i.e., \c GL_REPLACE,
170 * \c GL_BLEND, \c GL_DECAL, etc.).
171 * \param texBaseFormat Base format of the texture associated with the
172 * texture unit.
173 */
174 static void
175 calculate_derived_texenv( struct gl_tex_env_combine_state *state,
176 GLenum mode, GLenum texBaseFormat )
177 {
178 GLenum mode_rgb;
179 GLenum mode_a;
180
181 *state = default_combine_state;
182
183 switch (texBaseFormat) {
184 case GL_ALPHA:
185 state->SourceRGB[0] = GL_PREVIOUS;
186 break;
187
188 case GL_LUMINANCE_ALPHA:
189 case GL_INTENSITY:
190 case GL_RGBA:
191 break;
192
193 case GL_LUMINANCE:
194 case GL_RGB:
195 case GL_YCBCR_MESA:
196 state->SourceA[0] = GL_PREVIOUS;
197 break;
198
199 default:
200 _mesa_problem(NULL, "Invalid texBaseFormat in calculate_derived_texenv");
201 return;
202 }
203
204 switch (mode) {
205 case GL_REPLACE:
206 case GL_MODULATE:
207 mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : mode;
208 mode_a = mode;
209 break;
210
211 case GL_DECAL:
212 mode_rgb = GL_INTERPOLATE;
213 mode_a = GL_REPLACE;
214
215 state->SourceA[0] = GL_PREVIOUS;
216
217 /* Having alpha / luminance / intensity textures replace using the
218 * incoming fragment color matches the definition in NV_texture_shader.
219 * The 1.5 spec simply marks these as "undefined".
220 */
221 switch (texBaseFormat) {
222 case GL_ALPHA:
223 case GL_LUMINANCE:
224 case GL_LUMINANCE_ALPHA:
225 case GL_INTENSITY:
226 state->SourceRGB[0] = GL_PREVIOUS;
227 break;
228 case GL_RGB:
229 case GL_YCBCR_MESA:
230 mode_rgb = GL_REPLACE;
231 break;
232 case GL_RGBA:
233 state->SourceRGB[2] = GL_TEXTURE;
234 break;
235 }
236 break;
237
238 case GL_BLEND:
239 mode_rgb = GL_INTERPOLATE;
240 mode_a = GL_MODULATE;
241
242 switch (texBaseFormat) {
243 case GL_ALPHA:
244 mode_rgb = GL_REPLACE;
245 break;
246 case GL_INTENSITY:
247 mode_a = GL_INTERPOLATE;
248 state->SourceA[0] = GL_CONSTANT;
249 state->OperandA[2] = GL_SRC_ALPHA;
250 /* FALLTHROUGH */
251 case GL_LUMINANCE:
252 case GL_RGB:
253 case GL_LUMINANCE_ALPHA:
254 case GL_RGBA:
255 case GL_YCBCR_MESA:
256 state->SourceRGB[2] = GL_TEXTURE;
257 state->SourceA[2] = GL_TEXTURE;
258 state->SourceRGB[0] = GL_CONSTANT;
259 state->OperandRGB[2] = GL_SRC_COLOR;
260 break;
261 }
262 break;
263
264 case GL_ADD:
265 mode_rgb = (texBaseFormat == GL_ALPHA) ? GL_REPLACE : GL_ADD;
266 mode_a = (texBaseFormat == GL_INTENSITY) ? GL_ADD : GL_MODULATE;
267 break;
268
269 default:
270 _mesa_problem(NULL,
271 "Invalid texture env mode in calculate_derived_texenv");
272 return;
273 }
274
275 state->ModeRGB = (state->SourceRGB[0] != GL_PREVIOUS)
276 ? mode_rgb : GL_REPLACE;
277 state->ModeA = (state->SourceA[0] != GL_PREVIOUS)
278 ? mode_a : GL_REPLACE;
279 }
280
281
282 void GLAPIENTRY
283 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
284 {
285 GET_CURRENT_CONTEXT(ctx);
286 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
287 ASSERT_OUTSIDE_BEGIN_END(ctx);
288
289 #define TE_ERROR(errCode, msg, value) \
290 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
291
292 if (target == GL_TEXTURE_ENV) {
293 switch (pname) {
294 case GL_TEXTURE_ENV_MODE:
295 {
296 const GLenum mode = (GLenum) (GLint) *param;
297 if (texUnit->EnvMode == mode)
298 return;
299 if (mode == GL_MODULATE ||
300 mode == GL_BLEND ||
301 mode == GL_DECAL ||
302 mode == GL_REPLACE ||
303 (mode == GL_ADD && ctx->Extensions.EXT_texture_env_add) ||
304 (mode == GL_COMBINE &&
305 (ctx->Extensions.EXT_texture_env_combine ||
306 ctx->Extensions.ARB_texture_env_combine))) {
307 /* legal */
308 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
309 texUnit->EnvMode = mode;
310 }
311 else {
312 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
313 return;
314 }
315 }
316 break;
317 case GL_TEXTURE_ENV_COLOR:
318 {
319 GLfloat tmp[4];
320 tmp[0] = CLAMP( param[0], 0.0F, 1.0F );
321 tmp[1] = CLAMP( param[1], 0.0F, 1.0F );
322 tmp[2] = CLAMP( param[2], 0.0F, 1.0F );
323 tmp[3] = CLAMP( param[3], 0.0F, 1.0F );
324 if (TEST_EQ_4V(tmp, texUnit->EnvColor))
325 return;
326 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
327 COPY_4FV(texUnit->EnvColor, tmp);
328 }
329 break;
330 case GL_COMBINE_RGB:
331 if (ctx->Extensions.EXT_texture_env_combine ||
332 ctx->Extensions.ARB_texture_env_combine) {
333 const GLenum mode = (GLenum) (GLint) *param;
334 if (texUnit->Combine.ModeRGB == mode)
335 return;
336 switch (mode) {
337 case GL_REPLACE:
338 case GL_MODULATE:
339 case GL_ADD:
340 case GL_ADD_SIGNED:
341 case GL_INTERPOLATE:
342 /* OK */
343 break;
344 case GL_SUBTRACT:
345 if (!ctx->Extensions.ARB_texture_env_combine) {
346 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
347 return;
348 }
349 break;
350 case GL_DOT3_RGB_EXT:
351 case GL_DOT3_RGBA_EXT:
352 if (!ctx->Extensions.EXT_texture_env_dot3) {
353 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
354 return;
355 }
356 break;
357 case GL_DOT3_RGB:
358 case GL_DOT3_RGBA:
359 if (!ctx->Extensions.ARB_texture_env_dot3) {
360 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
361 return;
362 }
363 break;
364 case GL_MODULATE_ADD_ATI:
365 case GL_MODULATE_SIGNED_ADD_ATI:
366 case GL_MODULATE_SUBTRACT_ATI:
367 if (!ctx->Extensions.ATI_texture_env_combine3) {
368 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
369 return;
370 }
371 break;
372 default:
373 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
374 return;
375 }
376 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
377 texUnit->Combine.ModeRGB = mode;
378 }
379 else {
380 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
381 return;
382 }
383 break;
384 case GL_COMBINE_ALPHA:
385 if (ctx->Extensions.EXT_texture_env_combine ||
386 ctx->Extensions.ARB_texture_env_combine) {
387 const GLenum mode = (GLenum) (GLint) *param;
388 if (texUnit->Combine.ModeA == mode)
389 return;
390 switch (mode) {
391 case GL_REPLACE:
392 case GL_MODULATE:
393 case GL_ADD:
394 case GL_ADD_SIGNED:
395 case GL_INTERPOLATE:
396 /* OK */
397 break;
398 case GL_SUBTRACT:
399 if (!ctx->Extensions.ARB_texture_env_combine) {
400 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
401 return;
402 }
403 break;
404 case GL_MODULATE_ADD_ATI:
405 case GL_MODULATE_SIGNED_ADD_ATI:
406 case GL_MODULATE_SUBTRACT_ATI:
407 if (!ctx->Extensions.ATI_texture_env_combine3) {
408 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
409 return;
410 }
411 break;
412 default:
413 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
414 return;
415 }
416 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
417 texUnit->Combine.ModeA = mode;
418 }
419 else {
420 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
421 return;
422 }
423 break;
424 case GL_SOURCE0_RGB:
425 case GL_SOURCE1_RGB:
426 case GL_SOURCE2_RGB:
427 if (ctx->Extensions.EXT_texture_env_combine ||
428 ctx->Extensions.ARB_texture_env_combine) {
429 const GLenum source = (GLenum) (GLint) *param;
430 const GLuint s = pname - GL_SOURCE0_RGB;
431 if (texUnit->Combine.SourceRGB[s] == source)
432 return;
433 if (source == GL_TEXTURE ||
434 source == GL_CONSTANT ||
435 source == GL_PRIMARY_COLOR ||
436 source == GL_PREVIOUS ||
437 (ctx->Extensions.ARB_texture_env_crossbar &&
438 source >= GL_TEXTURE0 &&
439 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) ||
440 (ctx->Extensions.ATI_texture_env_combine3 &&
441 (source == GL_ZERO || source == GL_ONE))) {
442 /* legal */
443 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
444 texUnit->Combine.SourceRGB[s] = source;
445 }
446 else {
447 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source);
448 return;
449 }
450 }
451 else {
452 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
453 return;
454 }
455 break;
456 case GL_SOURCE0_ALPHA:
457 case GL_SOURCE1_ALPHA:
458 case GL_SOURCE2_ALPHA:
459 if (ctx->Extensions.EXT_texture_env_combine ||
460 ctx->Extensions.ARB_texture_env_combine) {
461 const GLenum source = (GLenum) (GLint) *param;
462 const GLuint s = pname - GL_SOURCE0_ALPHA;
463 if (texUnit->Combine.SourceA[s] == source)
464 return;
465 if (source == GL_TEXTURE ||
466 source == GL_CONSTANT ||
467 source == GL_PRIMARY_COLOR ||
468 source == GL_PREVIOUS ||
469 (ctx->Extensions.ARB_texture_env_crossbar &&
470 source >= GL_TEXTURE0 &&
471 source < GL_TEXTURE0 + ctx->Const.MaxTextureUnits) ||
472 (ctx->Extensions.ATI_texture_env_combine3 &&
473 (source == GL_ZERO || source == GL_ONE))) {
474 /* legal */
475 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
476 texUnit->Combine.SourceA[s] = source;
477 }
478 else {
479 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source);
480 return;
481 }
482 }
483 else {
484 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
485 return;
486 }
487 break;
488 case GL_OPERAND0_RGB:
489 case GL_OPERAND1_RGB:
490 if (ctx->Extensions.EXT_texture_env_combine ||
491 ctx->Extensions.ARB_texture_env_combine) {
492 const GLenum operand = (GLenum) (GLint) *param;
493 const GLuint s = pname - GL_OPERAND0_RGB;
494 if (texUnit->Combine.OperandRGB[s] == operand)
495 return;
496 switch (operand) {
497 case GL_SRC_COLOR:
498 case GL_ONE_MINUS_SRC_COLOR:
499 case GL_SRC_ALPHA:
500 case GL_ONE_MINUS_SRC_ALPHA:
501 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
502 texUnit->Combine.OperandRGB[s] = operand;
503 break;
504 default:
505 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
506 return;
507 }
508 }
509 else {
510 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
511 return;
512 }
513 break;
514 case GL_OPERAND0_ALPHA:
515 case GL_OPERAND1_ALPHA:
516 if (ctx->Extensions.EXT_texture_env_combine ||
517 ctx->Extensions.ARB_texture_env_combine) {
518 const GLenum operand = (GLenum) (GLint) *param;
519 if (texUnit->Combine.OperandA[pname-GL_OPERAND0_ALPHA] == operand)
520 return;
521 switch (operand) {
522 case GL_SRC_ALPHA:
523 case GL_ONE_MINUS_SRC_ALPHA:
524 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
525 texUnit->Combine.OperandA[pname-GL_OPERAND0_ALPHA] = operand;
526 break;
527 default:
528 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
529 return;
530 }
531 }
532 else {
533 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
534 return;
535 }
536 break;
537 case GL_OPERAND2_RGB:
538 if (ctx->Extensions.ARB_texture_env_combine) {
539 const GLenum operand = (GLenum) (GLint) *param;
540 if (texUnit->Combine.OperandRGB[2] == operand)
541 return;
542 switch (operand) {
543 case GL_SRC_COLOR: /* ARB combine only */
544 case GL_ONE_MINUS_SRC_COLOR: /* ARB combine only */
545 case GL_SRC_ALPHA:
546 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */
547 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
548 texUnit->Combine.OperandRGB[2] = operand;
549 break;
550 default:
551 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
552 return;
553 }
554 }
555 else if (ctx->Extensions.EXT_texture_env_combine) {
556 const GLenum operand = (GLenum) (GLint) *param;
557 if (texUnit->Combine.OperandRGB[2] == operand)
558 return;
559 /* operand must be GL_SRC_ALPHA which is the initial value - thus
560 don't need to actually compare the operand to the possible value */
561 else {
562 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
563 return;
564 }
565 }
566 else {
567 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
568 return;
569 }
570 break;
571 case GL_OPERAND2_ALPHA:
572 if (ctx->Extensions.ARB_texture_env_combine) {
573 const GLenum operand = (GLenum) (GLint) *param;
574 if (texUnit->Combine.OperandA[2] == operand)
575 return;
576 switch (operand) {
577 case GL_SRC_ALPHA:
578 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */
579 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
580 texUnit->Combine.OperandA[2] = operand;
581 break;
582 default:
583 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
584 return;
585 }
586 }
587 else if (ctx->Extensions.EXT_texture_env_combine) {
588 const GLenum operand = (GLenum) (GLint) *param;
589 if (texUnit->Combine.OperandA[2] == operand)
590 return;
591 /* operand must be GL_SRC_ALPHA which is the initial value - thus
592 don't need to actually compare the operand to the possible value */
593 else {
594 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
595 return;
596 }
597 }
598 else {
599 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
600 return;
601 }
602 break;
603 case GL_RGB_SCALE:
604 if (ctx->Extensions.EXT_texture_env_combine ||
605 ctx->Extensions.ARB_texture_env_combine) {
606 GLuint newshift;
607 if (*param == 1.0) {
608 newshift = 0;
609 }
610 else if (*param == 2.0) {
611 newshift = 1;
612 }
613 else if (*param == 4.0) {
614 newshift = 2;
615 }
616 else {
617 _mesa_error( ctx, GL_INVALID_VALUE,
618 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
619 return;
620 }
621 if (texUnit->Combine.ScaleShiftRGB == newshift)
622 return;
623 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
624 texUnit->Combine.ScaleShiftRGB = newshift;
625 }
626 else {
627 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
628 return;
629 }
630 break;
631 case GL_ALPHA_SCALE:
632 if (ctx->Extensions.EXT_texture_env_combine ||
633 ctx->Extensions.ARB_texture_env_combine) {
634 GLuint newshift;
635 if (*param == 1.0) {
636 newshift = 0;
637 }
638 else if (*param == 2.0) {
639 newshift = 1;
640 }
641 else if (*param == 4.0) {
642 newshift = 2;
643 }
644 else {
645 _mesa_error( ctx, GL_INVALID_VALUE,
646 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
647 return;
648 }
649 if (texUnit->Combine.ScaleShiftA == newshift)
650 return;
651 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
652 texUnit->Combine.ScaleShiftA = newshift;
653 }
654 else {
655 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
656 return;
657 }
658 break;
659 default:
660 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
661 return;
662 }
663 }
664 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
665 /* GL_EXT_texture_lod_bias */
666 if (!ctx->Extensions.EXT_texture_lod_bias) {
667 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target );
668 return;
669 }
670 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
671 if (texUnit->LodBias == param[0])
672 return;
673 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
674 texUnit->LodBias = param[0];
675 }
676 else {
677 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
678 return;
679 }
680 }
681 else if (target == GL_POINT_SPRITE_NV) {
682 /* GL_ARB_point_sprite / GL_NV_point_sprite */
683 if (!ctx->Extensions.NV_point_sprite
684 && !ctx->Extensions.ARB_point_sprite) {
685 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target );
686 return;
687 }
688 if (pname == GL_COORD_REPLACE_NV) {
689 const GLenum value = (GLenum) param[0];
690 if (value == GL_TRUE || value == GL_FALSE) {
691 /* It's kind of weird to set point state via glTexEnv,
692 * but that's what the spec calls for.
693 */
694 const GLboolean state = (GLboolean) value;
695 if (ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] == state)
696 return;
697 FLUSH_VERTICES(ctx, _NEW_POINT);
698 ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = state;
699 }
700 else {
701 _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", value);
702 return;
703 }
704 }
705 else {
706 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname );
707 return;
708 }
709 }
710 else {
711 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)",target );
712 return;
713 }
714
715 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
716 _mesa_debug(ctx, "glTexEnv %s %s %.1f(%s) ...\n",
717 _mesa_lookup_enum_by_nr(target),
718 _mesa_lookup_enum_by_nr(pname),
719 *param,
720 _mesa_lookup_enum_by_nr((GLenum) (GLint) *param));
721
722 /* Tell device driver about the new texture environment */
723 if (ctx->Driver.TexEnv) {
724 (*ctx->Driver.TexEnv)( ctx, target, pname, param );
725 }
726 }
727
728
729 void GLAPIENTRY
730 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
731 {
732 _mesa_TexEnvfv( target, pname, &param );
733 }
734
735
736
737 void GLAPIENTRY
738 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
739 {
740 GLfloat p[4];
741 p[0] = (GLfloat) param;
742 p[1] = p[2] = p[3] = 0.0;
743 _mesa_TexEnvfv( target, pname, p );
744 }
745
746
747 void GLAPIENTRY
748 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
749 {
750 GLfloat p[4];
751 if (pname == GL_TEXTURE_ENV_COLOR) {
752 p[0] = INT_TO_FLOAT( param[0] );
753 p[1] = INT_TO_FLOAT( param[1] );
754 p[2] = INT_TO_FLOAT( param[2] );
755 p[3] = INT_TO_FLOAT( param[3] );
756 }
757 else {
758 p[0] = (GLfloat) param[0];
759 p[1] = p[2] = p[3] = 0; /* init to zero, just to be safe */
760 }
761 _mesa_TexEnvfv( target, pname, p );
762 }
763
764
765 void GLAPIENTRY
766 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
767 {
768 GET_CURRENT_CONTEXT(ctx);
769 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
770 ASSERT_OUTSIDE_BEGIN_END(ctx);
771
772 if (target == GL_TEXTURE_ENV) {
773 switch (pname) {
774 case GL_TEXTURE_ENV_MODE:
775 *params = ENUM_TO_FLOAT(texUnit->EnvMode);
776 break;
777 case GL_TEXTURE_ENV_COLOR:
778 COPY_4FV( params, texUnit->EnvColor );
779 break;
780 case GL_COMBINE_RGB:
781 if (ctx->Extensions.EXT_texture_env_combine ||
782 ctx->Extensions.ARB_texture_env_combine) {
783 *params = (GLfloat) texUnit->Combine.ModeRGB;
784 }
785 else {
786 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
787 }
788 break;
789 case GL_COMBINE_ALPHA:
790 if (ctx->Extensions.EXT_texture_env_combine ||
791 ctx->Extensions.ARB_texture_env_combine) {
792 *params = (GLfloat) texUnit->Combine.ModeA;
793 }
794 else {
795 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
796 }
797 break;
798 case GL_SOURCE0_RGB:
799 if (ctx->Extensions.EXT_texture_env_combine ||
800 ctx->Extensions.ARB_texture_env_combine) {
801 *params = (GLfloat) texUnit->Combine.SourceRGB[0];
802 }
803 else {
804 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
805 }
806 break;
807 case GL_SOURCE1_RGB:
808 if (ctx->Extensions.EXT_texture_env_combine ||
809 ctx->Extensions.ARB_texture_env_combine) {
810 *params = (GLfloat) texUnit->Combine.SourceRGB[1];
811 }
812 else {
813 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
814 }
815 break;
816 case GL_SOURCE2_RGB:
817 if (ctx->Extensions.EXT_texture_env_combine ||
818 ctx->Extensions.ARB_texture_env_combine) {
819 *params = (GLfloat) texUnit->Combine.SourceRGB[2];
820 }
821 else {
822 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
823 }
824 break;
825 case GL_SOURCE0_ALPHA:
826 if (ctx->Extensions.EXT_texture_env_combine ||
827 ctx->Extensions.ARB_texture_env_combine) {
828 *params = (GLfloat) texUnit->Combine.SourceA[0];
829 }
830 else {
831 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
832 }
833 break;
834 case GL_SOURCE1_ALPHA:
835 if (ctx->Extensions.EXT_texture_env_combine ||
836 ctx->Extensions.ARB_texture_env_combine) {
837 *params = (GLfloat) texUnit->Combine.SourceA[1];
838 }
839 else {
840 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
841 }
842 break;
843 case GL_SOURCE2_ALPHA:
844 if (ctx->Extensions.EXT_texture_env_combine ||
845 ctx->Extensions.ARB_texture_env_combine) {
846 *params = (GLfloat) texUnit->Combine.SourceA[2];
847 }
848 else {
849 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
850 }
851 break;
852 case GL_OPERAND0_RGB:
853 if (ctx->Extensions.EXT_texture_env_combine ||
854 ctx->Extensions.ARB_texture_env_combine) {
855 *params = (GLfloat) texUnit->Combine.OperandRGB[0];
856 }
857 else {
858 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
859 }
860 break;
861 case GL_OPERAND1_RGB:
862 if (ctx->Extensions.EXT_texture_env_combine ||
863 ctx->Extensions.ARB_texture_env_combine) {
864 *params = (GLfloat) texUnit->Combine.OperandRGB[1];
865 }
866 else {
867 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
868 }
869 break;
870 case GL_OPERAND2_RGB:
871 if (ctx->Extensions.EXT_texture_env_combine ||
872 ctx->Extensions.ARB_texture_env_combine) {
873 *params = (GLfloat) texUnit->Combine.OperandRGB[2];
874 }
875 else {
876 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
877 }
878 break;
879 case GL_OPERAND0_ALPHA:
880 if (ctx->Extensions.EXT_texture_env_combine ||
881 ctx->Extensions.ARB_texture_env_combine) {
882 *params = (GLfloat) texUnit->Combine.OperandA[0];
883 }
884 else {
885 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
886 }
887 break;
888 case GL_OPERAND1_ALPHA:
889 if (ctx->Extensions.EXT_texture_env_combine ||
890 ctx->Extensions.ARB_texture_env_combine) {
891 *params = (GLfloat) texUnit->Combine.OperandA[1];
892 }
893 else {
894 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
895 }
896 break;
897 case GL_OPERAND2_ALPHA:
898 if (ctx->Extensions.EXT_texture_env_combine ||
899 ctx->Extensions.ARB_texture_env_combine) {
900 *params = (GLfloat) texUnit->Combine.OperandA[2];
901 }
902 else {
903 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
904 }
905 break;
906 case GL_RGB_SCALE:
907 if (ctx->Extensions.EXT_texture_env_combine ||
908 ctx->Extensions.ARB_texture_env_combine) {
909 if (texUnit->Combine.ScaleShiftRGB == 0)
910 *params = 1.0;
911 else if (texUnit->Combine.ScaleShiftRGB == 1)
912 *params = 2.0;
913 else
914 *params = 4.0;
915 }
916 else {
917 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
918 return;
919 }
920 break;
921 case GL_ALPHA_SCALE:
922 if (ctx->Extensions.EXT_texture_env_combine ||
923 ctx->Extensions.ARB_texture_env_combine) {
924 if (texUnit->Combine.ScaleShiftA == 0)
925 *params = 1.0;
926 else if (texUnit->Combine.ScaleShiftA == 1)
927 *params = 2.0;
928 else
929 *params = 4.0;
930 }
931 else {
932 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
933 return;
934 }
935 break;
936 default:
937 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname=0x%x)", pname);
938 }
939 }
940 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
941 /* GL_EXT_texture_lod_bias */
942 if (!ctx->Extensions.EXT_texture_lod_bias) {
943 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
944 return;
945 }
946 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
947 *params = texUnit->LodBias;
948 }
949 else {
950 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
951 return;
952 }
953 }
954 else if (target == GL_POINT_SPRITE_NV) {
955 /* GL_ARB_point_sprite / GL_NV_point_sprite */
956 if (!ctx->Extensions.NV_point_sprite
957 && !ctx->Extensions.ARB_point_sprite) {
958 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
959 return;
960 }
961 if (pname == GL_COORD_REPLACE_NV) {
962 *params = (GLfloat) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit];
963 }
964 else {
965 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
966 return;
967 }
968 }
969 else {
970 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
971 return;
972 }
973 }
974
975
976 void GLAPIENTRY
977 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
978 {
979 GET_CURRENT_CONTEXT(ctx);
980 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
981 ASSERT_OUTSIDE_BEGIN_END(ctx);
982
983 if (target == GL_TEXTURE_ENV) {
984 switch (pname) {
985 case GL_TEXTURE_ENV_MODE:
986 *params = (GLint) texUnit->EnvMode;
987 break;
988 case GL_TEXTURE_ENV_COLOR:
989 params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
990 params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
991 params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
992 params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
993 break;
994 case GL_COMBINE_RGB:
995 if (ctx->Extensions.EXT_texture_env_combine ||
996 ctx->Extensions.ARB_texture_env_combine) {
997 *params = (GLint) texUnit->Combine.ModeRGB;
998 }
999 else {
1000 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1001 }
1002 break;
1003 case GL_COMBINE_ALPHA:
1004 if (ctx->Extensions.EXT_texture_env_combine ||
1005 ctx->Extensions.ARB_texture_env_combine) {
1006 *params = (GLint) texUnit->Combine.ModeA;
1007 }
1008 else {
1009 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1010 }
1011 break;
1012 case GL_SOURCE0_RGB:
1013 if (ctx->Extensions.EXT_texture_env_combine ||
1014 ctx->Extensions.ARB_texture_env_combine) {
1015 *params = (GLint) texUnit->Combine.SourceRGB[0];
1016 }
1017 else {
1018 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1019 }
1020 break;
1021 case GL_SOURCE1_RGB:
1022 if (ctx->Extensions.EXT_texture_env_combine ||
1023 ctx->Extensions.ARB_texture_env_combine) {
1024 *params = (GLint) texUnit->Combine.SourceRGB[1];
1025 }
1026 else {
1027 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1028 }
1029 break;
1030 case GL_SOURCE2_RGB:
1031 if (ctx->Extensions.EXT_texture_env_combine ||
1032 ctx->Extensions.ARB_texture_env_combine) {
1033 *params = (GLint) texUnit->Combine.SourceRGB[2];
1034 }
1035 else {
1036 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1037 }
1038 break;
1039 case GL_SOURCE0_ALPHA:
1040 if (ctx->Extensions.EXT_texture_env_combine ||
1041 ctx->Extensions.ARB_texture_env_combine) {
1042 *params = (GLint) texUnit->Combine.SourceA[0];
1043 }
1044 else {
1045 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1046 }
1047 break;
1048 case GL_SOURCE1_ALPHA:
1049 if (ctx->Extensions.EXT_texture_env_combine ||
1050 ctx->Extensions.ARB_texture_env_combine) {
1051 *params = (GLint) texUnit->Combine.SourceA[1];
1052 }
1053 else {
1054 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1055 }
1056 break;
1057 case GL_SOURCE2_ALPHA:
1058 if (ctx->Extensions.EXT_texture_env_combine ||
1059 ctx->Extensions.ARB_texture_env_combine) {
1060 *params = (GLint) texUnit->Combine.SourceA[2];
1061 }
1062 else {
1063 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1064 }
1065 break;
1066 case GL_OPERAND0_RGB:
1067 if (ctx->Extensions.EXT_texture_env_combine ||
1068 ctx->Extensions.ARB_texture_env_combine) {
1069 *params = (GLint) texUnit->Combine.OperandRGB[0];
1070 }
1071 else {
1072 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1073 }
1074 break;
1075 case GL_OPERAND1_RGB:
1076 if (ctx->Extensions.EXT_texture_env_combine ||
1077 ctx->Extensions.ARB_texture_env_combine) {
1078 *params = (GLint) texUnit->Combine.OperandRGB[1];
1079 }
1080 else {
1081 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1082 }
1083 break;
1084 case GL_OPERAND2_RGB:
1085 if (ctx->Extensions.EXT_texture_env_combine ||
1086 ctx->Extensions.ARB_texture_env_combine) {
1087 *params = (GLint) texUnit->Combine.OperandRGB[2];
1088 }
1089 else {
1090 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1091 }
1092 break;
1093 case GL_OPERAND0_ALPHA:
1094 if (ctx->Extensions.EXT_texture_env_combine ||
1095 ctx->Extensions.ARB_texture_env_combine) {
1096 *params = (GLint) texUnit->Combine.OperandA[0];
1097 }
1098 else {
1099 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1100 }
1101 break;
1102 case GL_OPERAND1_ALPHA:
1103 if (ctx->Extensions.EXT_texture_env_combine ||
1104 ctx->Extensions.ARB_texture_env_combine) {
1105 *params = (GLint) texUnit->Combine.OperandA[1];
1106 }
1107 else {
1108 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1109 }
1110 break;
1111 case GL_OPERAND2_ALPHA:
1112 if (ctx->Extensions.EXT_texture_env_combine ||
1113 ctx->Extensions.ARB_texture_env_combine) {
1114 *params = (GLint) texUnit->Combine.OperandA[2];
1115 }
1116 else {
1117 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1118 }
1119 break;
1120 case GL_RGB_SCALE:
1121 if (ctx->Extensions.EXT_texture_env_combine ||
1122 ctx->Extensions.ARB_texture_env_combine) {
1123 if (texUnit->Combine.ScaleShiftRGB == 0)
1124 *params = 1;
1125 else if (texUnit->Combine.ScaleShiftRGB == 1)
1126 *params = 2;
1127 else
1128 *params = 4;
1129 }
1130 else {
1131 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1132 return;
1133 }
1134 break;
1135 case GL_ALPHA_SCALE:
1136 if (ctx->Extensions.EXT_texture_env_combine ||
1137 ctx->Extensions.ARB_texture_env_combine) {
1138 if (texUnit->Combine.ScaleShiftA == 0)
1139 *params = 1;
1140 else if (texUnit->Combine.ScaleShiftA == 1)
1141 *params = 2;
1142 else
1143 *params = 4;
1144 }
1145 else {
1146 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
1147 return;
1148 }
1149 break;
1150 default:
1151 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname=0x%x)",
1152 pname);
1153 }
1154 }
1155 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
1156 /* GL_EXT_texture_lod_bias */
1157 if (!ctx->Extensions.EXT_texture_lod_bias) {
1158 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
1159 return;
1160 }
1161 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
1162 *params = (GLint) texUnit->LodBias;
1163 }
1164 else {
1165 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
1166 return;
1167 }
1168 }
1169 else if (target == GL_POINT_SPRITE_NV) {
1170 /* GL_ARB_point_sprite / GL_NV_point_sprite */
1171 if (!ctx->Extensions.NV_point_sprite
1172 && !ctx->Extensions.ARB_point_sprite) {
1173 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
1174 return;
1175 }
1176 if (pname == GL_COORD_REPLACE_NV) {
1177 *params = (GLint) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit];
1178 }
1179 else {
1180 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
1181 return;
1182 }
1183 }
1184 else {
1185 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
1186 return;
1187 }
1188 }
1189
1190
1191
1192
1193 /**********************************************************************/
1194 /* Texture Parameters */
1195 /**********************************************************************/
1196
1197 static GLboolean
1198 _mesa_validate_texture_wrap_mode(GLcontext * ctx,
1199 GLenum target, GLenum eparam)
1200 {
1201 const struct gl_extensions * const e = & ctx->Extensions;
1202
1203 if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
1204 (eparam == GL_CLAMP_TO_BORDER && e->ARB_texture_border_clamp)) {
1205 /* any texture target */
1206 return GL_TRUE;
1207 }
1208 else if (target != GL_TEXTURE_RECTANGLE_NV &&
1209 (eparam == GL_REPEAT ||
1210 (eparam == GL_MIRRORED_REPEAT &&
1211 e->ARB_texture_mirrored_repeat) ||
1212 (eparam == GL_MIRROR_CLAMP_EXT &&
1213 (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
1214 (eparam == GL_MIRROR_CLAMP_TO_EDGE_EXT &&
1215 (e->ATI_texture_mirror_once || e->EXT_texture_mirror_clamp)) ||
1216 (eparam == GL_MIRROR_CLAMP_TO_BORDER_EXT &&
1217 (e->EXT_texture_mirror_clamp)))) {
1218 /* non-rectangle texture */
1219 return GL_TRUE;
1220 }
1221
1222 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1223 return GL_FALSE;
1224 }
1225
1226
1227 void GLAPIENTRY
1228 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
1229 {
1230 _mesa_TexParameterfv(target, pname, &param);
1231 }
1232
1233
1234 void GLAPIENTRY
1235 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1236 {
1237 GET_CURRENT_CONTEXT(ctx);
1238 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1239 GLenum eparam = (GLenum) (GLint) params[0];
1240 struct gl_texture_object *texObj;
1241 ASSERT_OUTSIDE_BEGIN_END(ctx);
1242
1243 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
1244 _mesa_debug(ctx, "glTexParameter %s %s %.1f(%s)...\n",
1245 _mesa_lookup_enum_by_nr(target),
1246 _mesa_lookup_enum_by_nr(pname),
1247 *params,
1248 _mesa_lookup_enum_by_nr(eparam));
1249
1250
1251 switch (target) {
1252 case GL_TEXTURE_1D:
1253 texObj = texUnit->Current1D;
1254 break;
1255 case GL_TEXTURE_2D:
1256 texObj = texUnit->Current2D;
1257 break;
1258 case GL_TEXTURE_3D:
1259 texObj = texUnit->Current3D;
1260 break;
1261 case GL_TEXTURE_CUBE_MAP:
1262 if (!ctx->Extensions.ARB_texture_cube_map) {
1263 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1264 return;
1265 }
1266 texObj = texUnit->CurrentCubeMap;
1267 break;
1268 case GL_TEXTURE_RECTANGLE_NV:
1269 if (!ctx->Extensions.NV_texture_rectangle) {
1270 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1271 return;
1272 }
1273 texObj = texUnit->CurrentRect;
1274 break;
1275 default:
1276 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1277 return;
1278 }
1279
1280 switch (pname) {
1281 case GL_TEXTURE_MIN_FILTER:
1282 /* A small optimization */
1283 if (texObj->MinFilter == eparam)
1284 return;
1285 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
1286 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1287 texObj->MinFilter = eparam;
1288 }
1289 else if ((eparam==GL_NEAREST_MIPMAP_NEAREST ||
1290 eparam==GL_LINEAR_MIPMAP_NEAREST ||
1291 eparam==GL_NEAREST_MIPMAP_LINEAR ||
1292 eparam==GL_LINEAR_MIPMAP_LINEAR) &&
1293 texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
1294 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1295 texObj->MinFilter = eparam;
1296 }
1297 else {
1298 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1299 return;
1300 }
1301 break;
1302 case GL_TEXTURE_MAG_FILTER:
1303 /* A small optimization */
1304 if (texObj->MagFilter == eparam)
1305 return;
1306
1307 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
1308 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1309 texObj->MagFilter = eparam;
1310 }
1311 else {
1312 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1313 return;
1314 }
1315 break;
1316 case GL_TEXTURE_WRAP_S:
1317 if (texObj->WrapS == eparam)
1318 return;
1319 if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
1320 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1321 texObj->WrapS = eparam;
1322 }
1323 else {
1324 return;
1325 }
1326 break;
1327 case GL_TEXTURE_WRAP_T:
1328 if (texObj->WrapT == eparam)
1329 return;
1330 if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
1331 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1332 texObj->WrapT = eparam;
1333 }
1334 else {
1335 return;
1336 }
1337 break;
1338 case GL_TEXTURE_WRAP_R:
1339 if (texObj->WrapR == eparam)
1340 return;
1341 if (_mesa_validate_texture_wrap_mode(ctx, texObj->Target, eparam)) {
1342 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1343 texObj->WrapR = eparam;
1344 }
1345 else {
1346 return;
1347 }
1348 break;
1349 case GL_TEXTURE_BORDER_COLOR:
1350 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1351 texObj->BorderColor[RCOMP] = params[0];
1352 texObj->BorderColor[GCOMP] = params[1];
1353 texObj->BorderColor[BCOMP] = params[2];
1354 texObj->BorderColor[ACOMP] = params[3];
1355 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[RCOMP], params[0]);
1356 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[GCOMP], params[1]);
1357 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[BCOMP], params[2]);
1358 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[ACOMP], params[3]);
1359 break;
1360 case GL_TEXTURE_MIN_LOD:
1361 if (texObj->MinLod == params[0])
1362 return;
1363 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1364 texObj->MinLod = params[0];
1365 break;
1366 case GL_TEXTURE_MAX_LOD:
1367 if (texObj->MaxLod == params[0])
1368 return;
1369 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1370 texObj->MaxLod = params[0];
1371 break;
1372 case GL_TEXTURE_BASE_LEVEL:
1373 if (params[0] < 0.0) {
1374 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1375 return;
1376 }
1377 if (target == GL_TEXTURE_RECTANGLE_NV && params[0] != 0.0) {
1378 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1379 return;
1380 }
1381 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1382 texObj->BaseLevel = (GLint) params[0];
1383 break;
1384 case GL_TEXTURE_MAX_LEVEL:
1385 if (params[0] < 0.0) {
1386 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1387 return;
1388 }
1389 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1390 texObj->MaxLevel = (GLint) params[0];
1391 break;
1392 case GL_TEXTURE_PRIORITY:
1393 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1394 texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
1395 break;
1396 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1397 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1398 if (params[0] < 1.0) {
1399 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1400 return;
1401 }
1402 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1403 /* clamp to max, that's what NVIDIA does */
1404 texObj->MaxAnisotropy = MIN2(params[0],
1405 ctx->Const.MaxTextureMaxAnisotropy);
1406 }
1407 else {
1408 _mesa_error(ctx, GL_INVALID_ENUM,
1409 "glTexParameter(pname=GL_TEXTURE_MAX_ANISOTROPY_EXT)");
1410 return;
1411 }
1412 break;
1413 case GL_TEXTURE_COMPARE_SGIX:
1414 if (ctx->Extensions.SGIX_shadow) {
1415 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1416 texObj->CompareFlag = params[0] ? GL_TRUE : GL_FALSE;
1417 }
1418 else {
1419 _mesa_error(ctx, GL_INVALID_ENUM,
1420 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1421 return;
1422 }
1423 break;
1424 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
1425 if (ctx->Extensions.SGIX_shadow) {
1426 GLenum op = (GLenum) params[0];
1427 if (op == GL_TEXTURE_LEQUAL_R_SGIX ||
1428 op == GL_TEXTURE_GEQUAL_R_SGIX) {
1429 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1430 texObj->CompareOperator = op;
1431 }
1432 else {
1433 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param)");
1434 }
1435 }
1436 else {
1437 _mesa_error(ctx, GL_INVALID_ENUM,
1438 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1439 return;
1440 }
1441 break;
1442 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1443 if (ctx->Extensions.SGIX_shadow_ambient) {
1444 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1445 texObj->ShadowAmbient = CLAMP(params[0], 0.0F, 1.0F);
1446 }
1447 else {
1448 _mesa_error(ctx, GL_INVALID_ENUM,
1449 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1450 return;
1451 }
1452 break;
1453 case GL_GENERATE_MIPMAP_SGIS:
1454 if (ctx->Extensions.SGIS_generate_mipmap) {
1455 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
1456 }
1457 else {
1458 _mesa_error(ctx, GL_INVALID_ENUM,
1459 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1460 return;
1461 }
1462 break;
1463 case GL_TEXTURE_COMPARE_MODE_ARB:
1464 if (ctx->Extensions.ARB_shadow) {
1465 const GLenum mode = (GLenum) params[0];
1466 if (mode == GL_NONE || mode == GL_COMPARE_R_TO_TEXTURE_ARB) {
1467 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1468 texObj->CompareMode = mode;
1469 }
1470 else {
1471 _mesa_error(ctx, GL_INVALID_ENUM,
1472 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB: 0x%x)", mode);
1473 return;
1474 }
1475 }
1476 else {
1477 _mesa_error(ctx, GL_INVALID_ENUM,
1478 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1479 return;
1480 }
1481 break;
1482 case GL_TEXTURE_COMPARE_FUNC_ARB:
1483 if (ctx->Extensions.ARB_shadow) {
1484 const GLenum func = (GLenum) params[0];
1485 if (func == GL_LEQUAL || func == GL_GEQUAL) {
1486 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1487 texObj->CompareFunc = func;
1488 }
1489 else if (ctx->Extensions.EXT_shadow_funcs &&
1490 (func == GL_EQUAL ||
1491 func == GL_NOTEQUAL ||
1492 func == GL_LESS ||
1493 func == GL_GREATER ||
1494 func == GL_ALWAYS ||
1495 func == GL_NEVER)) {
1496 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1497 texObj->CompareFunc = func;
1498 }
1499 else {
1500 _mesa_error(ctx, GL_INVALID_ENUM,
1501 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1502 return;
1503 }
1504 }
1505 else {
1506 _mesa_error(ctx, GL_INVALID_ENUM,
1507 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1508 return;
1509 }
1510 break;
1511 case GL_DEPTH_TEXTURE_MODE_ARB:
1512 if (ctx->Extensions.ARB_depth_texture) {
1513 const GLenum result = (GLenum) params[0];
1514 if (result == GL_LUMINANCE || result == GL_INTENSITY
1515 || result == GL_ALPHA) {
1516 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1517 texObj->DepthMode = result;
1518 }
1519 else {
1520 _mesa_error(ctx, GL_INVALID_ENUM,
1521 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1522 return;
1523 }
1524 }
1525 else {
1526 _mesa_error(ctx, GL_INVALID_ENUM,
1527 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1528 return;
1529 }
1530 break;
1531 case GL_TEXTURE_LOD_BIAS:
1532 /* NOTE: this is really part of OpenGL 1.4, not EXT_texture_lod_bias*/
1533 if (ctx->Extensions.EXT_texture_lod_bias) {
1534 if (texObj->LodBias != params[0]) {
1535 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1536 texObj->LodBias = params[0];
1537 }
1538 }
1539 break;
1540
1541 default:
1542 _mesa_error(ctx, GL_INVALID_ENUM,
1543 "glTexParameter(pname=0x%x)", pname);
1544 return;
1545 }
1546
1547 texObj->Complete = GL_FALSE;
1548
1549 if (ctx->Driver.TexParameter) {
1550 (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
1551 }
1552 }
1553
1554
1555 void GLAPIENTRY
1556 _mesa_TexParameteri( GLenum target, GLenum pname, GLint param )
1557 {
1558 GLfloat fparam[4];
1559 if (pname == GL_TEXTURE_PRIORITY)
1560 fparam[0] = INT_TO_FLOAT(param);
1561 else
1562 fparam[0] = (GLfloat) param;
1563 fparam[1] = fparam[2] = fparam[3] = 0.0;
1564 _mesa_TexParameterfv(target, pname, fparam);
1565 }
1566
1567
1568 void GLAPIENTRY
1569 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
1570 {
1571 GLfloat fparam[4];
1572 if (pname == GL_TEXTURE_BORDER_COLOR) {
1573 fparam[0] = INT_TO_FLOAT(params[0]);
1574 fparam[1] = INT_TO_FLOAT(params[1]);
1575 fparam[2] = INT_TO_FLOAT(params[2]);
1576 fparam[3] = INT_TO_FLOAT(params[3]);
1577 }
1578 else {
1579 if (pname == GL_TEXTURE_PRIORITY)
1580 fparam[0] = INT_TO_FLOAT(params[0]);
1581 else
1582 fparam[0] = (GLfloat) params[0];
1583 fparam[1] = fparam[2] = fparam[3] = 0.0F;
1584 }
1585 _mesa_TexParameterfv(target, pname, fparam);
1586 }
1587
1588
1589 void GLAPIENTRY
1590 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1591 GLenum pname, GLfloat *params )
1592 {
1593 GLint iparam;
1594 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
1595 *params = (GLfloat) iparam;
1596 }
1597
1598
1599 static GLuint
1600 tex_image_dimensions(GLcontext *ctx, GLenum target)
1601 {
1602 switch (target) {
1603 case GL_TEXTURE_1D:
1604 case GL_PROXY_TEXTURE_1D:
1605 return 1;
1606 case GL_TEXTURE_2D:
1607 case GL_PROXY_TEXTURE_2D:
1608 return 2;
1609 case GL_TEXTURE_3D:
1610 case GL_PROXY_TEXTURE_3D:
1611 return 3;
1612 case GL_TEXTURE_CUBE_MAP:
1613 case GL_PROXY_TEXTURE_CUBE_MAP:
1614 case GL_TEXTURE_CUBE_MAP_POSITIVE_X:
1615 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X:
1616 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y:
1617 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y:
1618 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z:
1619 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z:
1620 return ctx->Extensions.ARB_texture_cube_map ? 2 : 0;
1621 case GL_TEXTURE_RECTANGLE_NV:
1622 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1623 return ctx->Extensions.NV_texture_rectangle ? 2 : 0;
1624 default:
1625 _mesa_problem(ctx, "bad target in _mesa_tex_target_dimensions()");
1626 return 0;
1627 }
1628 }
1629
1630
1631 void GLAPIENTRY
1632 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1633 GLenum pname, GLint *params )
1634 {
1635 GET_CURRENT_CONTEXT(ctx);
1636 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1637 const struct gl_texture_image *img = NULL;
1638 GLuint dimensions;
1639 GLboolean isProxy;
1640 GLint maxLevels;
1641 ASSERT_OUTSIDE_BEGIN_END(ctx);
1642
1643 /* this will catch bad target values */
1644 dimensions = tex_image_dimensions(ctx, target); /* 1, 2 or 3 */
1645 if (dimensions == 0) {
1646 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
1647 return;
1648 }
1649
1650 maxLevels = _mesa_max_texture_levels(ctx, target);
1651 if (maxLevels == 0) {
1652 /* should not happen since <target> was just checked above */
1653 _mesa_problem(ctx, "maxLevels=0 in _mesa_GetTexLevelParameter");
1654 return;
1655 }
1656
1657 if (level < 0 || level >= maxLevels) {
1658 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
1659 return;
1660 }
1661
1662 img = _mesa_select_tex_image(ctx, texUnit, target, level);
1663 if (!img || !img->TexFormat) {
1664 /* undefined texture image */
1665 if (pname == GL_TEXTURE_COMPONENTS)
1666 *params = 1;
1667 else
1668 *params = 0;
1669 return;
1670 }
1671
1672 isProxy = _mesa_is_proxy_texture(target);
1673
1674 switch (pname) {
1675 case GL_TEXTURE_WIDTH:
1676 *params = img->Width;
1677 return;
1678 case GL_TEXTURE_HEIGHT:
1679 *params = img->Height;
1680 return;
1681 case GL_TEXTURE_DEPTH:
1682 *params = img->Depth;
1683 return;
1684 case GL_TEXTURE_INTERNAL_FORMAT:
1685 *params = img->InternalFormat;
1686 return;
1687 case GL_TEXTURE_BORDER:
1688 *params = img->Border;
1689 return;
1690 case GL_TEXTURE_RED_SIZE:
1691 if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
1692 *params = img->TexFormat->RedBits;
1693 else
1694 *params = 0;
1695 return;
1696 case GL_TEXTURE_GREEN_SIZE:
1697 if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
1698 *params = img->TexFormat->GreenBits;
1699 else
1700 *params = 0;
1701 return;
1702 case GL_TEXTURE_BLUE_SIZE:
1703 if (img->_BaseFormat == GL_RGB || img->_BaseFormat == GL_RGBA)
1704 *params = img->TexFormat->BlueBits;
1705 else
1706 *params = 0;
1707 return;
1708 case GL_TEXTURE_ALPHA_SIZE:
1709 if (img->_BaseFormat == GL_ALPHA ||
1710 img->_BaseFormat == GL_LUMINANCE_ALPHA ||
1711 img->_BaseFormat == GL_RGBA)
1712 *params = img->TexFormat->AlphaBits;
1713 else
1714 *params = 0;
1715 return;
1716 case GL_TEXTURE_INTENSITY_SIZE:
1717 if (img->_BaseFormat != GL_INTENSITY)
1718 *params = 0;
1719 else if (img->TexFormat->IntensityBits > 0)
1720 *params = img->TexFormat->IntensityBits;
1721 else /* intensity probably stored as rgb texture */
1722 *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
1723 return;
1724 case GL_TEXTURE_LUMINANCE_SIZE:
1725 if (img->_BaseFormat != GL_LUMINANCE &&
1726 img->_BaseFormat != GL_LUMINANCE_ALPHA)
1727 *params = 0;
1728 else if (img->TexFormat->LuminanceBits > 0)
1729 *params = img->TexFormat->LuminanceBits;
1730 else /* luminance probably stored as rgb texture */
1731 *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
1732 return;
1733 case GL_TEXTURE_INDEX_SIZE_EXT:
1734 if (img->_BaseFormat == GL_COLOR_INDEX)
1735 *params = img->TexFormat->IndexBits;
1736 else
1737 *params = 0;
1738 return;
1739 case GL_TEXTURE_DEPTH_SIZE_ARB:
1740 if (ctx->Extensions.SGIX_depth_texture ||
1741 ctx->Extensions.ARB_depth_texture)
1742 *params = img->TexFormat->DepthBits;
1743 else
1744 _mesa_error(ctx, GL_INVALID_ENUM,
1745 "glGetTexLevelParameter[if]v(pname)");
1746 return;
1747 case GL_TEXTURE_STENCIL_SIZE_EXT:
1748 if (ctx->Extensions.EXT_packed_depth_stencil) {
1749 *params = img->TexFormat->StencilBits;
1750 }
1751 else {
1752 _mesa_error(ctx, GL_INVALID_ENUM,
1753 "glGetTexLevelParameter[if]v(pname)");
1754 }
1755 return;
1756
1757 /* GL_ARB_texture_compression */
1758 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE:
1759 if (ctx->Extensions.ARB_texture_compression) {
1760 if (img->IsCompressed && !isProxy)
1761 *params = img->CompressedSize;
1762 else
1763 _mesa_error(ctx, GL_INVALID_OPERATION,
1764 "glGetTexLevelParameter[if]v(pname)");
1765 }
1766 else {
1767 _mesa_error(ctx, GL_INVALID_ENUM,
1768 "glGetTexLevelParameter[if]v(pname)");
1769 }
1770 return;
1771 case GL_TEXTURE_COMPRESSED:
1772 if (ctx->Extensions.ARB_texture_compression) {
1773 *params = (GLint) img->IsCompressed;
1774 }
1775 else {
1776 _mesa_error(ctx, GL_INVALID_ENUM,
1777 "glGetTexLevelParameter[if]v(pname)");
1778 }
1779 return;
1780
1781 /* GL_ARB_texture_float */
1782 case GL_TEXTURE_RED_TYPE_ARB:
1783 if (ctx->Extensions.ARB_texture_float) {
1784 *params = img->TexFormat->RedBits ? img->TexFormat->DataType : GL_NONE;
1785 }
1786 else {
1787 _mesa_error(ctx, GL_INVALID_ENUM,
1788 "glGetTexLevelParameter[if]v(pname)");
1789 }
1790 return;
1791 case GL_TEXTURE_GREEN_TYPE_ARB:
1792 if (ctx->Extensions.ARB_texture_float) {
1793 *params = img->TexFormat->GreenBits ? img->TexFormat->DataType : GL_NONE;
1794 }
1795 else {
1796 _mesa_error(ctx, GL_INVALID_ENUM,
1797 "glGetTexLevelParameter[if]v(pname)");
1798 }
1799 return;
1800 case GL_TEXTURE_BLUE_TYPE_ARB:
1801 if (ctx->Extensions.ARB_texture_float) {
1802 *params = img->TexFormat->BlueBits ? img->TexFormat->DataType : GL_NONE;
1803 }
1804 else {
1805 _mesa_error(ctx, GL_INVALID_ENUM,
1806 "glGetTexLevelParameter[if]v(pname)");
1807 }
1808 return;
1809 case GL_TEXTURE_ALPHA_TYPE_ARB:
1810 if (ctx->Extensions.ARB_texture_float) {
1811 *params = img->TexFormat->AlphaBits ? img->TexFormat->DataType : GL_NONE;
1812 }
1813 else {
1814 _mesa_error(ctx, GL_INVALID_ENUM,
1815 "glGetTexLevelParameter[if]v(pname)");
1816 }
1817 return;
1818 case GL_TEXTURE_LUMINANCE_TYPE_ARB:
1819 if (ctx->Extensions.ARB_texture_float) {
1820 *params = img->TexFormat->LuminanceBits ? img->TexFormat->DataType : GL_NONE;
1821 }
1822 else {
1823 _mesa_error(ctx, GL_INVALID_ENUM,
1824 "glGetTexLevelParameter[if]v(pname)");
1825 }
1826 return;
1827 case GL_TEXTURE_INTENSITY_TYPE_ARB:
1828 if (ctx->Extensions.ARB_texture_float) {
1829 *params = img->TexFormat->IntensityBits ? img->TexFormat->DataType : GL_NONE;
1830 }
1831 else {
1832 _mesa_error(ctx, GL_INVALID_ENUM,
1833 "glGetTexLevelParameter[if]v(pname)");
1834 }
1835 return;
1836 case GL_TEXTURE_DEPTH_TYPE_ARB:
1837 if (ctx->Extensions.ARB_texture_float) {
1838 *params = img->TexFormat->DepthBits ? img->TexFormat->DataType : GL_NONE;
1839 }
1840 else {
1841 _mesa_error(ctx, GL_INVALID_ENUM,
1842 "glGetTexLevelParameter[if]v(pname)");
1843 }
1844 return;
1845
1846 default:
1847 _mesa_error(ctx, GL_INVALID_ENUM,
1848 "glGetTexLevelParameter[if]v(pname)");
1849 }
1850 }
1851
1852
1853
1854 void GLAPIENTRY
1855 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1856 {
1857 GET_CURRENT_CONTEXT(ctx);
1858 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1859 struct gl_texture_object *obj;
1860 ASSERT_OUTSIDE_BEGIN_END(ctx);
1861
1862 obj = _mesa_select_tex_object(ctx, texUnit, target);
1863 if (!obj) {
1864 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
1865 return;
1866 }
1867
1868 switch (pname) {
1869 case GL_TEXTURE_MAG_FILTER:
1870 *params = ENUM_TO_FLOAT(obj->MagFilter);
1871 return;
1872 case GL_TEXTURE_MIN_FILTER:
1873 *params = ENUM_TO_FLOAT(obj->MinFilter);
1874 return;
1875 case GL_TEXTURE_WRAP_S:
1876 *params = ENUM_TO_FLOAT(obj->WrapS);
1877 return;
1878 case GL_TEXTURE_WRAP_T:
1879 *params = ENUM_TO_FLOAT(obj->WrapT);
1880 return;
1881 case GL_TEXTURE_WRAP_R:
1882 *params = ENUM_TO_FLOAT(obj->WrapR);
1883 return;
1884 case GL_TEXTURE_BORDER_COLOR:
1885 params[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
1886 params[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
1887 params[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
1888 params[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
1889 return;
1890 case GL_TEXTURE_RESIDENT:
1891 {
1892 GLboolean resident;
1893 if (ctx->Driver.IsTextureResident)
1894 resident = ctx->Driver.IsTextureResident(ctx, obj);
1895 else
1896 resident = GL_TRUE;
1897 *params = ENUM_TO_FLOAT(resident);
1898 }
1899 return;
1900 case GL_TEXTURE_PRIORITY:
1901 *params = obj->Priority;
1902 return;
1903 case GL_TEXTURE_MIN_LOD:
1904 *params = obj->MinLod;
1905 return;
1906 case GL_TEXTURE_MAX_LOD:
1907 *params = obj->MaxLod;
1908 return;
1909 case GL_TEXTURE_BASE_LEVEL:
1910 *params = (GLfloat) obj->BaseLevel;
1911 return;
1912 case GL_TEXTURE_MAX_LEVEL:
1913 *params = (GLfloat) obj->MaxLevel;
1914 return;
1915 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1916 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1917 *params = obj->MaxAnisotropy;
1918 return;
1919 }
1920 break;
1921 case GL_TEXTURE_COMPARE_SGIX:
1922 if (ctx->Extensions.SGIX_shadow) {
1923 *params = (GLfloat) obj->CompareFlag;
1924 return;
1925 }
1926 break;
1927 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
1928 if (ctx->Extensions.SGIX_shadow) {
1929 *params = (GLfloat) obj->CompareOperator;
1930 return;
1931 }
1932 break;
1933 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1934 if (ctx->Extensions.SGIX_shadow_ambient) {
1935 *params = obj->ShadowAmbient;
1936 return;
1937 }
1938 break;
1939 case GL_GENERATE_MIPMAP_SGIS:
1940 if (ctx->Extensions.SGIS_generate_mipmap) {
1941 *params = (GLfloat) obj->GenerateMipmap;
1942 return;
1943 }
1944 break;
1945 case GL_TEXTURE_COMPARE_MODE_ARB:
1946 if (ctx->Extensions.ARB_shadow) {
1947 *params = (GLfloat) obj->CompareMode;
1948 return;
1949 }
1950 break;
1951 case GL_TEXTURE_COMPARE_FUNC_ARB:
1952 if (ctx->Extensions.ARB_shadow) {
1953 *params = (GLfloat) obj->CompareFunc;
1954 return;
1955 }
1956 break;
1957 case GL_DEPTH_TEXTURE_MODE_ARB:
1958 if (ctx->Extensions.ARB_depth_texture) {
1959 *params = (GLfloat) obj->DepthMode;
1960 return;
1961 }
1962 break;
1963 case GL_TEXTURE_LOD_BIAS:
1964 if (ctx->Extensions.EXT_texture_lod_bias) {
1965 *params = obj->LodBias;
1966 return;
1967 }
1968 break;
1969 default:
1970 ; /* silence warnings */
1971 }
1972 /* If we get here, pname was an unrecognized enum */
1973 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname=0x%x)",
1974 pname);
1975 }
1976
1977
1978 void GLAPIENTRY
1979 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1980 {
1981 GET_CURRENT_CONTEXT(ctx);
1982 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1983 struct gl_texture_object *obj;
1984 ASSERT_OUTSIDE_BEGIN_END(ctx);
1985
1986 obj = _mesa_select_tex_object(ctx, texUnit, target);
1987 if (!obj) {
1988 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
1989 return;
1990 }
1991
1992 switch (pname) {
1993 case GL_TEXTURE_MAG_FILTER:
1994 *params = (GLint) obj->MagFilter;
1995 return;
1996 case GL_TEXTURE_MIN_FILTER:
1997 *params = (GLint) obj->MinFilter;
1998 return;
1999 case GL_TEXTURE_WRAP_S:
2000 *params = (GLint) obj->WrapS;
2001 return;
2002 case GL_TEXTURE_WRAP_T:
2003 *params = (GLint) obj->WrapT;
2004 return;
2005 case GL_TEXTURE_WRAP_R:
2006 *params = (GLint) obj->WrapR;
2007 return;
2008 case GL_TEXTURE_BORDER_COLOR:
2009 {
2010 GLfloat b[4];
2011 b[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
2012 b[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
2013 b[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
2014 b[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
2015 params[0] = FLOAT_TO_INT(b[0]);
2016 params[1] = FLOAT_TO_INT(b[1]);
2017 params[2] = FLOAT_TO_INT(b[2]);
2018 params[3] = FLOAT_TO_INT(b[3]);
2019 }
2020 return;
2021 case GL_TEXTURE_RESIDENT:
2022 {
2023 GLboolean resident;
2024 if (ctx->Driver.IsTextureResident)
2025 resident = ctx->Driver.IsTextureResident(ctx, obj);
2026 else
2027 resident = GL_TRUE;
2028 *params = (GLint) resident;
2029 }
2030 return;
2031 case GL_TEXTURE_PRIORITY:
2032 *params = FLOAT_TO_INT(obj->Priority);
2033 return;
2034 case GL_TEXTURE_MIN_LOD:
2035 *params = (GLint) obj->MinLod;
2036 return;
2037 case GL_TEXTURE_MAX_LOD:
2038 *params = (GLint) obj->MaxLod;
2039 return;
2040 case GL_TEXTURE_BASE_LEVEL:
2041 *params = obj->BaseLevel;
2042 return;
2043 case GL_TEXTURE_MAX_LEVEL:
2044 *params = obj->MaxLevel;
2045 return;
2046 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
2047 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
2048 *params = (GLint) obj->MaxAnisotropy;
2049 return;
2050 }
2051 break;
2052 case GL_TEXTURE_COMPARE_SGIX:
2053 if (ctx->Extensions.SGIX_shadow) {
2054 *params = (GLint) obj->CompareFlag;
2055 return;
2056 }
2057 break;
2058 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
2059 if (ctx->Extensions.SGIX_shadow) {
2060 *params = (GLint) obj->CompareOperator;
2061 return;
2062 }
2063 break;
2064 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
2065 if (ctx->Extensions.SGIX_shadow_ambient) {
2066 *params = (GLint) FLOAT_TO_INT(obj->ShadowAmbient);
2067 return;
2068 }
2069 break;
2070 case GL_GENERATE_MIPMAP_SGIS:
2071 if (ctx->Extensions.SGIS_generate_mipmap) {
2072 *params = (GLint) obj->GenerateMipmap;
2073 return;
2074 }
2075 break;
2076 case GL_TEXTURE_COMPARE_MODE_ARB:
2077 if (ctx->Extensions.ARB_shadow) {
2078 *params = (GLint) obj->CompareMode;
2079 return;
2080 }
2081 break;
2082 case GL_TEXTURE_COMPARE_FUNC_ARB:
2083 if (ctx->Extensions.ARB_shadow) {
2084 *params = (GLint) obj->CompareFunc;
2085 return;
2086 }
2087 break;
2088 case GL_DEPTH_TEXTURE_MODE_ARB:
2089 if (ctx->Extensions.ARB_depth_texture) {
2090 *params = (GLint) obj->DepthMode;
2091 return;
2092 }
2093 break;
2094 case GL_TEXTURE_LOD_BIAS:
2095 if (ctx->Extensions.EXT_texture_lod_bias) {
2096 *params = (GLint) obj->LodBias;
2097 return;
2098 }
2099 break;
2100 default:
2101 ; /* silence warnings */
2102 }
2103 /* If we get here, pname was an unrecognized enum */
2104 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname=0x%x)", pname);
2105 }
2106
2107
2108
2109
2110 /**********************************************************************/
2111 /* Texture Coord Generation */
2112 /**********************************************************************/
2113
2114 #if FEATURE_texgen
2115 void GLAPIENTRY
2116 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
2117 {
2118 GET_CURRENT_CONTEXT(ctx);
2119 GLuint tUnit = ctx->Texture.CurrentUnit;
2120 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2121 ASSERT_OUTSIDE_BEGIN_END(ctx);
2122
2123 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
2124 _mesa_debug(ctx, "glTexGen %s %s %.1f(%s)...\n",
2125 _mesa_lookup_enum_by_nr(coord),
2126 _mesa_lookup_enum_by_nr(pname),
2127 *params,
2128 _mesa_lookup_enum_by_nr((GLenum) (GLint) *params));
2129
2130 switch (coord) {
2131 case GL_S:
2132 if (pname==GL_TEXTURE_GEN_MODE) {
2133 GLenum mode = (GLenum) (GLint) *params;
2134 GLbitfield bits;
2135 switch (mode) {
2136 case GL_OBJECT_LINEAR:
2137 bits = TEXGEN_OBJ_LINEAR;
2138 break;
2139 case GL_EYE_LINEAR:
2140 bits = TEXGEN_EYE_LINEAR;
2141 break;
2142 case GL_REFLECTION_MAP_NV:
2143 bits = TEXGEN_REFLECTION_MAP_NV;
2144 break;
2145 case GL_NORMAL_MAP_NV:
2146 bits = TEXGEN_NORMAL_MAP_NV;
2147 break;
2148 case GL_SPHERE_MAP:
2149 bits = TEXGEN_SPHERE_MAP;
2150 break;
2151 default:
2152 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
2153 return;
2154 }
2155 if (texUnit->GenModeS == mode)
2156 return;
2157 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2158 texUnit->GenModeS = mode;
2159 texUnit->_GenBitS = bits;
2160 }
2161 else if (pname==GL_OBJECT_PLANE) {
2162 if (TEST_EQ_4V(texUnit->ObjectPlaneS, params))
2163 return;
2164 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2165 COPY_4FV(texUnit->ObjectPlaneS, params);
2166 }
2167 else if (pname==GL_EYE_PLANE) {
2168 GLfloat tmp[4];
2169 /* Transform plane equation by the inverse modelview matrix */
2170 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
2171 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2172 }
2173 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2174 if (TEST_EQ_4V(texUnit->EyePlaneS, tmp))
2175 return;
2176 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2177 COPY_4FV(texUnit->EyePlaneS, tmp);
2178 }
2179 else {
2180 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2181 return;
2182 }
2183 break;
2184 case GL_T:
2185 if (pname==GL_TEXTURE_GEN_MODE) {
2186 GLenum mode = (GLenum) (GLint) *params;
2187 GLbitfield bitt;
2188 switch (mode) {
2189 case GL_OBJECT_LINEAR:
2190 bitt = TEXGEN_OBJ_LINEAR;
2191 break;
2192 case GL_EYE_LINEAR:
2193 bitt = TEXGEN_EYE_LINEAR;
2194 break;
2195 case GL_REFLECTION_MAP_NV:
2196 bitt = TEXGEN_REFLECTION_MAP_NV;
2197 break;
2198 case GL_NORMAL_MAP_NV:
2199 bitt = TEXGEN_NORMAL_MAP_NV;
2200 break;
2201 case GL_SPHERE_MAP:
2202 bitt = TEXGEN_SPHERE_MAP;
2203 break;
2204 default:
2205 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
2206 return;
2207 }
2208 if (texUnit->GenModeT == mode)
2209 return;
2210 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2211 texUnit->GenModeT = mode;
2212 texUnit->_GenBitT = bitt;
2213 }
2214 else if (pname==GL_OBJECT_PLANE) {
2215 if (TEST_EQ_4V(texUnit->ObjectPlaneT, params))
2216 return;
2217 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2218 COPY_4FV(texUnit->ObjectPlaneT, params);
2219 }
2220 else if (pname==GL_EYE_PLANE) {
2221 GLfloat tmp[4];
2222 /* Transform plane equation by the inverse modelview matrix */
2223 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
2224 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2225 }
2226 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2227 if (TEST_EQ_4V(texUnit->EyePlaneT, tmp))
2228 return;
2229 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2230 COPY_4FV(texUnit->EyePlaneT, tmp);
2231 }
2232 else {
2233 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2234 return;
2235 }
2236 break;
2237 case GL_R:
2238 if (pname==GL_TEXTURE_GEN_MODE) {
2239 GLenum mode = (GLenum) (GLint) *params;
2240 GLbitfield bitr;
2241 switch (mode) {
2242 case GL_OBJECT_LINEAR:
2243 bitr = TEXGEN_OBJ_LINEAR;
2244 break;
2245 case GL_REFLECTION_MAP_NV:
2246 bitr = TEXGEN_REFLECTION_MAP_NV;
2247 break;
2248 case GL_NORMAL_MAP_NV:
2249 bitr = TEXGEN_NORMAL_MAP_NV;
2250 break;
2251 case GL_EYE_LINEAR:
2252 bitr = TEXGEN_EYE_LINEAR;
2253 break;
2254 default:
2255 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
2256 return;
2257 }
2258 if (texUnit->GenModeR == mode)
2259 return;
2260 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2261 texUnit->GenModeR = mode;
2262 texUnit->_GenBitR = bitr;
2263 }
2264 else if (pname==GL_OBJECT_PLANE) {
2265 if (TEST_EQ_4V(texUnit->ObjectPlaneR, params))
2266 return;
2267 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2268 COPY_4FV(texUnit->ObjectPlaneR, params);
2269 }
2270 else if (pname==GL_EYE_PLANE) {
2271 GLfloat tmp[4];
2272 /* Transform plane equation by the inverse modelview matrix */
2273 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
2274 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2275 }
2276 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2277 if (TEST_EQ_4V(texUnit->EyePlaneR, tmp))
2278 return;
2279 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2280 COPY_4FV(texUnit->EyePlaneR, tmp);
2281 }
2282 else {
2283 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2284 return;
2285 }
2286 break;
2287 case GL_Q:
2288 if (pname==GL_TEXTURE_GEN_MODE) {
2289 GLenum mode = (GLenum) (GLint) *params;
2290 GLbitfield bitq;
2291 switch (mode) {
2292 case GL_OBJECT_LINEAR:
2293 bitq = TEXGEN_OBJ_LINEAR;
2294 break;
2295 case GL_EYE_LINEAR:
2296 bitq = TEXGEN_EYE_LINEAR;
2297 break;
2298 default:
2299 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
2300 return;
2301 }
2302 if (texUnit->GenModeQ == mode)
2303 return;
2304 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2305 texUnit->GenModeQ = mode;
2306 texUnit->_GenBitQ = bitq;
2307 }
2308 else if (pname==GL_OBJECT_PLANE) {
2309 if (TEST_EQ_4V(texUnit->ObjectPlaneQ, params))
2310 return;
2311 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2312 COPY_4FV(texUnit->ObjectPlaneQ, params);
2313 }
2314 else if (pname==GL_EYE_PLANE) {
2315 GLfloat tmp[4];
2316 /* Transform plane equation by the inverse modelview matrix */
2317 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
2318 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2319 }
2320 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2321 if (TEST_EQ_4V(texUnit->EyePlaneQ, tmp))
2322 return;
2323 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2324 COPY_4FV(texUnit->EyePlaneQ, tmp);
2325 }
2326 else {
2327 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2328 return;
2329 }
2330 break;
2331 default:
2332 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
2333 return;
2334 }
2335
2336 if (ctx->Driver.TexGen)
2337 ctx->Driver.TexGen( ctx, coord, pname, params );
2338 }
2339
2340
2341 void GLAPIENTRY
2342 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
2343 {
2344 GLfloat p[4];
2345 p[0] = (GLfloat) params[0];
2346 if (pname == GL_TEXTURE_GEN_MODE) {
2347 p[1] = p[2] = p[3] = 0.0F;
2348 }
2349 else {
2350 p[1] = (GLfloat) params[1];
2351 p[2] = (GLfloat) params[2];
2352 p[3] = (GLfloat) params[3];
2353 }
2354 _mesa_TexGenfv(coord, pname, p);
2355 }
2356
2357
2358 void GLAPIENTRY
2359 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
2360 {
2361 GLfloat p = (GLfloat) param;
2362 _mesa_TexGenfv( coord, pname, &p );
2363 }
2364
2365
2366 void GLAPIENTRY
2367 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
2368 {
2369 GLfloat p[4];
2370 p[0] = (GLfloat) params[0];
2371 if (pname == GL_TEXTURE_GEN_MODE) {
2372 p[1] = p[2] = p[3] = 0.0F;
2373 }
2374 else {
2375 p[1] = (GLfloat) params[1];
2376 p[2] = (GLfloat) params[2];
2377 p[3] = (GLfloat) params[3];
2378 }
2379 _mesa_TexGenfv( coord, pname, p );
2380 }
2381
2382
2383 void GLAPIENTRY
2384 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
2385 {
2386 _mesa_TexGenfv(coord, pname, &param);
2387 }
2388
2389
2390 void GLAPIENTRY
2391 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
2392 {
2393 _mesa_TexGeniv( coord, pname, &param );
2394 }
2395
2396
2397
2398 void GLAPIENTRY
2399 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
2400 {
2401 GET_CURRENT_CONTEXT(ctx);
2402 GLuint tUnit = ctx->Texture.CurrentUnit;
2403 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2404 ASSERT_OUTSIDE_BEGIN_END(ctx);
2405
2406 switch (coord) {
2407 case GL_S:
2408 if (pname==GL_TEXTURE_GEN_MODE) {
2409 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
2410 }
2411 else if (pname==GL_OBJECT_PLANE) {
2412 COPY_4V( params, texUnit->ObjectPlaneS );
2413 }
2414 else if (pname==GL_EYE_PLANE) {
2415 COPY_4V( params, texUnit->EyePlaneS );
2416 }
2417 else {
2418 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2419 return;
2420 }
2421 break;
2422 case GL_T:
2423 if (pname==GL_TEXTURE_GEN_MODE) {
2424 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeT);
2425 }
2426 else if (pname==GL_OBJECT_PLANE) {
2427 COPY_4V( params, texUnit->ObjectPlaneT );
2428 }
2429 else if (pname==GL_EYE_PLANE) {
2430 COPY_4V( params, texUnit->EyePlaneT );
2431 }
2432 else {
2433 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2434 return;
2435 }
2436 break;
2437 case GL_R:
2438 if (pname==GL_TEXTURE_GEN_MODE) {
2439 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeR);
2440 }
2441 else if (pname==GL_OBJECT_PLANE) {
2442 COPY_4V( params, texUnit->ObjectPlaneR );
2443 }
2444 else if (pname==GL_EYE_PLANE) {
2445 COPY_4V( params, texUnit->EyePlaneR );
2446 }
2447 else {
2448 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2449 return;
2450 }
2451 break;
2452 case GL_Q:
2453 if (pname==GL_TEXTURE_GEN_MODE) {
2454 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeQ);
2455 }
2456 else if (pname==GL_OBJECT_PLANE) {
2457 COPY_4V( params, texUnit->ObjectPlaneQ );
2458 }
2459 else if (pname==GL_EYE_PLANE) {
2460 COPY_4V( params, texUnit->EyePlaneQ );
2461 }
2462 else {
2463 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2464 return;
2465 }
2466 break;
2467 default:
2468 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
2469 return;
2470 }
2471 }
2472
2473
2474
2475 void GLAPIENTRY
2476 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
2477 {
2478 GET_CURRENT_CONTEXT(ctx);
2479 GLuint tUnit = ctx->Texture.CurrentUnit;
2480 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2481 ASSERT_OUTSIDE_BEGIN_END(ctx);
2482
2483 switch (coord) {
2484 case GL_S:
2485 if (pname==GL_TEXTURE_GEN_MODE) {
2486 params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
2487 }
2488 else if (pname==GL_OBJECT_PLANE) {
2489 COPY_4V( params, texUnit->ObjectPlaneS );
2490 }
2491 else if (pname==GL_EYE_PLANE) {
2492 COPY_4V( params, texUnit->EyePlaneS );
2493 }
2494 else {
2495 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2496 return;
2497 }
2498 break;
2499 case GL_T:
2500 if (pname==GL_TEXTURE_GEN_MODE) {
2501 params[0] = ENUM_TO_FLOAT(texUnit->GenModeT);
2502 }
2503 else if (pname==GL_OBJECT_PLANE) {
2504 COPY_4V( params, texUnit->ObjectPlaneT );
2505 }
2506 else if (pname==GL_EYE_PLANE) {
2507 COPY_4V( params, texUnit->EyePlaneT );
2508 }
2509 else {
2510 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2511 return;
2512 }
2513 break;
2514 case GL_R:
2515 if (pname==GL_TEXTURE_GEN_MODE) {
2516 params[0] = ENUM_TO_FLOAT(texUnit->GenModeR);
2517 }
2518 else if (pname==GL_OBJECT_PLANE) {
2519 COPY_4V( params, texUnit->ObjectPlaneR );
2520 }
2521 else if (pname==GL_EYE_PLANE) {
2522 COPY_4V( params, texUnit->EyePlaneR );
2523 }
2524 else {
2525 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2526 return;
2527 }
2528 break;
2529 case GL_Q:
2530 if (pname==GL_TEXTURE_GEN_MODE) {
2531 params[0] = ENUM_TO_FLOAT(texUnit->GenModeQ);
2532 }
2533 else if (pname==GL_OBJECT_PLANE) {
2534 COPY_4V( params, texUnit->ObjectPlaneQ );
2535 }
2536 else if (pname==GL_EYE_PLANE) {
2537 COPY_4V( params, texUnit->EyePlaneQ );
2538 }
2539 else {
2540 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2541 return;
2542 }
2543 break;
2544 default:
2545 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
2546 return;
2547 }
2548 }
2549
2550
2551
2552 void GLAPIENTRY
2553 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
2554 {
2555 GET_CURRENT_CONTEXT(ctx);
2556 GLuint tUnit = ctx->Texture.CurrentUnit;
2557 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2558 ASSERT_OUTSIDE_BEGIN_END(ctx);
2559
2560 switch (coord) {
2561 case GL_S:
2562 if (pname==GL_TEXTURE_GEN_MODE) {
2563 params[0] = texUnit->GenModeS;
2564 }
2565 else if (pname==GL_OBJECT_PLANE) {
2566 params[0] = (GLint) texUnit->ObjectPlaneS[0];
2567 params[1] = (GLint) texUnit->ObjectPlaneS[1];
2568 params[2] = (GLint) texUnit->ObjectPlaneS[2];
2569 params[3] = (GLint) texUnit->ObjectPlaneS[3];
2570 }
2571 else if (pname==GL_EYE_PLANE) {
2572 params[0] = (GLint) texUnit->EyePlaneS[0];
2573 params[1] = (GLint) texUnit->EyePlaneS[1];
2574 params[2] = (GLint) texUnit->EyePlaneS[2];
2575 params[3] = (GLint) texUnit->EyePlaneS[3];
2576 }
2577 else {
2578 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2579 return;
2580 }
2581 break;
2582 case GL_T:
2583 if (pname==GL_TEXTURE_GEN_MODE) {
2584 params[0] = texUnit->GenModeT;
2585 }
2586 else if (pname==GL_OBJECT_PLANE) {
2587 params[0] = (GLint) texUnit->ObjectPlaneT[0];
2588 params[1] = (GLint) texUnit->ObjectPlaneT[1];
2589 params[2] = (GLint) texUnit->ObjectPlaneT[2];
2590 params[3] = (GLint) texUnit->ObjectPlaneT[3];
2591 }
2592 else if (pname==GL_EYE_PLANE) {
2593 params[0] = (GLint) texUnit->EyePlaneT[0];
2594 params[1] = (GLint) texUnit->EyePlaneT[1];
2595 params[2] = (GLint) texUnit->EyePlaneT[2];
2596 params[3] = (GLint) texUnit->EyePlaneT[3];
2597 }
2598 else {
2599 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2600 return;
2601 }
2602 break;
2603 case GL_R:
2604 if (pname==GL_TEXTURE_GEN_MODE) {
2605 params[0] = texUnit->GenModeR;
2606 }
2607 else if (pname==GL_OBJECT_PLANE) {
2608 params[0] = (GLint) texUnit->ObjectPlaneR[0];
2609 params[1] = (GLint) texUnit->ObjectPlaneR[1];
2610 params[2] = (GLint) texUnit->ObjectPlaneR[2];
2611 params[3] = (GLint) texUnit->ObjectPlaneR[3];
2612 }
2613 else if (pname==GL_EYE_PLANE) {
2614 params[0] = (GLint) texUnit->EyePlaneR[0];
2615 params[1] = (GLint) texUnit->EyePlaneR[1];
2616 params[2] = (GLint) texUnit->EyePlaneR[2];
2617 params[3] = (GLint) texUnit->EyePlaneR[3];
2618 }
2619 else {
2620 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2621 return;
2622 }
2623 break;
2624 case GL_Q:
2625 if (pname==GL_TEXTURE_GEN_MODE) {
2626 params[0] = texUnit->GenModeQ;
2627 }
2628 else if (pname==GL_OBJECT_PLANE) {
2629 params[0] = (GLint) texUnit->ObjectPlaneQ[0];
2630 params[1] = (GLint) texUnit->ObjectPlaneQ[1];
2631 params[2] = (GLint) texUnit->ObjectPlaneQ[2];
2632 params[3] = (GLint) texUnit->ObjectPlaneQ[3];
2633 }
2634 else if (pname==GL_EYE_PLANE) {
2635 params[0] = (GLint) texUnit->EyePlaneQ[0];
2636 params[1] = (GLint) texUnit->EyePlaneQ[1];
2637 params[2] = (GLint) texUnit->EyePlaneQ[2];
2638 params[3] = (GLint) texUnit->EyePlaneQ[3];
2639 }
2640 else {
2641 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2642 return;
2643 }
2644 break;
2645 default:
2646 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
2647 return;
2648 }
2649 }
2650 #endif
2651
2652 /* GL_ARB_multitexture */
2653 void GLAPIENTRY
2654 _mesa_ActiveTextureARB( GLenum target )
2655 {
2656 GET_CURRENT_CONTEXT(ctx);
2657 const GLuint texUnit = target - GL_TEXTURE0;
2658 ASSERT_OUTSIDE_BEGIN_END(ctx);
2659
2660 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2661 _mesa_debug(ctx, "glActiveTexture %s\n",
2662 _mesa_lookup_enum_by_nr(target));
2663
2664 /* Cater for texture unit 0 is first, therefore use >= */
2665 if (texUnit >= ctx->Const.MaxTextureUnits) {
2666 _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTexture(target)");
2667 return;
2668 }
2669
2670 if (ctx->Texture.CurrentUnit == texUnit)
2671 return;
2672
2673 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2674
2675 ctx->Texture.CurrentUnit = texUnit;
2676 if (ctx->Transform.MatrixMode == GL_TEXTURE) {
2677 /* update current stack pointer */
2678 ctx->CurrentStack = &ctx->TextureMatrixStack[texUnit];
2679 }
2680
2681 if (ctx->Driver.ActiveTexture) {
2682 (*ctx->Driver.ActiveTexture)( ctx, (GLuint) texUnit );
2683 }
2684 }
2685
2686
2687 /* GL_ARB_multitexture */
2688 void GLAPIENTRY
2689 _mesa_ClientActiveTextureARB( GLenum target )
2690 {
2691 GET_CURRENT_CONTEXT(ctx);
2692 GLuint texUnit = target - GL_TEXTURE0;
2693 ASSERT_OUTSIDE_BEGIN_END(ctx);
2694
2695 if (texUnit > ctx->Const.MaxTextureUnits) {
2696 _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTexture(target)");
2697 return;
2698 }
2699
2700 FLUSH_VERTICES(ctx, _NEW_ARRAY);
2701 ctx->Array.ActiveTexture = texUnit;
2702 }
2703
2704
2705
2706 /**********************************************************************/
2707 /* Pixel Texgen Extensions */
2708 /**********************************************************************/
2709
2710 void GLAPIENTRY
2711 _mesa_PixelTexGenSGIX(GLenum mode)
2712 {
2713 GLenum newRgbSource, newAlphaSource;
2714 GET_CURRENT_CONTEXT(ctx);
2715 ASSERT_OUTSIDE_BEGIN_END(ctx);
2716
2717 switch (mode) {
2718 case GL_NONE:
2719 newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
2720 newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
2721 break;
2722 case GL_ALPHA:
2723 newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
2724 newAlphaSource = GL_CURRENT_RASTER_COLOR;
2725 break;
2726 case GL_RGB:
2727 newRgbSource = GL_CURRENT_RASTER_COLOR;
2728 newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
2729 break;
2730 case GL_RGBA:
2731 newRgbSource = GL_CURRENT_RASTER_COLOR;
2732 newAlphaSource = GL_CURRENT_RASTER_COLOR;
2733 break;
2734 default:
2735 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenSGIX(mode)");
2736 return;
2737 }
2738
2739 if (newRgbSource == ctx->Pixel.FragmentRgbSource &&
2740 newAlphaSource == ctx->Pixel.FragmentAlphaSource)
2741 return;
2742
2743 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2744 ctx->Pixel.FragmentRgbSource = newRgbSource;
2745 ctx->Pixel.FragmentAlphaSource = newAlphaSource;
2746 }
2747
2748
2749 void GLAPIENTRY
2750 _mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
2751 {
2752 _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
2753 }
2754
2755
2756 void GLAPIENTRY
2757 _mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
2758 {
2759 _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
2760 }
2761
2762
2763 void GLAPIENTRY
2764 _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
2765 {
2766 GET_CURRENT_CONTEXT(ctx);
2767 ASSERT_OUTSIDE_BEGIN_END(ctx);
2768
2769 if (value != GL_CURRENT_RASTER_COLOR && value != GL_PIXEL_GROUP_COLOR_SGIS) {
2770 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(value)");
2771 return;
2772 }
2773
2774 switch (target) {
2775 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS:
2776 if (ctx->Pixel.FragmentRgbSource == (GLenum) value)
2777 return;
2778 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2779 ctx->Pixel.FragmentRgbSource = (GLenum) value;
2780 break;
2781 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS:
2782 if (ctx->Pixel.FragmentAlphaSource == (GLenum) value)
2783 return;
2784 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2785 ctx->Pixel.FragmentAlphaSource = (GLenum) value;
2786 break;
2787 default:
2788 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(target)");
2789 return;
2790 }
2791 }
2792
2793
2794 void GLAPIENTRY
2795 _mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
2796 {
2797 _mesa_PixelTexGenParameteriSGIS(target, *value);
2798 }
2799
2800
2801 void GLAPIENTRY
2802 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
2803 {
2804 GET_CURRENT_CONTEXT(ctx);
2805 ASSERT_OUTSIDE_BEGIN_END(ctx);
2806
2807 if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
2808 *value = (GLfloat) ctx->Pixel.FragmentRgbSource;
2809 }
2810 else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
2811 *value = (GLfloat) ctx->Pixel.FragmentAlphaSource;
2812 }
2813 else {
2814 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterfvSGIS(target)");
2815 }
2816 }
2817
2818
2819 void GLAPIENTRY
2820 _mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
2821 {
2822 GET_CURRENT_CONTEXT(ctx);
2823 ASSERT_OUTSIDE_BEGIN_END(ctx);
2824
2825 if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
2826 *value = (GLint) ctx->Pixel.FragmentRgbSource;
2827 }
2828 else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
2829 *value = (GLint) ctx->Pixel.FragmentAlphaSource;
2830 }
2831 else {
2832 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterivSGIS(target)");
2833 }
2834 }
2835
2836
2837
2838 /**********************************************************************/
2839 /***** State management *****/
2840 /**********************************************************************/
2841
2842
2843 /**
2844 * \note This routine refers to derived texture attribute values to
2845 * compute the ENABLE_TEXMAT flags, but is only called on
2846 * _NEW_TEXTURE_MATRIX. On changes to _NEW_TEXTURE, the ENABLE_TEXMAT
2847 * flags are updated by _mesa_update_textures(), below.
2848 *
2849 * \param ctx GL context.
2850 */
2851 static void
2852 update_texture_matrices( GLcontext *ctx )
2853 {
2854 GLuint i;
2855
2856 ctx->Texture._TexMatEnabled = 0;
2857
2858 for (i=0; i < ctx->Const.MaxTextureUnits; i++) {
2859 if (_math_matrix_is_dirty(ctx->TextureMatrixStack[i].Top)) {
2860 _math_matrix_analyse( ctx->TextureMatrixStack[i].Top );
2861
2862 if (ctx->Texture.Unit[i]._ReallyEnabled &&
2863 ctx->TextureMatrixStack[i].Top->type != MATRIX_IDENTITY)
2864 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(i);
2865
2866 if (ctx->Driver.TextureMatrix)
2867 ctx->Driver.TextureMatrix( ctx, i, ctx->TextureMatrixStack[i].Top);
2868 }
2869 }
2870 }
2871
2872
2873 /**
2874 * \note This routine refers to derived texture matrix values to
2875 * compute the ENABLE_TEXMAT flags, but is only called on
2876 * _NEW_TEXTURE. On changes to _NEW_TEXTURE_MATRIX, the ENABLE_TEXMAT
2877 * flags are updated by _mesa_update_texture_matrices, above.
2878 *
2879 * \param ctx GL context.
2880 */
2881 static void
2882 update_texture_state( GLcontext *ctx )
2883 {
2884 GLuint unit;
2885
2886 ctx->NewState |= _NEW_TEXTURE; /* TODO: only set this if there are
2887 * actual changes.
2888 */
2889
2890 ctx->Texture._EnabledUnits = 0;
2891 ctx->Texture._GenFlags = 0;
2892 ctx->Texture._TexMatEnabled = 0;
2893 ctx->Texture._TexGenEnabled = 0;
2894
2895 /* Update texture unit state.
2896 * XXX this loop should probably be broken into separate loops for
2897 * texture coord units and texture image units.
2898 */
2899 for (unit = 0; unit < ctx->Const.MaxTextureUnits; unit++) {
2900 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
2901 GLbitfield enableBits;
2902
2903 texUnit->_Current = NULL;
2904 texUnit->_ReallyEnabled = 0;
2905 texUnit->_GenFlags = 0;
2906
2907 /* Get the bitmask of texture enables */
2908 if (ctx->FragmentProgram._Enabled) {
2909 enableBits = ctx->FragmentProgram.Current->TexturesUsed[unit];
2910 }
2911 else {
2912 if (!texUnit->Enabled)
2913 continue;
2914 enableBits = texUnit->Enabled;
2915 }
2916
2917 /* Look for the highest-priority texture target that's enabled and
2918 * complete. That's the one we'll use for texturing. If we're using
2919 * a fragment program we're guaranteed that bitcount(enabledBits) <= 1.
2920 */
2921 if (enableBits & TEXTURE_CUBE_BIT) {
2922 struct gl_texture_object *texObj = texUnit->CurrentCubeMap;
2923 if (!texObj->Complete) {
2924 _mesa_test_texobj_completeness(ctx, texObj);
2925 }
2926 if (texObj->Complete) {
2927 texUnit->_ReallyEnabled = TEXTURE_CUBE_BIT;
2928 texUnit->_Current = texObj;
2929 }
2930 }
2931
2932 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_3D_BIT)) {
2933 struct gl_texture_object *texObj = texUnit->Current3D;
2934 if (!texObj->Complete) {
2935 _mesa_test_texobj_completeness(ctx, texObj);
2936 }
2937 if (texObj->Complete) {
2938 texUnit->_ReallyEnabled = TEXTURE_3D_BIT;
2939 texUnit->_Current = texObj;
2940 }
2941 }
2942
2943 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_RECT_BIT)) {
2944 struct gl_texture_object *texObj = texUnit->CurrentRect;
2945 if (!texObj->Complete) {
2946 _mesa_test_texobj_completeness(ctx, texObj);
2947 }
2948 if (texObj->Complete) {
2949 texUnit->_ReallyEnabled = TEXTURE_RECT_BIT;
2950 texUnit->_Current = texObj;
2951 }
2952 }
2953
2954 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_2D_BIT)) {
2955 struct gl_texture_object *texObj = texUnit->Current2D;
2956 if (!texObj->Complete) {
2957 _mesa_test_texobj_completeness(ctx, texObj);
2958 }
2959 if (texObj->Complete) {
2960 texUnit->_ReallyEnabled = TEXTURE_2D_BIT;
2961 texUnit->_Current = texObj;
2962 }
2963 }
2964
2965 if (!texUnit->_ReallyEnabled && (enableBits & TEXTURE_1D_BIT)) {
2966 struct gl_texture_object *texObj = texUnit->Current1D;
2967 if (!texObj->Complete) {
2968 _mesa_test_texobj_completeness(ctx, texObj);
2969 }
2970 if (texObj->Complete) {
2971 texUnit->_ReallyEnabled = TEXTURE_1D_BIT;
2972 texUnit->_Current = texObj;
2973 }
2974 }
2975
2976 if (!texUnit->_ReallyEnabled) {
2977 continue;
2978 }
2979
2980 if (texUnit->_ReallyEnabled)
2981 ctx->Texture._EnabledUnits |= (1 << unit);
2982
2983 if (texUnit->EnvMode == GL_COMBINE) {
2984 texUnit->_CurrentCombine = & texUnit->Combine;
2985 }
2986 else {
2987 GLenum format = texUnit->_Current->Image[0][0]->_BaseFormat;
2988 if (format == GL_COLOR_INDEX) {
2989 format = GL_RGBA; /* a bit of a hack */
2990 }
2991 else if (format == GL_DEPTH_COMPONENT
2992 || format == GL_DEPTH_STENCIL_EXT) {
2993 format = texUnit->_Current->DepthMode;
2994 }
2995 calculate_derived_texenv(&texUnit->_EnvMode, texUnit->EnvMode, format);
2996 texUnit->_CurrentCombine = & texUnit->_EnvMode;
2997 }
2998
2999 switch (texUnit->_CurrentCombine->ModeRGB) {
3000 case GL_REPLACE:
3001 texUnit->_CurrentCombine->_NumArgsRGB = 1;
3002 break;
3003 case GL_MODULATE:
3004 case GL_ADD:
3005 case GL_ADD_SIGNED:
3006 case GL_SUBTRACT:
3007 case GL_DOT3_RGB:
3008 case GL_DOT3_RGBA:
3009 case GL_DOT3_RGB_EXT:
3010 case GL_DOT3_RGBA_EXT:
3011 texUnit->_CurrentCombine->_NumArgsRGB = 2;
3012 break;
3013 case GL_INTERPOLATE:
3014 case GL_MODULATE_ADD_ATI:
3015 case GL_MODULATE_SIGNED_ADD_ATI:
3016 case GL_MODULATE_SUBTRACT_ATI:
3017 texUnit->_CurrentCombine->_NumArgsRGB = 3;
3018 break;
3019 default:
3020 texUnit->_CurrentCombine->_NumArgsRGB = 0;
3021 _mesa_problem(ctx, "invalid RGB combine mode in update_texture_state");
3022 return;
3023 }
3024
3025 switch (texUnit->_CurrentCombine->ModeA) {
3026 case GL_REPLACE:
3027 texUnit->_CurrentCombine->_NumArgsA = 1;
3028 break;
3029 case GL_MODULATE:
3030 case GL_ADD:
3031 case GL_ADD_SIGNED:
3032 case GL_SUBTRACT:
3033 texUnit->_CurrentCombine->_NumArgsA = 2;
3034 break;
3035 case GL_INTERPOLATE:
3036 case GL_MODULATE_ADD_ATI:
3037 case GL_MODULATE_SIGNED_ADD_ATI:
3038 case GL_MODULATE_SUBTRACT_ATI:
3039 texUnit->_CurrentCombine->_NumArgsA = 3;
3040 break;
3041 default:
3042 texUnit->_CurrentCombine->_NumArgsA = 0;
3043 _mesa_problem(ctx, "invalid Alpha combine mode in update_texture_state");
3044 break;
3045 }
3046
3047 if (texUnit->TexGenEnabled) {
3048 if (texUnit->TexGenEnabled & S_BIT) {
3049 texUnit->_GenFlags |= texUnit->_GenBitS;
3050 }
3051 if (texUnit->TexGenEnabled & T_BIT) {
3052 texUnit->_GenFlags |= texUnit->_GenBitT;
3053 }
3054 if (texUnit->TexGenEnabled & Q_BIT) {
3055 texUnit->_GenFlags |= texUnit->_GenBitQ;
3056 }
3057 if (texUnit->TexGenEnabled & R_BIT) {
3058 texUnit->_GenFlags |= texUnit->_GenBitR;
3059 }
3060
3061 ctx->Texture._TexGenEnabled |= ENABLE_TEXGEN(unit);
3062 ctx->Texture._GenFlags |= texUnit->_GenFlags;
3063 }
3064
3065 if (ctx->TextureMatrixStack[unit].Top->type != MATRIX_IDENTITY)
3066 ctx->Texture._TexMatEnabled |= ENABLE_TEXMAT(unit);
3067 }
3068
3069 ctx->Texture._EnabledCoordUnits = ctx->Texture._EnabledUnits;
3070 /* Fragment programs may need texture coordinates but not the
3071 * corresponding texture images.
3072 */
3073 if (ctx->FragmentProgram._Enabled) {
3074 ctx->Texture._EnabledCoordUnits |=
3075 (ctx->FragmentProgram.Current->InputsRead >> FRAG_ATTRIB_TEX0);
3076 }
3077 }
3078
3079
3080 void _mesa_update_texture( GLcontext *ctx, GLuint new_state )
3081 {
3082 if (new_state & _NEW_TEXTURE_MATRIX)
3083 update_texture_matrices( ctx );
3084
3085 if (new_state & (_NEW_TEXTURE | _NEW_PROGRAM))
3086 update_texture_state( ctx );
3087 }
3088
3089
3090 /**********************************************************************/
3091 /***** Initialization *****/
3092 /**********************************************************************/
3093
3094 /**
3095 * Allocate the proxy textures for the given context.
3096 *
3097 * \param ctx the context to allocate proxies for.
3098 *
3099 * \return GL_TRUE on success, or GL_FALSE on failure
3100 *
3101 * If run out of memory part way through the allocations, clean up and return
3102 * GL_FALSE.
3103 */
3104 static GLboolean
3105 alloc_proxy_textures( GLcontext *ctx )
3106 {
3107 ctx->Texture.Proxy1D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_1D);
3108 if (!ctx->Texture.Proxy1D)
3109 goto cleanup;
3110
3111 ctx->Texture.Proxy2D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_2D);
3112 if (!ctx->Texture.Proxy2D)
3113 goto cleanup;
3114
3115 ctx->Texture.Proxy3D = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_3D);
3116 if (!ctx->Texture.Proxy3D)
3117 goto cleanup;
3118
3119 ctx->Texture.ProxyCubeMap = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_CUBE_MAP_ARB);
3120 if (!ctx->Texture.ProxyCubeMap)
3121 goto cleanup;
3122
3123 ctx->Texture.ProxyRect = (*ctx->Driver.NewTextureObject)(ctx, 0, GL_TEXTURE_RECTANGLE_NV);
3124 if (!ctx->Texture.ProxyRect)
3125 goto cleanup;
3126
3127 return GL_TRUE;
3128
3129 cleanup:
3130 if (ctx->Texture.Proxy1D)
3131 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D);
3132 if (ctx->Texture.Proxy2D)
3133 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D);
3134 if (ctx->Texture.Proxy3D)
3135 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D);
3136 if (ctx->Texture.ProxyCubeMap)
3137 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap);
3138 if (ctx->Texture.ProxyRect)
3139 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect);
3140 return GL_FALSE;
3141 }
3142
3143
3144 /**
3145 * Initialize a texture unit.
3146 *
3147 * \param ctx GL context.
3148 * \param unit texture unit number to be initialized.
3149 */
3150 static void
3151 init_texture_unit( GLcontext *ctx, GLuint unit )
3152 {
3153 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
3154
3155 texUnit->EnvMode = GL_MODULATE;
3156 ASSIGN_4V( texUnit->EnvColor, 0.0, 0.0, 0.0, 0.0 );
3157
3158 texUnit->Combine = default_combine_state;
3159 texUnit->_EnvMode = default_combine_state;
3160 texUnit->_CurrentCombine = & texUnit->_EnvMode;
3161
3162 texUnit->TexGenEnabled = 0;
3163 texUnit->GenModeS = GL_EYE_LINEAR;
3164 texUnit->GenModeT = GL_EYE_LINEAR;
3165 texUnit->GenModeR = GL_EYE_LINEAR;
3166 texUnit->GenModeQ = GL_EYE_LINEAR;
3167 texUnit->_GenBitS = TEXGEN_EYE_LINEAR;
3168 texUnit->_GenBitT = TEXGEN_EYE_LINEAR;
3169 texUnit->_GenBitR = TEXGEN_EYE_LINEAR;
3170 texUnit->_GenBitQ = TEXGEN_EYE_LINEAR;
3171
3172 /* Yes, these plane coefficients are correct! */
3173 ASSIGN_4V( texUnit->ObjectPlaneS, 1.0, 0.0, 0.0, 0.0 );
3174 ASSIGN_4V( texUnit->ObjectPlaneT, 0.0, 1.0, 0.0, 0.0 );
3175 ASSIGN_4V( texUnit->ObjectPlaneR, 0.0, 0.0, 0.0, 0.0 );
3176 ASSIGN_4V( texUnit->ObjectPlaneQ, 0.0, 0.0, 0.0, 0.0 );
3177 ASSIGN_4V( texUnit->EyePlaneS, 1.0, 0.0, 0.0, 0.0 );
3178 ASSIGN_4V( texUnit->EyePlaneT, 0.0, 1.0, 0.0, 0.0 );
3179 ASSIGN_4V( texUnit->EyePlaneR, 0.0, 0.0, 0.0, 0.0 );
3180 ASSIGN_4V( texUnit->EyePlaneQ, 0.0, 0.0, 0.0, 0.0 );
3181
3182 texUnit->Current1D = ctx->Shared->Default1D;
3183 texUnit->Current2D = ctx->Shared->Default2D;
3184 texUnit->Current3D = ctx->Shared->Default3D;
3185 texUnit->CurrentCubeMap = ctx->Shared->DefaultCubeMap;
3186 texUnit->CurrentRect = ctx->Shared->DefaultRect;
3187 }
3188
3189
3190 /**
3191 * Initialize texture state for the given context.
3192 */
3193 GLboolean
3194 _mesa_init_texture(GLcontext *ctx)
3195 {
3196 GLuint i;
3197
3198 assert(MAX_TEXTURE_LEVELS >= MAX_3D_TEXTURE_LEVELS);
3199 assert(MAX_TEXTURE_LEVELS >= MAX_CUBE_TEXTURE_LEVELS);
3200
3201 /* Effectively bind the default textures to all texture units */
3202 ctx->Shared->Default1D->RefCount += MAX_TEXTURE_UNITS;
3203 ctx->Shared->Default2D->RefCount += MAX_TEXTURE_UNITS;
3204 ctx->Shared->Default3D->RefCount += MAX_TEXTURE_UNITS;
3205 ctx->Shared->DefaultCubeMap->RefCount += MAX_TEXTURE_UNITS;
3206 ctx->Shared->DefaultRect->RefCount += MAX_TEXTURE_UNITS;
3207
3208 /* Texture group */
3209 ctx->Texture.CurrentUnit = 0; /* multitexture */
3210 ctx->Texture._EnabledUnits = 0;
3211 for (i=0; i<MAX_TEXTURE_UNITS; i++)
3212 init_texture_unit( ctx, i );
3213 ctx->Texture.SharedPalette = GL_FALSE;
3214 _mesa_init_colortable(&ctx->Texture.Palette);
3215
3216 /* Allocate proxy textures */
3217 if (!alloc_proxy_textures( ctx ))
3218 return GL_FALSE;
3219
3220 return GL_TRUE;
3221 }
3222
3223
3224 /**
3225 * Free dynamically-allocted texture data attached to the given context.
3226 */
3227 void
3228 _mesa_free_texture_data(GLcontext *ctx)
3229 {
3230 GLuint i;
3231
3232 /* Free proxy texture objects */
3233 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy1D );
3234 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy2D );
3235 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.Proxy3D );
3236 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyCubeMap );
3237 (ctx->Driver.DeleteTexture)(ctx, ctx->Texture.ProxyRect );
3238
3239 for (i = 0; i < MAX_TEXTURE_IMAGE_UNITS; i++)
3240 _mesa_free_colortable_data( &ctx->Texture.Unit[i].ColorTable );
3241
3242 _mesa_TexEnvProgramCacheDestroy( ctx );
3243 }