Holger's fixes for GL_EXT_texture_env_combine
[mesa.git] / src / mesa / main / texstate.c
1 /* $Id: texstate.c,v 1.15 2000/07/05 16:14:24 brianp Exp $ */
2
3 /*
4 * Mesa 3-D graphics library
5 * Version: 3.3
6 *
7 * Copyright (C) 1999-2000 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 "context.h"
33 #include "enums.h"
34 #include "extensions.h"
35 #include "macros.h"
36 #include "matrix.h"
37 #include "texobj.h"
38 #include "teximage.h"
39 #include "texstate.h"
40 #include "texture.h"
41 #include "types.h"
42 #include "xform.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
60 /**********************************************************************/
61 /* Texture Environment */
62 /**********************************************************************/
63
64
65 void
66 _mesa_TexEnvfv( GLenum target, GLenum pname, const GLfloat *param )
67 {
68 GET_CURRENT_CONTEXT(ctx);
69 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
70
71 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexEnv");
72
73 if (target==GL_TEXTURE_ENV) {
74 switch (pname) {
75 case GL_TEXTURE_ENV_MODE:
76 {
77 GLenum mode = (GLenum) (GLint) *param;
78 switch (mode) {
79 case GL_MODULATE:
80 case GL_BLEND:
81 case GL_DECAL:
82 case GL_REPLACE:
83 case GL_ADD:
84 case GL_COMBINE_EXT:
85 if (mode == GL_ADD &&
86 !ctx->Extensions.HaveTextureEnvAdd) {
87 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
88 return;
89 }
90 if (mode == GL_COMBINE_EXT &&
91 !ctx->Extensions.HaveTextureEnvCombine) {
92 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(param)");
93 return;
94 }
95 if (texUnit->EnvMode == mode)
96 return; /* no change */
97 texUnit->EnvMode = mode;
98 ctx->NewState |= NEW_TEXTURE_ENV;
99 break;
100 default:
101 gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
102 return;
103 }
104 }
105 break;
106 case GL_TEXTURE_ENV_COLOR:
107 texUnit->EnvColor[0] = CLAMP( param[0], 0.0F, 1.0F );
108 texUnit->EnvColor[1] = CLAMP( param[1], 0.0F, 1.0F );
109 texUnit->EnvColor[2] = CLAMP( param[2], 0.0F, 1.0F );
110 texUnit->EnvColor[3] = CLAMP( param[3], 0.0F, 1.0F );
111 break;
112 case GL_COMBINE_RGB_EXT:
113 if (ctx->Extensions.HaveTextureEnvCombine) {
114 GLenum mode = (GLenum) (GLint) *param;
115 switch (mode) {
116 case GL_REPLACE:
117 case GL_MODULATE:
118 case GL_ADD:
119 case GL_ADD_SIGNED_EXT:
120 case GL_INTERPOLATE_EXT:
121 if (texUnit->CombineModeRGB == mode)
122 return; /* no change */
123 texUnit->CombineModeRGB = mode;
124 ctx->NewState |= NEW_TEXTURE_ENV;
125 break;
126 default:
127 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
128 return;
129 }
130 }
131 else {
132 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
133 return;
134 }
135 break;
136 case GL_COMBINE_ALPHA_EXT:
137 if (ctx->Extensions.HaveTextureEnvCombine) {
138 GLenum mode = (GLenum) (GLint) *param;
139 switch (mode) {
140 case GL_REPLACE:
141 case GL_MODULATE:
142 case GL_ADD:
143 case GL_ADD_SIGNED_EXT:
144 case GL_INTERPOLATE_EXT:
145 if (texUnit->CombineModeA == mode)
146 return; /* no change */
147 texUnit->CombineModeA = mode;
148 ctx->NewState |= NEW_TEXTURE_ENV;
149 break;
150 default:
151 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
152 return;
153 }
154 }
155 else {
156 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
157 return;
158 }
159 break;
160 case GL_SOURCE0_RGB_EXT:
161 case GL_SOURCE1_RGB_EXT:
162 case GL_SOURCE2_RGB_EXT:
163 if (ctx->Extensions.HaveTextureEnvCombine) {
164 GLenum source = (GLenum) (GLint) *param;
165 GLuint s = pname - GL_SOURCE0_RGB_EXT;
166 switch (source) {
167 case GL_TEXTURE:
168 case GL_CONSTANT_EXT:
169 case GL_PRIMARY_COLOR_EXT:
170 case GL_PREVIOUS_EXT:
171 if (texUnit->CombineSourceRGB[s] == source)
172 return; /* no change */
173 texUnit->CombineSourceRGB[s] = source;
174 ctx->NewState |= NEW_TEXTURE_ENV;
175 break;
176 default:
177 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
178 return;
179 }
180 }
181 else {
182 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
183 return;
184 }
185 break;
186 case GL_SOURCE0_ALPHA_EXT:
187 case GL_SOURCE1_ALPHA_EXT:
188 case GL_SOURCE2_ALPHA_EXT:
189 if (ctx->Extensions.HaveTextureEnvCombine) {
190 GLenum source = (GLenum) (GLint) *param;
191 GLuint s = pname - GL_SOURCE0_ALPHA_EXT;
192 switch (source) {
193 case GL_TEXTURE:
194 case GL_CONSTANT_EXT:
195 case GL_PRIMARY_COLOR_EXT:
196 case GL_PREVIOUS_EXT:
197 if (texUnit->CombineSourceA[s] == source) return;
198 texUnit->CombineSourceA[s] = source;
199 ctx->NewState |= NEW_TEXTURE_ENV;
200 break;
201 default:
202 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
203 return;
204 }
205 }
206 else {
207 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
208 return;
209 }
210 break;
211 case GL_OPERAND0_RGB_EXT:
212 case GL_OPERAND1_RGB_EXT:
213 if (ctx->Extensions.HaveTextureEnvCombine) {
214 GLenum operand = (GLenum) (GLint) *param;
215 GLuint s = pname - GL_OPERAND0_RGB_EXT;
216 switch (operand) {
217 case GL_SRC_COLOR:
218 case GL_ONE_MINUS_SRC_COLOR:
219 case GL_SRC_ALPHA:
220 case GL_ONE_MINUS_SRC_ALPHA:
221 texUnit->CombineOperandRGB[s] = operand;
222 ctx->NewState |= NEW_TEXTURE_ENV;
223 break;
224 default:
225 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
226 return;
227 }
228 }
229 else {
230 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
231 return;
232 }
233 break;
234 case GL_OPERAND0_ALPHA_EXT:
235 case GL_OPERAND1_ALPHA_EXT:
236 if (ctx->Extensions.HaveTextureEnvCombine) {
237 GLenum operand = (GLenum) (GLint) *param;
238 switch (operand) {
239 case GL_SRC_ALPHA:
240 case GL_ONE_MINUS_SRC_ALPHA:
241 texUnit->CombineOperandA[pname-GL_OPERAND0_ALPHA_EXT]
242 = operand;
243 ctx->NewState |= NEW_TEXTURE_ENV;
244 break;
245 default:
246 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
247 return;
248 }
249 }
250 else {
251 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
252 return;
253 }
254 break;
255 case GL_OPERAND2_RGB_EXT:
256 if (ctx->Extensions.HaveTextureEnvCombine) {
257 if ((GLenum) (GLint) *param == GL_SRC_ALPHA) {
258 texUnit->CombineOperandRGB[2] = (GLenum) (GLint) *param;
259 ctx->NewState |= NEW_TEXTURE_ENV;
260 }
261 else {
262 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
263 return;
264 }
265 }
266 else {
267 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
268 return;
269 }
270 break;
271 case GL_OPERAND2_ALPHA_EXT:
272 if (ctx->Extensions.HaveTextureEnvCombine) {
273 if ((GLenum) (GLint) *param == GL_SRC_ALPHA) {
274 texUnit->CombineOperandA[2] = (GLenum) (GLint) *param;
275 ctx->NewState |= NEW_TEXTURE_ENV;
276 }
277 else {
278 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
279 return;
280 }
281 }
282 else {
283 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
284 return;
285 }
286 break;
287 case GL_RGB_SCALE_EXT:
288 if (ctx->Extensions.HaveTextureEnvCombine) {
289 if (*param == 1.0) {
290 texUnit->CombineScaleShiftRGB = 0;
291 ctx->NewState |= NEW_TEXTURE_ENV;
292 }
293 else if (*param == 2.0) {
294 texUnit->CombineScaleShiftRGB = 1;
295 ctx->NewState |= NEW_TEXTURE_ENV;
296 }
297 else if (*param == 4.0) {
298 texUnit->CombineScaleShiftRGB = 2;
299 ctx->NewState |= NEW_TEXTURE_ENV;
300 }
301 else {
302 gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
303 return;
304 }
305 }
306 else {
307 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
308 return;
309 }
310 break;
311 case GL_ALPHA_SCALE:
312 if (ctx->Extensions.HaveTextureEnvCombine) {
313 if (*param == 1.0) {
314 texUnit->CombineScaleShiftA = 0;
315 ctx->NewState |= NEW_TEXTURE_ENV;
316 }
317 else if (*param == 2.0) {
318 texUnit->CombineScaleShiftA = 1;
319 ctx->NewState |= NEW_TEXTURE_ENV;
320 }
321 else if (*param == 4.0) {
322 texUnit->CombineScaleShiftA = 2;
323 ctx->NewState |= NEW_TEXTURE_ENV;
324 }
325 else {
326 gl_error( ctx, GL_INVALID_VALUE, "glTexEnv(param)" );
327 return;
328 }
329 }
330 else {
331 gl_error(ctx, GL_INVALID_ENUM, "glTexEnv(pname)");
332 return;
333 }
334 break;
335 default:
336 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
337 return;
338 }
339 }
340 else if (target==GL_TEXTURE_FILTER_CONTROL_EXT) {
341 if (!ctx->Extensions.HaveTextureLodBias) {
342 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
343 return;
344 }
345 if (pname == GL_TEXTURE_LOD_BIAS_EXT) {
346 texUnit->LodBias = param[0];
347 }
348 else {
349 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
350 return;
351 }
352 }
353 else {
354 gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
355 return;
356 }
357
358 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
359 fprintf(stderr, "glTexEnv %s %s %.1f(%s) ...\n",
360 gl_lookup_enum_by_nr(target),
361 gl_lookup_enum_by_nr(pname),
362 *param,
363 gl_lookup_enum_by_nr((GLenum) (GLint) *param));
364
365 /* Tell device driver about the new texture environment */
366 if (ctx->Driver.TexEnv) {
367 (*ctx->Driver.TexEnv)( ctx, target, pname, param );
368 }
369
370 }
371
372
373 void
374 _mesa_TexEnvf( GLenum target, GLenum pname, GLfloat param )
375 {
376 _mesa_TexEnvfv( target, pname, &param );
377 }
378
379
380
381 void
382 _mesa_TexEnvi( GLenum target, GLenum pname, GLint param )
383 {
384 GLfloat p[4];
385 p[0] = (GLfloat) param;
386 p[1] = p[2] = p[3] = 0.0;
387 _mesa_TexEnvfv( target, pname, p );
388 }
389
390
391 void
392 _mesa_TexEnviv( GLenum target, GLenum pname, const GLint *param )
393 {
394 GLfloat p[4];
395 p[0] = INT_TO_FLOAT( param[0] );
396 p[1] = INT_TO_FLOAT( param[1] );
397 p[2] = INT_TO_FLOAT( param[2] );
398 p[3] = INT_TO_FLOAT( param[3] );
399 _mesa_TexEnvfv( target, pname, p );
400 }
401
402
403 void
404 _mesa_GetTexEnvfv( GLenum target, GLenum pname, GLfloat *params )
405 {
406 GET_CURRENT_CONTEXT(ctx);
407 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
408
409 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnvfv");
410
411 if (target!=GL_TEXTURE_ENV) {
412 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
413 return;
414 }
415
416 switch (pname) {
417 case GL_TEXTURE_ENV_MODE:
418 *params = ENUM_TO_FLOAT(texUnit->EnvMode);
419 break;
420 case GL_TEXTURE_ENV_COLOR:
421 COPY_4FV( params, texUnit->EnvColor );
422 break;
423 case GL_RGB_SCALE_EXT:
424 if (ctx->Extensions.HaveTextureEnvCombine) {
425 if (texUnit->CombineScaleShiftRGB == 0)
426 *params = 1.0;
427 else if (texUnit->CombineScaleShiftRGB == 1)
428 *params = 2.0;
429 else
430 *params = 4.0;
431 }
432 else {
433 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
434 return;
435 }
436 break;
437 case GL_ALPHA_SCALE:
438 if (ctx->Extensions.HaveTextureEnvCombine) {
439 if (texUnit->CombineScaleShiftA == 0)
440 *params = 1.0;
441 else if (texUnit->CombineScaleShiftA == 1)
442 *params = 2.0;
443 else
444 *params = 4.0;
445 }
446 else {
447 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)");
448 return;
449 }
450 break;
451 default:
452 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
453 }
454 }
455
456
457 void
458 _mesa_GetTexEnviv( GLenum target, GLenum pname, GLint *params )
459 {
460 GET_CURRENT_CONTEXT(ctx);
461 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
462
463 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexEnviv");
464
465 if (target != GL_TEXTURE_ENV) {
466 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(target)" );
467 return;
468 }
469
470 switch (pname) {
471 case GL_TEXTURE_ENV_MODE:
472 *params = (GLint) texUnit->EnvMode;
473 break;
474 case GL_TEXTURE_ENV_COLOR:
475 params[0] = FLOAT_TO_INT( texUnit->EnvColor[0] );
476 params[1] = FLOAT_TO_INT( texUnit->EnvColor[1] );
477 params[2] = FLOAT_TO_INT( texUnit->EnvColor[2] );
478 params[3] = FLOAT_TO_INT( texUnit->EnvColor[3] );
479 break;
480 case GL_COMBINE_RGB_EXT:
481 if (ctx->Extensions.HaveTextureEnvCombine) {
482 *params = (GLint) texUnit->CombineModeRGB;
483 }
484 else {
485 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
486 }
487 break;
488 case GL_COMBINE_ALPHA_EXT:
489 if (ctx->Extensions.HaveTextureEnvCombine) {
490 *params = (GLint) texUnit->CombineModeA;
491 }
492 else {
493 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
494 }
495 break;
496 case GL_SOURCE0_RGB_EXT:
497 if (ctx->Extensions.HaveTextureEnvCombine) {
498 *params = (GLint) texUnit->CombineSourceRGB[0];
499 }
500 else {
501 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
502 }
503 break;
504 case GL_SOURCE1_RGB_EXT:
505 if (ctx->Extensions.HaveTextureEnvCombine) {
506 *params = (GLint) texUnit->CombineSourceRGB[1];
507 }
508 else {
509 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
510 }
511 break;
512 case GL_SOURCE2_RGB_EXT:
513 if (ctx->Extensions.HaveTextureEnvCombine) {
514 *params = (GLint) texUnit->CombineSourceRGB[2];
515 }
516 else {
517 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
518 }
519 break;
520 case GL_SOURCE0_ALPHA_EXT:
521 if (ctx->Extensions.HaveTextureEnvCombine) {
522 *params = (GLint) texUnit->CombineSourceA[0];
523 }
524 else {
525 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
526 }
527 break;
528 case GL_SOURCE1_ALPHA_EXT:
529 if (ctx->Extensions.HaveTextureEnvCombine) {
530 *params = (GLint) texUnit->CombineSourceA[1];
531 }
532 else {
533 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
534 }
535 break;
536 case GL_SOURCE2_ALPHA_EXT:
537 if (ctx->Extensions.HaveTextureEnvCombine) {
538 *params = (GLint) texUnit->CombineSourceA[2];
539 }
540 else {
541 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
542 }
543 break;
544 case GL_OPERAND0_RGB_EXT:
545 if (ctx->Extensions.HaveTextureEnvCombine) {
546 *params = (GLint) texUnit->CombineOperandRGB[0];
547 }
548 else {
549 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
550 }
551 break;
552 case GL_OPERAND1_RGB_EXT:
553 if (ctx->Extensions.HaveTextureEnvCombine) {
554 *params = (GLint) texUnit->CombineOperandRGB[1];
555 }
556 else {
557 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
558 }
559 break;
560 case GL_OPERAND2_RGB_EXT:
561 if (ctx->Extensions.HaveTextureEnvCombine) {
562 *params = (GLint) texUnit->CombineOperandRGB[2];
563 }
564 else {
565 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
566 }
567 break;
568 case GL_OPERAND0_ALPHA_EXT:
569 if (ctx->Extensions.HaveTextureEnvCombine) {
570 *params = (GLint) texUnit->CombineOperandA[0];
571 }
572 else {
573 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
574 }
575 break;
576 case GL_OPERAND1_ALPHA_EXT:
577 if (ctx->Extensions.HaveTextureEnvCombine) {
578 *params = (GLint) texUnit->CombineOperandA[1];
579 }
580 else {
581 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
582 }
583 break;
584 case GL_OPERAND2_ALPHA_EXT:
585 if (ctx->Extensions.HaveTextureEnvCombine) {
586 *params = (GLint) texUnit->CombineOperandA[2];
587 }
588 else {
589 gl_error(ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)");
590 }
591 break;
592 default:
593 gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnviv(pname)" );
594 }
595 }
596
597
598
599
600 /**********************************************************************/
601 /* Texture Parameters */
602 /**********************************************************************/
603
604
605 void
606 _mesa_TexParameterf( GLenum target, GLenum pname, GLfloat param )
607 {
608 _mesa_TexParameterfv(target, pname, &param);
609 }
610
611
612 void
613 _mesa_TexParameterfv( GLenum target, GLenum pname, const GLfloat *params )
614 {
615 GET_CURRENT_CONTEXT(ctx);
616 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
617 GLenum eparam = (GLenum) (GLint) params[0];
618 struct gl_texture_object *texObj;
619
620 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexParameterfv");
621
622 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
623 fprintf(stderr, "texPARAM %s %s %d...\n",
624 gl_lookup_enum_by_nr(target),
625 gl_lookup_enum_by_nr(pname),
626 eparam);
627
628
629 switch (target) {
630 case GL_TEXTURE_1D:
631 texObj = texUnit->CurrentD[1];
632 break;
633 case GL_TEXTURE_2D:
634 texObj = texUnit->CurrentD[2];
635 break;
636 case GL_TEXTURE_3D_EXT:
637 texObj = texUnit->CurrentD[3];
638 break;
639 case GL_TEXTURE_CUBE_MAP_ARB:
640 if (ctx->Extensions.HaveTextureCubeMap) {
641 texObj = texUnit->CurrentCubeMap;
642 break;
643 }
644 /* fallthrough */
645 default:
646 gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
647 return;
648 }
649
650 switch (pname) {
651 case GL_TEXTURE_MIN_FILTER:
652 /* A small optimization */
653 if (texObj->MinFilter == eparam)
654 return;
655
656 if (eparam==GL_NEAREST || eparam==GL_LINEAR
657 || eparam==GL_NEAREST_MIPMAP_NEAREST
658 || eparam==GL_LINEAR_MIPMAP_NEAREST
659 || eparam==GL_NEAREST_MIPMAP_LINEAR
660 || eparam==GL_LINEAR_MIPMAP_LINEAR) {
661 texObj->MinFilter = eparam;
662 ctx->NewState |= NEW_TEXTURING;
663 }
664 else {
665 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
666 return;
667 }
668 break;
669 case GL_TEXTURE_MAG_FILTER:
670 /* A small optimization */
671 if (texObj->MagFilter == eparam)
672 return;
673
674 if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
675 texObj->MagFilter = eparam;
676 ctx->NewState |= NEW_TEXTURING;
677 }
678 else {
679 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
680 return;
681 }
682 break;
683 case GL_TEXTURE_WRAP_S:
684 if (texObj->WrapS == eparam)
685 return;
686
687 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
688 texObj->WrapS = eparam;
689 ctx->NewState |= NEW_TEXTURING;
690 }
691 else {
692 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
693 return;
694 }
695 break;
696 case GL_TEXTURE_WRAP_T:
697 if (texObj->WrapT == eparam)
698 return;
699
700 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
701 texObj->WrapT = eparam;
702 ctx->NewState |= NEW_TEXTURING;
703 }
704 else {
705 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
706 return;
707 }
708 break;
709 case GL_TEXTURE_WRAP_R_EXT:
710 if (texObj->WrapR == eparam)
711 return;
712
713 if (eparam==GL_CLAMP || eparam==GL_REPEAT || eparam==GL_CLAMP_TO_EDGE) {
714 texObj->WrapR = eparam;
715 ctx->NewState |= NEW_TEXTURING;
716 }
717 else {
718 gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
719 }
720 break;
721 case GL_TEXTURE_BORDER_COLOR:
722 texObj->BorderColor[0] = (GLubyte) CLAMP((GLint)(params[0]*255.0), 0, 255);
723 texObj->BorderColor[1] = (GLubyte) CLAMP((GLint)(params[1]*255.0), 0, 255);
724 texObj->BorderColor[2] = (GLubyte) CLAMP((GLint)(params[2]*255.0), 0, 255);
725 texObj->BorderColor[3] = (GLubyte) CLAMP((GLint)(params[3]*255.0), 0, 255);
726 break;
727 case GL_TEXTURE_MIN_LOD:
728 texObj->MinLod = params[0];
729 ctx->NewState |= NEW_TEXTURING;
730 break;
731 case GL_TEXTURE_MAX_LOD:
732 texObj->MaxLod = params[0];
733 ctx->NewState |= NEW_TEXTURING;
734 break;
735 case GL_TEXTURE_BASE_LEVEL:
736 if (params[0] < 0.0) {
737 gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
738 return;
739 }
740 texObj->BaseLevel = (GLint) params[0];
741 ctx->NewState |= NEW_TEXTURING;
742 break;
743 case GL_TEXTURE_MAX_LEVEL:
744 if (params[0] < 0.0) {
745 gl_error(ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
746 return;
747 }
748 texObj->MaxLevel = (GLint) params[0];
749 ctx->NewState |= NEW_TEXTURING;
750 break;
751 case GL_TEXTURE_PRIORITY:
752 /* (keithh@netcomuk.co.uk) */
753 texObj->Priority = CLAMP( params[0], 0.0F, 1.0F );
754 break;
755 default:
756 gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
757 return;
758 }
759
760 gl_put_texobj_on_dirty_list( ctx, texObj );
761
762 if (ctx->Driver.TexParameter) {
763 (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
764 }
765 }
766
767
768 void
769 _mesa_TexParameteri( GLenum target, GLenum pname, const GLint param )
770 {
771 GLfloat fparam[4];
772 fparam[0] = (GLfloat) param;
773 fparam[1] = fparam[2] = fparam[3] = 0.0;
774 _mesa_TexParameterfv(target, pname, fparam);
775 }
776
777 void
778 _mesa_TexParameteriv( GLenum target, GLenum pname, const GLint *params )
779 {
780 GLfloat fparam[4];
781 fparam[0] = (GLfloat) params[0];
782 fparam[1] = fparam[2] = fparam[3] = 0.0;
783 _mesa_TexParameterfv(target, pname, fparam);
784 }
785
786
787 void
788 _mesa_GetTexLevelParameterfv( GLenum target, GLint level,
789 GLenum pname, GLfloat *params )
790 {
791 GLint iparam;
792 _mesa_GetTexLevelParameteriv( target, level, pname, &iparam );
793 *params = (GLfloat) iparam;
794 }
795
796
797 static GLuint
798 tex_image_dimensions(GLcontext *ctx, GLenum target)
799 {
800 switch (target) {
801 case GL_TEXTURE_1D:
802 case GL_PROXY_TEXTURE_1D:
803 return 1;
804 case GL_TEXTURE_2D:
805 case GL_PROXY_TEXTURE_2D:
806 return 2;
807 case GL_TEXTURE_3D:
808 case GL_PROXY_TEXTURE_3D:
809 return 3;
810 case GL_TEXTURE_CUBE_MAP_ARB:
811 case GL_PROXY_TEXTURE_CUBE_MAP_ARB:
812 return ctx->Extensions.HaveTextureCubeMap ? 2 : 0;
813 default:
814 gl_problem(ctx, "bad target in _mesa_tex_target_dimensions()");
815 return 0;
816 }
817 }
818
819
820 void
821 _mesa_GetTexLevelParameteriv( GLenum target, GLint level,
822 GLenum pname, GLint *params )
823 {
824 GET_CURRENT_CONTEXT(ctx);
825 const struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
826 const struct gl_texture_image *img = NULL;
827 GLuint dimensions;
828 GLboolean isProxy;
829
830 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexLevelParameter");
831
832 if (level < 0 || level >= ctx->Const.MaxTextureLevels) {
833 gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
834 return;
835 }
836
837 dimensions = tex_image_dimensions(ctx, target); /* 1, 2 or 3 */
838 if (dimensions == 0) {
839 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
840 return;
841 }
842
843 img = _mesa_select_tex_image(ctx, texUnit, target, level);
844 if (!img) {
845 if (pname == GL_TEXTURE_COMPONENTS)
846 *params = 1;
847 else
848 *params = 0;
849 return;
850 }
851
852 isProxy = (target == GL_PROXY_TEXTURE_1D) ||
853 (target == GL_PROXY_TEXTURE_2D) ||
854 (target == GL_PROXY_TEXTURE_3D) ||
855 (target == GL_PROXY_TEXTURE_CUBE_MAP_ARB);
856
857 switch (pname) {
858 case GL_TEXTURE_WIDTH:
859 *params = img->Width;
860 return;
861 case GL_TEXTURE_HEIGHT:
862 if (dimensions > 1) {
863 *params = img->Height;
864 }
865 else {
866 gl_error( ctx, GL_INVALID_ENUM,
867 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_HEIGHT)" );
868 }
869 return;
870 case GL_TEXTURE_DEPTH:
871 if (dimensions > 2) {
872 *params = img->Depth;
873 }
874 else {
875 gl_error( ctx, GL_INVALID_ENUM,
876 "glGetTexLevelParameter[if]v(pname=GL_TEXTURE_DEPTH)" );
877 }
878 return;
879 case GL_TEXTURE_COMPONENTS:
880 *params = img->IntFormat;
881 return;
882 case GL_TEXTURE_BORDER:
883 *params = img->Border;
884 return;
885 case GL_TEXTURE_RED_SIZE:
886 *params = img->RedBits;
887 return;
888 case GL_TEXTURE_GREEN_SIZE:
889 *params = img->GreenBits;
890 return;
891 case GL_TEXTURE_BLUE_SIZE:
892 *params = img->BlueBits;
893 return;
894 case GL_TEXTURE_ALPHA_SIZE:
895 *params = img->AlphaBits;
896 return;
897 case GL_TEXTURE_INTENSITY_SIZE:
898 *params = img->IntensityBits;
899 return;
900 case GL_TEXTURE_LUMINANCE_SIZE:
901 *params = img->LuminanceBits;
902 return;
903 case GL_TEXTURE_INDEX_SIZE_EXT:
904 *params = img->IndexBits;
905 return;
906
907 /* GL_ARB_texture_compression */
908 case GL_TEXTURE_COMPRESSED_IMAGE_SIZE_ARB:
909 if (ctx->Extensions.HaveTextureCompression) {
910 if (img->IsCompressed && !isProxy)
911 *params = img->CompressedSize;
912 else
913 gl_error(ctx, GL_INVALID_OPERATION,
914 "glGetTexLevelParameter[if]v(pname)");
915 }
916 else {
917 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
918 }
919 return;
920 case GL_TEXTURE_COMPRESSED_ARB:
921 if (ctx->Extensions.HaveTextureCompression) {
922 *params = (GLint) img->IsCompressed;
923 }
924 else {
925 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
926 }
927 return;
928
929 default:
930 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(pname)");
931 }
932 }
933
934
935
936 void
937 _mesa_GetTexParameterfv( GLenum target, GLenum pname, GLfloat *params )
938 {
939 GET_CURRENT_CONTEXT(ctx);
940 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
941 struct gl_texture_object *obj;
942
943 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameterfv");
944
945 obj = _mesa_select_tex_object(ctx, texUnit, target);
946 if (!obj) {
947 gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)");
948 return;
949 }
950
951 switch (pname) {
952 case GL_TEXTURE_MAG_FILTER:
953 *params = ENUM_TO_FLOAT(obj->MagFilter);
954 break;
955 case GL_TEXTURE_MIN_FILTER:
956 *params = ENUM_TO_FLOAT(obj->MinFilter);
957 break;
958 case GL_TEXTURE_WRAP_S:
959 *params = ENUM_TO_FLOAT(obj->WrapS);
960 break;
961 case GL_TEXTURE_WRAP_T:
962 *params = ENUM_TO_FLOAT(obj->WrapT);
963 break;
964 case GL_TEXTURE_WRAP_R_EXT:
965 *params = ENUM_TO_FLOAT(obj->WrapR);
966 break;
967 case GL_TEXTURE_BORDER_COLOR:
968 params[0] = obj->BorderColor[0] / 255.0F;
969 params[1] = obj->BorderColor[1] / 255.0F;
970 params[2] = obj->BorderColor[2] / 255.0F;
971 params[3] = obj->BorderColor[3] / 255.0F;
972 break;
973 case GL_TEXTURE_RESIDENT:
974 *params = ENUM_TO_FLOAT(GL_TRUE);
975 break;
976 case GL_TEXTURE_PRIORITY:
977 *params = obj->Priority;
978 break;
979 case GL_TEXTURE_MIN_LOD:
980 *params = obj->MinLod;
981 break;
982 case GL_TEXTURE_MAX_LOD:
983 *params = obj->MaxLod;
984 break;
985 case GL_TEXTURE_BASE_LEVEL:
986 *params = (GLfloat) obj->BaseLevel;
987 break;
988 case GL_TEXTURE_MAX_LEVEL:
989 *params = (GLfloat) obj->MaxLevel;
990 break;
991 default:
992 gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
993 }
994 }
995
996
997 void
998 _mesa_GetTexParameteriv( GLenum target, GLenum pname, GLint *params )
999 {
1000 GET_CURRENT_CONTEXT(ctx);
1001 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[ctx->Texture.CurrentUnit];
1002 struct gl_texture_object *obj;
1003
1004 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexParameteriv");
1005
1006 obj = _mesa_select_tex_object(ctx, texUnit, target);
1007 if (!obj) {
1008 gl_error(ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)");
1009 return;
1010 }
1011
1012 switch (pname) {
1013 case GL_TEXTURE_MAG_FILTER:
1014 *params = (GLint) obj->MagFilter;
1015 break;
1016 case GL_TEXTURE_MIN_FILTER:
1017 *params = (GLint) obj->MinFilter;
1018 break;
1019 case GL_TEXTURE_WRAP_S:
1020 *params = (GLint) obj->WrapS;
1021 break;
1022 case GL_TEXTURE_WRAP_T:
1023 *params = (GLint) obj->WrapT;
1024 break;
1025 case GL_TEXTURE_WRAP_R_EXT:
1026 *params = (GLint) obj->WrapR;
1027 break;
1028 case GL_TEXTURE_BORDER_COLOR:
1029 {
1030 GLfloat color[4];
1031 color[0] = obj->BorderColor[0] / 255.0F;
1032 color[1] = obj->BorderColor[1] / 255.0F;
1033 color[2] = obj->BorderColor[2] / 255.0F;
1034 color[3] = obj->BorderColor[3] / 255.0F;
1035 params[0] = FLOAT_TO_INT( color[0] );
1036 params[1] = FLOAT_TO_INT( color[1] );
1037 params[2] = FLOAT_TO_INT( color[2] );
1038 params[3] = FLOAT_TO_INT( color[3] );
1039 }
1040 break;
1041 case GL_TEXTURE_RESIDENT:
1042 *params = (GLint) GL_TRUE;
1043 break;
1044 case GL_TEXTURE_PRIORITY:
1045 *params = (GLint) obj->Priority;
1046 break;
1047 case GL_TEXTURE_MIN_LOD:
1048 *params = (GLint) obj->MinLod;
1049 break;
1050 case GL_TEXTURE_MAX_LOD:
1051 *params = (GLint) obj->MaxLod;
1052 break;
1053 case GL_TEXTURE_BASE_LEVEL:
1054 *params = obj->BaseLevel;
1055 break;
1056 case GL_TEXTURE_MAX_LEVEL:
1057 *params = obj->MaxLevel;
1058 break;
1059 default:
1060 gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
1061 }
1062 }
1063
1064
1065
1066
1067 /**********************************************************************/
1068 /* Texture Coord Generation */
1069 /**********************************************************************/
1070
1071
1072 void
1073 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
1074 {
1075 GET_CURRENT_CONTEXT(ctx);
1076 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1077 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1078 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glTexGenfv");
1079
1080 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
1081 fprintf(stderr, "texGEN %s %s %x...\n",
1082 gl_lookup_enum_by_nr(coord),
1083 gl_lookup_enum_by_nr(pname),
1084 *(int *)params);
1085
1086 switch (coord) {
1087 case GL_S:
1088 if (pname==GL_TEXTURE_GEN_MODE) {
1089 GLenum mode = (GLenum) (GLint) *params;
1090 switch (mode) {
1091 case GL_OBJECT_LINEAR:
1092 texUnit->GenModeS = mode;
1093 texUnit->GenBitS = TEXGEN_OBJ_LINEAR;
1094 break;
1095 case GL_EYE_LINEAR:
1096 texUnit->GenModeS = mode;
1097 texUnit->GenBitS = TEXGEN_EYE_LINEAR;
1098 break;
1099 case GL_REFLECTION_MAP_NV:
1100 texUnit->GenModeS = mode;
1101 texUnit->GenBitS = TEXGEN_REFLECTION_MAP_NV;
1102 break;
1103 case GL_NORMAL_MAP_NV:
1104 texUnit->GenModeS = mode;
1105 texUnit->GenBitS = TEXGEN_NORMAL_MAP_NV;
1106 break;
1107 case GL_SPHERE_MAP:
1108 texUnit->GenModeS = mode;
1109 texUnit->GenBitS = TEXGEN_SPHERE_MAP;
1110 break;
1111 default:
1112 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1113 return;
1114 }
1115 }
1116 else if (pname==GL_OBJECT_PLANE) {
1117 texUnit->ObjectPlaneS[0] = params[0];
1118 texUnit->ObjectPlaneS[1] = params[1];
1119 texUnit->ObjectPlaneS[2] = params[2];
1120 texUnit->ObjectPlaneS[3] = params[3];
1121 }
1122 else if (pname==GL_EYE_PLANE) {
1123 /* Transform plane equation by the inverse modelview matrix */
1124 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
1125 gl_matrix_analyze( &ctx->ModelView );
1126 }
1127 gl_transform_vector( texUnit->EyePlaneS, params,
1128 ctx->ModelView.inv );
1129 }
1130 else {
1131 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1132 return;
1133 }
1134 break;
1135 case GL_T:
1136 if (pname==GL_TEXTURE_GEN_MODE) {
1137 GLenum mode = (GLenum) (GLint) *params;
1138 switch (mode) {
1139 case GL_OBJECT_LINEAR:
1140 texUnit->GenModeT = GL_OBJECT_LINEAR;
1141 texUnit->GenBitT = TEXGEN_OBJ_LINEAR;
1142 break;
1143 case GL_EYE_LINEAR:
1144 texUnit->GenModeT = GL_EYE_LINEAR;
1145 texUnit->GenBitT = TEXGEN_EYE_LINEAR;
1146 break;
1147 case GL_REFLECTION_MAP_NV:
1148 texUnit->GenModeT = GL_REFLECTION_MAP_NV;
1149 texUnit->GenBitT = TEXGEN_REFLECTION_MAP_NV;
1150 break;
1151 case GL_NORMAL_MAP_NV:
1152 texUnit->GenModeT = GL_NORMAL_MAP_NV;
1153 texUnit->GenBitT = TEXGEN_NORMAL_MAP_NV;
1154 break;
1155 case GL_SPHERE_MAP:
1156 texUnit->GenModeT = GL_SPHERE_MAP;
1157 texUnit->GenBitT = TEXGEN_SPHERE_MAP;
1158 break;
1159 default:
1160 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1161 return;
1162 }
1163 }
1164 else if (pname==GL_OBJECT_PLANE) {
1165 texUnit->ObjectPlaneT[0] = params[0];
1166 texUnit->ObjectPlaneT[1] = params[1];
1167 texUnit->ObjectPlaneT[2] = params[2];
1168 texUnit->ObjectPlaneT[3] = params[3];
1169 }
1170 else if (pname==GL_EYE_PLANE) {
1171 /* Transform plane equation by the inverse modelview matrix */
1172 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
1173 gl_matrix_analyze( &ctx->ModelView );
1174 }
1175 gl_transform_vector( texUnit->EyePlaneT, params,
1176 ctx->ModelView.inv );
1177 }
1178 else {
1179 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1180 return;
1181 }
1182 break;
1183 case GL_R:
1184 if (pname==GL_TEXTURE_GEN_MODE) {
1185 GLenum mode = (GLenum) (GLint) *params;
1186 switch (mode) {
1187 case GL_OBJECT_LINEAR:
1188 texUnit->GenModeR = GL_OBJECT_LINEAR;
1189 texUnit->GenBitR = TEXGEN_OBJ_LINEAR;
1190 break;
1191 case GL_REFLECTION_MAP_NV:
1192 texUnit->GenModeR = GL_REFLECTION_MAP_NV;
1193 texUnit->GenBitR = TEXGEN_REFLECTION_MAP_NV;
1194 break;
1195 case GL_NORMAL_MAP_NV:
1196 texUnit->GenModeR = GL_NORMAL_MAP_NV;
1197 texUnit->GenBitR = TEXGEN_NORMAL_MAP_NV;
1198 break;
1199 case GL_EYE_LINEAR:
1200 texUnit->GenModeR = GL_EYE_LINEAR;
1201 texUnit->GenBitR = TEXGEN_EYE_LINEAR;
1202 break;
1203 default:
1204 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1205 return;
1206 }
1207 }
1208 else if (pname==GL_OBJECT_PLANE) {
1209 texUnit->ObjectPlaneR[0] = params[0];
1210 texUnit->ObjectPlaneR[1] = params[1];
1211 texUnit->ObjectPlaneR[2] = params[2];
1212 texUnit->ObjectPlaneR[3] = params[3];
1213 }
1214 else if (pname==GL_EYE_PLANE) {
1215 /* Transform plane equation by the inverse modelview matrix */
1216 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
1217 gl_matrix_analyze( &ctx->ModelView );
1218 }
1219 gl_transform_vector( texUnit->EyePlaneR, params,
1220 ctx->ModelView.inv );
1221 }
1222 else {
1223 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1224 return;
1225 }
1226 break;
1227 case GL_Q:
1228 if (pname==GL_TEXTURE_GEN_MODE) {
1229 GLenum mode = (GLenum) (GLint) *params;
1230 switch (mode) {
1231 case GL_OBJECT_LINEAR:
1232 texUnit->GenModeQ = GL_OBJECT_LINEAR;
1233 texUnit->GenBitQ = TEXGEN_OBJ_LINEAR;
1234 break;
1235 case GL_EYE_LINEAR:
1236 texUnit->GenModeQ = GL_EYE_LINEAR;
1237 texUnit->GenBitQ = TEXGEN_EYE_LINEAR;
1238 break;
1239 default:
1240 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
1241 return;
1242 }
1243 }
1244 else if (pname==GL_OBJECT_PLANE) {
1245 texUnit->ObjectPlaneQ[0] = params[0];
1246 texUnit->ObjectPlaneQ[1] = params[1];
1247 texUnit->ObjectPlaneQ[2] = params[2];
1248 texUnit->ObjectPlaneQ[3] = params[3];
1249 }
1250 else if (pname==GL_EYE_PLANE) {
1251 /* Transform plane equation by the inverse modelview matrix */
1252 if (ctx->ModelView.flags & MAT_DIRTY_INVERSE) {
1253 gl_matrix_analyze( &ctx->ModelView );
1254 }
1255 gl_transform_vector( texUnit->EyePlaneQ, params,
1256 ctx->ModelView.inv );
1257 }
1258 else {
1259 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
1260 return;
1261 }
1262 break;
1263 default:
1264 gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
1265 return;
1266 }
1267
1268 ctx->NewState |= NEW_TEXTURING;
1269 }
1270
1271
1272 void
1273 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
1274 {
1275 GLfloat p[4];
1276 p[0] = params[0];
1277 p[1] = params[1];
1278 p[2] = params[2];
1279 p[3] = params[3];
1280 _mesa_TexGenfv(coord, pname, p);
1281 }
1282
1283
1284 void
1285 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
1286 {
1287 GLfloat p = (GLfloat) param;
1288 _mesa_TexGenfv( coord, pname, &p );
1289 }
1290
1291
1292 void
1293 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
1294 {
1295 GLfloat p[4];
1296 p[0] = params[0];
1297 p[1] = params[1];
1298 p[2] = params[2];
1299 p[3] = params[3];
1300 _mesa_TexGenfv( coord, pname, p );
1301 }
1302
1303
1304 void
1305 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
1306 {
1307 _mesa_TexGenfv(coord, pname, &param);
1308 }
1309
1310
1311 void
1312 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
1313 {
1314 _mesa_TexGeniv( coord, pname, &param );
1315 }
1316
1317
1318
1319 void
1320 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
1321 {
1322 GET_CURRENT_CONTEXT(ctx);
1323 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1324 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1325
1326 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGendv");
1327
1328 switch (coord) {
1329 case GL_S:
1330 if (pname==GL_TEXTURE_GEN_MODE) {
1331 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeS);
1332 }
1333 else if (pname==GL_OBJECT_PLANE) {
1334 COPY_4V( params, texUnit->ObjectPlaneS );
1335 }
1336 else if (pname==GL_EYE_PLANE) {
1337 COPY_4V( params, texUnit->EyePlaneS );
1338 }
1339 else {
1340 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
1341 return;
1342 }
1343 break;
1344 case GL_T:
1345 if (pname==GL_TEXTURE_GEN_MODE) {
1346 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeT);
1347 }
1348 else if (pname==GL_OBJECT_PLANE) {
1349 COPY_4V( params, texUnit->ObjectPlaneT );
1350 }
1351 else if (pname==GL_EYE_PLANE) {
1352 COPY_4V( params, texUnit->EyePlaneT );
1353 }
1354 else {
1355 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
1356 return;
1357 }
1358 break;
1359 case GL_R:
1360 if (pname==GL_TEXTURE_GEN_MODE) {
1361 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeR);
1362 }
1363 else if (pname==GL_OBJECT_PLANE) {
1364 COPY_4V( params, texUnit->ObjectPlaneR );
1365 }
1366 else if (pname==GL_EYE_PLANE) {
1367 COPY_4V( params, texUnit->EyePlaneR );
1368 }
1369 else {
1370 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
1371 return;
1372 }
1373 break;
1374 case GL_Q:
1375 if (pname==GL_TEXTURE_GEN_MODE) {
1376 params[0] = ENUM_TO_DOUBLE(texUnit->GenModeQ);
1377 }
1378 else if (pname==GL_OBJECT_PLANE) {
1379 COPY_4V( params, texUnit->ObjectPlaneQ );
1380 }
1381 else if (pname==GL_EYE_PLANE) {
1382 COPY_4V( params, texUnit->EyePlaneQ );
1383 }
1384 else {
1385 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
1386 return;
1387 }
1388 break;
1389 default:
1390 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
1391 return;
1392 }
1393 }
1394
1395
1396
1397 void
1398 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
1399 {
1400 GET_CURRENT_CONTEXT(ctx);
1401 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1402 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1403
1404 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGenfv");
1405
1406 switch (coord) {
1407 case GL_S:
1408 if (pname==GL_TEXTURE_GEN_MODE) {
1409 params[0] = ENUM_TO_FLOAT(texUnit->GenModeS);
1410 }
1411 else if (pname==GL_OBJECT_PLANE) {
1412 COPY_4V( params, texUnit->ObjectPlaneS );
1413 }
1414 else if (pname==GL_EYE_PLANE) {
1415 COPY_4V( params, texUnit->EyePlaneS );
1416 }
1417 else {
1418 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1419 return;
1420 }
1421 break;
1422 case GL_T:
1423 if (pname==GL_TEXTURE_GEN_MODE) {
1424 params[0] = ENUM_TO_FLOAT(texUnit->GenModeT);
1425 }
1426 else if (pname==GL_OBJECT_PLANE) {
1427 COPY_4V( params, texUnit->ObjectPlaneT );
1428 }
1429 else if (pname==GL_EYE_PLANE) {
1430 COPY_4V( params, texUnit->EyePlaneT );
1431 }
1432 else {
1433 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1434 return;
1435 }
1436 break;
1437 case GL_R:
1438 if (pname==GL_TEXTURE_GEN_MODE) {
1439 params[0] = ENUM_TO_FLOAT(texUnit->GenModeR);
1440 }
1441 else if (pname==GL_OBJECT_PLANE) {
1442 COPY_4V( params, texUnit->ObjectPlaneR );
1443 }
1444 else if (pname==GL_EYE_PLANE) {
1445 COPY_4V( params, texUnit->EyePlaneR );
1446 }
1447 else {
1448 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1449 return;
1450 }
1451 break;
1452 case GL_Q:
1453 if (pname==GL_TEXTURE_GEN_MODE) {
1454 params[0] = ENUM_TO_FLOAT(texUnit->GenModeQ);
1455 }
1456 else if (pname==GL_OBJECT_PLANE) {
1457 COPY_4V( params, texUnit->ObjectPlaneQ );
1458 }
1459 else if (pname==GL_EYE_PLANE) {
1460 COPY_4V( params, texUnit->EyePlaneQ );
1461 }
1462 else {
1463 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
1464 return;
1465 }
1466 break;
1467 default:
1468 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
1469 return;
1470 }
1471 }
1472
1473
1474
1475 void
1476 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
1477 {
1478 GET_CURRENT_CONTEXT(ctx);
1479 GLuint tUnit = ctx->Texture.CurrentTransformUnit;
1480 struct gl_texture_unit *texUnit = &ctx->Texture.Unit[tUnit];
1481
1482 ASSERT_OUTSIDE_BEGIN_END_AND_FLUSH(ctx, "glGetTexGeniv");
1483
1484 switch (coord) {
1485 case GL_S:
1486 if (pname==GL_TEXTURE_GEN_MODE) {
1487 params[0] = texUnit->GenModeS;
1488 }
1489 else if (pname==GL_OBJECT_PLANE) {
1490 params[0] = (GLint) texUnit->ObjectPlaneS[0];
1491 params[1] = (GLint) texUnit->ObjectPlaneS[1];
1492 params[2] = (GLint) texUnit->ObjectPlaneS[2];
1493 params[3] = (GLint) texUnit->ObjectPlaneS[3];
1494 }
1495 else if (pname==GL_EYE_PLANE) {
1496 params[0] = (GLint) texUnit->EyePlaneS[0];
1497 params[1] = (GLint) texUnit->EyePlaneS[1];
1498 params[2] = (GLint) texUnit->EyePlaneS[2];
1499 params[3] = (GLint) texUnit->EyePlaneS[3];
1500 }
1501 else {
1502 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1503 return;
1504 }
1505 break;
1506 case GL_T:
1507 if (pname==GL_TEXTURE_GEN_MODE) {
1508 params[0] = texUnit->GenModeT;
1509 }
1510 else if (pname==GL_OBJECT_PLANE) {
1511 params[0] = (GLint) texUnit->ObjectPlaneT[0];
1512 params[1] = (GLint) texUnit->ObjectPlaneT[1];
1513 params[2] = (GLint) texUnit->ObjectPlaneT[2];
1514 params[3] = (GLint) texUnit->ObjectPlaneT[3];
1515 }
1516 else if (pname==GL_EYE_PLANE) {
1517 params[0] = (GLint) texUnit->EyePlaneT[0];
1518 params[1] = (GLint) texUnit->EyePlaneT[1];
1519 params[2] = (GLint) texUnit->EyePlaneT[2];
1520 params[3] = (GLint) texUnit->EyePlaneT[3];
1521 }
1522 else {
1523 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1524 return;
1525 }
1526 break;
1527 case GL_R:
1528 if (pname==GL_TEXTURE_GEN_MODE) {
1529 params[0] = texUnit->GenModeR;
1530 }
1531 else if (pname==GL_OBJECT_PLANE) {
1532 params[0] = (GLint) texUnit->ObjectPlaneR[0];
1533 params[1] = (GLint) texUnit->ObjectPlaneR[1];
1534 params[2] = (GLint) texUnit->ObjectPlaneR[2];
1535 params[3] = (GLint) texUnit->ObjectPlaneR[3];
1536 }
1537 else if (pname==GL_EYE_PLANE) {
1538 params[0] = (GLint) texUnit->EyePlaneR[0];
1539 params[1] = (GLint) texUnit->EyePlaneR[1];
1540 params[2] = (GLint) texUnit->EyePlaneR[2];
1541 params[3] = (GLint) texUnit->EyePlaneR[3];
1542 }
1543 else {
1544 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1545 return;
1546 }
1547 break;
1548 case GL_Q:
1549 if (pname==GL_TEXTURE_GEN_MODE) {
1550 params[0] = texUnit->GenModeQ;
1551 }
1552 else if (pname==GL_OBJECT_PLANE) {
1553 params[0] = (GLint) texUnit->ObjectPlaneQ[0];
1554 params[1] = (GLint) texUnit->ObjectPlaneQ[1];
1555 params[2] = (GLint) texUnit->ObjectPlaneQ[2];
1556 params[3] = (GLint) texUnit->ObjectPlaneQ[3];
1557 }
1558 else if (pname==GL_EYE_PLANE) {
1559 params[0] = (GLint) texUnit->EyePlaneQ[0];
1560 params[1] = (GLint) texUnit->EyePlaneQ[1];
1561 params[2] = (GLint) texUnit->EyePlaneQ[2];
1562 params[3] = (GLint) texUnit->EyePlaneQ[3];
1563 }
1564 else {
1565 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
1566 return;
1567 }
1568 break;
1569 default:
1570 gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
1571 return;
1572 }
1573 }
1574
1575
1576 /* GL_ARB_multitexture */
1577 void
1578 _mesa_ActiveTextureARB( GLenum target )
1579 {
1580 GET_CURRENT_CONTEXT(ctx);
1581 GLint maxUnits = ctx->Const.MaxTextureUnits;
1582
1583 ASSERT_OUTSIDE_BEGIN_END( ctx, "glActiveTextureARB" );
1584
1585 if (MESA_VERBOSE & (VERBOSE_API|VERBOSE_TEXTURE))
1586 fprintf(stderr, "glActiveTexture %s\n",
1587 gl_lookup_enum_by_nr(target));
1588
1589 if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
1590 GLint texUnit = target - GL_TEXTURE0_ARB;
1591 ctx->Texture.CurrentUnit = texUnit;
1592 ctx->Texture.CurrentTransformUnit = texUnit;
1593 if (ctx->Driver.ActiveTexture) {
1594 (*ctx->Driver.ActiveTexture)( ctx, (GLuint) texUnit );
1595 }
1596 }
1597 else {
1598 gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
1599 }
1600 }
1601
1602
1603 /* GL_ARB_multitexture */
1604 void
1605 _mesa_ClientActiveTextureARB( GLenum target )
1606 {
1607 GET_CURRENT_CONTEXT(ctx);
1608 GLint maxUnits = ctx->Const.MaxTextureUnits;
1609
1610 ASSERT_OUTSIDE_BEGIN_END( ctx, "glClientActiveTextureARB" );
1611
1612 if (target >= GL_TEXTURE0_ARB && target < GL_TEXTURE0_ARB + maxUnits) {
1613 GLint texUnit = target - GL_TEXTURE0_ARB;
1614 ctx->Array.ActiveTexture = texUnit;
1615 }
1616 else {
1617 gl_error(ctx, GL_INVALID_OPERATION, "glActiveTextureARB(target)");
1618 }
1619 }
1620
1621
1622
1623 /*
1624 * Put the given texture object into the list of dirty texture objects.
1625 * When a texture object is dirty we have to reexamine it for completeness
1626 * and perhaps choose a different texture sampling function.
1627 */
1628 void gl_put_texobj_on_dirty_list( GLcontext *ctx, struct gl_texture_object *t )
1629 {
1630 ASSERT(ctx);
1631 ASSERT(t);
1632 /* Only insert if not already in the dirty list.
1633 * The Dirty flag is only set iff the texture object is in the dirty list.
1634 */
1635 if (!t->Dirty) {
1636 ASSERT(t->NextDirty == NULL);
1637 t->Dirty = GL_TRUE;
1638 t->NextDirty = ctx->Shared->DirtyTexObjList;
1639 ctx->Shared->DirtyTexObjList = t;
1640 }
1641 #ifdef DEBUG
1642 else {
1643 /* make sure t is in the list */
1644 struct gl_texture_object *obj = ctx->Shared->DirtyTexObjList;
1645 while (obj) {
1646 if (obj == t) {
1647 return;
1648 }
1649 obj = obj->NextDirty;
1650 }
1651 gl_problem(ctx, "Error in gl_put_texobj_on_dirty_list");
1652 }
1653 #endif
1654 }
1655
1656
1657 /*
1658 * Remove a texture object from the dirty texture list.
1659 */
1660 void gl_remove_texobj_from_dirty_list( struct gl_shared_state *shared,
1661 struct gl_texture_object *tObj )
1662 {
1663 struct gl_texture_object *t, *prev = NULL;
1664 ASSERT(shared);
1665 ASSERT(tObj);
1666 for (t = shared->DirtyTexObjList; t; t = t->NextDirty) {
1667 if (t == tObj) {
1668 if (prev) {
1669 prev->NextDirty = t->NextDirty;
1670 }
1671 else {
1672 shared->DirtyTexObjList = t->NextDirty;
1673 }
1674 return;
1675 }
1676 prev = t;
1677 }
1678 }
1679
1680
1681 /*
1682 * This is called by gl_update_state() if the NEW_TEXTURING bit in
1683 * ctx->NewState is set.
1684 */
1685 void gl_update_dirty_texobjs( GLcontext *ctx )
1686 {
1687 struct gl_texture_object *t, *next;
1688 for (t = ctx->Shared->DirtyTexObjList; t; t = next) {
1689 next = t->NextDirty;
1690 _mesa_test_texobj_completeness(ctx, t);
1691 _mesa_set_texture_sampler(t);
1692 t->NextDirty = NULL;
1693 t->Dirty = GL_FALSE;
1694 }
1695 ctx->Shared->DirtyTexObjList = NULL;
1696 }