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/mfeatures.h"
38 #include "main/texgen.h"
39 #include "main/texstate.h"
40 #include "math/m_matrix.h"
41 #include "main/dispatch.h"
48 * Return texgen state for given coordinate
50 static struct gl_texgen *
51 get_texgen(struct gl_texture_unit *texUnit, GLenum coord)
55 return &texUnit->GenS;
57 return &texUnit->GenT;
59 return &texUnit->GenR;
61 return &texUnit->GenQ;
69 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
71 struct gl_texture_unit *texUnit;
72 struct gl_texgen *texgen;
73 GET_CURRENT_CONTEXT(ctx);
74 ASSERT_OUTSIDE_BEGIN_END(ctx);
76 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
77 _mesa_debug(ctx, "glTexGen %s %s %.1f(%s)...\n",
78 _mesa_lookup_enum_by_nr(coord),
79 _mesa_lookup_enum_by_nr(pname),
81 _mesa_lookup_enum_by_nr((GLenum) (GLint) *params));
83 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
84 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexGen(current unit)");
88 texUnit = _mesa_get_current_tex_unit(ctx);
90 texgen = get_texgen(texUnit, coord);
92 _mesa_error(ctx, GL_INVALID_ENUM, "glTexGen(coord)");
97 case GL_TEXTURE_GEN_MODE:
99 GLenum mode = (GLenum) (GLint) params[0];
100 GLbitfield bit = 0x0;
101 if (texgen->Mode == mode)
104 case GL_OBJECT_LINEAR:
105 bit = TEXGEN_OBJ_LINEAR;
108 bit = TEXGEN_EYE_LINEAR;
111 if (coord == GL_S || coord == GL_T)
112 bit = TEXGEN_SPHERE_MAP;
114 case GL_REFLECTION_MAP_NV:
116 bit = TEXGEN_REFLECTION_MAP_NV;
118 case GL_NORMAL_MAP_NV:
120 bit = TEXGEN_NORMAL_MAP_NV;
126 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
129 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
131 texgen->_ModeBit = bit;
135 case GL_OBJECT_PLANE:
137 if (TEST_EQ_4V(texgen->ObjectPlane, params))
139 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
140 COPY_4FV(texgen->ObjectPlane, params);
147 /* Transform plane equation by the inverse modelview matrix */
148 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
149 _math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
151 _mesa_transform_vector(tmp, params,
152 ctx->ModelviewMatrixStack.Top->inv);
153 if (TEST_EQ_4V(texgen->EyePlane, tmp))
155 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
156 COPY_4FV(texgen->EyePlane, tmp);
161 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
165 if (ctx->Driver.TexGen)
166 ctx->Driver.TexGen( ctx, coord, pname, params );
170 static void GLAPIENTRY
171 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
174 p[0] = (GLfloat) params[0];
175 if (pname == GL_TEXTURE_GEN_MODE) {
176 p[1] = p[2] = p[3] = 0.0F;
179 p[1] = (GLfloat) params[1];
180 p[2] = (GLfloat) params[2];
181 p[3] = (GLfloat) params[3];
183 _mesa_TexGenfv(coord, pname, p);
187 static void GLAPIENTRY
188 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
191 p[0] = (GLfloat) param;
192 p[1] = p[2] = p[3] = 0.0F;
193 _mesa_TexGenfv( coord, pname, p );
199 _es_GetTexGenfv(GLenum coord, GLenum pname, GLfloat *params)
201 ASSERT(coord == GL_TEXTURE_GEN_STR_OES);
202 _mesa_GetTexGenfv(GL_S, pname, params);
207 _es_TexGenf(GLenum coord, GLenum pname, GLfloat param)
209 ASSERT(coord == GL_TEXTURE_GEN_STR_OES);
210 /* set S, T, and R at the same time */
211 _mesa_TexGenf(GL_S, pname, param);
212 _mesa_TexGenf(GL_T, pname, param);
213 _mesa_TexGenf(GL_R, pname, param);
218 _es_TexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
220 ASSERT(coord == GL_TEXTURE_GEN_STR_OES);
221 /* set S, T, and R at the same time */
222 _mesa_TexGenfv(GL_S, pname, params);
223 _mesa_TexGenfv(GL_T, pname, params);
224 _mesa_TexGenfv(GL_R, pname, params);
229 static void GLAPIENTRY
230 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
233 p[0] = (GLfloat) params[0];
234 if (pname == GL_TEXTURE_GEN_MODE) {
235 p[1] = p[2] = p[3] = 0.0F;
238 p[1] = (GLfloat) params[1];
239 p[2] = (GLfloat) params[2];
240 p[3] = (GLfloat) params[3];
242 _mesa_TexGenfv( coord, pname, p );
247 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
251 p[1] = p[2] = p[3] = 0.0F;
252 _mesa_TexGenfv(coord, pname, p);
257 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
261 p[1] = p[2] = p[3] = 0;
262 _mesa_TexGeniv( coord, pname, p );
267 static void GLAPIENTRY
268 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
270 struct gl_texture_unit *texUnit;
271 struct gl_texgen *texgen;
272 GET_CURRENT_CONTEXT(ctx);
273 ASSERT_OUTSIDE_BEGIN_END(ctx);
275 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
276 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGendv(current unit)");
280 texUnit = _mesa_get_current_tex_unit(ctx);
282 texgen = get_texgen(texUnit, coord);
284 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)");
289 case GL_TEXTURE_GEN_MODE:
290 params[0] = ENUM_TO_DOUBLE(texgen->Mode);
292 case GL_OBJECT_PLANE:
293 COPY_4V(params, texgen->ObjectPlane);
296 COPY_4V(params, texgen->EyePlane);
299 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
306 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
308 struct gl_texture_unit *texUnit;
309 struct gl_texgen *texgen;
310 GET_CURRENT_CONTEXT(ctx);
311 ASSERT_OUTSIDE_BEGIN_END(ctx);
313 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
314 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGenfv(current unit)");
318 texUnit = _mesa_get_current_tex_unit(ctx);
320 texgen = get_texgen(texUnit, coord);
322 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)");
327 case GL_TEXTURE_GEN_MODE:
328 params[0] = ENUM_TO_FLOAT(texgen->Mode);
330 case GL_OBJECT_PLANE:
331 COPY_4V(params, texgen->ObjectPlane);
334 COPY_4V(params, texgen->EyePlane);
337 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
343 static void GLAPIENTRY
344 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
346 struct gl_texture_unit *texUnit;
347 struct gl_texgen *texgen;
348 GET_CURRENT_CONTEXT(ctx);
349 ASSERT_OUTSIDE_BEGIN_END(ctx);
351 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
352 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGeniv(current unit)");
356 texUnit = _mesa_get_current_tex_unit(ctx);
358 texgen = get_texgen(texUnit, coord);
360 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)");
365 case GL_TEXTURE_GEN_MODE:
366 params[0] = texgen->Mode;
368 case GL_OBJECT_PLANE:
369 params[0] = (GLint) texgen->ObjectPlane[0];
370 params[1] = (GLint) texgen->ObjectPlane[1];
371 params[2] = (GLint) texgen->ObjectPlane[2];
372 params[3] = (GLint) texgen->ObjectPlane[3];
375 params[0] = (GLint) texgen->EyePlane[0];
376 params[1] = (GLint) texgen->EyePlane[1];
377 params[2] = (GLint) texgen->EyePlane[2];
378 params[3] = (GLint) texgen->EyePlane[3];
381 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
387 _mesa_init_texgen_dispatch(struct _glapi_table *disp)
389 SET_GetTexGendv(disp, _mesa_GetTexGendv);
390 SET_GetTexGenfv(disp, _mesa_GetTexGenfv);
391 SET_GetTexGeniv(disp, _mesa_GetTexGeniv);
392 SET_TexGend(disp, _mesa_TexGend);
393 SET_TexGendv(disp, _mesa_TexGendv);
394 SET_TexGenf(disp, _mesa_TexGenf);
395 SET_TexGenfv(disp, _mesa_TexGenfv);
396 SET_TexGeni(disp, _mesa_TexGeni);
397 SET_TexGeniv(disp, _mesa_TexGeniv);
401 #endif /* FEATURE_texgen */