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 "math/m_matrix.h"
42 * Return texgen state for given coordinate
44 static struct gl_texgen
*
45 get_texgen(struct gl_texture_unit
*texUnit
, GLenum coord
)
49 return &texUnit
->GenS
;
51 return &texUnit
->GenT
;
53 return &texUnit
->GenR
;
55 return &texUnit
->GenQ
;
63 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
65 struct gl_texture_unit
*texUnit
;
66 struct gl_texgen
*texgen
;
67 GET_CURRENT_CONTEXT(ctx
);
68 ASSERT_OUTSIDE_BEGIN_END(ctx
);
70 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
71 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
72 _mesa_lookup_enum_by_nr(coord
),
73 _mesa_lookup_enum_by_nr(pname
),
75 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
77 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
78 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
82 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
84 texgen
= get_texgen(texUnit
, coord
);
86 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
91 case GL_TEXTURE_GEN_MODE
:
93 GLenum mode
= (GLenum
) (GLint
) params
[0];
95 if (texgen
->Mode
== mode
)
98 case GL_OBJECT_LINEAR
:
99 bit
= TEXGEN_OBJ_LINEAR
;
102 bit
= TEXGEN_EYE_LINEAR
;
105 if (coord
== GL_S
|| coord
== GL_T
)
106 bit
= TEXGEN_SPHERE_MAP
;
108 case GL_REFLECTION_MAP_NV
:
110 bit
= TEXGEN_REFLECTION_MAP_NV
;
112 case GL_NORMAL_MAP_NV
:
114 bit
= TEXGEN_NORMAL_MAP_NV
;
120 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
123 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
125 texgen
->_ModeBit
= bit
;
129 case GL_OBJECT_PLANE
:
131 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
133 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
134 COPY_4FV(texgen
->ObjectPlane
, params
);
141 /* Transform plane equation by the inverse modelview matrix */
142 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
143 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
145 _mesa_transform_vector(tmp
, params
,
146 ctx
->ModelviewMatrixStack
.Top
->inv
);
147 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
149 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
150 COPY_4FV(texgen
->EyePlane
, tmp
);
155 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
159 if (ctx
->Driver
.TexGen
)
160 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
165 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
168 p
[0] = (GLfloat
) params
[0];
169 if (pname
== GL_TEXTURE_GEN_MODE
) {
170 p
[1] = p
[2] = p
[3] = 0.0F
;
173 p
[1] = (GLfloat
) params
[1];
174 p
[2] = (GLfloat
) params
[2];
175 p
[3] = (GLfloat
) params
[3];
177 _mesa_TexGenfv(coord
, pname
, p
);
182 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
184 GLfloat p
= (GLfloat
) param
;
185 _mesa_TexGenfv( coord
, pname
, &p
);
190 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
193 p
[0] = (GLfloat
) params
[0];
194 if (pname
== GL_TEXTURE_GEN_MODE
) {
195 p
[1] = p
[2] = p
[3] = 0.0F
;
198 p
[1] = (GLfloat
) params
[1];
199 p
[2] = (GLfloat
) params
[2];
200 p
[3] = (GLfloat
) params
[3];
202 _mesa_TexGenfv( coord
, pname
, p
);
207 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
209 _mesa_TexGenfv(coord
, pname
, ¶m
);
214 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
216 _mesa_TexGeniv( coord
, pname
, ¶m
);
222 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
224 struct gl_texture_unit
*texUnit
;
225 struct gl_texgen
*texgen
;
226 GET_CURRENT_CONTEXT(ctx
);
227 ASSERT_OUTSIDE_BEGIN_END(ctx
);
229 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
230 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
234 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
236 texgen
= get_texgen(texUnit
, coord
);
238 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
243 case GL_TEXTURE_GEN_MODE
:
244 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
246 case GL_OBJECT_PLANE
:
247 COPY_4V(params
, texgen
->ObjectPlane
);
250 COPY_4V(params
, texgen
->EyePlane
);
253 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
260 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
262 struct gl_texture_unit
*texUnit
;
263 struct gl_texgen
*texgen
;
264 GET_CURRENT_CONTEXT(ctx
);
265 ASSERT_OUTSIDE_BEGIN_END(ctx
);
267 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
268 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
272 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
274 texgen
= get_texgen(texUnit
, coord
);
276 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
281 case GL_TEXTURE_GEN_MODE
:
282 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
284 case GL_OBJECT_PLANE
:
285 COPY_4V(params
, texgen
->ObjectPlane
);
288 COPY_4V(params
, texgen
->EyePlane
);
291 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
298 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
300 struct gl_texture_unit
*texUnit
;
301 struct gl_texgen
*texgen
;
302 GET_CURRENT_CONTEXT(ctx
);
303 ASSERT_OUTSIDE_BEGIN_END(ctx
);
305 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
306 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
310 texUnit
= &ctx
->Texture
.Unit
[ctx
->Texture
.CurrentUnit
];
312 texgen
= get_texgen(texUnit
, coord
);
314 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
319 case GL_TEXTURE_GEN_MODE
:
320 params
[0] = texgen
->Mode
;
322 case GL_OBJECT_PLANE
:
323 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
324 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
325 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
326 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
329 params
[0] = (GLint
) texgen
->EyePlane
[0];
330 params
[1] = (GLint
) texgen
->EyePlane
[1];
331 params
[2] = (GLint
) texgen
->EyePlane
[2];
332 params
[3] = (GLint
) texgen
->EyePlane
[3];
335 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );