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"
45 * Return texgen state for given coordinate
47 static struct gl_texgen
*
48 get_texgen(struct gl_context
*ctx
, struct gl_texture_unit
*texUnit
,
51 if (ctx
->API
== API_OPENGLES
) {
52 return (coord
== GL_TEXTURE_GEN_STR_OES
)
53 ? &texUnit
->GenS
: NULL
;
58 return &texUnit
->GenS
;
60 return &texUnit
->GenT
;
62 return &texUnit
->GenR
;
64 return &texUnit
->GenQ
;
72 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
74 struct gl_texture_unit
*texUnit
;
75 struct gl_texgen
*texgen
;
76 GET_CURRENT_CONTEXT(ctx
);
78 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
79 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
80 _mesa_lookup_enum_by_nr(coord
),
81 _mesa_lookup_enum_by_nr(pname
),
83 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
85 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
86 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
90 texUnit
= _mesa_get_current_tex_unit(ctx
);
92 texgen
= get_texgen(ctx
, texUnit
, coord
);
94 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
99 case GL_TEXTURE_GEN_MODE
:
101 GLenum mode
= (GLenum
) (GLint
) params
[0];
102 GLbitfield bit
= 0x0;
103 if (texgen
->Mode
== mode
)
106 case GL_OBJECT_LINEAR
:
107 bit
= TEXGEN_OBJ_LINEAR
;
110 bit
= TEXGEN_EYE_LINEAR
;
113 if (coord
== GL_S
|| coord
== GL_T
)
114 bit
= TEXGEN_SPHERE_MAP
;
116 case GL_REFLECTION_MAP_NV
:
118 bit
= TEXGEN_REFLECTION_MAP_NV
;
120 case GL_NORMAL_MAP_NV
:
122 bit
= TEXGEN_NORMAL_MAP_NV
;
128 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
131 if (ctx
->API
!= API_OPENGL_COMPAT
132 && (bit
& (TEXGEN_REFLECTION_MAP_NV
| TEXGEN_NORMAL_MAP_NV
)) == 0) {
133 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
137 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
139 texgen
->_ModeBit
= bit
;
143 case GL_OBJECT_PLANE
:
145 if (ctx
->API
!= API_OPENGL_COMPAT
) {
146 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
149 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
151 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
152 COPY_4FV(texgen
->ObjectPlane
, params
);
160 if (ctx
->API
!= API_OPENGL_COMPAT
) {
161 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
165 /* Transform plane equation by the inverse modelview matrix */
166 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
167 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
169 _mesa_transform_vector(tmp
, params
,
170 ctx
->ModelviewMatrixStack
.Top
->inv
);
171 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
173 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
174 COPY_4FV(texgen
->EyePlane
, tmp
);
179 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
183 if (ctx
->Driver
.TexGen
)
184 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
189 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
192 p
[0] = (GLfloat
) params
[0];
193 if (pname
== GL_TEXTURE_GEN_MODE
) {
194 p
[1] = p
[2] = p
[3] = 0.0F
;
197 p
[1] = (GLfloat
) params
[1];
198 p
[2] = (GLfloat
) params
[2];
199 p
[3] = (GLfloat
) params
[3];
201 _mesa_TexGenfv(coord
, pname
, p
);
206 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
209 p
[0] = (GLfloat
) param
;
210 p
[1] = p
[2] = p
[3] = 0.0F
;
211 _mesa_TexGenfv( coord
, pname
, p
);
216 _es_GetTexGenfv(GLenum coord
, GLenum pname
, GLfloat
*params
)
218 _mesa_GetTexGenfv(GL_S
, pname
, params
);
223 _es_TexGenf(GLenum coord
, GLenum pname
, GLfloat param
)
225 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
226 GET_CURRENT_CONTEXT(ctx
);
227 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx](pname)" );
230 /* set S, T, and R at the same time */
231 _mesa_TexGenf(GL_S
, pname
, param
);
232 _mesa_TexGenf(GL_T
, pname
, param
);
233 _mesa_TexGenf(GL_R
, pname
, param
);
238 _es_TexGenfv(GLenum coord
, GLenum pname
, const GLfloat
*params
)
240 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
241 GET_CURRENT_CONTEXT(ctx
);
242 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx]v(pname)" );
245 /* set S, T, and R at the same time */
246 _mesa_TexGenfv(GL_S
, pname
, params
);
247 _mesa_TexGenfv(GL_T
, pname
, params
);
248 _mesa_TexGenfv(GL_R
, pname
, params
);
253 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
256 p
[0] = (GLfloat
) params
[0];
257 if (pname
== GL_TEXTURE_GEN_MODE
) {
258 p
[1] = p
[2] = p
[3] = 0.0F
;
261 p
[1] = (GLfloat
) params
[1];
262 p
[2] = (GLfloat
) params
[2];
263 p
[3] = (GLfloat
) params
[3];
265 _mesa_TexGenfv( coord
, pname
, p
);
270 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
274 p
[1] = p
[2] = p
[3] = 0.0F
;
275 _mesa_TexGenfv(coord
, pname
, p
);
280 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
284 p
[1] = p
[2] = p
[3] = 0;
285 _mesa_TexGeniv( coord
, pname
, p
);
291 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
293 struct gl_texture_unit
*texUnit
;
294 struct gl_texgen
*texgen
;
295 GET_CURRENT_CONTEXT(ctx
);
297 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
298 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
302 texUnit
= _mesa_get_current_tex_unit(ctx
);
304 texgen
= get_texgen(ctx
, texUnit
, coord
);
306 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
311 case GL_TEXTURE_GEN_MODE
:
312 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
314 case GL_OBJECT_PLANE
:
315 COPY_4V(params
, texgen
->ObjectPlane
);
318 COPY_4V(params
, texgen
->EyePlane
);
321 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
328 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
330 struct gl_texture_unit
*texUnit
;
331 struct gl_texgen
*texgen
;
332 GET_CURRENT_CONTEXT(ctx
);
334 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
335 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
339 texUnit
= _mesa_get_current_tex_unit(ctx
);
341 texgen
= get_texgen(ctx
, texUnit
, coord
);
343 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
348 case GL_TEXTURE_GEN_MODE
:
349 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
351 case GL_OBJECT_PLANE
:
352 if (ctx
->API
!= API_OPENGL_COMPAT
) {
353 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
356 COPY_4V(params
, texgen
->ObjectPlane
);
359 if (ctx
->API
!= API_OPENGL_COMPAT
) {
360 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
363 COPY_4V(params
, texgen
->EyePlane
);
366 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
373 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
375 struct gl_texture_unit
*texUnit
;
376 struct gl_texgen
*texgen
;
377 GET_CURRENT_CONTEXT(ctx
);
379 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
380 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
384 texUnit
= _mesa_get_current_tex_unit(ctx
);
386 texgen
= get_texgen(ctx
, texUnit
, coord
);
388 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
393 case GL_TEXTURE_GEN_MODE
:
394 params
[0] = texgen
->Mode
;
396 case GL_OBJECT_PLANE
:
397 if (ctx
->API
!= API_OPENGL_COMPAT
) {
398 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
401 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
402 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
403 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
404 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
407 if (ctx
->API
!= API_OPENGL_COMPAT
) {
408 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
411 params
[0] = (GLint
) texgen
->EyePlane
[0];
412 params
[1] = (GLint
) texgen
->EyePlane
[1];
413 params
[2] = (GLint
) texgen
->EyePlane
[2];
414 params
[3] = (GLint
) texgen
->EyePlane
[3];
417 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );