xref: /reactos/dll/opengl/mesa/texstate.c (revision 1734f297)
1 /* $Id: texstate.c,v 1.10 1998/02/03 23:45:02 brianp Exp $ */
2 
3 /*
4  * Mesa 3-D graphics library
5  * Version:  2.6
6  * Copyright (C) 1995-1997  Brian Paul
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Library General Public
10  * License as published by the Free Software Foundation; either
11  * version 2 of the License, or (at your option) any later version.
12  *
13  * This library is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * Library General Public License for more details.
17  *
18  * You should have received a copy of the GNU Library General Public
19  * License along with this library; if not, write to the Free
20  * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21  */
22 
23 
24 /*
25  * $Log: texstate.c,v $
26  * Revision 1.10  1998/02/03 23:45:02  brianp
27  * added casts to prevent warnings with Amiga StormC compiler
28  *
29  * Revision 1.9  1997/12/31 06:10:03  brianp
30  * added Henk Kok's texture validation optimization (AnyDirty flag)
31  *
32  * Revision 1.8  1997/10/13 23:56:01  brianp
33  * replaced UpdateTexture() call with TexParameter()
34  *
35  * Revision 1.7  1997/09/29 23:28:14  brianp
36  * updated for new device driver texture functions
37  *
38  * Revision 1.6  1997/09/27 00:14:39  brianp
39  * added GL_EXT_paletted_texture extension
40  *
41  * Revision 1.5  1997/07/24 01:25:34  brianp
42  * changed precompiled header symbol from PCH to PC_HEADER
43  *
44  * Revision 1.4  1997/05/28 03:26:49  brianp
45  * added precompiled header (PCH) support
46  *
47  * Revision 1.3  1997/05/03 00:53:28  brianp
48  * misc changes related to new texture object sampling function pointer
49  *
50  * Revision 1.2  1997/04/28 23:34:39  brianp
51  * simplified gl_update_texture_state()
52  *
53  * Revision 1.1  1997/04/14 01:59:54  brianp
54  * Initial revision
55  *
56  */
57 
58 
59 #ifdef PC_HEADER
60 #include "all.h"
61 #else
62 #include "context.h"
63 #include "macros.h"
64 #include "matrix.h"
65 #include "texobj.h"
66 #include "texstate.h"
67 #include "texture.h"
68 #include "types.h"
69 #include "xform.h"
70 #endif
71 
72 
73 #ifdef SPECIALCAST
74 /* Needed for an Amiga compiler */
75 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
76 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
77 #else
78 /* all other compilers */
79 #define ENUM_TO_FLOAT(X) ((GLfloat)(X))
80 #define ENUM_TO_DOUBLE(X) ((GLdouble)(X))
81 #endif
82 
83 
84 
85 /**********************************************************************/
86 /*                       Texture Environment                          */
87 /**********************************************************************/
88 
89 
90 void gl_TexEnvfv( GLcontext *ctx,
91                   GLenum target, GLenum pname, const GLfloat *param )
92 {
93    if (INSIDE_BEGIN_END(ctx)) {
94       gl_error( ctx, GL_INVALID_OPERATION, "glTexEnv" );
95       return;
96    }
97 
98    if (target!=GL_TEXTURE_ENV) {
99       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(target)" );
100       return;
101    }
102 
103    if (pname==GL_TEXTURE_ENV_MODE) {
104       GLenum mode = (GLenum) (GLint) *param;
105       switch (mode) {
106 	 case GL_MODULATE:
107 	 case GL_BLEND:
108 	 case GL_DECAL:
109 	 case GL_REPLACE:
110 	    ctx->Texture.EnvMode = mode;
111 	    break;
112 	 default:
113 	    gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(param)" );
114 	    return;
115       }
116    }
117    else if (pname==GL_TEXTURE_ENV_COLOR) {
118       ctx->Texture.EnvColor[0] = CLAMP( param[0], 0.0, 1.0 );
119       ctx->Texture.EnvColor[1] = CLAMP( param[1], 0.0, 1.0 );
120       ctx->Texture.EnvColor[2] = CLAMP( param[2], 0.0, 1.0 );
121       ctx->Texture.EnvColor[3] = CLAMP( param[3], 0.0, 1.0 );
122    }
123    else {
124       gl_error( ctx, GL_INVALID_ENUM, "glTexEnv(pname)" );
125       return;
126    }
127 
128    /* Tell device driver about the new texture environment */
129    if (ctx->Driver.TexEnv) {
130       (*ctx->Driver.TexEnv)( ctx, pname, param );
131    }
132 }
133 
134 
135 
136 
137 
138 void gl_GetTexEnvfv( GLcontext *ctx,
139                      GLenum target, GLenum pname, GLfloat *params )
140 {
141    if (target!=GL_TEXTURE_ENV) {
142       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
143       return;
144    }
145    switch (pname) {
146       case GL_TEXTURE_ENV_MODE:
147          *params = ENUM_TO_FLOAT(ctx->Texture.EnvMode);
148 	 break;
149       case GL_TEXTURE_ENV_COLOR:
150 	 COPY_4V( params, ctx->Texture.EnvColor );
151 	 break;
152       default:
153          gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
154    }
155 }
156 
157 
158 void gl_GetTexEnviv( GLcontext *ctx,
159                      GLenum target, GLenum pname, GLint *params )
160 {
161    if (target!=GL_TEXTURE_ENV) {
162       gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(target)" );
163       return;
164    }
165    switch (pname) {
166       case GL_TEXTURE_ENV_MODE:
167          *params = (GLint) ctx->Texture.EnvMode;
168 	 break;
169       case GL_TEXTURE_ENV_COLOR:
170 	 params[0] = FLOAT_TO_INT( ctx->Texture.EnvColor[0] );
171 	 params[1] = FLOAT_TO_INT( ctx->Texture.EnvColor[1] );
172 	 params[2] = FLOAT_TO_INT( ctx->Texture.EnvColor[2] );
173 	 params[3] = FLOAT_TO_INT( ctx->Texture.EnvColor[3] );
174 	 break;
175       default:
176          gl_error( ctx, GL_INVALID_ENUM, "glGetTexEnvfv(pname)" );
177    }
178 }
179 
180 
181 
182 
183 /**********************************************************************/
184 /*                       Texture Parameters                           */
185 /**********************************************************************/
186 
187 
188 void gl_TexParameterfv( GLcontext *ctx,
189                         GLenum target, GLenum pname, const GLfloat *params )
190 {
191    GLenum eparam = (GLenum) (GLint) params[0];
192    struct gl_texture_object *texObj;
193 
194    switch (target) {
195       case GL_TEXTURE_1D:
196          texObj = ctx->Texture.Current1D;
197          break;
198       case GL_TEXTURE_2D:
199          texObj = ctx->Texture.Current2D;
200          break;
201       default:
202          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(target)" );
203          return;
204    }
205 
206    switch (pname) {
207       case GL_TEXTURE_MIN_FILTER:
208          if (eparam==GL_NEAREST || eparam==GL_LINEAR
209              || eparam==GL_NEAREST_MIPMAP_NEAREST
210              || eparam==GL_LINEAR_MIPMAP_NEAREST
211              || eparam==GL_NEAREST_MIPMAP_LINEAR
212              || eparam==GL_LINEAR_MIPMAP_LINEAR) {
213             texObj->MinFilter = eparam;
214             ctx->NewState |= NEW_TEXTURING;
215          }
216          else {
217             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
218             return;
219          }
220          break;
221       case GL_TEXTURE_MAG_FILTER:
222          if (eparam==GL_NEAREST || eparam==GL_LINEAR) {
223             texObj->MagFilter = eparam;
224             ctx->NewState |= NEW_TEXTURING;
225          }
226          else {
227             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
228             return;
229          }
230          break;
231       case GL_TEXTURE_WRAP_S:
232          if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
233             texObj->WrapS = eparam;
234          }
235          else {
236             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
237             return;
238          }
239          break;
240       case GL_TEXTURE_WRAP_T:
241          if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
242             texObj->WrapT = eparam;
243          }
244          else {
245             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
246             return;
247          }
248          break;
249       case GL_TEXTURE_WRAP_R_EXT:
250          if (eparam==GL_CLAMP || eparam==GL_REPEAT) {
251             texObj->WrapR = eparam;
252          }
253          else {
254             gl_error( ctx, GL_INVALID_VALUE, "glTexParameter(param)" );
255          }
256          break;
257       case GL_TEXTURE_BORDER_COLOR:
258          texObj->BorderColor[0] = CLAMP((GLint)(params[0]*255.0), 0, 255);
259          texObj->BorderColor[1] = CLAMP((GLint)(params[1]*255.0), 0, 255);
260          texObj->BorderColor[2] = CLAMP((GLint)(params[2]*255.0), 0, 255);
261          texObj->BorderColor[3] = CLAMP((GLint)(params[3]*255.0), 0, 255);
262          break;
263       default:
264          gl_error( ctx, GL_INVALID_ENUM, "glTexParameter(pname)" );
265          return;
266    }
267 
268    texObj->Dirty = GL_TRUE;
269    ctx->Texture.AnyDirty = GL_TRUE;
270 
271    if (ctx->Driver.TexParameter) {
272       (*ctx->Driver.TexParameter)( ctx, target, texObj, pname, params );
273    }
274 }
275 
276 
277 
278 void gl_GetTexLevelParameterfv( GLcontext *ctx, GLenum target, GLint level,
279                                 GLenum pname, GLfloat *params )
280 {
281    GLint iparam;
282 
283    gl_GetTexLevelParameteriv( ctx, target, level, pname, &iparam );
284    *params = (GLfloat) iparam;
285 }
286 
287 
288 
289 void gl_GetTexLevelParameteriv( GLcontext *ctx, GLenum target, GLint level,
290                                 GLenum pname, GLint *params )
291 {
292    struct gl_texture_image *tex;
293 
294    if (level<0 || level>=MAX_TEXTURE_LEVELS) {
295       gl_error( ctx, GL_INVALID_VALUE, "glGetTexLevelParameter[if]v" );
296       return;
297    }
298 
299    switch (target) {
300       case GL_TEXTURE_1D:
301          tex = ctx->Texture.Current1D->Image[level];
302          switch (pname) {
303 	    case GL_TEXTURE_WIDTH:
304 	       *params = tex->Width;
305 	       break;
306 	    case GL_TEXTURE_COMPONENTS:
307 	       *params = tex->Format;
308 	       break;
309 	    case GL_TEXTURE_BORDER:
310 	       *params = tex->Border;
311 	       break;
312             case GL_TEXTURE_RED_SIZE:
313             case GL_TEXTURE_GREEN_SIZE:
314             case GL_TEXTURE_BLUE_SIZE:
315             case GL_TEXTURE_ALPHA_SIZE:
316             case GL_TEXTURE_INTENSITY_SIZE:
317             case GL_TEXTURE_LUMINANCE_SIZE:
318                *params = 8;  /* 8-bits */
319                break;
320             case GL_TEXTURE_INDEX_SIZE_EXT:
321                *params = 8;
322                break;
323 	    default:
324 	       gl_error( ctx, GL_INVALID_ENUM,
325                          "glGetTexLevelParameter[if]v(pname)" );
326 	 }
327 	 break;
328       case GL_TEXTURE_2D:
329          tex = ctx->Texture.Current2D->Image[level];
330 	 switch (pname) {
331 	    case GL_TEXTURE_WIDTH:
332 	       *params = tex->Width;
333 	       break;
334 	    case GL_TEXTURE_HEIGHT:
335 	       *params = tex->Height;
336 	       break;
337 	    case GL_TEXTURE_COMPONENTS:
338 	       *params = tex->Format;
339 	       break;
340 	    case GL_TEXTURE_BORDER:
341 	       *params = tex->Border;
342 	       break;
343             case GL_TEXTURE_RED_SIZE:
344             case GL_TEXTURE_GREEN_SIZE:
345             case GL_TEXTURE_BLUE_SIZE:
346             case GL_TEXTURE_ALPHA_SIZE:
347             case GL_TEXTURE_INTENSITY_SIZE:
348             case GL_TEXTURE_LUMINANCE_SIZE:
349                *params = 8;  /* 8-bits */
350                break;
351             case GL_TEXTURE_INDEX_SIZE_EXT:
352                *params = 8;
353                break;
354 	    default:
355 	       gl_error( ctx, GL_INVALID_ENUM,
356                          "glGetTexLevelParameter[if]v(pname)" );
357 	 }
358 	 break;
359       case GL_PROXY_TEXTURE_1D:
360          tex = ctx->Texture.Proxy1D->Image[level];
361          switch (pname) {
362 	    case GL_TEXTURE_WIDTH:
363 	       *params = tex->Width;
364 	       break;
365 	    case GL_TEXTURE_COMPONENTS:
366 	       *params = tex->Format;
367 	       break;
368 	    case GL_TEXTURE_BORDER:
369 	       *params = tex->Border;
370 	       break;
371             case GL_TEXTURE_RED_SIZE:
372             case GL_TEXTURE_GREEN_SIZE:
373             case GL_TEXTURE_BLUE_SIZE:
374             case GL_TEXTURE_ALPHA_SIZE:
375             case GL_TEXTURE_INTENSITY_SIZE:
376             case GL_TEXTURE_LUMINANCE_SIZE:
377                *params = 8;  /* 8-bits */
378                break;
379             case GL_TEXTURE_INDEX_SIZE_EXT:
380                *params = 8;
381                break;
382 	    default:
383 	       gl_error( ctx, GL_INVALID_ENUM,
384                          "glGetTexLevelParameter[if]v(pname)" );
385 	 }
386 	 break;
387       case GL_PROXY_TEXTURE_2D:
388          tex = ctx->Texture.Proxy2D->Image[level];
389 	 switch (pname) {
390 	    case GL_TEXTURE_WIDTH:
391 	       *params = tex->Width;
392 	       break;
393 	    case GL_TEXTURE_HEIGHT:
394 	       *params = tex->Height;
395 	       break;
396 	    case GL_TEXTURE_COMPONENTS:
397 	       *params = tex->Format;
398 	       break;
399 	    case GL_TEXTURE_BORDER:
400 	       *params = tex->Border;
401 	       break;
402             case GL_TEXTURE_RED_SIZE:
403             case GL_TEXTURE_GREEN_SIZE:
404             case GL_TEXTURE_BLUE_SIZE:
405             case GL_TEXTURE_ALPHA_SIZE:
406             case GL_TEXTURE_INTENSITY_SIZE:
407             case GL_TEXTURE_LUMINANCE_SIZE:
408                *params = 8;  /* 8-bits */
409                break;
410             case GL_TEXTURE_INDEX_SIZE_EXT:
411                *params = 8;
412                break;
413 	    default:
414 	       gl_error( ctx, GL_INVALID_ENUM,
415                          "glGetTexLevelParameter[if]v(pname)" );
416 	 }
417 	 break;
418      default:
419 	 gl_error(ctx, GL_INVALID_ENUM, "glGetTexLevelParameter[if]v(target)");
420    }
421 }
422 
423 
424 
425 
426 void gl_GetTexParameterfv( GLcontext *ctx,
427                            GLenum target, GLenum pname, GLfloat *params )
428 {
429    switch (target) {
430       case GL_TEXTURE_1D:
431          switch (pname) {
432 	    case GL_TEXTURE_MAG_FILTER:
433 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current1D->MagFilter);
434 	       break;
435 	    case GL_TEXTURE_MIN_FILTER:
436 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current1D->MinFilter);
437 	       break;
438 	    case GL_TEXTURE_WRAP_S:
439 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current1D->WrapS);
440 	       break;
441 	    case GL_TEXTURE_WRAP_T:
442 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current1D->WrapT);
443 	       break;
444 	    case GL_TEXTURE_BORDER_COLOR:
445                params[0] = ctx->Texture.Current1D->BorderColor[0] / 255.0f;
446                params[1] = ctx->Texture.Current1D->BorderColor[1] / 255.0f;
447                params[2] = ctx->Texture.Current1D->BorderColor[2] / 255.0f;
448                params[3] = ctx->Texture.Current1D->BorderColor[3] / 255.0f;
449 	       break;
450 	    case GL_TEXTURE_RESIDENT:
451                *params = ENUM_TO_FLOAT(GL_TRUE);
452 	       break;
453             case GL_TEXTURE_PRIORITY:
454                *params = ctx->Texture.Current1D->Priority;
455 	       break;
456 	    default:
457 	       gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
458 	 }
459          break;
460       case GL_TEXTURE_2D:
461          switch (pname) {
462 	    case GL_TEXTURE_MAG_FILTER:
463 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current2D->MagFilter);
464 	       break;
465 	    case GL_TEXTURE_MIN_FILTER:
466 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current2D->MinFilter);
467 	       break;
468 	    case GL_TEXTURE_WRAP_S:
469 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current2D->WrapS);
470 	       break;
471 	    case GL_TEXTURE_WRAP_T:
472 	       *params = ENUM_TO_FLOAT(ctx->Texture.Current2D->WrapT);
473 	       break;
474 	    case GL_TEXTURE_BORDER_COLOR:
475                params[0] = ctx->Texture.Current2D->BorderColor[0] / 255.0f;
476                params[1] = ctx->Texture.Current2D->BorderColor[1] / 255.0f;
477                params[2] = ctx->Texture.Current2D->BorderColor[2] / 255.0f;
478                params[3] = ctx->Texture.Current2D->BorderColor[3] / 255.0f;
479                break;
480 	    case GL_TEXTURE_RESIDENT:
481                *params = ENUM_TO_FLOAT(GL_TRUE);
482 	       break;
483 	    case GL_TEXTURE_PRIORITY:
484                *params = ctx->Texture.Current2D->Priority;
485 	       break;
486 	    default:
487 	       gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(pname)" );
488 	 }
489 	 break;
490       default:
491          gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameterfv(target)" );
492    }
493 }
494 
495 
496 void gl_GetTexParameteriv( GLcontext *ctx,
497                            GLenum target, GLenum pname, GLint *params )
498 {
499    switch (target) {
500       case GL_TEXTURE_1D:
501          switch (pname) {
502 	    case GL_TEXTURE_MAG_FILTER:
503 	       *params = (GLint) ctx->Texture.Current1D->MagFilter;
504 	       break;
505 	    case GL_TEXTURE_MIN_FILTER:
506 	       *params = (GLint) ctx->Texture.Current1D->MinFilter;
507 	       break;
508 	    case GL_TEXTURE_WRAP_S:
509 	       *params = (GLint) ctx->Texture.Current1D->WrapS;
510 	       break;
511 	    case GL_TEXTURE_WRAP_T:
512 	       *params = (GLint) ctx->Texture.Current1D->WrapT;
513 	       break;
514 	    case GL_TEXTURE_BORDER_COLOR:
515                {
516                   GLfloat color[4];
517                   color[0] = ctx->Texture.Current1D->BorderColor[0]/255.0;
518                   color[1] = ctx->Texture.Current1D->BorderColor[1]/255.0;
519                   color[2] = ctx->Texture.Current1D->BorderColor[2]/255.0;
520                   color[3] = ctx->Texture.Current1D->BorderColor[3]/255.0;
521                   params[0] = FLOAT_TO_INT( color[0] );
522                   params[1] = FLOAT_TO_INT( color[1] );
523                   params[2] = FLOAT_TO_INT( color[2] );
524                   params[3] = FLOAT_TO_INT( color[3] );
525                }
526 	       break;
527 	    case GL_TEXTURE_RESIDENT:
528                *params = (GLint) GL_TRUE;
529 	       break;
530 	    case GL_TEXTURE_PRIORITY:
531                *params = (GLint) ctx->Texture.Current1D->Priority;
532 	       break;
533 	    default:
534 	       gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
535 	 }
536          break;
537       case GL_TEXTURE_2D:
538          switch (pname) {
539 	    case GL_TEXTURE_MAG_FILTER:
540 	       *params = (GLint) ctx->Texture.Current2D->MagFilter;
541 	       break;
542 	    case GL_TEXTURE_MIN_FILTER:
543 	       *params = (GLint) ctx->Texture.Current2D->MinFilter;
544 	       break;
545 	    case GL_TEXTURE_WRAP_S:
546 	       *params = (GLint) ctx->Texture.Current2D->WrapS;
547 	       break;
548 	    case GL_TEXTURE_WRAP_T:
549 	       *params = (GLint) ctx->Texture.Current2D->WrapT;
550 	       break;
551 	    case GL_TEXTURE_BORDER_COLOR:
552                {
553                   GLfloat color[4];
554                   color[0] = ctx->Texture.Current2D->BorderColor[0]/255.0;
555                   color[1] = ctx->Texture.Current2D->BorderColor[1]/255.0;
556                   color[2] = ctx->Texture.Current2D->BorderColor[2]/255.0;
557                   color[3] = ctx->Texture.Current2D->BorderColor[3]/255.0;
558                   params[0] = FLOAT_TO_INT( color[0] );
559                   params[1] = FLOAT_TO_INT( color[1] );
560                   params[2] = FLOAT_TO_INT( color[2] );
561                   params[3] = FLOAT_TO_INT( color[3] );
562                }
563 	       break;
564 	    case GL_TEXTURE_RESIDENT:
565                *params = (GLint) GL_TRUE;
566 	       break;
567 	    case GL_TEXTURE_PRIORITY:
568                *params = (GLint) ctx->Texture.Current2D->Priority;
569 	       break;
570 	    default:
571 	       gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(pname)" );
572 	 }
573 	 break;
574       default:
575          gl_error( ctx, GL_INVALID_ENUM, "glGetTexParameteriv(target)" );
576    }
577 }
578 
579 
580 
581 
582 /**********************************************************************/
583 /*                    Texture Coord Generation                        */
584 /**********************************************************************/
585 
586 
587 void gl_TexGenfv( GLcontext *ctx,
588                   GLenum coord, GLenum pname, const GLfloat *params )
589 {
590    if (INSIDE_BEGIN_END(ctx)) {
591       gl_error( ctx, GL_INVALID_OPERATION, "glTexGenfv" );
592       return;
593    }
594 
595    switch( coord ) {
596       case GL_S:
597          if (pname==GL_TEXTURE_GEN_MODE) {
598 	    GLenum mode = (GLenum) (GLint) *params;
599 	    if (mode==GL_OBJECT_LINEAR ||
600 		mode==GL_EYE_LINEAR ||
601 		mode==GL_SPHERE_MAP) {
602 	       ctx->Texture.GenModeS = mode;
603 	    }
604 	    else {
605 	       gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
606 	       return;
607 	    }
608 	 }
609 	 else if (pname==GL_OBJECT_PLANE) {
610 	    ctx->Texture.ObjectPlaneS[0] = params[0];
611 	    ctx->Texture.ObjectPlaneS[1] = params[1];
612 	    ctx->Texture.ObjectPlaneS[2] = params[2];
613 	    ctx->Texture.ObjectPlaneS[3] = params[3];
614 	 }
615 	 else if (pname==GL_EYE_PLANE) {
616             /* Transform plane equation by the inverse modelview matrix */
617             if (ctx->NewModelViewMatrix) {
618                gl_analyze_modelview_matrix(ctx);
619             }
620             gl_transform_vector( ctx->Texture.EyePlaneS, params,
621                                  ctx->ModelViewInv );
622 	 }
623 	 else {
624 	    gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
625 	    return;
626 	 }
627 	 break;
628       case GL_T:
629          if (pname==GL_TEXTURE_GEN_MODE) {
630 	    GLenum mode = (GLenum) (GLint) *params;
631 	    if (mode==GL_OBJECT_LINEAR ||
632 		mode==GL_EYE_LINEAR ||
633 		mode==GL_SPHERE_MAP) {
634 	       ctx->Texture.GenModeT = mode;
635 	    }
636 	    else {
637 	       gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
638 	       return;
639 	    }
640 	 }
641 	 else if (pname==GL_OBJECT_PLANE) {
642 	    ctx->Texture.ObjectPlaneT[0] = params[0];
643 	    ctx->Texture.ObjectPlaneT[1] = params[1];
644 	    ctx->Texture.ObjectPlaneT[2] = params[2];
645 	    ctx->Texture.ObjectPlaneT[3] = params[3];
646 	 }
647 	 else if (pname==GL_EYE_PLANE) {
648             /* Transform plane equation by the inverse modelview matrix */
649             if (ctx->NewModelViewMatrix) {
650                gl_analyze_modelview_matrix(ctx);
651             }
652             gl_transform_vector( ctx->Texture.EyePlaneT, params,
653                                  ctx->ModelViewInv );
654 	 }
655 	 else {
656 	    gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
657 	    return;
658 	 }
659 	 break;
660       case GL_R:
661          if (pname==GL_TEXTURE_GEN_MODE) {
662 	    GLenum mode = (GLenum) (GLint) *params;
663 	    if (mode==GL_OBJECT_LINEAR ||
664 		mode==GL_EYE_LINEAR) {
665 	       ctx->Texture.GenModeR = mode;
666 	    }
667 	    else {
668 	       gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
669 	       return;
670 	    }
671 	 }
672 	 else if (pname==GL_OBJECT_PLANE) {
673 	    ctx->Texture.ObjectPlaneR[0] = params[0];
674 	    ctx->Texture.ObjectPlaneR[1] = params[1];
675 	    ctx->Texture.ObjectPlaneR[2] = params[2];
676 	    ctx->Texture.ObjectPlaneR[3] = params[3];
677 	 }
678 	 else if (pname==GL_EYE_PLANE) {
679             /* Transform plane equation by the inverse modelview matrix */
680             if (ctx->NewModelViewMatrix) {
681                gl_analyze_modelview_matrix(ctx);
682             }
683             gl_transform_vector( ctx->Texture.EyePlaneR, params,
684                                  ctx->ModelViewInv );
685 	 }
686 	 else {
687 	    gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
688 	    return;
689 	 }
690 	 break;
691       case GL_Q:
692          if (pname==GL_TEXTURE_GEN_MODE) {
693 	    GLenum mode = (GLenum) (GLint) *params;
694 	    if (mode==GL_OBJECT_LINEAR ||
695 		mode==GL_EYE_LINEAR) {
696 	       ctx->Texture.GenModeQ = mode;
697 	    }
698 	    else {
699 	       gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
700 	       return;
701 	    }
702 	 }
703 	 else if (pname==GL_OBJECT_PLANE) {
704 	    ctx->Texture.ObjectPlaneQ[0] = params[0];
705 	    ctx->Texture.ObjectPlaneQ[1] = params[1];
706 	    ctx->Texture.ObjectPlaneQ[2] = params[2];
707 	    ctx->Texture.ObjectPlaneQ[3] = params[3];
708 	 }
709 	 else if (pname==GL_EYE_PLANE) {
710             /* Transform plane equation by the inverse modelview matrix */
711             if (ctx->NewModelViewMatrix) {
712                gl_analyze_modelview_matrix(ctx);
713             }
714             gl_transform_vector( ctx->Texture.EyePlaneQ, params,
715                                  ctx->ModelViewInv );
716 	 }
717 	 else {
718 	    gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
719 	    return;
720 	 }
721 	 break;
722       default:
723          gl_error( ctx, GL_INVALID_ENUM, "glTexGenfv(coord)" );
724 	 return;
725    }
726 
727    ctx->NewState |= NEW_TEXTURING;
728 }
729 
730 
731 
732 void gl_GetTexGendv( GLcontext *ctx,
733                      GLenum coord, GLenum pname, GLdouble *params )
734 {
735    if (INSIDE_BEGIN_END(ctx)) {
736       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGendv" );
737       return;
738    }
739 
740    switch( coord ) {
741       case GL_S:
742          if (pname==GL_TEXTURE_GEN_MODE) {
743             params[0] = ENUM_TO_DOUBLE(ctx->Texture.GenModeS);
744 	 }
745 	 else if (pname==GL_OBJECT_PLANE) {
746             COPY_4V( params, ctx->Texture.ObjectPlaneS );
747 	 }
748 	 else if (pname==GL_EYE_PLANE) {
749             COPY_4V( params, ctx->Texture.EyePlaneS );
750 	 }
751 	 else {
752 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
753 	    return;
754 	 }
755 	 break;
756       case GL_T:
757          if (pname==GL_TEXTURE_GEN_MODE) {
758             params[0] = ENUM_TO_DOUBLE(ctx->Texture.GenModeT);
759 	 }
760 	 else if (pname==GL_OBJECT_PLANE) {
761             COPY_4V( params, ctx->Texture.ObjectPlaneT );
762 	 }
763 	 else if (pname==GL_EYE_PLANE) {
764             COPY_4V( params, ctx->Texture.EyePlaneT );
765 	 }
766 	 else {
767 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
768 	    return;
769 	 }
770 	 break;
771       case GL_R:
772          if (pname==GL_TEXTURE_GEN_MODE) {
773             params[0] = ENUM_TO_DOUBLE(ctx->Texture.GenModeR);
774 	 }
775 	 else if (pname==GL_OBJECT_PLANE) {
776             COPY_4V( params, ctx->Texture.ObjectPlaneR );
777 	 }
778 	 else if (pname==GL_EYE_PLANE) {
779             COPY_4V( params, ctx->Texture.EyePlaneR );
780 	 }
781 	 else {
782 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
783 	    return;
784 	 }
785 	 break;
786       case GL_Q:
787          if (pname==GL_TEXTURE_GEN_MODE) {
788             params[0] = ENUM_TO_DOUBLE(ctx->Texture.GenModeQ);
789 	 }
790 	 else if (pname==GL_OBJECT_PLANE) {
791             COPY_4V( params, ctx->Texture.ObjectPlaneQ );
792 	 }
793 	 else if (pname==GL_EYE_PLANE) {
794             COPY_4V( params, ctx->Texture.EyePlaneQ );
795 	 }
796 	 else {
797 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
798 	    return;
799 	 }
800 	 break;
801       default:
802          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)" );
803 	 return;
804    }
805 }
806 
807 
808 
809 void gl_GetTexGenfv( GLcontext *ctx,
810                      GLenum coord, GLenum pname, GLfloat *params )
811 {
812    if (INSIDE_BEGIN_END(ctx)) {
813       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGenfv" );
814       return;
815    }
816 
817    switch( coord ) {
818       case GL_S:
819          if (pname==GL_TEXTURE_GEN_MODE) {
820             params[0] = ENUM_TO_FLOAT(ctx->Texture.GenModeS);
821 	 }
822 	 else if (pname==GL_OBJECT_PLANE) {
823             COPY_4V( params, ctx->Texture.ObjectPlaneS );
824 	 }
825 	 else if (pname==GL_EYE_PLANE) {
826             COPY_4V( params, ctx->Texture.EyePlaneS );
827 	 }
828 	 else {
829 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
830 	    return;
831 	 }
832 	 break;
833       case GL_T:
834          if (pname==GL_TEXTURE_GEN_MODE) {
835             params[0] = ENUM_TO_FLOAT(ctx->Texture.GenModeT);
836 	 }
837 	 else if (pname==GL_OBJECT_PLANE) {
838             COPY_4V( params, ctx->Texture.ObjectPlaneT );
839 	 }
840 	 else if (pname==GL_EYE_PLANE) {
841             COPY_4V( params, ctx->Texture.EyePlaneT );
842 	 }
843 	 else {
844 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
845 	    return;
846 	 }
847 	 break;
848       case GL_R:
849          if (pname==GL_TEXTURE_GEN_MODE) {
850             params[0] = ENUM_TO_FLOAT(ctx->Texture.GenModeR);
851 	 }
852 	 else if (pname==GL_OBJECT_PLANE) {
853             COPY_4V( params, ctx->Texture.ObjectPlaneR );
854 	 }
855 	 else if (pname==GL_EYE_PLANE) {
856             COPY_4V( params, ctx->Texture.EyePlaneR );
857 	 }
858 	 else {
859 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
860 	    return;
861 	 }
862 	 break;
863       case GL_Q:
864          if (pname==GL_TEXTURE_GEN_MODE) {
865             params[0] = ENUM_TO_FLOAT(ctx->Texture.GenModeQ);
866 	 }
867 	 else if (pname==GL_OBJECT_PLANE) {
868             COPY_4V( params, ctx->Texture.ObjectPlaneQ );
869 	 }
870 	 else if (pname==GL_EYE_PLANE) {
871             COPY_4V( params, ctx->Texture.EyePlaneQ );
872 	 }
873 	 else {
874 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
875 	    return;
876 	 }
877 	 break;
878       default:
879          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)" );
880 	 return;
881    }
882 }
883 
884 
885 
886 void gl_GetTexGeniv( GLcontext *ctx,
887                      GLenum coord, GLenum pname, GLint *params )
888 {
889    if (INSIDE_BEGIN_END(ctx)) {
890       gl_error( ctx, GL_INVALID_OPERATION, "glGetTexGeniv" );
891       return;
892    }
893 
894    switch( coord ) {
895       case GL_S:
896          if (pname==GL_TEXTURE_GEN_MODE) {
897             params[0] = ctx->Texture.GenModeS;
898 	 }
899 	 else if (pname==GL_OBJECT_PLANE) {
900             COPY_4V( params, ctx->Texture.ObjectPlaneS );
901 	 }
902 	 else if (pname==GL_EYE_PLANE) {
903             COPY_4V( params, ctx->Texture.EyePlaneS );
904 	 }
905 	 else {
906 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
907 	    return;
908 	 }
909 	 break;
910       case GL_T:
911          if (pname==GL_TEXTURE_GEN_MODE) {
912             params[0] = ctx->Texture.GenModeT;
913 	 }
914 	 else if (pname==GL_OBJECT_PLANE) {
915             COPY_4V( params, ctx->Texture.ObjectPlaneT );
916 	 }
917 	 else if (pname==GL_EYE_PLANE) {
918             COPY_4V( params, ctx->Texture.EyePlaneT );
919 	 }
920 	 else {
921 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
922 	    return;
923 	 }
924 	 break;
925       case GL_R:
926          if (pname==GL_TEXTURE_GEN_MODE) {
927             params[0] = ctx->Texture.GenModeR;
928 	 }
929 	 else if (pname==GL_OBJECT_PLANE) {
930             COPY_4V( params, ctx->Texture.ObjectPlaneR );
931 	 }
932 	 else if (pname==GL_EYE_PLANE) {
933             COPY_4V( params, ctx->Texture.EyePlaneR );
934 	 }
935 	 else {
936 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
937 	    return;
938 	 }
939 	 break;
940       case GL_Q:
941          if (pname==GL_TEXTURE_GEN_MODE) {
942             params[0] = ctx->Texture.GenModeQ;
943 	 }
944 	 else if (pname==GL_OBJECT_PLANE) {
945             COPY_4V( params, ctx->Texture.ObjectPlaneQ );
946 	 }
947 	 else if (pname==GL_EYE_PLANE) {
948             COPY_4V( params, ctx->Texture.EyePlaneQ );
949 	 }
950 	 else {
951 	    gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
952 	    return;
953 	 }
954 	 break;
955       default:
956          gl_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)" );
957 	 return;
958    }
959 }
960 
961 
962 
963 /*
964  * This is called by gl_update_state() if the NEW_TEXTURING bit in
965  * ctx->NewState is set.
966  */
967 void gl_update_texture_state( GLcontext *ctx )
968 {
969    struct gl_texture_object *t;
970 
971    if (ctx->Texture.Enabled & TEXTURE_2D)
972       ctx->Texture.Current = ctx->Texture.Current2D;
973    else if (ctx->Texture.Enabled & TEXTURE_1D)
974       ctx->Texture.Current = ctx->Texture.Current1D;
975    else
976       ctx->Texture.Current = NULL;
977 
978    if (ctx->Texture.AnyDirty) {
979       for (t = ctx->Shared->TexObjectList; t; t = t->Next) {
980          if (t->Dirty) {
981             gl_test_texture_object_completeness(t);
982             gl_set_texture_sampler(t);
983             t->Dirty = GL_FALSE;
984          }
985       }
986       ctx->Texture.AnyDirty = GL_FALSE;
987    }
988 }
989