disable _glapi_set_warning_func() call as it's not present in older libGLs
[mesa.git] / src / mesa / main / texstate.c
1 /* $Id: texstate.c,v 1.80 2002/10/04 19:10:08 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 4.1
6 *
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 */
26
27
28 #ifdef PC_HEADER
29 #include "all.h"
30 #else
31 #include "glheader.h"
32 #include "colormac.h"
33 #include "context.h"
34 #include "enums.h"
35 #include "extensions.h"
36 #include "macros.h"
37 #include "texobj.h"
38 #include "teximage.h"
39 #include "texstate.h"
40 #include "mtypes.h"
41 #include "math/m_xform.h"
42 #include "math/m_matrix.h"
43 #endif
44
45
46
47 #ifdef SPECIALCAST
48 /* Needed for an Amiga compiler */
49 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
50 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
51 #else
52 /* all other compilers */
53 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
54 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
55 #endif
56
57
58
59 void
60 _mesa_copy_texture_state( const GLcontext *src, GLcontext *dst )
61 {
62 GLuint i;
63
64 ASSERT(src);
65 ASSERT(dst);
66
67 dst->Texture.CurrentUnit = src->Texture.CurrentUnit;
68 dst->Texture._GenFlags = src->Texture._GenFlags;
69 dst->Texture._TexGenEnabled = src->Texture._TexGenEnabled;
70 dst->Texture._TexMatEnabled = src->Texture._TexMatEnabled;
71 dst->Texture.SharedPalette = src->Texture.SharedPalette;
72
73 /* per-unit state */
74 for (i = 0; i < src->Const.MaxTextureUnits; i++) {
75 dst->Texture.Unit[i].Enabled = src->Texture.Unit[i].Enabled;
76 dst->Texture.Unit[i].EnvMode = src->Texture.Unit[i].EnvMode;
77 COPY_4V(dst->Texture.Unit[i].EnvColor, src->Texture.Unit[i].EnvColor);
78 dst->Texture.Unit[i].TexGenEnabled = src->Texture.Unit[i].TexGenEnabled;
79 dst->Texture.Unit[i].GenModeS = src->Texture.Unit[i].GenModeS;
80 dst->Texture.Unit[i].GenModeT = src->Texture.Unit[i].GenModeT;
81 dst->Texture.Unit[i].GenModeR = src->Texture.Unit[i].GenModeR;
82 dst->Texture.Unit[i].GenModeQ = src->Texture.Unit[i].GenModeQ;
83 dst->Texture.Unit[i]._GenBitS = src->Texture.Unit[i]._GenBitS;
84 dst->Texture.Unit[i]._GenBitT = src->Texture.Unit[i]._GenBitT;
85 dst->Texture.Unit[i]._GenBitR = src->Texture.Unit[i]._GenBitR;
86 dst->Texture.Unit[i]._GenBitQ = src->Texture.Unit[i]._GenBitQ;
87 dst->Texture.Unit[i]._GenFlags = src->Texture.Unit[i]._GenFlags;
88 COPY_4V(dst->Texture.Unit[i].ObjectPlaneS, src->Texture.Unit[i].ObjectPlaneS);
89 COPY_4V(dst->Texture.Unit[i].ObjectPlaneT, src->Texture.Unit[i].ObjectPlaneT);
90 COPY_4V(dst->Texture.Unit[i].ObjectPlaneR, src->Texture.Unit[i].ObjectPlaneR);
91 COPY_4V(dst->Texture.Unit[i].ObjectPlaneQ, src->Texture.Unit[i].ObjectPlaneQ);
92 COPY_4V(dst->Texture.Unit[i].EyePlaneS, src->Texture.Unit[i].EyePlaneS);
93 COPY_4V(dst->Texture.Unit[i].EyePlaneT, src->Texture.Unit[i].EyePlaneT);
94 COPY_4V(dst->Texture.Unit[i].EyePlaneR, src->Texture.Unit[i].EyePlaneR);
95 COPY_4V(dst->Texture.Unit[i].EyePlaneQ, src->Texture.Unit[i].EyePlaneQ);
96 dst->Texture.Unit[i].LodBias = src->Texture.Unit[i].LodBias;
97
98 /* GL_EXT_texture_env_combine */
99 dst->Texture.Unit[i].CombineModeRGB = src->Texture.Unit[i].CombineModeRGB;
100 dst->Texture.Unit[i].CombineModeA = src->Texture.Unit[i].CombineModeA;
101 COPY_3V(dst->Texture.Unit[i].CombineSourceRGB, src->Texture.Unit[i].CombineSourceRGB);
102 COPY_3V(dst->Texture.Unit[i].CombineSourceA, src->Texture.Unit[i].CombineSourceA);
103 COPY_3V(dst->Texture.Unit[i].CombineOperandRGB, src->Texture.Unit[i].CombineOperandRGB);
104 COPY_3V(dst->Texture.Unit[i].CombineOperandA, src->Texture.Unit[i].CombineOperandA);
105 dst->Texture.Unit[i].CombineScaleShiftRGB = src->Texture.Unit[i].CombineScaleShiftRGB;
106 dst->Texture.Unit[i].CombineScaleShiftA = src->Texture.Unit[i].CombineScaleShiftA;
107
108 /* texture object state */
109 _mesa_copy_texture_object(dst->Texture.Unit[i].Current1D,
110 src->Texture.Unit[i].Current1D);
111 _mesa_copy_texture_object(dst->Texture.Unit[i].Current2D,
112 src->Texture.Unit[i].Current2D);
113 _mesa_copy_texture_object(dst->Texture.Unit[i].Current3D,
114 src->Texture.Unit[i].Current3D);
115 _mesa_copy_texture_object(dst->Texture.Unit[i].CurrentCubeMap,
116 src->Texture.Unit[i].CurrentCubeMap);
117 }
118 }
119
120
121 /**********************************************************************/
122 /* Texture Environment */
123 /**********************************************************************/
124
125
126 void
127 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
128 {
129 GET_CURRENT_CONTEXT(ctx);
130 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
131 ASSERT_OUTSIDE_BEGIN_END(ctx);
132
133 #define TE_ERROR(errCode, msg, value) \
134 _mesa_error(ctx, errCode, msg, _mesa_lookup_enum_by_nr(value));
135
136 if (target == GL_TEXTURE_ENV) {
137 switch (pname) {
138 case GL_TEXTURE_ENV_MODE:
139 {
140 const GLenum mode = (GLenum) (GLint) *param;
141 if (mode == GL_MODULATE ||
142 mode == GL_BLEND ||
143 mode == GL_DECAL ||
144 mode == GL_REPLACE ||
145 (mode == GL_ADD && ctx->Extensions.EXT_texture_env_add) ||
146 (mode == GL_COMBINE_EXT &&
147 (ctx->Extensions.EXT_texture_env_combine ||
148 ctx->Extensions.ARB_texture_env_combine))) {
149 /* legal */
150 if (texUnit->EnvMode == mode)
151 return;
152 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
153 texUnit->EnvMode = mode;
154 }
155 else {
156 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
157 return;
158 }
159 }
160 break;
161 case GL_TEXTURE_ENV_COLOR:
162 {
163 GLfloat tmp[4];
164 tmp[0] = CLAMP( param[0], 0.0F, 1.0F );
165 tmp[1] = CLAMP( param[1], 0.0F, 1.0F );
166 tmp[2] = CLAMP( param[2], 0.0F, 1.0F );
167 tmp[3] = CLAMP( param[3], 0.0F, 1.0F );
168 if (TEST_EQ_4V(tmp, texUnit->EnvColor))
169 return;
170 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
171 COPY_4FV(texUnit->EnvColor, tmp);
172 }
173 break;
174 case GL_COMBINE_RGB_EXT:
175 if (ctx->Extensions.EXT_texture_env_combine ||
176 ctx->Extensions.ARB_texture_env_combine) {
177 const GLenum mode = (GLenum) (GLint) *param;
178 switch (mode) {
179 case GL_REPLACE:
180 case GL_MODULATE:
181 case GL_ADD:
182 case GL_ADD_SIGNED_EXT:
183 case GL_INTERPOLATE_EXT:
184 /* OK */
185 break;
186 case GL_SUBTRACT_ARB:
187 if (!ctx->Extensions.ARB_texture_env_combine) {
188 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
189 return;
190 }
191 break;
192 case GL_DOT3_RGB_EXT:
193 case GL_DOT3_RGBA_EXT:
194 if (!ctx->Extensions.EXT_texture_env_dot3) {
195 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
196 return;
197 }
198 break;
199 case GL_DOT3_RGB_ARB:
200 case GL_DOT3_RGBA_ARB:
201 if (!ctx->Extensions.ARB_texture_env_dot3) {
202 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
203 return;
204 }
205 break;
206 default:
207 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
208 return;
209 }
210 if (texUnit->CombineModeRGB == mode)
211 return;
212 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
213 texUnit->CombineModeRGB = mode;
214 }
215 else {
216 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
217 return;
218 }
219 break;
220 case GL_COMBINE_ALPHA_EXT:
221 if (ctx->Extensions.EXT_texture_env_combine ||
222 ctx->Extensions.ARB_texture_env_combine) {
223 const GLenum mode = (GLenum) (GLint) *param;
224 if (mode == GL_REPLACE ||
225 mode == GL_MODULATE ||
226 mode == GL_ADD ||
227 mode == GL_ADD_SIGNED_EXT ||
228 mode == GL_INTERPOLATE_EXT ||
229 (mode == GL_SUBTRACT_ARB &&
230 ctx->Extensions.ARB_texture_env_combine)) {
231 /* legal */
232 if (texUnit->CombineModeA == mode)
233 return;
234 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
235 texUnit->CombineModeA = mode;
236 }
237 else {
238 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", mode);
239 return;
240 }
241 }
242 else {
243 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
244 return;
245 }
246 break;
247 case GL_SOURCE0_RGB_EXT:
248 case GL_SOURCE1_RGB_EXT:
249 case GL_SOURCE2_RGB_EXT:
250 if (ctx->Extensions.EXT_texture_env_combine ||
251 ctx->Extensions.ARB_texture_env_combine) {
252 const GLenum source = (GLenum) (GLint) *param;
253 const GLuint s = pname - GL_SOURCE0_RGB_EXT;
254 if (source == GL_TEXTURE ||
255 source == GL_CONSTANT_EXT ||
256 source == GL_PRIMARY_COLOR_EXT ||
257 source == GL_PREVIOUS_EXT ||
258 (ctx->Extensions.ARB_texture_env_crossbar &&
259 source >= GL_TEXTURE0_ARB &&
260 source < GL_TEXTURE0_ARB + ctx->Const.MaxTextureUnits)) {
261 /* legal */
262 if (texUnit->CombineSourceRGB[s] == source)
263 return;
264 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
265 texUnit->CombineSourceRGB[s] = source;
266 }
267 else {
268 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source);
269 return;
270 }
271 }
272 else {
273 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
274 return;
275 }
276 break;
277 case GL_SOURCE0_ALPHA_EXT:
278 case GL_SOURCE1_ALPHA_EXT:
279 case GL_SOURCE2_ALPHA_EXT:
280 if (ctx->Extensions.EXT_texture_env_combine ||
281 ctx->Extensions.ARB_texture_env_combine) {
282 const GLenum source = (GLenum) (GLint) *param;
283 const GLuint s = pname - GL_SOURCE0_ALPHA_EXT;
284 if (source == GL_TEXTURE ||
285 source == GL_CONSTANT_EXT ||
286 source == GL_PRIMARY_COLOR_EXT ||
287 source == GL_PREVIOUS_EXT ||
288 (ctx->Extensions.ARB_texture_env_crossbar &&
289 source >= GL_TEXTURE0_ARB &&
290 source < GL_TEXTURE0_ARB + ctx->Const.MaxTextureUnits)) {
291 /* legal */
292 if (texUnit->CombineSourceA[s] == source)
293 return;
294 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
295 texUnit->CombineSourceA[s] = source;
296 }
297 else {
298 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", source);
299 return;
300 }
301 }
302 else {
303 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
304 return;
305 }
306 break;
307 case GL_OPERAND0_RGB_EXT:
308 case GL_OPERAND1_RGB_EXT:
309 if (ctx->Extensions.EXT_texture_env_combine ||
310 ctx->Extensions.ARB_texture_env_combine) {
311 const GLenum operand = (GLenum) (GLint) *param;
312 const GLuint s = pname - GL_OPERAND0_RGB_EXT;
313 switch (operand) {
314 case GL_SRC_COLOR:
315 case GL_ONE_MINUS_SRC_COLOR:
316 case GL_SRC_ALPHA:
317 case GL_ONE_MINUS_SRC_ALPHA:
318 if (texUnit->CombineOperandRGB[s] == operand)
319 return;
320 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
321 texUnit->CombineOperandRGB[s] = operand;
322 break;
323 default:
324 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
325 return;
326 }
327 }
328 else {
329 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
330 return;
331 }
332 break;
333 case GL_OPERAND0_ALPHA_EXT:
334 case GL_OPERAND1_ALPHA_EXT:
335 if (ctx->Extensions.EXT_texture_env_combine ||
336 ctx->Extensions.ARB_texture_env_combine) {
337 const GLenum operand = (GLenum) (GLint) *param;
338 switch (operand) {
339 case GL_SRC_ALPHA:
340 case GL_ONE_MINUS_SRC_ALPHA:
341 if (texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT] ==
342 operand)
343 return;
344 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
345 texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT] = operand;
346 break;
347 default:
348 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
349 return;
350 }
351 }
352 else {
353 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
354 return;
355 }
356 break;
357 case GL_OPERAND2_RGB_EXT:
358 if (ctx->Extensions.EXT_texture_env_combine ||
359 ctx->Extensions.ARB_texture_env_combine) {
360 const GLenum operand = (GLenum) (GLint) *param;
361 switch (operand) {
362 case GL_SRC_COLOR: /* ARB combine only */
363 case GL_ONE_MINUS_SRC_COLOR: /* ARB combine only */
364 case GL_SRC_ALPHA:
365 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */
366 if (texUnit->CombineOperandRGB[2] == operand)
367 return;
368 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
369 texUnit->CombineOperandRGB[2] = operand;
370 default:
371 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
372 return;
373 }
374 }
375 else {
376 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
377 return;
378 }
379 break;
380 case GL_OPERAND2_ALPHA_EXT:
381 if (ctx->Extensions.EXT_texture_env_combine ||
382 ctx->Extensions.ARB_texture_env_combine) {
383 const GLenum operand = (GLenum) (GLint) *param;
384 switch (operand) {
385 case GL_SRC_ALPHA:
386 case GL_ONE_MINUS_SRC_ALPHA: /* ARB combine only */
387 if (texUnit->CombineOperandA[2] == operand)
388 return;
389 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
390 texUnit->CombineOperandA[2] = operand;
391 break;
392 default:
393 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(param=%s)", operand);
394 return;
395 }
396 }
397 else {
398 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
399 return;
400 }
401 break;
402 case GL_RGB_SCALE_EXT:
403 if (ctx->Extensions.EXT_texture_env_combine ||
404 ctx->Extensions.ARB_texture_env_combine) {
405 GLuint newshift;
406 if (*param == 1.0) {
407 newshift = 0;
408 }
409 else if (*param == 2.0) {
410 newshift = 1;
411 }
412 else if (*param == 4.0) {
413 newshift = 2;
414 }
415 else {
416 _mesa_error( ctx, GL_INVALID_VALUE,
417 "glTexEnv(GL_RGB_SCALE not 1, 2 or 4)" );
418 return;
419 }
420 if (texUnit->CombineScaleShiftRGB == newshift)
421 return;
422 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
423 texUnit->CombineScaleShiftRGB = newshift;
424 }
425 else {
426 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
427 return;
428 }
429 break;
430 case GL_ALPHA_SCALE:
431 if (ctx->Extensions.EXT_texture_env_combine ||
432 ctx->Extensions.ARB_texture_env_combine) {
433 GLuint newshift;
434 if (*param == 1.0) {
435 newshift = 0;
436 }
437 else if (*param == 2.0) {
438 newshift = 1;
439 }
440 else if (*param == 4.0) {
441 newshift = 2;
442 }
443 else {
444 _mesa_error( ctx, GL_INVALID_VALUE,
445 "glTexEnv(GL_ALPHA_SCALE not 1, 2 or 4)" );
446 return;
447 }
448 if (texUnit->CombineScaleShiftA == newshift)
449 return;
450 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
451 texUnit->CombineScaleShiftA = newshift;
452 }
453 else {
454 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
455 return;
456 }
457 break;
458 default:
459 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
460 return;
461 }
462 }
463 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
464 /* GL_EXT_texture_lod_bias */
465 if (!ctx->Extensions.EXT_texture_lod_bias) {
466 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target );
467 return;
468 }
469 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
470 if (texUnit->LodBias == param[0])
471 return;
472 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
473 texUnit->LodBias = CLAMP(param[0], -ctx->Const.MaxTextureLodBias,
474 ctx->Const.MaxTextureLodBias);
475 }
476 else {
477 TE_ERROR(GL_INVALID_ENUM, "glTexEnv(pname=%s)", pname);
478 return;
479 }
480 }
481 else if (target == GL_POINT_SPRITE_NV) {
482 /* GL_NV_point_sprite */
483 if (!ctx->Extensions.NV_point_sprite) {
484 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)", target );
485 return;
486 }
487 if (pname == GL_COORD_REPLACE_NV) {
488 const GLenum value = (GLenum) param[0];
489 if (value == GL_TRUE || value == GL_FALSE) {
490 /* It's kind of weird to set point state via glTexEnv,
491 * but that's what the spec calls for.
492 */
493 const GLboolean state = (GLboolean) value;
494 if (ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] == state)
495 return;
496 FLUSH_VERTICES(ctx, _NEW_POINT);
497 ctx->Point.CoordReplace[ctx->Texture.CurrentUnit] = state;
498 }
499 else {
500 _mesa_error( ctx, GL_INVALID_VALUE, "glTexEnv(param=0x%x)", value);
501 return;
502 }
503 }
504 else {
505 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname=0x%x)", pname );
506 return;
507 }
508 }
509 else {
510 _mesa_error( ctx, GL_INVALID_ENUM, "glTexEnv(target=0x%x)",target );
511 return;
512 }
513
514 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
515 _mesa_debug(ctx, "glTexEnv %s %s %.1f(%s) ...\n",
516 _mesa_lookup_enum_by_nr(target),
517 _mesa_lookup_enum_by_nr(pname),
518 *param,
519 _mesa_lookup_enum_by_nr((GLenum) (GLint) *param));
520
521 /* Tell device driver about the new texture environment */
522 if (ctx->Driver.TexEnv) {
523 (*ctx->Driver.TexEnv)( ctx, target, pname, param );
524 }
525 }
526
527
528 void
529 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
530 {
531 _mesa_TexEnvfv( target, pname, &param );
532 }
533
534
535
536 void
537 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
538 {
539 GLfloat p[4];
540 p[0] = (GLfloat) param;
541 p[1] = p[2] = p[3] = 0.0;
542 _mesa_TexEnvfv( target, pname, p );
543 }
544
545
546 void
547 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
548 {
549 GLfloat p[4];
550 if (pname == GL_TEXTURE_ENV_COLOR) {
551 p[0] = INT_TO_FLOAT( param[0] );
552 p[1] = INT_TO_FLOAT( param[1] );
553 p[2] = INT_TO_FLOAT( param[2] );
554 p[3] = INT_TO_FLOAT( param[3] );
555 }
556 else {
557 p[0] = (GLint) param[0];
558 p[1] = p[2] = p[3] = 0; /* init to zero, just to be safe */
559 }
560 _mesa_TexEnvfv( target, pname, p );
561 }
562
563
564 void
565 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
566 {
567 GET_CURRENT_CONTEXT(ctx);
568 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
569 ASSERT_OUTSIDE_BEGIN_END(ctx);
570
571 if (target == GL_TEXTURE_ENV) {
572 switch (pname) {
573 case GL_TEXTURE_ENV_MODE:
574 *params = ENUM_TO_FLOAT(texUnit->EnvMode);
575 break;
576 case GL_TEXTURE_ENV_COLOR:
577 COPY_4FV( params, texUnit->EnvColor );
578 break;
579 case GL_COMBINE_RGB_EXT:
580 if (ctx->Extensions.EXT_texture_env_combine ||
581 ctx->Extensions.ARB_texture_env_combine) {
582 *params = (GLfloat) texUnit->CombineModeRGB;
583 }
584 else {
585 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
586 }
587 break;
588 case GL_COMBINE_ALPHA_EXT:
589 if (ctx->Extensions.EXT_texture_env_combine ||
590 ctx->Extensions.ARB_texture_env_combine) {
591 *params = (GLfloat) texUnit->CombineModeA;
592 }
593 else {
594 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
595 }
596 break;
597 case GL_SOURCE0_RGB_EXT:
598 if (ctx->Extensions.EXT_texture_env_combine ||
599 ctx->Extensions.ARB_texture_env_combine) {
600 *params = (GLfloat) texUnit->CombineSourceRGB[0];
601 }
602 else {
603 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
604 }
605 break;
606 case GL_SOURCE1_RGB_EXT:
607 if (ctx->Extensions.EXT_texture_env_combine ||
608 ctx->Extensions.ARB_texture_env_combine) {
609 *params = (GLfloat) texUnit->CombineSourceRGB[1];
610 }
611 else {
612 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
613 }
614 break;
615 case GL_SOURCE2_RGB_EXT:
616 if (ctx->Extensions.EXT_texture_env_combine ||
617 ctx->Extensions.ARB_texture_env_combine) {
618 *params = (GLfloat) texUnit->CombineSourceRGB[2];
619 }
620 else {
621 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
622 }
623 break;
624 case GL_SOURCE0_ALPHA_EXT:
625 if (ctx->Extensions.EXT_texture_env_combine ||
626 ctx->Extensions.ARB_texture_env_combine) {
627 *params = (GLfloat) texUnit->CombineSourceA[0];
628 }
629 else {
630 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
631 }
632 break;
633 case GL_SOURCE1_ALPHA_EXT:
634 if (ctx->Extensions.EXT_texture_env_combine ||
635 ctx->Extensions.ARB_texture_env_combine) {
636 *params = (GLfloat) texUnit->CombineSourceA[1];
637 }
638 else {
639 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
640 }
641 break;
642 case GL_SOURCE2_ALPHA_EXT:
643 if (ctx->Extensions.EXT_texture_env_combine ||
644 ctx->Extensions.ARB_texture_env_combine) {
645 *params = (GLfloat) texUnit->CombineSourceA[2];
646 }
647 else {
648 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
649 }
650 break;
651 case GL_OPERAND0_RGB_EXT:
652 if (ctx->Extensions.EXT_texture_env_combine ||
653 ctx->Extensions.ARB_texture_env_combine) {
654 *params = (GLfloat) texUnit->CombineOperandRGB[0];
655 }
656 else {
657 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
658 }
659 break;
660 case GL_OPERAND1_RGB_EXT:
661 if (ctx->Extensions.EXT_texture_env_combine ||
662 ctx->Extensions.ARB_texture_env_combine) {
663 *params = (GLfloat) texUnit->CombineOperandRGB[1];
664 }
665 else {
666 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
667 }
668 break;
669 case GL_OPERAND2_RGB_EXT:
670 if (ctx->Extensions.EXT_texture_env_combine ||
671 ctx->Extensions.ARB_texture_env_combine) {
672 *params = (GLfloat) texUnit->CombineOperandRGB[2];
673 }
674 else {
675 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
676 }
677 break;
678 case GL_OPERAND0_ALPHA_EXT:
679 if (ctx->Extensions.EXT_texture_env_combine ||
680 ctx->Extensions.ARB_texture_env_combine) {
681 *params = (GLfloat) texUnit->CombineOperandA[0];
682 }
683 else {
684 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
685 }
686 break;
687 case GL_OPERAND1_ALPHA_EXT:
688 if (ctx->Extensions.EXT_texture_env_combine ||
689 ctx->Extensions.ARB_texture_env_combine) {
690 *params = (GLfloat) texUnit->CombineOperandA[1];
691 }
692 else {
693 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
694 }
695 break;
696 case GL_OPERAND2_ALPHA_EXT:
697 if (ctx->Extensions.EXT_texture_env_combine ||
698 ctx->Extensions.ARB_texture_env_combine) {
699 *params = (GLfloat) texUnit->CombineOperandA[2];
700 }
701 else {
702 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
703 }
704 break;
705 case GL_RGB_SCALE_EXT:
706 if (ctx->Extensions.EXT_texture_env_combine ||
707 ctx->Extensions.ARB_texture_env_combine) {
708 if (texUnit->CombineScaleShiftRGB == 0)
709 *params = 1.0;
710 else if (texUnit->CombineScaleShiftRGB == 1)
711 *params = 2.0;
712 else
713 *params = 4.0;
714 }
715 else {
716 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
717 return;
718 }
719 break;
720 case GL_ALPHA_SCALE:
721 if (ctx->Extensions.EXT_texture_env_combine ||
722 ctx->Extensions.ARB_texture_env_combine) {
723 if (texUnit->CombineScaleShiftA == 0)
724 *params = 1.0;
725 else if (texUnit->CombineScaleShiftA == 1)
726 *params = 2.0;
727 else
728 *params = 4.0;
729 }
730 else {
731 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
732 return;
733 }
734 break;
735 default:
736 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
737 }
738 }
739 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
740 /* GL_EXT_texture_lod_bias */
741 if (!ctx->Extensions.EXT_texture_lod_bias) {
742 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
743 return;
744 }
745 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
746 *params = texUnit->LodBias;
747 }
748 else {
749 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
750 return;
751 }
752 }
753 else if (target == GL_POINT_SPRITE_NV) {
754 /* GL_NV_point_sprite */
755 if (!ctx->Extensions.NV_point_sprite) {
756 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
757 return;
758 }
759 if (pname == GL_COORD_REPLACE_NV) {
760 *params = (GLfloat) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit];
761 }
762 else {
763 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
764 return;
765 }
766 }
767 else {
768 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
769 return;
770 }
771 }
772
773
774 void
775 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
776 {
777 GET_CURRENT_CONTEXT(ctx);
778 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
779 ASSERT_OUTSIDE_BEGIN_END(ctx);
780
781 if (target == GL_TEXTURE_ENV) {
782 switch (pname) {
783 case GL_TEXTURE_ENV_MODE:
784 *params = (GLint) texUnit->EnvMode;
785 break;
786 case GL_TEXTURE_ENV_COLOR:
787 params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
788 params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
789 params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
790 params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
791 break;
792 case GL_COMBINE_RGB_EXT:
793 if (ctx->Extensions.EXT_texture_env_combine ||
794 ctx->Extensions.ARB_texture_env_combine) {
795 *params = (GLint) texUnit->CombineModeRGB;
796 }
797 else {
798 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
799 }
800 break;
801 case GL_COMBINE_ALPHA_EXT:
802 if (ctx->Extensions.EXT_texture_env_combine ||
803 ctx->Extensions.ARB_texture_env_combine) {
804 *params = (GLint) texUnit->CombineModeA;
805 }
806 else {
807 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
808 }
809 break;
810 case GL_SOURCE0_RGB_EXT:
811 if (ctx->Extensions.EXT_texture_env_combine ||
812 ctx->Extensions.ARB_texture_env_combine) {
813 *params = (GLint) texUnit->CombineSourceRGB[0];
814 }
815 else {
816 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
817 }
818 break;
819 case GL_SOURCE1_RGB_EXT:
820 if (ctx->Extensions.EXT_texture_env_combine ||
821 ctx->Extensions.ARB_texture_env_combine) {
822 *params = (GLint) texUnit->CombineSourceRGB[1];
823 }
824 else {
825 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
826 }
827 break;
828 case GL_SOURCE2_RGB_EXT:
829 if (ctx->Extensions.EXT_texture_env_combine ||
830 ctx->Extensions.ARB_texture_env_combine) {
831 *params = (GLint) texUnit->CombineSourceRGB[2];
832 }
833 else {
834 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
835 }
836 break;
837 case GL_SOURCE0_ALPHA_EXT:
838 if (ctx->Extensions.EXT_texture_env_combine ||
839 ctx->Extensions.ARB_texture_env_combine) {
840 *params = (GLint) texUnit->CombineSourceA[0];
841 }
842 else {
843 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
844 }
845 break;
846 case GL_SOURCE1_ALPHA_EXT:
847 if (ctx->Extensions.EXT_texture_env_combine ||
848 ctx->Extensions.ARB_texture_env_combine) {
849 *params = (GLint) texUnit->CombineSourceA[1];
850 }
851 else {
852 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
853 }
854 break;
855 case GL_SOURCE2_ALPHA_EXT:
856 if (ctx->Extensions.EXT_texture_env_combine ||
857 ctx->Extensions.ARB_texture_env_combine) {
858 *params = (GLint) texUnit->CombineSourceA[2];
859 }
860 else {
861 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
862 }
863 break;
864 case GL_OPERAND0_RGB_EXT:
865 if (ctx->Extensions.EXT_texture_env_combine ||
866 ctx->Extensions.ARB_texture_env_combine) {
867 *params = (GLint) texUnit->CombineOperandRGB[0];
868 }
869 else {
870 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
871 }
872 break;
873 case GL_OPERAND1_RGB_EXT:
874 if (ctx->Extensions.EXT_texture_env_combine ||
875 ctx->Extensions.ARB_texture_env_combine) {
876 *params = (GLint) texUnit->CombineOperandRGB[1];
877 }
878 else {
879 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
880 }
881 break;
882 case GL_OPERAND2_RGB_EXT:
883 if (ctx->Extensions.EXT_texture_env_combine ||
884 ctx->Extensions.ARB_texture_env_combine) {
885 *params = (GLint) texUnit->CombineOperandRGB[2];
886 }
887 else {
888 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
889 }
890 break;
891 case GL_OPERAND0_ALPHA_EXT:
892 if (ctx->Extensions.EXT_texture_env_combine ||
893 ctx->Extensions.ARB_texture_env_combine) {
894 *params = (GLint) texUnit->CombineOperandA[0];
895 }
896 else {
897 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
898 }
899 break;
900 case GL_OPERAND1_ALPHA_EXT:
901 if (ctx->Extensions.EXT_texture_env_combine ||
902 ctx->Extensions.ARB_texture_env_combine) {
903 *params = (GLint) texUnit->CombineOperandA[1];
904 }
905 else {
906 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
907 }
908 break;
909 case GL_OPERAND2_ALPHA_EXT:
910 if (ctx->Extensions.EXT_texture_env_combine ||
911 ctx->Extensions.ARB_texture_env_combine) {
912 *params = (GLint) texUnit->CombineOperandA[2];
913 }
914 else {
915 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
916 }
917 break;
918 case GL_RGB_SCALE_EXT:
919 if (ctx->Extensions.EXT_texture_env_combine ||
920 ctx->Extensions.ARB_texture_env_combine) {
921 if (texUnit->CombineScaleShiftRGB == 0)
922 *params = 1;
923 else if (texUnit->CombineScaleShiftRGB == 1)
924 *params = 2;
925 else
926 *params = 4;
927 }
928 else {
929 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
930 return;
931 }
932 break;
933 case GL_ALPHA_SCALE:
934 if (ctx->Extensions.EXT_texture_env_combine ||
935 ctx->Extensions.ARB_texture_env_combine) {
936 if (texUnit->CombineScaleShiftA == 0)
937 *params = 1;
938 else if (texUnit->CombineScaleShiftA == 1)
939 *params = 2;
940 else
941 *params = 4;
942 }
943 else {
944 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
945 return;
946 }
947 break;
948 default:
949 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
950 }
951 }
952 else if (target == GL_TEXTURE_FILTER_CONTROL_EXT) {
953 /* GL_EXT_texture_lod_bias */
954 if (!ctx->Extensions.EXT_texture_lod_bias) {
955 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
956 return;
957 }
958 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
959 *params = (GLint) texUnit->LodBias;
960 }
961 else {
962 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
963 return;
964 }
965 }
966 else if (target == GL_POINT_SPRITE_NV) {
967 /* GL_NV_point_sprite */
968 if (!ctx->Extensions.NV_point_sprite) {
969 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
970 return;
971 }
972 if (pname == GL_COORD_REPLACE_NV) {
973 *params = (GLint) ctx->Point.CoordReplace[ctx->Texture.CurrentUnit];
974 }
975 else {
976 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
977 return;
978 }
979 }
980 else {
981 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
982 return;
983 }
984 }
985
986
987
988
989 /**********************************************************************/
990 /* Texture Parameters */
991 /**********************************************************************/
992
993
994 void
995 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
996 {
997 _mesa_TexParameterfv(target, pname, &param);
998 }
999
1000
1001 void
1002 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
1003 {
1004 GET_CURRENT_CONTEXT(ctx);
1005 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1006 GLenum eparam = (GLenum) (GLint) params[0];
1007 struct gl_texture_object *texObj;
1008 ASSERT_OUTSIDE_BEGIN_END(ctx);
1009
1010 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
1011 _mesa_debug(ctx, "texPARAM %s %s %d...\n",
1012 _mesa_lookup_enum_by_nr(target),
1013 _mesa_lookup_enum_by_nr(pname),
1014 eparam);
1015
1016
1017 switch (target) {
1018 case GL_TEXTURE_1D:
1019 texObj = texUnit->Current1D;
1020 break;
1021 case GL_TEXTURE_2D:
1022 texObj = texUnit->Current2D;
1023 break;
1024 case GL_TEXTURE_3D_EXT:
1025 texObj = texUnit->Current3D;
1026 break;
1027 case GL_TEXTURE_CUBE_MAP_ARB:
1028 if (!ctx->Extensions.ARB_texture_cube_map) {
1029 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1030 return;
1031 }
1032 texObj = texUnit->CurrentCubeMap;
1033 break;
1034 case GL_TEXTURE_RECTANGLE_NV:
1035 if (!ctx->Extensions.NV_texture_rectangle) {
1036 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1037 return;
1038 }
1039 texObj = texUnit->CurrentRect;
1040 break;
1041 default:
1042 _mesa_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
1043 return;
1044 }
1045
1046 switch (pname) {
1047 case GL_TEXTURE_MIN_FILTER:
1048 /* A small optimization */
1049 if (texObj->MinFilter == eparam)
1050 return;
1051
1052 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
1053 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1054 texObj->MinFilter = eparam;
1055 }
1056 else if ((eparam==GL_NEAREST_MIPMAP_NEAREST ||
1057 eparam==GL_LINEAR_MIPMAP_NEAREST ||
1058 eparam==GL_NEAREST_MIPMAP_LINEAR ||
1059 eparam==GL_LINEAR_MIPMAP_LINEAR) &&
1060 texObj->Target != GL_TEXTURE_RECTANGLE_NV) {
1061 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1062 texObj->MinFilter = eparam;
1063 }
1064 else {
1065 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1066 return;
1067 }
1068 break;
1069 case GL_TEXTURE_MAG_FILTER:
1070 /* A small optimization */
1071 if (texObj->MagFilter == eparam)
1072 return;
1073
1074 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
1075 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1076 texObj->MagFilter = eparam;
1077 }
1078 else {
1079 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1080 return;
1081 }
1082 break;
1083 case GL_TEXTURE_WRAP_S:
1084 if (texObj->WrapS == eparam)
1085 return;
1086 if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
1087 (eparam == GL_CLAMP_TO_BORDER_ARB &&
1088 ctx->Extensions.ARB_texture_border_clamp)) {
1089 /* any texture target */
1090 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1091 texObj->WrapS = eparam;
1092 }
1093 else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
1094 (eparam == GL_REPEAT ||
1095 (eparam == GL_MIRRORED_REPEAT_ARB &&
1096 ctx->Extensions.ARB_texture_mirrored_repeat))) {
1097 /* non-rectangle texture */
1098 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1099 texObj->WrapS = eparam;
1100 }
1101 else {
1102 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1103 return;
1104 }
1105 break;
1106 case GL_TEXTURE_WRAP_T:
1107 if (texObj->WrapT == eparam)
1108 return;
1109 if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
1110 (eparam == GL_CLAMP_TO_BORDER_ARB &&
1111 ctx->Extensions.ARB_texture_border_clamp)) {
1112 /* any texture target */
1113 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1114 texObj->WrapT = eparam;
1115 }
1116 else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
1117 (eparam == GL_REPEAT ||
1118 (eparam == GL_MIRRORED_REPEAT_ARB &&
1119 ctx->Extensions.ARB_texture_mirrored_repeat))) {
1120 /* non-rectangle texture */
1121 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1122 texObj->WrapT = eparam;
1123 }
1124 else {
1125 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1126 return;
1127 }
1128 break;
1129 case GL_TEXTURE_WRAP_R_EXT:
1130 if (texObj->WrapR == eparam)
1131 return;
1132 if (eparam == GL_CLAMP || eparam == GL_CLAMP_TO_EDGE ||
1133 (eparam == GL_CLAMP_TO_BORDER_ARB &&
1134 ctx->Extensions.ARB_texture_border_clamp)) {
1135 /* any texture target */
1136 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1137 texObj->WrapR = eparam;
1138 }
1139 else if (texObj->Target != GL_TEXTURE_RECTANGLE_NV &&
1140 (eparam == GL_REPEAT ||
1141 (eparam == GL_MIRRORED_REPEAT_ARB &&
1142 ctx->Extensions.ARB_texture_mirrored_repeat))) {
1143 /* non-rectangle texture */
1144 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1145 texObj->WrapR = eparam;
1146 }
1147 else {
1148 _mesa_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1149 }
1150 break;
1151 case GL_TEXTURE_BORDER_COLOR:
1152 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1153 texObj->BorderColor[RCOMP] = params[0];
1154 texObj->BorderColor[GCOMP] = params[1];
1155 texObj->BorderColor[BCOMP] = params[2];
1156 texObj->BorderColor[ACOMP] = params[3];
1157 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[RCOMP], params[0]);
1158 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[GCOMP], params[1]);
1159 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[BCOMP], params[2]);
1160 UNCLAMPED_FLOAT_TO_CHAN(texObj->_BorderChan[ACOMP], params[3]);
1161 break;
1162 case GL_TEXTURE_MIN_LOD:
1163 if (texObj->MinLod == params[0])
1164 return;
1165 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1166 texObj->MinLod = params[0];
1167 break;
1168 case GL_TEXTURE_MAX_LOD:
1169 if (texObj->MaxLod == params[0])
1170 return;
1171 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1172 texObj->MaxLod = params[0];
1173 break;
1174 case GL_TEXTURE_BASE_LEVEL:
1175 if (params[0] < 0.0) {
1176 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1177 return;
1178 }
1179 if (target == GL_TEXTURE_RECTANGLE_NV && params[0] != 0.0) {
1180 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1181 return;
1182 }
1183 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1184 texObj->BaseLevel = (GLint) params[0];
1185 break;
1186 case GL_TEXTURE_MAX_LEVEL:
1187 if (params[0] < 0.0) {
1188 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1189 return;
1190 }
1191 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1192 texObj->MaxLevel = (GLint) params[0];
1193 break;
1194 case GL_TEXTURE_PRIORITY:
1195 /* (keithh@netcomuk.co.uk) */
1196 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1197 texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
1198 break;
1199 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1200 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1201 if (params[0] < 1.0) {
1202 _mesa_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
1203 return;
1204 }
1205 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1206 texObj->MaxAnisotropy = params[0];
1207 }
1208 else {
1209 _mesa_error(ctx, GL_INVALID_ENUM,
1210 "glTexParameter(pname=GL_MAX_TEXTURE_ANISOTROPY_EXT)");
1211 return;
1212 }
1213 break;
1214 case GL_TEXTURE_COMPARE_SGIX:
1215 if (ctx->Extensions.SGIX_shadow) {
1216 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1217 texObj->CompareFlag = params[0] ? GL_TRUE : GL_FALSE;
1218 }
1219 else {
1220 _mesa_error(ctx, GL_INVALID_ENUM,
1221 "glTexParameter(pname=GL_TEXTURE_COMPARE_SGIX)");
1222 return;
1223 }
1224 break;
1225 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
1226 if (ctx->Extensions.SGIX_shadow) {
1227 GLenum op = (GLenum) params[0];
1228 if (op == GL_TEXTURE_LEQUAL_R_SGIX ||
1229 op == GL_TEXTURE_GEQUAL_R_SGIX) {
1230 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1231 texObj->CompareOperator = op;
1232 }
1233 else {
1234 _mesa_error(ctx, GL_INVALID_ENUM, "glTexParameter(param)");
1235 }
1236 }
1237 else {
1238 _mesa_error(ctx, GL_INVALID_ENUM,
1239 "glTexParameter(pname=GL_TEXTURE_COMPARE_OPERATOR_SGIX)");
1240 return;
1241 }
1242 break;
1243 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1244 if (ctx->Extensions.SGIX_shadow_ambient) {
1245 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1246 texObj->ShadowAmbient = CLAMP(params[0], 0.0F, 1.0F);
1247 }
1248 else {
1249 _mesa_error(ctx, GL_INVALID_ENUM,
1250 "glTexParameter(pname=GL_SHADOW_AMBIENT_SGIX)");
1251 return;
1252 }
1253 break;
1254 case GL_GENERATE_MIPMAP_SGIS:
1255 if (ctx->Extensions.SGIS_generate_mipmap) {
1256 texObj->GenerateMipmap = params[0] ? GL_TRUE : GL_FALSE;
1257 }
1258 else {
1259 _mesa_error(ctx, GL_INVALID_ENUM,
1260 "glTexParameter(pname=GL_GENERATE_MIPMAP_SGIS)");
1261 return;
1262 }
1263 break;
1264 case GL_TEXTURE_COMPARE_MODE_ARB:
1265 if (ctx->Extensions.ARB_shadow) {
1266 const GLenum mode = (GLenum) params[0];
1267 if (mode == GL_NONE || mode == GL_COMPARE_R_TO_TEXTURE_ARB) {
1268 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1269 texObj->CompareMode = mode;
1270 }
1271 else {
1272 _mesa_error(ctx, GL_INVALID_ENUM,
1273 "glTexParameter(bad GL_TEXTURE_COMPARE_MODE_ARB)");
1274 return;
1275 }
1276 }
1277 else {
1278 _mesa_error(ctx, GL_INVALID_ENUM,
1279 "glTexParameter(pname=GL_TEXTURE_COMPARE_MODE_ARB)");
1280 return;
1281 }
1282 break;
1283 case GL_TEXTURE_COMPARE_FUNC_ARB:
1284 if (ctx->Extensions.ARB_shadow) {
1285 const GLenum func = (GLenum) params[0];
1286 if (func == GL_LEQUAL || func == GL_GEQUAL) {
1287 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1288 texObj->CompareFunc = func;
1289 }
1290 else if (ctx->Extensions.EXT_shadow_funcs &&
1291 (func == GL_EQUAL ||
1292 func == GL_NOTEQUAL ||
1293 func == GL_LESS ||
1294 func == GL_GREATER ||
1295 func == GL_ALWAYS ||
1296 func == GL_NEVER)) {
1297 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1298 texObj->CompareFunc = func;
1299 }
1300 else {
1301 _mesa_error(ctx, GL_INVALID_ENUM,
1302 "glTexParameter(bad GL_TEXTURE_COMPARE_FUNC_ARB)");
1303 return;
1304 }
1305 }
1306 else {
1307 _mesa_error(ctx, GL_INVALID_ENUM,
1308 "glTexParameter(pname=GL_TEXTURE_COMPARE_FUNC_ARB)");
1309 return;
1310 }
1311 break;
1312 case GL_DEPTH_TEXTURE_MODE_ARB:
1313 if (ctx->Extensions.ARB_depth_texture) {
1314 const GLenum result = (GLenum) params[0];
1315 if (result == GL_LUMINANCE || result == GL_INTENSITY
1316 || result == GL_ALPHA) {
1317 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1318 texObj->DepthMode = result;
1319 }
1320 else {
1321 _mesa_error(ctx, GL_INVALID_ENUM,
1322 "glTexParameter(bad GL_DEPTH_TEXTURE_MODE_ARB)");
1323 return;
1324 }
1325 }
1326 else {
1327 _mesa_error(ctx, GL_INVALID_ENUM,
1328 "glTexParameter(pname=GL_DEPTH_TEXTURE_MODE_ARB)");
1329 return;
1330 }
1331 break;
1332
1333 default:
1334 _mesa_error(ctx, GL_INVALID_ENUM,
1335 "glTexParameter(pname=0x%x)", pname);
1336 return;
1337 }
1338
1339 texObj->Complete = GL_FALSE;
1340
1341 if (ctx->Driver.TexParameter) {
1342 (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
1343 }
1344 }
1345
1346
1347 void
1348 _mesa_TexParameteri( GLenum target, GLenum pname, GLint param )
1349 {
1350 GLfloat fparam[4];
1351 fparam[0] = (GLfloat) param;
1352 fparam[1] = fparam[2] = fparam[3] = 0.0;
1353 _mesa_TexParameterfv(target, pname, fparam);
1354 }
1355
1356 void
1357 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
1358 {
1359 GLfloat fparam[4];
1360 fparam[0] = (GLfloat) params[0];
1361 fparam[1] = fparam[2] = fparam[3] = 0.0;
1362 _mesa_TexParameterfv(target, pname, fparam);
1363 }
1364
1365
1366 void
1367 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
1368 GLenum pname, GLfloat *params )
1369 {
1370 GLint iparam;
1371 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
1372 *params = (GLfloat) iparam;
1373 }
1374
1375
1376 static GLuint
1377 tex_image_dimensions(GLcontext *ctx, GLenum target)
1378 {
1379 switch (target) {
1380 case GL_TEXTURE_1D:
1381 case GL_PROXY_TEXTURE_1D:
1382 return 1;
1383 case GL_TEXTURE_2D:
1384 case GL_PROXY_TEXTURE_2D:
1385 return 2;
1386 case GL_TEXTURE_3D:
1387 case GL_PROXY_TEXTURE_3D:
1388 return 3;
1389 case GL_TEXTURE_CUBE_MAP_ARB:
1390 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1391 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
1392 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
1393 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
1394 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
1395 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
1396 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
1397 return ctx->Extensions.ARB_texture_cube_map ? 2 : 0;
1398 case GL_TEXTURE_RECTANGLE_NV:
1399 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1400 return ctx->Extensions.NV_texture_rectangle ? 2 : 0;
1401 default:
1402 _mesa_problem(ctx, "bad target in _mesa_tex_target_dimensions()");
1403 return 0;
1404 }
1405 }
1406
1407
1408 void
1409 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
1410 GLenum pname, GLint *params )
1411 {
1412 GET_CURRENT_CONTEXT(ctx);
1413 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1414 const struct gl_texture_image *img = NULL;
1415 GLuint dimensions;
1416 GLboolean isProxy;
1417 GLint maxLevels;
1418 ASSERT_OUTSIDE_BEGIN_END(ctx);
1419
1420 /* this will catch bad target values */
1421 dimensions = tex_image_dimensions(ctx, target); /* 1, 2 or 3 */
1422 if (dimensions == 0) {
1423 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
1424 return;
1425 }
1426
1427 switch (target) {
1428 case GL_TEXTURE_1D:
1429 case GL_PROXY_TEXTURE_1D:
1430 case GL_TEXTURE_2D:
1431 case GL_PROXY_TEXTURE_2D:
1432 maxLevels = ctx->Const.MaxTextureLevels;
1433 break;
1434 case GL_TEXTURE_3D:
1435 case GL_PROXY_TEXTURE_3D:
1436 maxLevels = ctx->Const.Max3DTextureLevels;
1437 break;
1438 case GL_TEXTURE_CUBE_MAP_POSITIVE_X_ARB:
1439 case GL_TEXTURE_CUBE_MAP_NEGATIVE_X_ARB:
1440 case GL_TEXTURE_CUBE_MAP_POSITIVE_Y_ARB:
1441 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Y_ARB:
1442 case GL_TEXTURE_CUBE_MAP_POSITIVE_Z_ARB:
1443 case GL_TEXTURE_CUBE_MAP_NEGATIVE_Z_ARB:
1444 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
1445 maxLevels = ctx->Const.MaxCubeTextureLevels;
1446 break;
1447 case GL_TEXTURE_RECTANGLE_NV:
1448 case GL_PROXY_TEXTURE_RECTANGLE_NV:
1449 maxLevels = 1;
1450 break;
1451 default:
1452 _mesa_problem(ctx, "switch in _mesa_GetTexLevelParameter");
1453 return;
1454 }
1455
1456 if (level < 0 || level >= maxLevels) {
1457 _mesa_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
1458 return;
1459 }
1460
1461 img = _mesa_select_tex_image(ctx, texUnit, target, level);
1462 if (!img || !img->TexFormat) {
1463 /* undefined texture image */
1464 if (pname == GL_TEXTURE_COMPONENTS)
1465 *params = 1;
1466 else
1467 *params = 0;
1468 return;
1469 }
1470
1471 isProxy = (target == GL_PROXY_TEXTURE_1D) ||
1472 (target == GL_PROXY_TEXTURE_2D) ||
1473 (target == GL_PROXY_TEXTURE_3D) ||
1474 (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB) ||
1475 (target == GL_PROXY_TEXTURE_RECTANGLE_NV);
1476
1477 switch (pname) {
1478 case GL_TEXTURE_WIDTH:
1479 *params = img->Width;
1480 return;
1481 case GL_TEXTURE_HEIGHT:
1482 *params = img->Height;
1483 return;
1484 case GL_TEXTURE_DEPTH:
1485 *params = img->Depth;
1486 return;
1487 case GL_TEXTURE_INTERNAL_FORMAT:
1488 *params = img->IntFormat;
1489 return;
1490 case GL_TEXTURE_BORDER:
1491 *params = img->Border;
1492 return;
1493 case GL_TEXTURE_RED_SIZE:
1494 if (img->Format == GL_RGB || img->Format == GL_RGBA)
1495 *params = img->TexFormat->RedBits;
1496 else
1497 *params = 0;
1498 return;
1499 case GL_TEXTURE_GREEN_SIZE:
1500 if (img->Format == GL_RGB || img->Format == GL_RGBA)
1501 *params = img->TexFormat->GreenBits;
1502 else
1503 *params = 0;
1504 return;
1505 case GL_TEXTURE_BLUE_SIZE:
1506 if (img->Format == GL_RGB || img->Format == GL_RGBA)
1507 *params = img->TexFormat->BlueBits;
1508 else
1509 *params = 0;
1510 return;
1511 case GL_TEXTURE_ALPHA_SIZE:
1512 if (img->Format == GL_ALPHA || img->Format == GL_LUMINANCE_ALPHA ||
1513 img->Format == GL_RGBA)
1514 *params = img->TexFormat->AlphaBits;
1515 else
1516 *params = 0;
1517 return;
1518 case GL_TEXTURE_INTENSITY_SIZE:
1519 if (img->Format != GL_INTENSITY)
1520 *params = 0;
1521 else if (img->TexFormat->IntensityBits > 0)
1522 *params = img->TexFormat->IntensityBits;
1523 else /* intensity probably stored as rgb texture */
1524 *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
1525 return;
1526 case GL_TEXTURE_LUMINANCE_SIZE:
1527 if (img->Format != GL_LUMINANCE &&
1528 img->Format != GL_LUMINANCE_ALPHA)
1529 *params = 0;
1530 else if (img->TexFormat->LuminanceBits > 0)
1531 *params = img->TexFormat->LuminanceBits;
1532 else /* luminance probably stored as rgb texture */
1533 *params = MIN2(img->TexFormat->RedBits, img->TexFormat->GreenBits);
1534 return;
1535 case GL_TEXTURE_INDEX_SIZE_EXT:
1536 if (img->Format == GL_COLOR_INDEX)
1537 *params = img->TexFormat->IndexBits;
1538 else
1539 *params = 0;
1540 return;
1541 case GL_DEPTH_BITS:
1542 /* XXX this isn't in the GL_SGIX_depth_texture spec
1543 * but seems appropriate.
1544 */
1545 if (ctx->Extensions.SGIX_depth_texture)
1546 *params = img->TexFormat->DepthBits;
1547 else
1548 _mesa_error(ctx, GL_INVALID_ENUM,
1549 "glGetTexLevelParameter[if]v(pname)");
1550 return;
1551
1552 /* GL_ARB_texture_compression */
1553 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
1554 if (ctx->Extensions.ARB_texture_compression) {
1555 if (img->IsCompressed && !isProxy)
1556 *params = img->CompressedSize;
1557 else
1558 _mesa_error(ctx, GL_INVALID_OPERATION,
1559 "glGetTexLevelParameter[if]v(pname)");
1560 }
1561 else {
1562 _mesa_error(ctx, GL_INVALID_ENUM,
1563 "glGetTexLevelParameter[if]v(pname)");
1564 }
1565 return;
1566 case GL_TEXTURE_COMPRESSED_ARB:
1567 if (ctx->Extensions.ARB_texture_compression) {
1568 *params = (GLint) img->IsCompressed;
1569 }
1570 else {
1571 _mesa_error(ctx, GL_INVALID_ENUM,
1572 "glGetTexLevelParameter[if]v(pname)");
1573 }
1574 return;
1575
1576 default:
1577 _mesa_error(ctx, GL_INVALID_ENUM,
1578 "glGetTexLevelParameter[if]v(pname)");
1579 }
1580 }
1581
1582
1583
1584 void
1585 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
1586 {
1587 GET_CURRENT_CONTEXT(ctx);
1588 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1589 struct gl_texture_object *obj;
1590 ASSERT_OUTSIDE_BEGIN_END(ctx);
1591
1592 obj = _mesa_select_tex_object(ctx, texUnit, target);
1593 if (!obj) {
1594 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
1595 return;
1596 }
1597
1598 switch (pname) {
1599 case GL_TEXTURE_MAG_FILTER:
1600 *params = ENUM_TO_FLOAT(obj->MagFilter);
1601 return;
1602 case GL_TEXTURE_MIN_FILTER:
1603 *params = ENUM_TO_FLOAT(obj->MinFilter);
1604 return;
1605 case GL_TEXTURE_WRAP_S:
1606 *params = ENUM_TO_FLOAT(obj->WrapS);
1607 return;
1608 case GL_TEXTURE_WRAP_T:
1609 *params = ENUM_TO_FLOAT(obj->WrapT);
1610 return;
1611 case GL_TEXTURE_WRAP_R_EXT:
1612 *params = ENUM_TO_FLOAT(obj->WrapR);
1613 return;
1614 case GL_TEXTURE_BORDER_COLOR:
1615 params[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
1616 params[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
1617 params[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
1618 params[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
1619 return;
1620 case GL_TEXTURE_RESIDENT:
1621 {
1622 GLboolean resident;
1623 if (ctx->Driver.IsTextureResident)
1624 resident = ctx->Driver.IsTextureResident(ctx, obj);
1625 else
1626 resident = GL_TRUE;
1627 *params = ENUM_TO_FLOAT(resident);
1628 }
1629 return;
1630 case GL_TEXTURE_PRIORITY:
1631 *params = obj->Priority;
1632 return;
1633 case GL_TEXTURE_MIN_LOD:
1634 *params = obj->MinLod;
1635 return;
1636 case GL_TEXTURE_MAX_LOD:
1637 *params = obj->MaxLod;
1638 return;
1639 case GL_TEXTURE_BASE_LEVEL:
1640 *params = (GLfloat) obj->BaseLevel;
1641 return;
1642 case GL_TEXTURE_MAX_LEVEL:
1643 *params = (GLfloat) obj->MaxLevel;
1644 return;
1645 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1646 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1647 *params = obj->MaxAnisotropy;
1648 return;
1649 }
1650 break;
1651 case GL_TEXTURE_COMPARE_SGIX:
1652 if (ctx->Extensions.SGIX_shadow) {
1653 *params = (GLfloat) obj->CompareFlag;
1654 return;
1655 }
1656 break;
1657 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
1658 if (ctx->Extensions.SGIX_shadow) {
1659 *params = (GLfloat) obj->CompareOperator;
1660 return;
1661 }
1662 break;
1663 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1664 if (ctx->Extensions.SGIX_shadow_ambient) {
1665 *params = obj->ShadowAmbient;
1666 return;
1667 }
1668 break;
1669 case GL_GENERATE_MIPMAP_SGIS:
1670 if (ctx->Extensions.SGIS_generate_mipmap) {
1671 *params = (GLfloat) obj->GenerateMipmap;
1672 return;
1673 }
1674 break;
1675 case GL_TEXTURE_COMPARE_MODE_ARB:
1676 if (ctx->Extensions.ARB_shadow) {
1677 *params = (GLfloat) obj->CompareMode;
1678 return;
1679 }
1680 break;
1681 case GL_TEXTURE_COMPARE_FUNC_ARB:
1682 if (ctx->Extensions.ARB_shadow) {
1683 *params = (GLfloat) obj->CompareFunc;
1684 return;
1685 }
1686 break;
1687 case GL_DEPTH_TEXTURE_MODE_ARB:
1688 if (ctx->Extensions.ARB_depth_texture) {
1689 *params = (GLfloat) obj->DepthMode;
1690 return;
1691 }
1692 break;
1693 default:
1694 ; /* silence warnings */
1695 }
1696 /* If we get here, pname was an unrecognized enum */
1697 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
1698 }
1699
1700
1701 void
1702 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
1703 {
1704 GET_CURRENT_CONTEXT(ctx);
1705 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1706 struct gl_texture_object *obj;
1707 ASSERT_OUTSIDE_BEGIN_END(ctx);
1708
1709 obj = _mesa_select_tex_object(ctx, texUnit, target);
1710 if (!obj) {
1711 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
1712 return;
1713 }
1714
1715 switch (pname) {
1716 case GL_TEXTURE_MAG_FILTER:
1717 *params = (GLint) obj->MagFilter;
1718 return;
1719 case GL_TEXTURE_MIN_FILTER:
1720 *params = (GLint) obj->MinFilter;
1721 return;
1722 case GL_TEXTURE_WRAP_S:
1723 *params = (GLint) obj->WrapS;
1724 return;
1725 case GL_TEXTURE_WRAP_T:
1726 *params = (GLint) obj->WrapT;
1727 return;
1728 case GL_TEXTURE_WRAP_R_EXT:
1729 *params = (GLint) obj->WrapR;
1730 return;
1731 case GL_TEXTURE_BORDER_COLOR:
1732 {
1733 GLfloat b[4];
1734 b[0] = CLAMP(obj->BorderColor[0], 0.0F, 1.0F);
1735 b[1] = CLAMP(obj->BorderColor[1], 0.0F, 1.0F);
1736 b[2] = CLAMP(obj->BorderColor[2], 0.0F, 1.0F);
1737 b[3] = CLAMP(obj->BorderColor[3], 0.0F, 1.0F);
1738 params[0] = FLOAT_TO_INT(b[0]);
1739 params[1] = FLOAT_TO_INT(b[1]);
1740 params[2] = FLOAT_TO_INT(b[2]);
1741 params[3] = FLOAT_TO_INT(b[3]);
1742 }
1743 return;
1744 case GL_TEXTURE_RESIDENT:
1745 {
1746 GLboolean resident;
1747 if (ctx->Driver.IsTextureResident)
1748 resident = ctx->Driver.IsTextureResident(ctx, obj);
1749 else
1750 resident = GL_TRUE;
1751 *params = (GLint) resident;
1752 }
1753 return;
1754 case GL_TEXTURE_PRIORITY:
1755 *params = (GLint) obj->Priority;
1756 return;
1757 case GL_TEXTURE_MIN_LOD:
1758 *params = (GLint) obj->MinLod;
1759 return;
1760 case GL_TEXTURE_MAX_LOD:
1761 *params = (GLint) obj->MaxLod;
1762 return;
1763 case GL_TEXTURE_BASE_LEVEL:
1764 *params = obj->BaseLevel;
1765 return;
1766 case GL_TEXTURE_MAX_LEVEL:
1767 *params = obj->MaxLevel;
1768 return;
1769 case GL_TEXTURE_MAX_ANISOTROPY_EXT:
1770 if (ctx->Extensions.EXT_texture_filter_anisotropic) {
1771 *params = (GLint) obj->MaxAnisotropy;
1772 return;
1773 }
1774 break;
1775 case GL_TEXTURE_COMPARE_SGIX:
1776 if (ctx->Extensions.SGIX_shadow) {
1777 *params = (GLint) obj->CompareFlag;
1778 return;
1779 }
1780 break;
1781 case GL_TEXTURE_COMPARE_OPERATOR_SGIX:
1782 if (ctx->Extensions.SGIX_shadow) {
1783 *params = (GLint) obj->CompareOperator;
1784 return;
1785 }
1786 break;
1787 case GL_SHADOW_AMBIENT_SGIX: /* aka GL_TEXTURE_COMPARE_FAIL_VALUE_ARB */
1788 if (ctx->Extensions.SGIX_shadow_ambient) {
1789 *params = (GLint) FLOAT_TO_INT(obj->ShadowAmbient);
1790 return;
1791 }
1792 break;
1793 case GL_GENERATE_MIPMAP_SGIS:
1794 if (ctx->Extensions.SGIS_generate_mipmap) {
1795 *params = (GLint) obj->GenerateMipmap;
1796 return;
1797 }
1798 break;
1799 case GL_TEXTURE_COMPARE_MODE_ARB:
1800 if (ctx->Extensions.ARB_shadow) {
1801 *params = (GLint) obj->CompareMode;
1802 return;
1803 }
1804 break;
1805 case GL_TEXTURE_COMPARE_FUNC_ARB:
1806 if (ctx->Extensions.ARB_shadow) {
1807 *params = (GLint) obj->CompareFunc;
1808 return;
1809 }
1810 break;
1811 case GL_DEPTH_TEXTURE_MODE_ARB:
1812 if (ctx->Extensions.ARB_depth_texture) {
1813 *params = (GLint) obj->DepthMode;
1814 return;
1815 }
1816 break;
1817 default:
1818 ; /* silence warnings */
1819 }
1820 /* If we get here, pname was an unrecognized enum */
1821 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
1822 }
1823
1824
1825
1826
1827 /**********************************************************************/
1828 /* Texture Coord Generation */
1829 /**********************************************************************/
1830
1831
1832 void
1833 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1834 {
1835 GET_CURRENT_CONTEXT(ctx);
1836 GLuint tUnit = ctx->Texture.CurrentUnit;
1837 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1838 ASSERT_OUTSIDE_BEGIN_END(ctx);
1839
1840 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
1841 _mesa_debug(ctx, "texGEN %s %s %x...\n",
1842 _mesa_lookup_enum_by_nr(coord),
1843 _mesa_lookup_enum_by_nr(pname),
1844 *(int *)params);
1845
1846 switch (coord) {
1847 case GL_S:
1848 if (pname==GL_TEXTURE_GEN_MODE) {
1849 GLenum mode = (GLenum) (GLint) *params;
1850 GLuint bits;
1851 switch (mode) {
1852 case GL_OBJECT_LINEAR:
1853 bits = TEXGEN_OBJ_LINEAR;
1854 break;
1855 case GL_EYE_LINEAR:
1856 bits = TEXGEN_EYE_LINEAR;
1857 break;
1858 case GL_REFLECTION_MAP_NV:
1859 bits = TEXGEN_REFLECTION_MAP_NV;
1860 break;
1861 case GL_NORMAL_MAP_NV:
1862 bits = TEXGEN_NORMAL_MAP_NV;
1863 break;
1864 case GL_SPHERE_MAP:
1865 bits = TEXGEN_SPHERE_MAP;
1866 break;
1867 default:
1868 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1869 return;
1870 }
1871 if (texUnit->GenModeS == mode)
1872 return;
1873 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1874 texUnit->GenModeS = mode;
1875 texUnit->_GenBitS = bits;
1876 }
1877 else if (pname==GL_OBJECT_PLANE) {
1878 if (TEST_EQ_4V(texUnit->ObjectPlaneS, params))
1879 return;
1880 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1881 texUnit->ObjectPlaneS[0] = params[0];
1882 texUnit->ObjectPlaneS[1] = params[1];
1883 texUnit->ObjectPlaneS[2] = params[2];
1884 texUnit->ObjectPlaneS[3] = params[3];
1885 }
1886 else if (pname==GL_EYE_PLANE) {
1887 GLfloat tmp[4];
1888
1889 /* Transform plane equation by the inverse modelview matrix */
1890 if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY_INVERSE) {
1891 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
1892 }
1893 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
1894 if (TEST_EQ_4V(texUnit->EyePlaneS, tmp))
1895 return;
1896 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1897 COPY_4FV(texUnit->EyePlaneS, tmp);
1898 }
1899 else {
1900 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1901 return;
1902 }
1903 break;
1904 case GL_T:
1905 if (pname==GL_TEXTURE_GEN_MODE) {
1906 GLenum mode = (GLenum) (GLint) *params;
1907 GLuint bitt;
1908 switch (mode) {
1909 case GL_OBJECT_LINEAR:
1910 bitt = TEXGEN_OBJ_LINEAR;
1911 break;
1912 case GL_EYE_LINEAR:
1913 bitt = TEXGEN_EYE_LINEAR;
1914 break;
1915 case GL_REFLECTION_MAP_NV:
1916 bitt = TEXGEN_REFLECTION_MAP_NV;
1917 break;
1918 case GL_NORMAL_MAP_NV:
1919 bitt = TEXGEN_NORMAL_MAP_NV;
1920 break;
1921 case GL_SPHERE_MAP:
1922 bitt = TEXGEN_SPHERE_MAP;
1923 break;
1924 default:
1925 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1926 return;
1927 }
1928 if (texUnit->GenModeT == mode)
1929 return;
1930 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1931 texUnit->GenModeT = mode;
1932 texUnit->_GenBitT = bitt;
1933 }
1934 else if (pname==GL_OBJECT_PLANE) {
1935 if (TEST_EQ_4V(texUnit->ObjectPlaneT, params))
1936 return;
1937 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1938 texUnit->ObjectPlaneT[0] = params[0];
1939 texUnit->ObjectPlaneT[1] = params[1];
1940 texUnit->ObjectPlaneT[2] = params[2];
1941 texUnit->ObjectPlaneT[3] = params[3];
1942 }
1943 else if (pname==GL_EYE_PLANE) {
1944 GLfloat tmp[4];
1945 /* Transform plane equation by the inverse modelview matrix */
1946 if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY_INVERSE) {
1947 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
1948 }
1949 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
1950 if (TEST_EQ_4V(texUnit->EyePlaneT, tmp))
1951 return;
1952 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1953 COPY_4FV(texUnit->EyePlaneT, tmp);
1954 }
1955 else {
1956 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1957 return;
1958 }
1959 break;
1960 case GL_R:
1961 if (pname==GL_TEXTURE_GEN_MODE) {
1962 GLenum mode = (GLenum) (GLint) *params;
1963 GLuint bitr;
1964 switch (mode) {
1965 case GL_OBJECT_LINEAR:
1966 bitr = TEXGEN_OBJ_LINEAR;
1967 break;
1968 case GL_REFLECTION_MAP_NV:
1969 bitr = TEXGEN_REFLECTION_MAP_NV;
1970 break;
1971 case GL_NORMAL_MAP_NV:
1972 bitr = TEXGEN_NORMAL_MAP_NV;
1973 break;
1974 case GL_EYE_LINEAR:
1975 bitr = TEXGEN_EYE_LINEAR;
1976 break;
1977 default:
1978 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1979 return;
1980 }
1981 if (texUnit->GenModeR == mode)
1982 return;
1983 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1984 texUnit->GenModeR = mode;
1985 texUnit->_GenBitR = bitr;
1986 }
1987 else if (pname==GL_OBJECT_PLANE) {
1988 if (TEST_EQ_4V(texUnit->ObjectPlaneR, params))
1989 return;
1990 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
1991 texUnit->ObjectPlaneR[0] = params[0];
1992 texUnit->ObjectPlaneR[1] = params[1];
1993 texUnit->ObjectPlaneR[2] = params[2];
1994 texUnit->ObjectPlaneR[3] = params[3];
1995 }
1996 else if (pname==GL_EYE_PLANE) {
1997 GLfloat tmp[4];
1998 /* Transform plane equation by the inverse modelview matrix */
1999 if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY_INVERSE) {
2000 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2001 }
2002 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2003 if (TEST_EQ_4V(texUnit->EyePlaneR, tmp))
2004 return;
2005 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2006 COPY_4FV(texUnit->EyePlaneR, tmp);
2007 }
2008 else {
2009 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2010 return;
2011 }
2012 break;
2013 case GL_Q:
2014 if (pname==GL_TEXTURE_GEN_MODE) {
2015 GLenum mode = (GLenum) (GLint) *params;
2016 GLuint bitq;
2017 switch (mode) {
2018 case GL_OBJECT_LINEAR:
2019 bitq = TEXGEN_OBJ_LINEAR;
2020 break;
2021 case GL_EYE_LINEAR:
2022 bitq = TEXGEN_EYE_LINEAR;
2023 break;
2024 default:
2025 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
2026 return;
2027 }
2028 if (texUnit->GenModeQ == mode)
2029 return;
2030 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2031 texUnit->GenModeQ = mode;
2032 texUnit->_GenBitQ = bitq;
2033 }
2034 else if (pname==GL_OBJECT_PLANE) {
2035 if (TEST_EQ_4V(texUnit->ObjectPlaneQ, params))
2036 return;
2037 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2038 texUnit->ObjectPlaneQ[0] = params[0];
2039 texUnit->ObjectPlaneQ[1] = params[1];
2040 texUnit->ObjectPlaneQ[2] = params[2];
2041 texUnit->ObjectPlaneQ[3] = params[3];
2042 }
2043 else if (pname==GL_EYE_PLANE) {
2044 GLfloat tmp[4];
2045 /* Transform plane equation by the inverse modelview matrix */
2046 if (ctx->ModelviewMatrixStack.Top->flags & MAT_DIRTY_INVERSE) {
2047 _math_matrix_analyse( ctx->ModelviewMatrixStack.Top );
2048 }
2049 _mesa_transform_vector( tmp, params, ctx->ModelviewMatrixStack.Top->inv );
2050 if (TEST_EQ_4V(texUnit->EyePlaneQ, tmp))
2051 return;
2052 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2053 COPY_4FV(texUnit->EyePlaneQ, tmp);
2054 }
2055 else {
2056 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
2057 return;
2058 }
2059 break;
2060 default:
2061 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
2062 return;
2063 }
2064
2065 if (ctx->Driver.TexGen)
2066 ctx->Driver.TexGen( ctx, coord, pname, params );
2067 }
2068
2069
2070 void
2071 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
2072 {
2073 GLfloat p[4];
2074 p[0] = (GLfloat) params[0];
2075 p[1] = (GLfloat) params[1];
2076 p[2] = (GLfloat) params[2];
2077 p[3] = (GLfloat) params[3];
2078 _mesa_TexGenfv(coord, pname, p);
2079 }
2080
2081
2082 void
2083 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
2084 {
2085 GLfloat p = (GLfloat) param;
2086 _mesa_TexGenfv( coord, pname, &p );
2087 }
2088
2089
2090 void
2091 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
2092 {
2093 GLfloat p[4];
2094 p[0] = (GLfloat) params[0];
2095 p[1] = (GLfloat) params[1];
2096 p[2] = (GLfloat) params[2];
2097 p[3] = (GLfloat) params[3];
2098 _mesa_TexGenfv( coord, pname, p );
2099 }
2100
2101
2102 void
2103 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
2104 {
2105 _mesa_TexGenfv(coord, pname, &param);
2106 }
2107
2108
2109 void
2110 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
2111 {
2112 _mesa_TexGeniv( coord, pname, &param );
2113 }
2114
2115
2116
2117 void
2118 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
2119 {
2120 GET_CURRENT_CONTEXT(ctx);
2121 GLuint tUnit = ctx->Texture.CurrentUnit;
2122 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2123 ASSERT_OUTSIDE_BEGIN_END(ctx);
2124
2125 switch (coord) {
2126 case GL_S:
2127 if (pname==GL_TEXTURE_GEN_MODE) {
2128 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
2129 }
2130 else if (pname==GL_OBJECT_PLANE) {
2131 COPY_4V( params, texUnit->ObjectPlaneS );
2132 }
2133 else if (pname==GL_EYE_PLANE) {
2134 COPY_4V( params, texUnit->EyePlaneS );
2135 }
2136 else {
2137 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2138 return;
2139 }
2140 break;
2141 case GL_T:
2142 if (pname==GL_TEXTURE_GEN_MODE) {
2143 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeT);
2144 }
2145 else if (pname==GL_OBJECT_PLANE) {
2146 COPY_4V( params, texUnit->ObjectPlaneT );
2147 }
2148 else if (pname==GL_EYE_PLANE) {
2149 COPY_4V( params, texUnit->EyePlaneT );
2150 }
2151 else {
2152 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2153 return;
2154 }
2155 break;
2156 case GL_R:
2157 if (pname==GL_TEXTURE_GEN_MODE) {
2158 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeR);
2159 }
2160 else if (pname==GL_OBJECT_PLANE) {
2161 COPY_4V( params, texUnit->ObjectPlaneR );
2162 }
2163 else if (pname==GL_EYE_PLANE) {
2164 COPY_4V( params, texUnit->EyePlaneR );
2165 }
2166 else {
2167 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2168 return;
2169 }
2170 break;
2171 case GL_Q:
2172 if (pname==GL_TEXTURE_GEN_MODE) {
2173 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeQ);
2174 }
2175 else if (pname==GL_OBJECT_PLANE) {
2176 COPY_4V( params, texUnit->ObjectPlaneQ );
2177 }
2178 else if (pname==GL_EYE_PLANE) {
2179 COPY_4V( params, texUnit->EyePlaneQ );
2180 }
2181 else {
2182 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
2183 return;
2184 }
2185 break;
2186 default:
2187 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
2188 return;
2189 }
2190 }
2191
2192
2193
2194 void
2195 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
2196 {
2197 GET_CURRENT_CONTEXT(ctx);
2198 GLuint tUnit = ctx->Texture.CurrentUnit;
2199 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2200 ASSERT_OUTSIDE_BEGIN_END(ctx);
2201
2202 switch (coord) {
2203 case GL_S:
2204 if (pname==GL_TEXTURE_GEN_MODE) {
2205 params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
2206 }
2207 else if (pname==GL_OBJECT_PLANE) {
2208 COPY_4V( params, texUnit->ObjectPlaneS );
2209 }
2210 else if (pname==GL_EYE_PLANE) {
2211 COPY_4V( params, texUnit->EyePlaneS );
2212 }
2213 else {
2214 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2215 return;
2216 }
2217 break;
2218 case GL_T:
2219 if (pname==GL_TEXTURE_GEN_MODE) {
2220 params[0] = ENUM_TO_FLOAT(texUnit->GenModeT);
2221 }
2222 else if (pname==GL_OBJECT_PLANE) {
2223 COPY_4V( params, texUnit->ObjectPlaneT );
2224 }
2225 else if (pname==GL_EYE_PLANE) {
2226 COPY_4V( params, texUnit->EyePlaneT );
2227 }
2228 else {
2229 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2230 return;
2231 }
2232 break;
2233 case GL_R:
2234 if (pname==GL_TEXTURE_GEN_MODE) {
2235 params[0] = ENUM_TO_FLOAT(texUnit->GenModeR);
2236 }
2237 else if (pname==GL_OBJECT_PLANE) {
2238 COPY_4V( params, texUnit->ObjectPlaneR );
2239 }
2240 else if (pname==GL_EYE_PLANE) {
2241 COPY_4V( params, texUnit->EyePlaneR );
2242 }
2243 else {
2244 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2245 return;
2246 }
2247 break;
2248 case GL_Q:
2249 if (pname==GL_TEXTURE_GEN_MODE) {
2250 params[0] = ENUM_TO_FLOAT(texUnit->GenModeQ);
2251 }
2252 else if (pname==GL_OBJECT_PLANE) {
2253 COPY_4V( params, texUnit->ObjectPlaneQ );
2254 }
2255 else if (pname==GL_EYE_PLANE) {
2256 COPY_4V( params, texUnit->EyePlaneQ );
2257 }
2258 else {
2259 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
2260 return;
2261 }
2262 break;
2263 default:
2264 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
2265 return;
2266 }
2267 }
2268
2269
2270
2271 void
2272 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
2273 {
2274 GET_CURRENT_CONTEXT(ctx);
2275 GLuint tUnit = ctx->Texture.CurrentUnit;
2276 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
2277 ASSERT_OUTSIDE_BEGIN_END(ctx);
2278
2279 switch (coord) {
2280 case GL_S:
2281 if (pname==GL_TEXTURE_GEN_MODE) {
2282 params[0] = texUnit->GenModeS;
2283 }
2284 else if (pname==GL_OBJECT_PLANE) {
2285 params[0] = (GLint) texUnit->ObjectPlaneS[0];
2286 params[1] = (GLint) texUnit->ObjectPlaneS[1];
2287 params[2] = (GLint) texUnit->ObjectPlaneS[2];
2288 params[3] = (GLint) texUnit->ObjectPlaneS[3];
2289 }
2290 else if (pname==GL_EYE_PLANE) {
2291 params[0] = (GLint) texUnit->EyePlaneS[0];
2292 params[1] = (GLint) texUnit->EyePlaneS[1];
2293 params[2] = (GLint) texUnit->EyePlaneS[2];
2294 params[3] = (GLint) texUnit->EyePlaneS[3];
2295 }
2296 else {
2297 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2298 return;
2299 }
2300 break;
2301 case GL_T:
2302 if (pname==GL_TEXTURE_GEN_MODE) {
2303 params[0] = texUnit->GenModeT;
2304 }
2305 else if (pname==GL_OBJECT_PLANE) {
2306 params[0] = (GLint) texUnit->ObjectPlaneT[0];
2307 params[1] = (GLint) texUnit->ObjectPlaneT[1];
2308 params[2] = (GLint) texUnit->ObjectPlaneT[2];
2309 params[3] = (GLint) texUnit->ObjectPlaneT[3];
2310 }
2311 else if (pname==GL_EYE_PLANE) {
2312 params[0] = (GLint) texUnit->EyePlaneT[0];
2313 params[1] = (GLint) texUnit->EyePlaneT[1];
2314 params[2] = (GLint) texUnit->EyePlaneT[2];
2315 params[3] = (GLint) texUnit->EyePlaneT[3];
2316 }
2317 else {
2318 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2319 return;
2320 }
2321 break;
2322 case GL_R:
2323 if (pname==GL_TEXTURE_GEN_MODE) {
2324 params[0] = texUnit->GenModeR;
2325 }
2326 else if (pname==GL_OBJECT_PLANE) {
2327 params[0] = (GLint) texUnit->ObjectPlaneR[0];
2328 params[1] = (GLint) texUnit->ObjectPlaneR[1];
2329 params[2] = (GLint) texUnit->ObjectPlaneR[2];
2330 params[3] = (GLint) texUnit->ObjectPlaneR[3];
2331 }
2332 else if (pname==GL_EYE_PLANE) {
2333 params[0] = (GLint) texUnit->EyePlaneR[0];
2334 params[1] = (GLint) texUnit->EyePlaneR[1];
2335 params[2] = (GLint) texUnit->EyePlaneR[2];
2336 params[3] = (GLint) texUnit->EyePlaneR[3];
2337 }
2338 else {
2339 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2340 return;
2341 }
2342 break;
2343 case GL_Q:
2344 if (pname==GL_TEXTURE_GEN_MODE) {
2345 params[0] = texUnit->GenModeQ;
2346 }
2347 else if (pname==GL_OBJECT_PLANE) {
2348 params[0] = (GLint) texUnit->ObjectPlaneQ[0];
2349 params[1] = (GLint) texUnit->ObjectPlaneQ[1];
2350 params[2] = (GLint) texUnit->ObjectPlaneQ[2];
2351 params[3] = (GLint) texUnit->ObjectPlaneQ[3];
2352 }
2353 else if (pname==GL_EYE_PLANE) {
2354 params[0] = (GLint) texUnit->EyePlaneQ[0];
2355 params[1] = (GLint) texUnit->EyePlaneQ[1];
2356 params[2] = (GLint) texUnit->EyePlaneQ[2];
2357 params[3] = (GLint) texUnit->EyePlaneQ[3];
2358 }
2359 else {
2360 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
2361 return;
2362 }
2363 break;
2364 default:
2365 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
2366 return;
2367 }
2368 }
2369
2370
2371 /* GL_ARB_multitexture */
2372 void
2373 _mesa_ActiveTextureARB( GLenum target )
2374 {
2375 GET_CURRENT_CONTEXT(ctx);
2376 GLuint texUnit = target - GL_TEXTURE0_ARB;
2377 ASSERT_OUTSIDE_BEGIN_END(ctx);
2378
2379 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
2380 _mesa_debug(ctx, "glActiveTexture %s\n",
2381 _mesa_lookup_enum_by_nr(target));
2382
2383 if (texUnit > ctx->Const.MaxTextureUnits) {
2384 _mesa_error(ctx, GL_INVALID_ENUM, "glActiveTextureARB(target)");
2385 return;
2386 }
2387
2388 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
2389 ctx->Texture.CurrentUnit = texUnit;
2390 if (ctx->Driver.ActiveTexture) {
2391 (*ctx->Driver.ActiveTexture)( ctx, (GLuint) texUnit );
2392 }
2393 }
2394
2395
2396 /* GL_ARB_multitexture */
2397 void
2398 _mesa_ClientActiveTextureARB( GLenum target )
2399 {
2400 GET_CURRENT_CONTEXT(ctx);
2401 GLuint texUnit = target - GL_TEXTURE0_ARB;
2402 ASSERT_OUTSIDE_BEGIN_END(ctx);
2403
2404 if (texUnit > ctx->Const.MaxTextureUnits) {
2405 _mesa_error(ctx, GL_INVALID_ENUM, "glClientActiveTextureARB(target)");
2406 return;
2407 }
2408
2409 FLUSH_VERTICES(ctx, _NEW_ARRAY);
2410 ctx->Array.ActiveTexture = texUnit;
2411 }
2412
2413
2414
2415 /**********************************************************************/
2416 /* Pixel Texgen Extensions */
2417 /**********************************************************************/
2418
2419 void
2420 _mesa_PixelTexGenSGIX(GLenum mode)
2421 {
2422 GLenum newRgbSource, newAlphaSource;
2423 GET_CURRENT_CONTEXT(ctx);
2424 ASSERT_OUTSIDE_BEGIN_END(ctx);
2425
2426 switch (mode) {
2427 case GL_NONE:
2428 newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
2429 newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
2430 break;
2431 case GL_ALPHA:
2432 newRgbSource = GL_PIXEL_GROUP_COLOR_SGIS;
2433 newAlphaSource = GL_CURRENT_RASTER_COLOR;
2434 break;
2435 case GL_RGB:
2436 newRgbSource = GL_CURRENT_RASTER_COLOR;
2437 newAlphaSource = GL_PIXEL_GROUP_COLOR_SGIS;
2438 break;
2439 case GL_RGBA:
2440 newRgbSource = GL_CURRENT_RASTER_COLOR;
2441 newAlphaSource = GL_CURRENT_RASTER_COLOR;
2442 break;
2443 default:
2444 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenSGIX(mode)");
2445 return;
2446 }
2447
2448 if (newRgbSource == ctx->Pixel.FragmentRgbSource &&
2449 newAlphaSource == ctx->Pixel.FragmentAlphaSource)
2450 return;
2451
2452 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2453 ctx->Pixel.FragmentRgbSource = newRgbSource;
2454 ctx->Pixel.FragmentAlphaSource = newAlphaSource;
2455 }
2456
2457
2458 void
2459 _mesa_PixelTexGenParameterfSGIS(GLenum target, GLfloat value)
2460 {
2461 _mesa_PixelTexGenParameteriSGIS(target, (GLint) value);
2462 }
2463
2464
2465 void
2466 _mesa_PixelTexGenParameterfvSGIS(GLenum target, const GLfloat *value)
2467 {
2468 _mesa_PixelTexGenParameteriSGIS(target, (GLint) *value);
2469 }
2470
2471
2472 void
2473 _mesa_PixelTexGenParameteriSGIS(GLenum target, GLint value)
2474 {
2475 GET_CURRENT_CONTEXT(ctx);
2476 ASSERT_OUTSIDE_BEGIN_END(ctx);
2477
2478 if (value != GL_CURRENT_RASTER_COLOR && value != GL_PIXEL_GROUP_COLOR_SGIS) {
2479 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(value)");
2480 return;
2481 }
2482
2483 switch (target) {
2484 case GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS:
2485 if (ctx->Pixel.FragmentRgbSource == (GLenum) value)
2486 return;
2487 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2488 ctx->Pixel.FragmentRgbSource = (GLenum) value;
2489 break;
2490 case GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS:
2491 if (ctx->Pixel.FragmentAlphaSource == (GLenum) value)
2492 return;
2493 FLUSH_VERTICES(ctx, _NEW_PIXEL);
2494 ctx->Pixel.FragmentAlphaSource = (GLenum) value;
2495 break;
2496 default:
2497 _mesa_error(ctx, GL_INVALID_ENUM, "glPixelTexGenParameterSGIS(target)");
2498 return;
2499 }
2500 }
2501
2502
2503 void
2504 _mesa_PixelTexGenParameterivSGIS(GLenum target, const GLint *value)
2505 {
2506 _mesa_PixelTexGenParameteriSGIS(target, *value);
2507 }
2508
2509
2510 void
2511 _mesa_GetPixelTexGenParameterfvSGIS(GLenum target, GLfloat *value)
2512 {
2513 GET_CURRENT_CONTEXT(ctx);
2514 ASSERT_OUTSIDE_BEGIN_END(ctx);
2515
2516 if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
2517 *value = (GLfloat) ctx->Pixel.FragmentRgbSource;
2518 }
2519 else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
2520 *value = (GLfloat) ctx->Pixel.FragmentAlphaSource;
2521 }
2522 else {
2523 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterfvSGIS(target)");
2524 }
2525 }
2526
2527
2528 void
2529 _mesa_GetPixelTexGenParameterivSGIS(GLenum target, GLint *value)
2530 {
2531 GET_CURRENT_CONTEXT(ctx);
2532 ASSERT_OUTSIDE_BEGIN_END(ctx);
2533
2534 if (target == GL_PIXEL_FRAGMENT_RGB_SOURCE_SGIS) {
2535 *value = (GLint) ctx->Pixel.FragmentRgbSource;
2536 }
2537 else if (target == GL_PIXEL_FRAGMENT_ALPHA_SOURCE_SGIS) {
2538 *value = (GLint) ctx->Pixel.FragmentAlphaSource;
2539 }
2540 else {
2541 _mesa_error(ctx, GL_INVALID_ENUM, "glGetPixelTexGenParameterivSGIS(target)");
2542 }
2543 }