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"
40 #include "main/dispatch.h"
47 * Return texgen state for given coordinate
49 static struct gl_texgen
*
50 get_texgen(struct gl_texture_unit
*texUnit
, GLenum coord
)
54 return &texUnit
->GenS
;
56 return &texUnit
->GenT
;
58 return &texUnit
->GenR
;
60 return &texUnit
->GenQ
;
68 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
70 struct gl_texture_unit
*texUnit
;
71 struct gl_texgen
*texgen
;
72 GET_CURRENT_CONTEXT(ctx
);
73 ASSERT_OUTSIDE_BEGIN_END(ctx
);
75 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
76 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
77 _mesa_lookup_enum_by_nr(coord
),
78 _mesa_lookup_enum_by_nr(pname
),
80 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
82 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
83 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
87 texUnit
= _mesa_get_current_tex_unit(ctx
);
89 texgen
= get_texgen(texUnit
, coord
);
91 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
96 case GL_TEXTURE_GEN_MODE
:
98 GLenum mode
= (GLenum
) (GLint
) params
[0];
100 if (texgen
->Mode
== mode
)
103 case GL_OBJECT_LINEAR
:
104 bit
= TEXGEN_OBJ_LINEAR
;
107 bit
= TEXGEN_EYE_LINEAR
;
110 if (coord
== GL_S
|| coord
== GL_T
)
111 bit
= TEXGEN_SPHERE_MAP
;
113 case GL_REFLECTION_MAP_NV
:
115 bit
= TEXGEN_REFLECTION_MAP_NV
;
117 case GL_NORMAL_MAP_NV
:
119 bit
= TEXGEN_NORMAL_MAP_NV
;
125 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
128 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
130 texgen
->_ModeBit
= bit
;
134 case GL_OBJECT_PLANE
:
136 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
138 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
139 COPY_4FV(texgen
->ObjectPlane
, params
);
146 /* Transform plane equation by the inverse modelview matrix */
147 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
148 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
150 _mesa_transform_vector(tmp
, params
,
151 ctx
->ModelviewMatrixStack
.Top
->inv
);
152 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
154 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
155 COPY_4FV(texgen
->EyePlane
, tmp
);
160 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
164 if (ctx
->Driver
.TexGen
)
165 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
169 static void GLAPIENTRY
170 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
173 p
[0] = (GLfloat
) params
[0];
174 if (pname
== GL_TEXTURE_GEN_MODE
) {
175 p
[1] = p
[2] = p
[3] = 0.0F
;
178 p
[1] = (GLfloat
) params
[1];
179 p
[2] = (GLfloat
) params
[2];
180 p
[3] = (GLfloat
) params
[3];
182 _mesa_TexGenfv(coord
, pname
, p
);
186 static void GLAPIENTRY
187 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
190 p
[0] = (GLfloat
) param
;
191 p
[1] = p
[2] = p
[3] = 0.0F
;
192 _mesa_TexGenfv( coord
, pname
, p
);
196 static void GLAPIENTRY
197 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
200 p
[0] = (GLfloat
) params
[0];
201 if (pname
== GL_TEXTURE_GEN_MODE
) {
202 p
[1] = p
[2] = p
[3] = 0.0F
;
205 p
[1] = (GLfloat
) params
[1];
206 p
[2] = (GLfloat
) params
[2];
207 p
[3] = (GLfloat
) params
[3];
209 _mesa_TexGenfv( coord
, pname
, p
);
214 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
218 p
[1] = p
[2] = p
[3] = 0.0F
;
219 _mesa_TexGenfv(coord
, pname
, p
);
224 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
228 p
[1] = p
[2] = p
[3] = 0;
229 _mesa_TexGeniv( coord
, pname
, p
);
234 static void GLAPIENTRY
235 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
237 struct gl_texture_unit
*texUnit
;
238 struct gl_texgen
*texgen
;
239 GET_CURRENT_CONTEXT(ctx
);
240 ASSERT_OUTSIDE_BEGIN_END(ctx
);
242 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
243 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
247 texUnit
= _mesa_get_current_tex_unit(ctx
);
249 texgen
= get_texgen(texUnit
, coord
);
251 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
256 case GL_TEXTURE_GEN_MODE
:
257 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
259 case GL_OBJECT_PLANE
:
260 COPY_4V(params
, texgen
->ObjectPlane
);
263 COPY_4V(params
, texgen
->EyePlane
);
266 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
273 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
275 struct gl_texture_unit
*texUnit
;
276 struct gl_texgen
*texgen
;
277 GET_CURRENT_CONTEXT(ctx
);
278 ASSERT_OUTSIDE_BEGIN_END(ctx
);
280 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
281 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
285 texUnit
= _mesa_get_current_tex_unit(ctx
);
287 texgen
= get_texgen(texUnit
, coord
);
289 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
294 case GL_TEXTURE_GEN_MODE
:
295 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
297 case GL_OBJECT_PLANE
:
298 COPY_4V(params
, texgen
->ObjectPlane
);
301 COPY_4V(params
, texgen
->EyePlane
);
304 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
310 static void GLAPIENTRY
311 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
313 struct gl_texture_unit
*texUnit
;
314 struct gl_texgen
*texgen
;
315 GET_CURRENT_CONTEXT(ctx
);
316 ASSERT_OUTSIDE_BEGIN_END(ctx
);
318 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
319 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
323 texUnit
= _mesa_get_current_tex_unit(ctx
);
325 texgen
= get_texgen(texUnit
, coord
);
327 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
332 case GL_TEXTURE_GEN_MODE
:
333 params
[0] = texgen
->Mode
;
335 case GL_OBJECT_PLANE
:
336 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
337 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
338 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
339 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
342 params
[0] = (GLint
) texgen
->EyePlane
[0];
343 params
[1] = (GLint
) texgen
->EyePlane
[1];
344 params
[2] = (GLint
) texgen
->EyePlane
[2];
345 params
[3] = (GLint
) texgen
->EyePlane
[3];
348 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
354 _mesa_init_texgen_dispatch(struct _glapi_table
*disp
)
356 SET_GetTexGendv(disp
, _mesa_GetTexGendv
);
357 SET_GetTexGenfv(disp
, _mesa_GetTexGenfv
);
358 SET_GetTexGeniv(disp
, _mesa_GetTexGeniv
);
359 SET_TexGend(disp
, _mesa_TexGend
);
360 SET_TexGendv(disp
, _mesa_TexGendv
);
361 SET_TexGenf(disp
, _mesa_TexGenf
);
362 SET_TexGenfv(disp
, _mesa_TexGenfv
);
363 SET_TexGeni(disp
, _mesa_TexGeni
);
364 SET_TexGeniv(disp
, _mesa_TexGeniv
);
368 #endif /* FEATURE_texgen */