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_context
*ctx
, struct gl_texture_unit
*texUnit
,
54 if (ctx
->API
== API_OPENGLES
) {
55 return (coord
== GL_TEXTURE_GEN_STR_OES
)
56 ? &texUnit
->GenS
: NULL
;
61 return &texUnit
->GenS
;
63 return &texUnit
->GenT
;
65 return &texUnit
->GenR
;
67 return &texUnit
->GenQ
;
75 _mesa_TexGenfv( GLenum coord
, GLenum pname
, const GLfloat
*params
)
77 struct gl_texture_unit
*texUnit
;
78 struct gl_texgen
*texgen
;
79 GET_CURRENT_CONTEXT(ctx
);
80 ASSERT_OUTSIDE_BEGIN_END(ctx
);
82 if (MESA_VERBOSE
&(VERBOSE_API
|VERBOSE_TEXTURE
))
83 _mesa_debug(ctx
, "glTexGen %s %s %.1f(%s)...\n",
84 _mesa_lookup_enum_by_nr(coord
),
85 _mesa_lookup_enum_by_nr(pname
),
87 _mesa_lookup_enum_by_nr((GLenum
) (GLint
) *params
));
89 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
90 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glTexGen(current unit)");
94 texUnit
= _mesa_get_current_tex_unit(ctx
);
96 texgen
= get_texgen(ctx
, texUnit
, coord
);
98 _mesa_error(ctx
, GL_INVALID_ENUM
, "glTexGen(coord)");
103 case GL_TEXTURE_GEN_MODE
:
105 GLenum mode
= (GLenum
) (GLint
) params
[0];
106 GLbitfield bit
= 0x0;
107 if (texgen
->Mode
== mode
)
110 case GL_OBJECT_LINEAR
:
111 bit
= TEXGEN_OBJ_LINEAR
;
114 bit
= TEXGEN_EYE_LINEAR
;
117 if (coord
== GL_S
|| coord
== GL_T
)
118 bit
= TEXGEN_SPHERE_MAP
;
120 case GL_REFLECTION_MAP_NV
:
122 bit
= TEXGEN_REFLECTION_MAP_NV
;
124 case GL_NORMAL_MAP_NV
:
126 bit
= TEXGEN_NORMAL_MAP_NV
;
132 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
135 if (ctx
->API
!= API_OPENGL
136 && (bit
& (TEXGEN_REFLECTION_MAP_NV
| TEXGEN_NORMAL_MAP_NV
)) == 0) {
137 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
141 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
143 texgen
->_ModeBit
= bit
;
147 case GL_OBJECT_PLANE
:
149 if (ctx
->API
!= API_OPENGL
) {
150 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
153 if (TEST_EQ_4V(texgen
->ObjectPlane
, params
))
155 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
156 COPY_4FV(texgen
->ObjectPlane
, params
);
164 if (ctx
->API
!= API_OPENGL
) {
165 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(param)" );
169 /* Transform plane equation by the inverse modelview matrix */
170 if (_math_matrix_is_dirty(ctx
->ModelviewMatrixStack
.Top
)) {
171 _math_matrix_analyse(ctx
->ModelviewMatrixStack
.Top
);
173 _mesa_transform_vector(tmp
, params
,
174 ctx
->ModelviewMatrixStack
.Top
->inv
);
175 if (TEST_EQ_4V(texgen
->EyePlane
, tmp
))
177 FLUSH_VERTICES(ctx
, _NEW_TEXTURE
);
178 COPY_4FV(texgen
->EyePlane
, tmp
);
183 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGenfv(pname)" );
187 if (ctx
->Driver
.TexGen
)
188 ctx
->Driver
.TexGen( ctx
, coord
, pname
, params
);
192 static void GLAPIENTRY
193 _mesa_TexGeniv(GLenum coord
, GLenum pname
, const GLint
*params
)
196 p
[0] = (GLfloat
) params
[0];
197 if (pname
== GL_TEXTURE_GEN_MODE
) {
198 p
[1] = p
[2] = p
[3] = 0.0F
;
201 p
[1] = (GLfloat
) params
[1];
202 p
[2] = (GLfloat
) params
[2];
203 p
[3] = (GLfloat
) params
[3];
205 _mesa_TexGenfv(coord
, pname
, p
);
209 static void GLAPIENTRY
210 _mesa_TexGend(GLenum coord
, GLenum pname
, GLdouble param
)
213 p
[0] = (GLfloat
) param
;
214 p
[1] = p
[2] = p
[3] = 0.0F
;
215 _mesa_TexGenfv( coord
, pname
, p
);
221 _es_GetTexGenfv(GLenum coord
, GLenum pname
, GLfloat
*params
)
223 _mesa_GetTexGenfv(GL_S
, pname
, params
);
228 _es_TexGenf(GLenum coord
, GLenum pname
, GLfloat param
)
230 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
231 GET_CURRENT_CONTEXT(ctx
);
232 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx](pname)" );
235 /* set S, T, and R at the same time */
236 _mesa_TexGenf(GL_S
, pname
, param
);
237 _mesa_TexGenf(GL_T
, pname
, param
);
238 _mesa_TexGenf(GL_R
, pname
, param
);
243 _es_TexGenfv(GLenum coord
, GLenum pname
, const GLfloat
*params
)
245 if (coord
!= GL_TEXTURE_GEN_STR_OES
) {
246 GET_CURRENT_CONTEXT(ctx
);
247 _mesa_error( ctx
, GL_INVALID_ENUM
, "glTexGen[fx]v(pname)" );
250 /* set S, T, and R at the same time */
251 _mesa_TexGenfv(GL_S
, pname
, params
);
252 _mesa_TexGenfv(GL_T
, pname
, params
);
253 _mesa_TexGenfv(GL_R
, pname
, params
);
258 static void GLAPIENTRY
259 _mesa_TexGendv(GLenum coord
, GLenum pname
, const GLdouble
*params
)
262 p
[0] = (GLfloat
) params
[0];
263 if (pname
== GL_TEXTURE_GEN_MODE
) {
264 p
[1] = p
[2] = p
[3] = 0.0F
;
267 p
[1] = (GLfloat
) params
[1];
268 p
[2] = (GLfloat
) params
[2];
269 p
[3] = (GLfloat
) params
[3];
271 _mesa_TexGenfv( coord
, pname
, p
);
276 _mesa_TexGenf( GLenum coord
, GLenum pname
, GLfloat param
)
280 p
[1] = p
[2] = p
[3] = 0.0F
;
281 _mesa_TexGenfv(coord
, pname
, p
);
286 _mesa_TexGeni( GLenum coord
, GLenum pname
, GLint param
)
290 p
[1] = p
[2] = p
[3] = 0;
291 _mesa_TexGeniv( coord
, pname
, p
);
296 static void GLAPIENTRY
297 _mesa_GetTexGendv( GLenum coord
, GLenum pname
, GLdouble
*params
)
299 struct gl_texture_unit
*texUnit
;
300 struct gl_texgen
*texgen
;
301 GET_CURRENT_CONTEXT(ctx
);
302 ASSERT_OUTSIDE_BEGIN_END(ctx
);
304 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
305 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGendv(current unit)");
309 texUnit
= _mesa_get_current_tex_unit(ctx
);
311 texgen
= get_texgen(ctx
, texUnit
, coord
);
313 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGendv(coord)");
318 case GL_TEXTURE_GEN_MODE
:
319 params
[0] = ENUM_TO_DOUBLE(texgen
->Mode
);
321 case GL_OBJECT_PLANE
:
322 COPY_4V(params
, texgen
->ObjectPlane
);
325 COPY_4V(params
, texgen
->EyePlane
);
328 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGendv(pname)" );
335 _mesa_GetTexGenfv( GLenum coord
, GLenum pname
, GLfloat
*params
)
337 struct gl_texture_unit
*texUnit
;
338 struct gl_texgen
*texgen
;
339 GET_CURRENT_CONTEXT(ctx
);
340 ASSERT_OUTSIDE_BEGIN_END(ctx
);
342 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
343 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGenfv(current unit)");
347 texUnit
= _mesa_get_current_tex_unit(ctx
);
349 texgen
= get_texgen(ctx
, texUnit
, coord
);
351 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(coord)");
356 case GL_TEXTURE_GEN_MODE
:
357 params
[0] = ENUM_TO_FLOAT(texgen
->Mode
);
359 case GL_OBJECT_PLANE
:
360 if (ctx
->API
!= API_OPENGL
) {
361 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
364 COPY_4V(params
, texgen
->ObjectPlane
);
367 if (ctx
->API
!= API_OPENGL
) {
368 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(param)" );
371 COPY_4V(params
, texgen
->EyePlane
);
374 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGenfv(pname)" );
381 _mesa_GetTexGeniv( GLenum coord
, GLenum pname
, GLint
*params
)
383 struct gl_texture_unit
*texUnit
;
384 struct gl_texgen
*texgen
;
385 GET_CURRENT_CONTEXT(ctx
);
386 ASSERT_OUTSIDE_BEGIN_END(ctx
);
388 if (ctx
->Texture
.CurrentUnit
>= ctx
->Const
.MaxTextureCoordUnits
) {
389 _mesa_error(ctx
, GL_INVALID_OPERATION
, "glGetTexGeniv(current unit)");
393 texUnit
= _mesa_get_current_tex_unit(ctx
);
395 texgen
= get_texgen(ctx
, texUnit
, coord
);
397 _mesa_error(ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(coord)");
402 case GL_TEXTURE_GEN_MODE
:
403 params
[0] = texgen
->Mode
;
405 case GL_OBJECT_PLANE
:
406 if (ctx
->API
!= API_OPENGL
) {
407 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
410 params
[0] = (GLint
) texgen
->ObjectPlane
[0];
411 params
[1] = (GLint
) texgen
->ObjectPlane
[1];
412 params
[2] = (GLint
) texgen
->ObjectPlane
[2];
413 params
[3] = (GLint
) texgen
->ObjectPlane
[3];
416 if (ctx
->API
!= API_OPENGL
) {
417 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(param)" );
420 params
[0] = (GLint
) texgen
->EyePlane
[0];
421 params
[1] = (GLint
) texgen
->EyePlane
[1];
422 params
[2] = (GLint
) texgen
->EyePlane
[2];
423 params
[3] = (GLint
) texgen
->EyePlane
[3];
426 _mesa_error( ctx
, GL_INVALID_ENUM
, "glGetTexGeniv(pname)" );
432 _mesa_init_texgen_dispatch(struct _glapi_table
*disp
)
434 SET_GetTexGendv(disp
, _mesa_GetTexGendv
);
435 SET_GetTexGenfv(disp
, _mesa_GetTexGenfv
);
436 SET_GetTexGeniv(disp
, _mesa_GetTexGeniv
);
437 SET_TexGend(disp
, _mesa_TexGend
);
438 SET_TexGendv(disp
, _mesa_TexGendv
);
439 SET_TexGenf(disp
, _mesa_TexGenf
);
440 SET_TexGenfv(disp
, _mesa_TexGenfv
);
441 SET_TexGeni(disp
, _mesa_TexGeni
);
442 SET_TexGeniv(disp
, _mesa_TexGeniv
);
446 #endif /* FEATURE_texgen */