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"
43 * Return texgen state for given coordinate
45 static struct gl_texgen
*
46 get_texgen(struct gl_context
*ctx
, struct gl_fixedfunc_texture_unit
*texUnit
,
49 if (ctx
->API
== API_OPENGLES
) {
50 return (coord
== GL_TEXTURE_GEN_STR_OES
)
51 ? &texUnit
->GenS
: NULL
;
56 return &texUnit
->GenS
;
58 return &texUnit
->GenT
;
60 return &texUnit
->GenR
;
62 return &texUnit
->GenQ
;
70 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
72 struct gl_fixedfunc_texture_unit
*texUnit
;
73 struct gl_texgen
*texgen
;
74 GET_CURRENT_CONTEXT(ctx
);
76 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
77 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
78 _mesa_enum_to_string(coord
),
79 _mesa_enum_to_string(pname
),
81 _mesa_enum_to_string((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_fixedfunc_tex_unit(ctx
, ctx
->Texture
.CurrentUnit
);
90 texgen
= get_texgen(ctx
, 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 if (ctx
->API
!= API_OPENGL_COMPAT
130 && (bit
& (TEXGEN_REFLECTION_MAP_NV
| TEXGEN_NORMAL_MAP_NV
)) == 0) {
131 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
135 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
137 texgen
->_ModeBit
= bit
;
141 case GL_OBJECT_PLANE
:
143 if (ctx
->API
!= API_OPENGL_COMPAT
) {
144 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
147 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
149 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
150 COPY_4FV(texgen
->ObjectPlane
, params
);
158 if (ctx
->API
!= API_OPENGL_COMPAT
) {
159 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
163 /* Transform plane equation by the inverse modelview matrix */
164 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
165 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
167 _mesa_transform_vector(tmp
, params
,
168 ctx
->ModelviewMatrixStack
.Top
->inv
);
169 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
171 FLUSH_VERTICES(ctx
, _NEW_TEXTURE_STATE
);
172 COPY_4FV(texgen
->EyePlane
, tmp
);
177 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
181 if (ctx
->Driver
.TexGen
)
182 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
187 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
190 p
[0] = (GLfloat
) params
[0];
191 if (pname
== GL_TEXTURE_GEN_MODE
) {
192 p
[1] = p
[2] = p
[3] = 0.0F
;
195 p
[1] = (GLfloat
) params
[1];
196 p
[2] = (GLfloat
) params
[2];
197 p
[3] = (GLfloat
) params
[3];
199 _mesa_TexGenfv(coord
, pname
, p
);
204 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
207 p
[0] = (GLfloat
) param
;
208 p
[1] = p
[2] = p
[3] = 0.0F
;
209 _mesa_TexGenfv( coord
, pname
, p
);
214 _es_GetTexGenfv(GLenum coord
, GLenum pname
, GLfloat
*params
)
216 _mesa_GetTexGenfv(GL_S
, pname
, params
);
221 _es_TexGenf(GLenum coord
, GLenum pname
, GLfloat param
)
223 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
224 GET_CURRENT_CONTEXT(ctx
);
225 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx](pname)" );
228 /* set S, T, and R at the same time */
229 _mesa_TexGenf(GL_S
, pname
, param
);
230 _mesa_TexGenf(GL_T
, pname
, param
);
231 _mesa_TexGenf(GL_R
, pname
, param
);
236 _es_TexGenfv(GLenum coord
, GLenum pname
, const GLfloat
*params
)
238 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
239 GET_CURRENT_CONTEXT(ctx
);
240 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx]v(pname)" );
243 /* set S, T, and R at the same time */
244 _mesa_TexGenfv(GL_S
, pname
, params
);
245 _mesa_TexGenfv(GL_T
, pname
, params
);
246 _mesa_TexGenfv(GL_R
, pname
, params
);
251 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
254 p
[0] = (GLfloat
) params
[0];
255 if (pname
== GL_TEXTURE_GEN_MODE
) {
256 p
[1] = p
[2] = p
[3] = 0.0F
;
259 p
[1] = (GLfloat
) params
[1];
260 p
[2] = (GLfloat
) params
[2];
261 p
[3] = (GLfloat
) params
[3];
263 _mesa_TexGenfv( coord
, pname
, p
);
268 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
272 p
[1] = p
[2] = p
[3] = 0.0F
;
273 _mesa_TexGenfv(coord
, pname
, p
);
278 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
282 p
[1] = p
[2] = p
[3] = 0;
283 _mesa_TexGeniv( coord
, pname
, p
);
289 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
291 struct gl_fixedfunc_texture_unit
*texUnit
;
292 struct gl_texgen
*texgen
;
293 GET_CURRENT_CONTEXT(ctx
);
295 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
296 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
300 texUnit
= _mesa_get_fixedfunc_tex_unit(ctx
, ctx
->Texture
.CurrentUnit
);
302 texgen
= get_texgen(ctx
, texUnit
, coord
);
304 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
309 case GL_TEXTURE_GEN_MODE
:
310 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
312 case GL_OBJECT_PLANE
:
313 COPY_4V(params
, texgen
->ObjectPlane
);
316 COPY_4V(params
, texgen
->EyePlane
);
319 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
326 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
328 struct gl_fixedfunc_texture_unit
*texUnit
;
329 struct gl_texgen
*texgen
;
330 GET_CURRENT_CONTEXT(ctx
);
332 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
333 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
337 texUnit
= _mesa_get_fixedfunc_tex_unit(ctx
, ctx
->Texture
.CurrentUnit
);
339 texgen
= get_texgen(ctx
, texUnit
, coord
);
341 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
346 case GL_TEXTURE_GEN_MODE
:
347 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
349 case GL_OBJECT_PLANE
:
350 if (ctx
->API
!= API_OPENGL_COMPAT
) {
351 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
354 COPY_4V(params
, texgen
->ObjectPlane
);
357 if (ctx
->API
!= API_OPENGL_COMPAT
) {
358 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
361 COPY_4V(params
, texgen
->EyePlane
);
364 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
371 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
373 struct gl_fixedfunc_texture_unit
*texUnit
;
374 struct gl_texgen
*texgen
;
375 GET_CURRENT_CONTEXT(ctx
);
377 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
378 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
382 texUnit
= _mesa_get_fixedfunc_tex_unit(ctx
, ctx
->Texture
.CurrentUnit
);
384 texgen
= get_texgen(ctx
, texUnit
, coord
);
386 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
391 case GL_TEXTURE_GEN_MODE
:
392 params
[0] = texgen
->Mode
;
394 case GL_OBJECT_PLANE
:
395 if (ctx
->API
!= API_OPENGL_COMPAT
) {
396 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
399 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
400 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
401 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
402 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
405 if (ctx
->API
!= API_OPENGL_COMPAT
) {
406 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
409 params
[0] = (GLint
) texgen
->EyePlane
[0];
410 params
[1] = (GLint
) texgen
->EyePlane
[1];
411 params
[2] = (GLint
) texgen
->EyePlane
[2];
412 params
[3] = (GLint
) texgen
->EyePlane
[3];
415 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );