dispatch: Remove a few FEATURE_ES1 conditionals.
[mesa.git] / src / mesa / main / texgen.c
1 /*
2 * Mesa 3-D graphics library
3 * Version: 7.5
4 *
5 * Copyright (C) 1999-2008 Brian Paul All Rights Reserved.
6 * Copyright (C) 2009 VMware, Inc. All Rights Reserved.
7 *
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:
14 *
15 * The above copyright notice and this permission notice shall be included
16 * in all copies or substantial portions of the Software.
17 *
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.
24 */
25
26 /**
27 * \file texgen.c
28 *
29 * glTexGen-related functions
30 */
31
32
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"
42
43
44 /**
45 * Return texgen state for given coordinate
46 */
47 static struct gl_texgen *
48 get_texgen(struct gl_context *ctx, struct gl_texture_unit *texUnit,
49 GLenum coord)
50 {
51 if (ctx->API == API_OPENGLES) {
52 return (coord == GL_TEXTURE_GEN_STR_OES)
53 ? &texUnit->GenS : NULL;
54 }
55
56 switch (coord) {
57 case GL_S:
58 return &texUnit->GenS;
59 case GL_T:
60 return &texUnit->GenT;
61 case GL_R:
62 return &texUnit->GenR;
63 case GL_Q:
64 return &texUnit->GenQ;
65 default:
66 return NULL;
67 }
68 }
69
70
71 void GLAPIENTRY
72 _mesa_TexGenfv( GLenum coord, GLenum pname, const GLfloat *params )
73 {
74 struct gl_texture_unit *texUnit;
75 struct gl_texgen *texgen;
76 GET_CURRENT_CONTEXT(ctx);
77 ASSERT_OUTSIDE_BEGIN_END(ctx);
78
79 if (MESA_VERBOSE&(VERBOSE_API|VERBOSE_TEXTURE))
80 _mesa_debug(ctx, "glTexGen %s %s %.1f(%s)...\n",
81 _mesa_lookup_enum_by_nr(coord),
82 _mesa_lookup_enum_by_nr(pname),
83 *params,
84 _mesa_lookup_enum_by_nr((GLenum) (GLint) *params));
85
86 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
87 _mesa_error(ctx, GL_INVALID_OPERATION, "glTexGen(current unit)");
88 return;
89 }
90
91 texUnit = _mesa_get_current_tex_unit(ctx);
92
93 texgen = get_texgen(ctx, texUnit, coord);
94 if (!texgen) {
95 _mesa_error(ctx, GL_INVALID_ENUM, "glTexGen(coord)");
96 return;
97 }
98
99 switch (pname) {
100 case GL_TEXTURE_GEN_MODE:
101 {
102 GLenum mode = (GLenum) (GLint) params[0];
103 GLbitfield bit = 0x0;
104 if (texgen->Mode == mode)
105 return;
106 switch (mode) {
107 case GL_OBJECT_LINEAR:
108 bit = TEXGEN_OBJ_LINEAR;
109 break;
110 case GL_EYE_LINEAR:
111 bit = TEXGEN_EYE_LINEAR;
112 break;
113 case GL_SPHERE_MAP:
114 if (coord == GL_S || coord == GL_T)
115 bit = TEXGEN_SPHERE_MAP;
116 break;
117 case GL_REFLECTION_MAP_NV:
118 if (coord != GL_Q)
119 bit = TEXGEN_REFLECTION_MAP_NV;
120 break;
121 case GL_NORMAL_MAP_NV:
122 if (coord != GL_Q)
123 bit = TEXGEN_NORMAL_MAP_NV;
124 break;
125 default:
126 ; /* nop */
127 }
128 if (!bit) {
129 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
130 return;
131 }
132 if (ctx->API != API_OPENGL
133 && (bit & (TEXGEN_REFLECTION_MAP_NV | TEXGEN_NORMAL_MAP_NV)) == 0) {
134 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
135 return;
136 }
137
138 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
139 texgen->Mode = mode;
140 texgen->_ModeBit = bit;
141 }
142 break;
143
144 case GL_OBJECT_PLANE:
145 {
146 if (ctx->API != API_OPENGL) {
147 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
148 return;
149 }
150 if (TEST_EQ_4V(texgen->ObjectPlane, params))
151 return;
152 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
153 COPY_4FV(texgen->ObjectPlane, params);
154 }
155 break;
156
157 case GL_EYE_PLANE:
158 {
159 GLfloat tmp[4];
160
161 if (ctx->API != API_OPENGL) {
162 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(param)" );
163 return;
164 }
165
166 /* Transform plane equation by the inverse modelview matrix */
167 if (_math_matrix_is_dirty(ctx->ModelviewMatrixStack.Top)) {
168 _math_matrix_analyse(ctx->ModelviewMatrixStack.Top);
169 }
170 _mesa_transform_vector(tmp, params,
171 ctx->ModelviewMatrixStack.Top->inv);
172 if (TEST_EQ_4V(texgen->EyePlane, tmp))
173 return;
174 FLUSH_VERTICES(ctx, _NEW_TEXTURE);
175 COPY_4FV(texgen->EyePlane, tmp);
176 }
177 break;
178
179 default:
180 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGenfv(pname)" );
181 return;
182 }
183
184 if (ctx->Driver.TexGen)
185 ctx->Driver.TexGen( ctx, coord, pname, params );
186 }
187
188
189 static void GLAPIENTRY
190 _mesa_TexGeniv(GLenum coord, GLenum pname, const GLint *params )
191 {
192 GLfloat p[4];
193 p[0] = (GLfloat) params[0];
194 if (pname == GL_TEXTURE_GEN_MODE) {
195 p[1] = p[2] = p[3] = 0.0F;
196 }
197 else {
198 p[1] = (GLfloat) params[1];
199 p[2] = (GLfloat) params[2];
200 p[3] = (GLfloat) params[3];
201 }
202 _mesa_TexGenfv(coord, pname, p);
203 }
204
205
206 static void GLAPIENTRY
207 _mesa_TexGend(GLenum coord, GLenum pname, GLdouble param )
208 {
209 GLfloat p[4];
210 p[0] = (GLfloat) param;
211 p[1] = p[2] = p[3] = 0.0F;
212 _mesa_TexGenfv( coord, pname, p );
213 }
214
215
216 void GLAPIENTRY
217 _es_GetTexGenfv(GLenum coord, GLenum pname, GLfloat *params)
218 {
219 _mesa_GetTexGenfv(GL_S, pname, params);
220 }
221
222
223 void GLAPIENTRY
224 _es_TexGenf(GLenum coord, GLenum pname, GLfloat param)
225 {
226 if (coord != GL_TEXTURE_GEN_STR_OES) {
227 GET_CURRENT_CONTEXT(ctx);
228 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGen[fx](pname)" );
229 return;
230 }
231 /* set S, T, and R at the same time */
232 _mesa_TexGenf(GL_S, pname, param);
233 _mesa_TexGenf(GL_T, pname, param);
234 _mesa_TexGenf(GL_R, pname, param);
235 }
236
237
238 void GLAPIENTRY
239 _es_TexGenfv(GLenum coord, GLenum pname, const GLfloat *params)
240 {
241 if (coord != GL_TEXTURE_GEN_STR_OES) {
242 GET_CURRENT_CONTEXT(ctx);
243 _mesa_error( ctx, GL_INVALID_ENUM, "glTexGen[fx]v(pname)" );
244 return;
245 }
246 /* set S, T, and R at the same time */
247 _mesa_TexGenfv(GL_S, pname, params);
248 _mesa_TexGenfv(GL_T, pname, params);
249 _mesa_TexGenfv(GL_R, pname, params);
250 }
251
252
253 static void GLAPIENTRY
254 _mesa_TexGendv(GLenum coord, GLenum pname, const GLdouble *params )
255 {
256 GLfloat p[4];
257 p[0] = (GLfloat) params[0];
258 if (pname == GL_TEXTURE_GEN_MODE) {
259 p[1] = p[2] = p[3] = 0.0F;
260 }
261 else {
262 p[1] = (GLfloat) params[1];
263 p[2] = (GLfloat) params[2];
264 p[3] = (GLfloat) params[3];
265 }
266 _mesa_TexGenfv( coord, pname, p );
267 }
268
269
270 void GLAPIENTRY
271 _mesa_TexGenf( GLenum coord, GLenum pname, GLfloat param )
272 {
273 GLfloat p[4];
274 p[0] = param;
275 p[1] = p[2] = p[3] = 0.0F;
276 _mesa_TexGenfv(coord, pname, p);
277 }
278
279
280 void GLAPIENTRY
281 _mesa_TexGeni( GLenum coord, GLenum pname, GLint param )
282 {
283 GLint p[4];
284 p[0] = param;
285 p[1] = p[2] = p[3] = 0;
286 _mesa_TexGeniv( coord, pname, p );
287 }
288
289
290
291 static void GLAPIENTRY
292 _mesa_GetTexGendv( GLenum coord, GLenum pname, GLdouble *params )
293 {
294 struct gl_texture_unit *texUnit;
295 struct gl_texgen *texgen;
296 GET_CURRENT_CONTEXT(ctx);
297 ASSERT_OUTSIDE_BEGIN_END(ctx);
298
299 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
300 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGendv(current unit)");
301 return;
302 }
303
304 texUnit = _mesa_get_current_tex_unit(ctx);
305
306 texgen = get_texgen(ctx, texUnit, coord);
307 if (!texgen) {
308 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGendv(coord)");
309 return;
310 }
311
312 switch (pname) {
313 case GL_TEXTURE_GEN_MODE:
314 params[0] = ENUM_TO_DOUBLE(texgen->Mode);
315 break;
316 case GL_OBJECT_PLANE:
317 COPY_4V(params, texgen->ObjectPlane);
318 break;
319 case GL_EYE_PLANE:
320 COPY_4V(params, texgen->EyePlane);
321 break;
322 default:
323 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGendv(pname)" );
324 }
325 }
326
327
328
329 void GLAPIENTRY
330 _mesa_GetTexGenfv( GLenum coord, GLenum pname, GLfloat *params )
331 {
332 struct gl_texture_unit *texUnit;
333 struct gl_texgen *texgen;
334 GET_CURRENT_CONTEXT(ctx);
335 ASSERT_OUTSIDE_BEGIN_END(ctx);
336
337 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
338 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGenfv(current unit)");
339 return;
340 }
341
342 texUnit = _mesa_get_current_tex_unit(ctx);
343
344 texgen = get_texgen(ctx, texUnit, coord);
345 if (!texgen) {
346 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGenfv(coord)");
347 return;
348 }
349
350 switch (pname) {
351 case GL_TEXTURE_GEN_MODE:
352 params[0] = ENUM_TO_FLOAT(texgen->Mode);
353 break;
354 case GL_OBJECT_PLANE:
355 if (ctx->API != API_OPENGL) {
356 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(param)" );
357 return;
358 }
359 COPY_4V(params, texgen->ObjectPlane);
360 break;
361 case GL_EYE_PLANE:
362 if (ctx->API != API_OPENGL) {
363 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(param)" );
364 return;
365 }
366 COPY_4V(params, texgen->EyePlane);
367 break;
368 default:
369 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGenfv(pname)" );
370 }
371 }
372
373
374
375 void GLAPIENTRY
376 _mesa_GetTexGeniv( GLenum coord, GLenum pname, GLint *params )
377 {
378 struct gl_texture_unit *texUnit;
379 struct gl_texgen *texgen;
380 GET_CURRENT_CONTEXT(ctx);
381 ASSERT_OUTSIDE_BEGIN_END(ctx);
382
383 if (ctx->Texture.CurrentUnit >= ctx->Const.MaxTextureCoordUnits) {
384 _mesa_error(ctx, GL_INVALID_OPERATION, "glGetTexGeniv(current unit)");
385 return;
386 }
387
388 texUnit = _mesa_get_current_tex_unit(ctx);
389
390 texgen = get_texgen(ctx, texUnit, coord);
391 if (!texgen) {
392 _mesa_error(ctx, GL_INVALID_ENUM, "glGetTexGeniv(coord)");
393 return;
394 }
395
396 switch (pname) {
397 case GL_TEXTURE_GEN_MODE:
398 params[0] = texgen->Mode;
399 break;
400 case GL_OBJECT_PLANE:
401 if (ctx->API != API_OPENGL) {
402 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(param)" );
403 return;
404 }
405 params[0] = (GLint) texgen->ObjectPlane[0];
406 params[1] = (GLint) texgen->ObjectPlane[1];
407 params[2] = (GLint) texgen->ObjectPlane[2];
408 params[3] = (GLint) texgen->ObjectPlane[3];
409 break;
410 case GL_EYE_PLANE:
411 if (ctx->API != API_OPENGL) {
412 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(param)" );
413 return;
414 }
415 params[0] = (GLint) texgen->EyePlane[0];
416 params[1] = (GLint) texgen->EyePlane[1];
417 params[2] = (GLint) texgen->EyePlane[2];
418 params[3] = (GLint) texgen->EyePlane[3];
419 break;
420 default:
421 _mesa_error( ctx, GL_INVALID_ENUM, "glGetTexGeniv(pname)" );
422 }
423 }
424
425
426 void
427 _mesa_init_texgen_dispatch(struct gl_context *ctx, struct _glapi_table *disp)
428 {
429 SET_GetTexGenfv(disp, _mesa_GetTexGenfv);
430 SET_GetTexGeniv(disp, _mesa_GetTexGeniv);
431 SET_TexGenf(disp, _mesa_TexGenf);
432 SET_TexGenfv(disp, _mesa_TexGenfv);
433 SET_TexGeni(disp, _mesa_TexGeni);
434 SET_TexGeniv(disp, _mesa_TexGeniv);
435 if (ctx->API == API_OPENGL) {
436 SET_GetTexGendv(disp, _mesa_GetTexGendv);
437 SET_TexGend(disp, _mesa_TexGend);
438 SET_TexGendv(disp, _mesa_TexGendv);
439 }
440 }