2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
5 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included
15 * in all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
18 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
23 * 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"
44 * Return texgen state for given coordinate
46 static struct gl_texgen
*
47 get_texgen(struct gl_context
*ctx
, struct gl_texture_unit
*texUnit
,
50 if (ctx
->API
== API_OPENGLES
) {
51 return (coord
== GL_TEXTURE_GEN_STR_OES
)
52 ? &texUnit
->GenS
: NULL
;
57 return &texUnit
->GenS
;
59 return &texUnit
->GenT
;
61 return &texUnit
->GenR
;
63 return &texUnit
->GenQ
;
71 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
73 struct gl_texture_unit
*texUnit
;
74 struct gl_texgen
*texgen
;
75 GET_CURRENT_CONTEXT(ctx
);
77 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
78 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
79 _mesa_enum_to_string(coord
),
80 _mesa_enum_to_string(pname
),
82 _mesa_enum_to_string((GLenum
) (GLint
) *params
));
84 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
85 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
89 texUnit
= _mesa_get_current_tex_unit(ctx
);
91 texgen
= get_texgen(ctx
, texUnit
, coord
);
93 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
98 case GL_TEXTURE_GEN_MODE
:
100 GLenum mode
= (GLenum
) (GLint
) params
[0];
101 GLbitfield bit
= 0x0;
102 if (texgen
->Mode
== mode
)
105 case GL_OBJECT_LINEAR
:
106 bit
= TEXGEN_OBJ_LINEAR
;
109 bit
= TEXGEN_EYE_LINEAR
;
112 if (coord
== GL_S
|| coord
== GL_T
)
113 bit
= TEXGEN_SPHERE_MAP
;
115 case GL_REFLECTION_MAP_NV
:
117 bit
= TEXGEN_REFLECTION_MAP_NV
;
119 case GL_NORMAL_MAP_NV
:
121 bit
= TEXGEN_NORMAL_MAP_NV
;
127 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
130 if (ctx
->API
!= API_OPENGL_COMPAT
131 && (bit
& (TEXGEN_REFLECTION_MAP_NV
| TEXGEN_NORMAL_MAP_NV
)) == 0) {
132 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
136 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
138 texgen
->_ModeBit
= bit
;
142 case GL_OBJECT_PLANE
:
144 if (ctx
->API
!= API_OPENGL_COMPAT
) {
145 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
148 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
150 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
151 COPY_4FV(texgen
->ObjectPlane
, params
);
159 if (ctx
->API
!= API_OPENGL_COMPAT
) {
160 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
164 /* Transform plane equation by the inverse modelview matrix */
165 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
166 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
168 _mesa_transform_vector(tmp
, params
,
169 ctx
->ModelviewMatrixStack
.Top
->inv
);
170 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
172 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
173 COPY_4FV(texgen
->EyePlane
, tmp
);
178 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
182 if (ctx
->Driver
.TexGen
)
183 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
188 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
191 p
[0] = (GLfloat
) params
[0];
192 if (pname
== GL_TEXTURE_GEN_MODE
) {
193 p
[1] = p
[2] = p
[3] = 0.0F
;
196 p
[1] = (GLfloat
) params
[1];
197 p
[2] = (GLfloat
) params
[2];
198 p
[3] = (GLfloat
) params
[3];
200 _mesa_TexGenfv(coord
, pname
, p
);
205 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
208 p
[0] = (GLfloat
) param
;
209 p
[1] = p
[2] = p
[3] = 0.0F
;
210 _mesa_TexGenfv( coord
, pname
, p
);
215 _es_GetTexGenfv(GLenum coord
, GLenum pname
, GLfloat
*params
)
217 _mesa_GetTexGenfv(GL_S
, pname
, params
);
222 _es_TexGenf(GLenum coord
, GLenum pname
, GLfloat param
)
224 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
225 GET_CURRENT_CONTEXT(ctx
);
226 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx](pname)" );
229 /* set S, T, and R at the same time */
230 _mesa_TexGenf(GL_S
, pname
, param
);
231 _mesa_TexGenf(GL_T
, pname
, param
);
232 _mesa_TexGenf(GL_R
, pname
, param
);
237 _es_TexGenfv(GLenum coord
, GLenum pname
, const GLfloat
*params
)
239 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
240 GET_CURRENT_CONTEXT(ctx
);
241 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx]v(pname)" );
244 /* set S, T, and R at the same time */
245 _mesa_TexGenfv(GL_S
, pname
, params
);
246 _mesa_TexGenfv(GL_T
, pname
, params
);
247 _mesa_TexGenfv(GL_R
, pname
, params
);
252 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
255 p
[0] = (GLfloat
) params
[0];
256 if (pname
== GL_TEXTURE_GEN_MODE
) {
257 p
[1] = p
[2] = p
[3] = 0.0F
;
260 p
[1] = (GLfloat
) params
[1];
261 p
[2] = (GLfloat
) params
[2];
262 p
[3] = (GLfloat
) params
[3];
264 _mesa_TexGenfv( coord
, pname
, p
);
269 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
273 p
[1] = p
[2] = p
[3] = 0.0F
;
274 _mesa_TexGenfv(coord
, pname
, p
);
279 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
283 p
[1] = p
[2] = p
[3] = 0;
284 _mesa_TexGeniv( coord
, pname
, p
);
290 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
292 struct gl_texture_unit
*texUnit
;
293 struct gl_texgen
*texgen
;
294 GET_CURRENT_CONTEXT(ctx
);
296 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
297 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
301 texUnit
= _mesa_get_current_tex_unit(ctx
);
303 texgen
= get_texgen(ctx
, texUnit
, coord
);
305 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
310 case GL_TEXTURE_GEN_MODE
:
311 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
313 case GL_OBJECT_PLANE
:
314 COPY_4V(params
, texgen
->ObjectPlane
);
317 COPY_4V(params
, texgen
->EyePlane
);
320 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
327 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
329 struct gl_texture_unit
*texUnit
;
330 struct gl_texgen
*texgen
;
331 GET_CURRENT_CONTEXT(ctx
);
333 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
334 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
338 texUnit
= _mesa_get_current_tex_unit(ctx
);
340 texgen
= get_texgen(ctx
, texUnit
, coord
);
342 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
347 case GL_TEXTURE_GEN_MODE
:
348 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
350 case GL_OBJECT_PLANE
:
351 if (ctx
->API
!= API_OPENGL_COMPAT
) {
352 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
355 COPY_4V(params
, texgen
->ObjectPlane
);
358 if (ctx
->API
!= API_OPENGL_COMPAT
) {
359 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
362 COPY_4V(params
, texgen
->EyePlane
);
365 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
372 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
374 struct gl_texture_unit
*texUnit
;
375 struct gl_texgen
*texgen
;
376 GET_CURRENT_CONTEXT(ctx
);
378 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
379 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
383 texUnit
= _mesa_get_current_tex_unit(ctx
);
385 texgen
= get_texgen(ctx
, texUnit
, coord
);
387 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
392 case GL_TEXTURE_GEN_MODE
:
393 params
[0] = texgen
->Mode
;
395 case GL_OBJECT_PLANE
:
396 if (ctx
->API
!= API_OPENGL_COMPAT
) {
397 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
400 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
401 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
402 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
403 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
406 if (ctx
->API
!= API_OPENGL_COMPAT
) {
407 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
410 params
[0] = (GLint
) texgen
->EyePlane
[0];
411 params
[1] = (GLint
) texgen
->EyePlane
[1];
412 params
[2] = (GLint
) texgen
->EyePlane
[2];
413 params
[3] = (GLint
) texgen
->EyePlane
[3];
416 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );