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
38 * Return texgen state for given coordinate
40 static struct gl_texgen
*
41 get_texgen(struct gl_texture_unit
*texUnit
, GLenum coord
)
45 return &texUnit
->GenS
;
47 return &texUnit
->GenT
;
49 return &texUnit
->GenR
;
51 return &texUnit
->GenQ
;
59 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
61 struct gl_texture_unit
*texUnit
;
62 struct gl_texgen
*texgen
;
63 GET_CURRENT_CONTEXT(ctx
);
64 ASSERT_OUTSIDE_BEGIN_END(ctx
);
66 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
67 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
68 _mesa_lookup_enum_by_nr(coord
),
69 _mesa_lookup_enum_by_nr(pname
),
71 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
73 texUnit
= &ctx
->Texture
.Unit
;
75 texgen
= get_texgen(texUnit
, coord
);
77 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
82 case GL_TEXTURE_GEN_MODE
:
84 GLenum mode
= (GLenum
) (GLint
) params
[0];
86 if (texgen
->Mode
== mode
)
89 case GL_OBJECT_LINEAR
:
90 bit
= TEXGEN_OBJ_LINEAR
;
93 bit
= TEXGEN_EYE_LINEAR
;
96 if (coord
== GL_S
|| coord
== GL_T
)
97 bit
= TEXGEN_SPHERE_MAP
;
99 case GL_REFLECTION_MAP_NV
:
101 bit
= TEXGEN_REFLECTION_MAP_NV
;
103 case GL_NORMAL_MAP_NV
:
105 bit
= TEXGEN_NORMAL_MAP_NV
;
111 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
114 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
116 texgen
->_ModeBit
= bit
;
120 case GL_OBJECT_PLANE
:
122 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
124 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
125 COPY_4FV(texgen
->ObjectPlane
, params
);
132 /* Transform plane equation by the inverse modelview matrix */
133 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
134 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
136 _mesa_transform_vector(tmp
, params
,
137 ctx
->ModelviewMatrixStack
.Top
->inv
);
138 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
140 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
141 COPY_4FV(texgen
->EyePlane
, tmp
);
146 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
150 if (ctx
->Driver
.TexGen
)
151 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
155 static void GLAPIENTRY
156 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
159 p
[0] = (GLfloat
) params
[0];
160 if (pname
== GL_TEXTURE_GEN_MODE
) {
161 p
[1] = p
[2] = p
[3] = 0.0F
;
164 p
[1] = (GLfloat
) params
[1];
165 p
[2] = (GLfloat
) params
[2];
166 p
[3] = (GLfloat
) params
[3];
168 _mesa_TexGenfv(coord
, pname
, p
);
172 static void GLAPIENTRY
173 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
176 p
[0] = (GLfloat
) param
;
177 p
[1] = p
[2] = p
[3] = 0.0F
;
178 _mesa_TexGenfv( coord
, pname
, p
);
184 _es_GetTexGenfv(GLenum coord
, GLenum pname
, GLfloat
*params
)
186 ASSERT(coord
== GL_TEXTURE_GEN_STR_OES
);
187 _mesa_GetTexGenfv(GL_S
, pname
, params
);
192 _es_TexGenf(GLenum coord
, GLenum pname
, GLfloat param
)
194 ASSERT(coord
== GL_TEXTURE_GEN_STR_OES
);
195 /* set S, T, and R at the same time */
196 _mesa_TexGenf(GL_S
, pname
, param
);
197 _mesa_TexGenf(GL_T
, pname
, param
);
198 _mesa_TexGenf(GL_R
, pname
, param
);
203 _es_TexGenfv(GLenum coord
, GLenum pname
, const GLfloat
*params
)
205 ASSERT(coord
== GL_TEXTURE_GEN_STR_OES
);
206 /* set S, T, and R at the same time */
207 _mesa_TexGenfv(GL_S
, pname
, params
);
208 _mesa_TexGenfv(GL_T
, pname
, params
);
209 _mesa_TexGenfv(GL_R
, pname
, params
);
214 static void GLAPIENTRY
215 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
218 p
[0] = (GLfloat
) params
[0];
219 if (pname
== GL_TEXTURE_GEN_MODE
) {
220 p
[1] = p
[2] = p
[3] = 0.0F
;
223 p
[1] = (GLfloat
) params
[1];
224 p
[2] = (GLfloat
) params
[2];
225 p
[3] = (GLfloat
) params
[3];
227 _mesa_TexGenfv( coord
, pname
, p
);
232 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
236 p
[1] = p
[2] = p
[3] = 0.0F
;
237 _mesa_TexGenfv(coord
, pname
, p
);
242 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
246 p
[1] = p
[2] = p
[3] = 0;
247 _mesa_TexGeniv( coord
, pname
, p
);
252 static void GLAPIENTRY
253 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
255 struct gl_texture_unit
*texUnit
;
256 struct gl_texgen
*texgen
;
257 GET_CURRENT_CONTEXT(ctx
);
258 ASSERT_OUTSIDE_BEGIN_END(ctx
);
260 texUnit
= &ctx
->Texture
.Unit
;
262 texgen
= get_texgen(texUnit
, coord
);
264 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
269 case GL_TEXTURE_GEN_MODE
:
270 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
272 case GL_OBJECT_PLANE
:
273 COPY_4V(params
, texgen
->ObjectPlane
);
276 COPY_4V(params
, texgen
->EyePlane
);
279 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
286 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
288 struct gl_texture_unit
*texUnit
;
289 struct gl_texgen
*texgen
;
290 GET_CURRENT_CONTEXT(ctx
);
291 ASSERT_OUTSIDE_BEGIN_END(ctx
);
293 texUnit
= &ctx
->Texture
.Unit
;
295 texgen
= get_texgen(texUnit
, coord
);
297 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
302 case GL_TEXTURE_GEN_MODE
:
303 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
305 case GL_OBJECT_PLANE
:
306 COPY_4V(params
, texgen
->ObjectPlane
);
309 COPY_4V(params
, texgen
->EyePlane
);
312 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
318 static void GLAPIENTRY
319 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
321 struct gl_texture_unit
*texUnit
;
322 struct gl_texgen
*texgen
;
323 GET_CURRENT_CONTEXT(ctx
);
324 ASSERT_OUTSIDE_BEGIN_END(ctx
);
326 texUnit
= &ctx
->Texture
.Unit
;
328 texgen
= get_texgen(texUnit
, coord
);
330 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
335 case GL_TEXTURE_GEN_MODE
:
336 params
[0] = texgen
->Mode
;
338 case GL_OBJECT_PLANE
:
339 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
340 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
341 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
342 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
345 params
[0] = (GLint
) texgen
->EyePlane
[0];
346 params
[1] = (GLint
) texgen
->EyePlane
[1];
347 params
[2] = (GLint
) texgen
->EyePlane
[2];
348 params
[3] = (GLint
) texgen
->EyePlane
[3];
351 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
357 _mesa_init_texgen_dispatch(struct _glapi_table
*disp
)
359 SET_GetTexGendv(disp
, _mesa_GetTexGendv
);
360 SET_GetTexGenfv(disp
, _mesa_GetTexGenfv
);
361 SET_GetTexGeniv(disp
, _mesa_GetTexGeniv
);
362 SET_TexGend(disp
, _mesa_TexGend
);
363 SET_TexGendv(disp
, _mesa_TexGendv
);
364 SET_TexGenf(disp
, _mesa_TexGenf
);
365 SET_TexGenfv(disp
, _mesa_TexGenfv
);
366 SET_TexGeni(disp
, _mesa_TexGeni
);
367 SET_TexGeniv(disp
, _mesa_TexGeniv
);
371 #endif /* FEATURE_texgen */