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_matrix.h"
42 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
44 GET_CURRENT_CONTEXT(ctx
);
45 struct gl_texture_unit
*texUnit
;
46 ASSERT_OUTSIDE_BEGIN_END(ctx
);
48 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
49 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
50 _mesa_lookup_enum_by_nr(coord
),
51 _mesa_lookup_enum_by_nr(pname
),
53 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
55 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
56 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
60 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
64 if (pname
==GL_TEXTURE_GEN_MODE
) {
65 GLenum mode
= (GLenum
) (GLint
) *params
;
68 case GL_OBJECT_LINEAR
:
69 bits
= TEXGEN_OBJ_LINEAR
;
72 bits
= TEXGEN_EYE_LINEAR
;
74 case GL_REFLECTION_MAP_NV
:
75 bits
= TEXGEN_REFLECTION_MAP_NV
;
77 case GL_NORMAL_MAP_NV
:
78 bits
= TEXGEN_NORMAL_MAP_NV
;
81 bits
= TEXGEN_SPHERE_MAP
;
84 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
87 if (texUnit
->GenModeS
== mode
)
89 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
90 texUnit
->GenModeS
= mode
;
91 texUnit
->_GenBitS
= bits
;
93 else if (pname
==GL_OBJECT_PLANE
) {
94 if (TEST_EQ_4V(texUnit
->ObjectPlaneS
, params
))
96 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
97 COPY_4FV(texUnit
->ObjectPlaneS
, params
);
99 else if (pname
==GL_EYE_PLANE
) {
101 /* Transform plane equation by the inverse modelview matrix */
102 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
103 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
105 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
106 if (TEST_EQ_4V(texUnit
->EyePlaneS
, tmp
))
108 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
109 COPY_4FV(texUnit
->EyePlaneS
, tmp
);
112 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
117 if (pname
==GL_TEXTURE_GEN_MODE
) {
118 GLenum mode
= (GLenum
) (GLint
) *params
;
121 case GL_OBJECT_LINEAR
:
122 bitt
= TEXGEN_OBJ_LINEAR
;
125 bitt
= TEXGEN_EYE_LINEAR
;
127 case GL_REFLECTION_MAP_NV
:
128 bitt
= TEXGEN_REFLECTION_MAP_NV
;
130 case GL_NORMAL_MAP_NV
:
131 bitt
= TEXGEN_NORMAL_MAP_NV
;
134 bitt
= TEXGEN_SPHERE_MAP
;
137 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
140 if (texUnit
->GenModeT
== mode
)
142 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
143 texUnit
->GenModeT
= mode
;
144 texUnit
->_GenBitT
= bitt
;
146 else if (pname
==GL_OBJECT_PLANE
) {
147 if (TEST_EQ_4V(texUnit
->ObjectPlaneT
, params
))
149 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
150 COPY_4FV(texUnit
->ObjectPlaneT
, params
);
152 else if (pname
==GL_EYE_PLANE
) {
154 /* Transform plane equation by the inverse modelview matrix */
155 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
156 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
158 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
159 if (TEST_EQ_4V(texUnit
->EyePlaneT
, tmp
))
161 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
162 COPY_4FV(texUnit
->EyePlaneT
, tmp
);
165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
170 if (pname
==GL_TEXTURE_GEN_MODE
) {
171 GLenum mode
= (GLenum
) (GLint
) *params
;
174 case GL_OBJECT_LINEAR
:
175 bitr
= TEXGEN_OBJ_LINEAR
;
177 case GL_REFLECTION_MAP_NV
:
178 bitr
= TEXGEN_REFLECTION_MAP_NV
;
180 case GL_NORMAL_MAP_NV
:
181 bitr
= TEXGEN_NORMAL_MAP_NV
;
184 bitr
= TEXGEN_EYE_LINEAR
;
187 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
190 if (texUnit
->GenModeR
== mode
)
192 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
193 texUnit
->GenModeR
= mode
;
194 texUnit
->_GenBitR
= bitr
;
196 else if (pname
==GL_OBJECT_PLANE
) {
197 if (TEST_EQ_4V(texUnit
->ObjectPlaneR
, params
))
199 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
200 COPY_4FV(texUnit
->ObjectPlaneR
, params
);
202 else if (pname
==GL_EYE_PLANE
) {
204 /* Transform plane equation by the inverse modelview matrix */
205 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
206 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
208 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
209 if (TEST_EQ_4V(texUnit
->EyePlaneR
, tmp
))
211 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
212 COPY_4FV(texUnit
->EyePlaneR
, tmp
);
215 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
220 if (pname
==GL_TEXTURE_GEN_MODE
) {
221 GLenum mode
= (GLenum
) (GLint
) *params
;
224 case GL_OBJECT_LINEAR
:
225 bitq
= TEXGEN_OBJ_LINEAR
;
228 bitq
= TEXGEN_EYE_LINEAR
;
231 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
234 if (texUnit
->GenModeQ
== mode
)
236 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
237 texUnit
->GenModeQ
= mode
;
238 texUnit
->_GenBitQ
= bitq
;
240 else if (pname
==GL_OBJECT_PLANE
) {
241 if (TEST_EQ_4V(texUnit
->ObjectPlaneQ
, params
))
243 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
244 COPY_4FV(texUnit
->ObjectPlaneQ
, params
);
246 else if (pname
==GL_EYE_PLANE
) {
248 /* Transform plane equation by the inverse modelview matrix */
249 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
250 _math_matrix_analyse( ctx
->ModelviewMatrixStack
.Top
);
252 _mesa_transform_vector( tmp
, params
, ctx
->ModelviewMatrixStack
.Top
->inv
);
253 if (TEST_EQ_4V(texUnit
->EyePlaneQ
, tmp
))
255 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
256 COPY_4FV(texUnit
->EyePlaneQ
, tmp
);
259 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
264 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(coord)" );
268 if (ctx
->Driver
.TexGen
)
269 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
274 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
277 p
[0] = (GLfloat
) params
[0];
278 if (pname
== GL_TEXTURE_GEN_MODE
) {
279 p
[1] = p
[2] = p
[3] = 0.0F
;
282 p
[1] = (GLfloat
) params
[1];
283 p
[2] = (GLfloat
) params
[2];
284 p
[3] = (GLfloat
) params
[3];
286 _mesa_TexGenfv(coord
, pname
, p
);
291 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
293 GLfloat p
= (GLfloat
) param
;
294 _mesa_TexGenfv( coord
, pname
, &p
);
299 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
302 p
[0] = (GLfloat
) params
[0];
303 if (pname
== GL_TEXTURE_GEN_MODE
) {
304 p
[1] = p
[2] = p
[3] = 0.0F
;
307 p
[1] = (GLfloat
) params
[1];
308 p
[2] = (GLfloat
) params
[2];
309 p
[3] = (GLfloat
) params
[3];
311 _mesa_TexGenfv( coord
, pname
, p
);
316 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
318 _mesa_TexGenfv(coord
, pname
, ¶m
);
323 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
325 _mesa_TexGeniv( coord
, pname
, ¶m
);
331 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
333 const struct gl_texture_unit
*texUnit
;
334 GET_CURRENT_CONTEXT(ctx
);
335 ASSERT_OUTSIDE_BEGIN_END(ctx
);
337 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
338 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
342 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
346 if (pname
==GL_TEXTURE_GEN_MODE
) {
347 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeS
);
349 else if (pname
==GL_OBJECT_PLANE
) {
350 COPY_4V( params
, texUnit
->ObjectPlaneS
);
352 else if (pname
==GL_EYE_PLANE
) {
353 COPY_4V( params
, texUnit
->EyePlaneS
);
356 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
361 if (pname
==GL_TEXTURE_GEN_MODE
) {
362 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeT
);
364 else if (pname
==GL_OBJECT_PLANE
) {
365 COPY_4V( params
, texUnit
->ObjectPlaneT
);
367 else if (pname
==GL_EYE_PLANE
) {
368 COPY_4V( params
, texUnit
->EyePlaneT
);
371 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
376 if (pname
==GL_TEXTURE_GEN_MODE
) {
377 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeR
);
379 else if (pname
==GL_OBJECT_PLANE
) {
380 COPY_4V( params
, texUnit
->ObjectPlaneR
);
382 else if (pname
==GL_EYE_PLANE
) {
383 COPY_4V( params
, texUnit
->EyePlaneR
);
386 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
391 if (pname
==GL_TEXTURE_GEN_MODE
) {
392 params
[0] = ENUM_TO_DOUBLE(texUnit
->GenModeQ
);
394 else if (pname
==GL_OBJECT_PLANE
) {
395 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
397 else if (pname
==GL_EYE_PLANE
) {
398 COPY_4V( params
, texUnit
->EyePlaneQ
);
401 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
406 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)" );
414 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
416 const struct gl_texture_unit
*texUnit
;
417 GET_CURRENT_CONTEXT(ctx
);
418 ASSERT_OUTSIDE_BEGIN_END(ctx
);
420 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
421 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
425 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
429 if (pname
==GL_TEXTURE_GEN_MODE
) {
430 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeS
);
432 else if (pname
==GL_OBJECT_PLANE
) {
433 COPY_4V( params
, texUnit
->ObjectPlaneS
);
435 else if (pname
==GL_EYE_PLANE
) {
436 COPY_4V( params
, texUnit
->EyePlaneS
);
439 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
444 if (pname
==GL_TEXTURE_GEN_MODE
) {
445 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeT
);
447 else if (pname
==GL_OBJECT_PLANE
) {
448 COPY_4V( params
, texUnit
->ObjectPlaneT
);
450 else if (pname
==GL_EYE_PLANE
) {
451 COPY_4V( params
, texUnit
->EyePlaneT
);
454 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
459 if (pname
==GL_TEXTURE_GEN_MODE
) {
460 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeR
);
462 else if (pname
==GL_OBJECT_PLANE
) {
463 COPY_4V( params
, texUnit
->ObjectPlaneR
);
465 else if (pname
==GL_EYE_PLANE
) {
466 COPY_4V( params
, texUnit
->EyePlaneR
);
469 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
474 if (pname
==GL_TEXTURE_GEN_MODE
) {
475 params
[0] = ENUM_TO_FLOAT(texUnit
->GenModeQ
);
477 else if (pname
==GL_OBJECT_PLANE
) {
478 COPY_4V( params
, texUnit
->ObjectPlaneQ
);
480 else if (pname
==GL_EYE_PLANE
) {
481 COPY_4V( params
, texUnit
->EyePlaneQ
);
484 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
489 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)" );
497 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
499 const struct gl_texture_unit
*texUnit
;
500 GET_CURRENT_CONTEXT(ctx
);
501 ASSERT_OUTSIDE_BEGIN_END(ctx
);
503 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
504 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
508 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
512 if (pname
==GL_TEXTURE_GEN_MODE
) {
513 params
[0] = texUnit
->GenModeS
;
515 else if (pname
==GL_OBJECT_PLANE
) {
516 params
[0] = (GLint
) texUnit
->ObjectPlaneS
[0];
517 params
[1] = (GLint
) texUnit
->ObjectPlaneS
[1];
518 params
[2] = (GLint
) texUnit
->ObjectPlaneS
[2];
519 params
[3] = (GLint
) texUnit
->ObjectPlaneS
[3];
521 else if (pname
==GL_EYE_PLANE
) {
522 params
[0] = (GLint
) texUnit
->EyePlaneS
[0];
523 params
[1] = (GLint
) texUnit
->EyePlaneS
[1];
524 params
[2] = (GLint
) texUnit
->EyePlaneS
[2];
525 params
[3] = (GLint
) texUnit
->EyePlaneS
[3];
528 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
533 if (pname
==GL_TEXTURE_GEN_MODE
) {
534 params
[0] = texUnit
->GenModeT
;
536 else if (pname
==GL_OBJECT_PLANE
) {
537 params
[0] = (GLint
) texUnit
->ObjectPlaneT
[0];
538 params
[1] = (GLint
) texUnit
->ObjectPlaneT
[1];
539 params
[2] = (GLint
) texUnit
->ObjectPlaneT
[2];
540 params
[3] = (GLint
) texUnit
->ObjectPlaneT
[3];
542 else if (pname
==GL_EYE_PLANE
) {
543 params
[0] = (GLint
) texUnit
->EyePlaneT
[0];
544 params
[1] = (GLint
) texUnit
->EyePlaneT
[1];
545 params
[2] = (GLint
) texUnit
->EyePlaneT
[2];
546 params
[3] = (GLint
) texUnit
->EyePlaneT
[3];
549 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
554 if (pname
==GL_TEXTURE_GEN_MODE
) {
555 params
[0] = texUnit
->GenModeR
;
557 else if (pname
==GL_OBJECT_PLANE
) {
558 params
[0] = (GLint
) texUnit
->ObjectPlaneR
[0];
559 params
[1] = (GLint
) texUnit
->ObjectPlaneR
[1];
560 params
[2] = (GLint
) texUnit
->ObjectPlaneR
[2];
561 params
[3] = (GLint
) texUnit
->ObjectPlaneR
[3];
563 else if (pname
==GL_EYE_PLANE
) {
564 params
[0] = (GLint
) texUnit
->EyePlaneR
[0];
565 params
[1] = (GLint
) texUnit
->EyePlaneR
[1];
566 params
[2] = (GLint
) texUnit
->EyePlaneR
[2];
567 params
[3] = (GLint
) texUnit
->EyePlaneR
[3];
570 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
575 if (pname
==GL_TEXTURE_GEN_MODE
) {
576 params
[0] = texUnit
->GenModeQ
;
578 else if (pname
==GL_OBJECT_PLANE
) {
579 params
[0] = (GLint
) texUnit
->ObjectPlaneQ
[0];
580 params
[1] = (GLint
) texUnit
->ObjectPlaneQ
[1];
581 params
[2] = (GLint
) texUnit
->ObjectPlaneQ
[2];
582 params
[3] = (GLint
) texUnit
->ObjectPlaneQ
[3];
584 else if (pname
==GL_EYE_PLANE
) {
585 params
[0] = (GLint
) texUnit
->EyePlaneQ
[0];
586 params
[1] = (GLint
) texUnit
->EyePlaneQ
[1];
587 params
[2] = (GLint
) texUnit
->EyePlaneQ
[2];
588 params
[3] = (GLint
) texUnit
->EyePlaneQ
[3];
591 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
596 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)" );