2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
22 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
23 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 * glTexGen-related functions
33 #include "main/glheader.h"
34 #include "main/context.h"
35 #include "main/enums.h"
36 #include "main/macros.h"
37 #include "main/texgen.h"
38 #include "main/texstate.h"
39 #include "math/m_matrix.h"
43 * Return texgen state for given coordinate
45 static struct gl_texgen
*
46 get_texgen(struct gl_texture_unit
*texUnit
, GLenum coord
)
50 return &texUnit
->GenS
;
52 return &texUnit
->GenT
;
54 return &texUnit
->GenR
;
56 return &texUnit
->GenQ
;
64 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
66 struct gl_texture_unit
*texUnit
;
67 struct gl_texgen
*texgen
;
68 GET_CURRENT_CONTEXT(ctx
);
69 ASSERT_OUTSIDE_BEGIN_END(ctx
);
71 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
72 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
73 _mesa_lookup_enum_by_nr(coord
),
74 _mesa_lookup_enum_by_nr(pname
),
76 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
78 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
79 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
83 texUnit
= _mesa_get_current_tex_unit(ctx
);
85 texgen
= get_texgen(texUnit
, coord
);
87 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
92 case GL_TEXTURE_GEN_MODE
:
94 GLenum mode
= (GLenum
) (GLint
) params
[0];
96 if (texgen
->Mode
== mode
)
99 case GL_OBJECT_LINEAR
:
100 bit
= TEXGEN_OBJ_LINEAR
;
103 bit
= TEXGEN_EYE_LINEAR
;
106 if (coord
== GL_S
|| coord
== GL_T
)
107 bit
= TEXGEN_SPHERE_MAP
;
109 case GL_REFLECTION_MAP_NV
:
111 bit
= TEXGEN_REFLECTION_MAP_NV
;
113 case GL_NORMAL_MAP_NV
:
115 bit
= TEXGEN_NORMAL_MAP_NV
;
121 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
124 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
126 texgen
->_ModeBit
= bit
;
130 case GL_OBJECT_PLANE
:
132 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
134 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
135 COPY_4FV(texgen
->ObjectPlane
, params
);
142 /* Transform plane equation by the inverse modelview matrix */
143 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
144 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
146 _mesa_transform_vector(tmp
, params
,
147 ctx
->ModelviewMatrixStack
.Top
->inv
);
148 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
150 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
151 COPY_4FV(texgen
->EyePlane
, tmp
);
156 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
160 if (ctx
->Driver
.TexGen
)
161 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
166 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
169 p
[0] = (GLfloat
) params
[0];
170 if (pname
== GL_TEXTURE_GEN_MODE
) {
171 p
[1] = p
[2] = p
[3] = 0.0F
;
174 p
[1] = (GLfloat
) params
[1];
175 p
[2] = (GLfloat
) params
[2];
176 p
[3] = (GLfloat
) params
[3];
178 _mesa_TexGenfv(coord
, pname
, p
);
183 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
185 GLfloat p
= (GLfloat
) param
;
186 _mesa_TexGenfv( coord
, pname
, &p
);
191 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
194 p
[0] = (GLfloat
) params
[0];
195 if (pname
== GL_TEXTURE_GEN_MODE
) {
196 p
[1] = p
[2] = p
[3] = 0.0F
;
199 p
[1] = (GLfloat
) params
[1];
200 p
[2] = (GLfloat
) params
[2];
201 p
[3] = (GLfloat
) params
[3];
203 _mesa_TexGenfv( coord
, pname
, p
);
208 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
210 _mesa_TexGenfv(coord
, pname
, ¶m
);
215 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
217 _mesa_TexGeniv( coord
, pname
, ¶m
);
223 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
225 struct gl_texture_unit
*texUnit
;
226 struct gl_texgen
*texgen
;
227 GET_CURRENT_CONTEXT(ctx
);
228 ASSERT_OUTSIDE_BEGIN_END(ctx
);
230 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
231 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
235 texUnit
= _mesa_get_current_tex_unit(ctx
);
237 texgen
= get_texgen(texUnit
, coord
);
239 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
244 case GL_TEXTURE_GEN_MODE
:
245 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
247 case GL_OBJECT_PLANE
:
248 COPY_4V(params
, texgen
->ObjectPlane
);
251 COPY_4V(params
, texgen
->EyePlane
);
254 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
261 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
263 struct gl_texture_unit
*texUnit
;
264 struct gl_texgen
*texgen
;
265 GET_CURRENT_CONTEXT(ctx
);
266 ASSERT_OUTSIDE_BEGIN_END(ctx
);
268 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
269 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
273 texUnit
= _mesa_get_current_tex_unit(ctx
);
275 texgen
= get_texgen(texUnit
, coord
);
277 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
282 case GL_TEXTURE_GEN_MODE
:
283 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
285 case GL_OBJECT_PLANE
:
286 COPY_4V(params
, texgen
->ObjectPlane
);
289 COPY_4V(params
, texgen
->EyePlane
);
292 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
299 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
301 struct gl_texture_unit
*texUnit
;
302 struct gl_texgen
*texgen
;
303 GET_CURRENT_CONTEXT(ctx
);
304 ASSERT_OUTSIDE_BEGIN_END(ctx
);
306 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
307 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
311 texUnit
= _mesa_get_current_tex_unit(ctx
);
313 texgen
= get_texgen(texUnit
, coord
);
315 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
320 case GL_TEXTURE_GEN_MODE
:
321 params
[0] = texgen
->Mode
;
323 case GL_OBJECT_PLANE
:
324 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
325 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
326 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
327 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
330 params
[0] = (GLint
) texgen
->EyePlane
[0];
331 params
[1] = (GLint
) texgen
->EyePlane
[1];
332 params
[2] = (GLint
) texgen
->EyePlane
[2];
333 params
[3] = (GLint
) texgen
->EyePlane
[3];
336 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );