2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
28 * glTexGen-related functions
32 #include "main/glheader.h"
33 #include "main/context.h"
34 #include "main/enums.h"
35 #include "main/macros.h"
36 #include "main/texgen.h"
37 #include "math/m_xform.h"
40 #define ENUM_TO_FLOAT(X) ((GLfloat)(GLint)(X))
41 #define ENUM_TO_DOUBLE(X) ((GLdouble)(GLint)(X))
46 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
48 GET_CURRENT_CONTEXT(ctx
);
49 struct gl_texture_unit
*texUnit
;
50 ASSERT_OUTSIDE_BEGIN_END(ctx
);
52 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
53 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
54 _mesa_lookup_enum_by_nr(coord
),
55 _mesa_lookup_enum_by_nr(pname
),
57 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
59 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
60 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
64 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
68 if (pname
==GL_TEXTURE_GEN_MODE
) {
69 GLenum mode
= (GLenum
) (GLint
) *params
;
72 case GL_OBJECT_LINEAR
:
73 bits
= TEXGEN_OBJ_LINEAR
;
76 bits
= TEXGEN_EYE_LINEAR
;
78 case GL_REFLECTION_MAP_NV
:
79 bits
= TEXGEN_REFLECTION_MAP_NV
;
81 case GL_NORMAL_MAP_NV
:
82 bits
= TEXGEN_NORMAL_MAP_NV
;
85 bits
= TEXGEN_SPHERE_MAP
;
88 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
91 if (texUnit
->GenModeS
== mode
)
93 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
94 texUnit
->GenModeS
= mode
;
95 texUnit
->_GenBitS
= bits
;
97 else if (pname
==GL_OBJECT_PLANE
) {
98 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
100 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
101 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
103 else if (pname
==GL_EYE_PLANE
) {
105 /* Transform plane equation by the inverse modelview matrix */
106 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
107 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
109 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
110 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
112 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
113 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
116 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
121 if (pname
==GL_TEXTURE_GEN_MODE
) {
122 GLenum mode
= (GLenum
) (GLint
) *params
;
125 case GL_OBJECT_LINEAR
:
126 bitt
= TEXGEN_OBJ_LINEAR
;
129 bitt
= TEXGEN_EYE_LINEAR
;
131 case GL_REFLECTION_MAP_NV
:
132 bitt
= TEXGEN_REFLECTION_MAP_NV
;
134 case GL_NORMAL_MAP_NV
:
135 bitt
= TEXGEN_NORMAL_MAP_NV
;
138 bitt
= TEXGEN_SPHERE_MAP
;
141 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
144 if (texUnit
->GenModeT
== mode
)
146 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
147 texUnit
->GenModeT
= mode
;
148 texUnit
->_GenBitT
= bitt
;
150 else if (pname
==GL_OBJECT_PLANE
) {
151 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
153 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
154 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
156 else if (pname
==GL_EYE_PLANE
) {
158 /* Transform plane equation by the inverse modelview matrix */
159 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
160 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
162 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
163 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
165 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
166 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
169 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
174 if (pname
==GL_TEXTURE_GEN_MODE
) {
175 GLenum mode
= (GLenum
) (GLint
) *params
;
178 case GL_OBJECT_LINEAR
:
179 bitr
= TEXGEN_OBJ_LINEAR
;
181 case GL_REFLECTION_MAP_NV
:
182 bitr
= TEXGEN_REFLECTION_MAP_NV
;
184 case GL_NORMAL_MAP_NV
:
185 bitr
= TEXGEN_NORMAL_MAP_NV
;
188 bitr
= TEXGEN_EYE_LINEAR
;
191 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
194 if (texUnit
->GenModeR
== mode
)
196 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
197 texUnit
->GenModeR
= mode
;
198 texUnit
->_GenBitR
= bitr
;
200 else if (pname
==GL_OBJECT_PLANE
) {
201 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
203 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
204 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
206 else if (pname
==GL_EYE_PLANE
) {
208 /* Transform plane equation by the inverse modelview matrix */
209 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
210 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
212 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
213 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
215 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
216 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
219 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
224 if (pname
==GL_TEXTURE_GEN_MODE
) {
225 GLenum mode
= (GLenum
) (GLint
) *params
;
228 case GL_OBJECT_LINEAR
:
229 bitq
= TEXGEN_OBJ_LINEAR
;
232 bitq
= TEXGEN_EYE_LINEAR
;
235 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
238 if (texUnit
->GenModeQ
== mode
)
240 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
241 texUnit
->GenModeQ
= mode
;
242 texUnit
->_GenBitQ
= bitq
;
244 else if (pname
==GL_OBJECT_PLANE
) {
245 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
247 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
248 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
250 else if (pname
==GL_EYE_PLANE
) {
252 /* Transform plane equation by the inverse modelview matrix */
253 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
254 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
256 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
257 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
259 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
260 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
263 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
268 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
272 if (ctx
->Driver
.TexGen
)
273 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
278 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
281 p
[0] = (GLfloat
) params
[0];
282 if (pname
== GL_TEXTURE_GEN_MODE
) {
283 p
[1] = p
[2] = p
[3] = 0.0F
;
286 p
[1] = (GLfloat
) params
[1];
287 p
[2] = (GLfloat
) params
[2];
288 p
[3] = (GLfloat
) params
[3];
290 _mesa_TexGenfv(coord
, pname
, p
);
295 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
297 GLfloat p
= (GLfloat
) param
;
298 _mesa_TexGenfv( coord
, pname
, &p
);
303 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
306 p
[0] = (GLfloat
) params
[0];
307 if (pname
== GL_TEXTURE_GEN_MODE
) {
308 p
[1] = p
[2] = p
[3] = 0.0F
;
311 p
[1] = (GLfloat
) params
[1];
312 p
[2] = (GLfloat
) params
[2];
313 p
[3] = (GLfloat
) params
[3];
315 _mesa_TexGenfv( coord
, pname
, p
);
320 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
322 _mesa_TexGenfv(coord
, pname
, ¶m
);
327 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
329 _mesa_TexGeniv( coord
, pname
, ¶m
);
335 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
337 const struct gl_texture_unit
*texUnit
;
338 GET_CURRENT_CONTEXT(ctx
);
339 ASSERT_OUTSIDE_BEGIN_END(ctx
);
341 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
342 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
346 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
350 if (pname
==GL_TEXTURE_GEN_MODE
) {
351 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
353 else if (pname
==GL_OBJECT_PLANE
) {
354 COPY_4V( params
, texUnit
->ObjectPlaneS
);
356 else if (pname
==GL_EYE_PLANE
) {
357 COPY_4V( params
, texUnit
->EyePlaneS
);
360 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
365 if (pname
==GL_TEXTURE_GEN_MODE
) {
366 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
368 else if (pname
==GL_OBJECT_PLANE
) {
369 COPY_4V( params
, texUnit
->ObjectPlaneT
);
371 else if (pname
==GL_EYE_PLANE
) {
372 COPY_4V( params
, texUnit
->EyePlaneT
);
375 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
380 if (pname
==GL_TEXTURE_GEN_MODE
) {
381 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
383 else if (pname
==GL_OBJECT_PLANE
) {
384 COPY_4V( params
, texUnit
->ObjectPlaneR
);
386 else if (pname
==GL_EYE_PLANE
) {
387 COPY_4V( params
, texUnit
->EyePlaneR
);
390 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
395 if (pname
==GL_TEXTURE_GEN_MODE
) {
396 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
398 else if (pname
==GL_OBJECT_PLANE
) {
399 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
401 else if (pname
==GL_EYE_PLANE
) {
402 COPY_4V( params
, texUnit
->EyePlaneQ
);
405 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
410 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
418 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
420 const struct gl_texture_unit
*texUnit
;
421 GET_CURRENT_CONTEXT(ctx
);
422 ASSERT_OUTSIDE_BEGIN_END(ctx
);
424 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
425 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
429 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
433 if (pname
==GL_TEXTURE_GEN_MODE
) {
434 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
436 else if (pname
==GL_OBJECT_PLANE
) {
437 COPY_4V( params
, texUnit
->ObjectPlaneS
);
439 else if (pname
==GL_EYE_PLANE
) {
440 COPY_4V( params
, texUnit
->EyePlaneS
);
443 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
448 if (pname
==GL_TEXTURE_GEN_MODE
) {
449 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
451 else if (pname
==GL_OBJECT_PLANE
) {
452 COPY_4V( params
, texUnit
->ObjectPlaneT
);
454 else if (pname
==GL_EYE_PLANE
) {
455 COPY_4V( params
, texUnit
->EyePlaneT
);
458 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
463 if (pname
==GL_TEXTURE_GEN_MODE
) {
464 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
466 else if (pname
==GL_OBJECT_PLANE
) {
467 COPY_4V( params
, texUnit
->ObjectPlaneR
);
469 else if (pname
==GL_EYE_PLANE
) {
470 COPY_4V( params
, texUnit
->EyePlaneR
);
473 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
478 if (pname
==GL_TEXTURE_GEN_MODE
) {
479 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
481 else if (pname
==GL_OBJECT_PLANE
) {
482 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
484 else if (pname
==GL_EYE_PLANE
) {
485 COPY_4V( params
, texUnit
->EyePlaneQ
);
488 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
493 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
501 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
503 const struct gl_texture_unit
*texUnit
;
504 GET_CURRENT_CONTEXT(ctx
);
505 ASSERT_OUTSIDE_BEGIN_END(ctx
);
507 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
508 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
512 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
516 if (pname
==GL_TEXTURE_GEN_MODE
) {
517 params
[0] = texUnit
->GenModeS
;
519 else if (pname
==GL_OBJECT_PLANE
) {
520 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
521 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
522 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
523 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
525 else if (pname
==GL_EYE_PLANE
) {
526 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
527 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
528 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
529 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
532 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
537 if (pname
==GL_TEXTURE_GEN_MODE
) {
538 params
[0] = texUnit
->GenModeT
;
540 else if (pname
==GL_OBJECT_PLANE
) {
541 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
542 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
543 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
544 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
546 else if (pname
==GL_EYE_PLANE
) {
547 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
548 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
549 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
550 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
553 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
558 if (pname
==GL_TEXTURE_GEN_MODE
) {
559 params
[0] = texUnit
->GenModeR
;
561 else if (pname
==GL_OBJECT_PLANE
) {
562 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
563 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
564 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
565 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
567 else if (pname
==GL_EYE_PLANE
) {
568 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
569 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
570 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
571 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
574 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
579 if (pname
==GL_TEXTURE_GEN_MODE
) {
580 params
[0] = texUnit
->GenModeQ
;
582 else if (pname
==GL_OBJECT_PLANE
) {
583 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
584 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
585 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
586 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
588 else if (pname
==GL_EYE_PLANE
) {
589 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
590 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
591 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
592 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
595 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
600 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );