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