2 * Mesa 3-D graphics library
5 * Copyright (C) 1999-2004 Brian Paul 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 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
21 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
22 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keith@tungstengraphics.com>
28 #include "main/glheader.h"
29 #include "main/context.h"
30 #include "main/macros.h"
31 #include "math/m_eval.h"
32 #include "glapi/dispatch.h"
36 static void clear_active_eval1( struct vbo_exec_context *exec, GLuint attr )
38 exec->eval.map1[attr].map = NULL;
41 static void clear_active_eval2( struct vbo_exec_context *exec, GLuint attr )
43 exec->eval.map2[attr].map = NULL;
46 static void set_active_eval1( struct vbo_exec_context *exec, GLuint attr, GLuint dim,
47 struct gl_1d_map *map )
49 if (!exec->eval.map1[attr].map) {
50 exec->eval.map1[attr].map = map;
51 exec->eval.map1[attr].sz = dim;
55 static void set_active_eval2( struct vbo_exec_context *exec, GLuint attr, GLuint dim,
56 struct gl_2d_map *map )
58 if (!exec->eval.map2[attr].map) {
59 exec->eval.map2[attr].map = map;
60 exec->eval.map2[attr].sz = dim;
64 void vbo_exec_eval_update( struct vbo_exec_context *exec )
66 GLcontext *ctx = exec->ctx;
69 /* Vertex program maps have priority over conventional attribs */
71 for (attr = 0; attr < VBO_ATTRIB_FIRST_MATERIAL; attr++) {
72 clear_active_eval1( exec, attr );
73 clear_active_eval2( exec, attr );
77 if (ctx->VertexProgram._Enabled) {
78 for (attr = 0; attr < VBO_ATTRIB_FIRST_MATERIAL; attr++) {
80 if (ctx->Eval.Map1Attrib[attr])
81 set_active_eval1( exec, attr, 4, &ctx->EvalMap.Map1Attrib[attr] );
83 if (ctx->Eval.Map2Attrib[attr])
84 set_active_eval2( exec, attr, 4, &ctx->EvalMap.Map2Attrib[attr] );
88 if (ctx->Eval.Map1Color4)
89 set_active_eval1( exec, VBO_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map1Color4 );
91 if (ctx->Eval.Map2Color4)
92 set_active_eval2( exec, VBO_ATTRIB_COLOR0, 4, &ctx->EvalMap.Map2Color4 );
94 if (ctx->Eval.Map1TextureCoord4)
95 set_active_eval1( exec, VBO_ATTRIB_TEX0, 4, &ctx->EvalMap.Map1Texture4 );
96 else if (ctx->Eval.Map1TextureCoord3)
97 set_active_eval1( exec, VBO_ATTRIB_TEX0, 3, &ctx->EvalMap.Map1Texture3 );
98 else if (ctx->Eval.Map1TextureCoord2)
99 set_active_eval1( exec, VBO_ATTRIB_TEX0, 2, &ctx->EvalMap.Map1Texture2 );
100 else if (ctx->Eval.Map1TextureCoord1)
101 set_active_eval1( exec, VBO_ATTRIB_TEX0, 1, &ctx->EvalMap.Map1Texture1 );
103 if (ctx->Eval.Map2TextureCoord4)
104 set_active_eval2( exec, VBO_ATTRIB_TEX0, 4, &ctx->EvalMap.Map2Texture4 );
105 else if (ctx->Eval.Map2TextureCoord3)
106 set_active_eval2( exec, VBO_ATTRIB_TEX0, 3, &ctx->EvalMap.Map2Texture3 );
107 else if (ctx->Eval.Map2TextureCoord2)
108 set_active_eval2( exec, VBO_ATTRIB_TEX0, 2, &ctx->EvalMap.Map2Texture2 );
109 else if (ctx->Eval.Map2TextureCoord1)
110 set_active_eval2( exec, VBO_ATTRIB_TEX0, 1, &ctx->EvalMap.Map2Texture1 );
112 if (ctx->Eval.Map1Normal)
113 set_active_eval1( exec, VBO_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map1Normal );
115 if (ctx->Eval.Map2Normal)
116 set_active_eval2( exec, VBO_ATTRIB_NORMAL, 3, &ctx->EvalMap.Map2Normal );
118 if (ctx->Eval.Map1Vertex4)
119 set_active_eval1( exec, VBO_ATTRIB_POS, 4, &ctx->EvalMap.Map1Vertex4 );
120 else if (ctx->Eval.Map1Vertex3)
121 set_active_eval1( exec, VBO_ATTRIB_POS, 3, &ctx->EvalMap.Map1Vertex3 );
123 if (ctx->Eval.Map2Vertex4)
124 set_active_eval2( exec, VBO_ATTRIB_POS, 4, &ctx->EvalMap.Map2Vertex4 );
125 else if (ctx->Eval.Map2Vertex3)
126 set_active_eval2( exec, VBO_ATTRIB_POS, 3, &ctx->EvalMap.Map2Vertex3 );
128 exec->eval.recalculate_maps = 0;
133 void vbo_exec_do_EvalCoord1f(struct vbo_exec_context *exec, GLfloat u)
137 for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) {
138 struct gl_1d_map *map = exec->eval.map1[attr].map;
140 GLfloat uu = (u - map->u1) * map->du;
143 ASSIGN_4V(data, 0, 0, 0, 1);
145 _math_horner_bezier_curve(map->Points, data, uu,
146 exec->eval.map1[attr].sz,
149 COPY_SZ_4V( exec->vtx.attrptr[attr],
150 exec->vtx.attrsz[attr],
155 /** Vertex -- EvalCoord1f is a noop if this map not enabled:
157 if (exec->eval.map1[0].map) {
158 struct gl_1d_map *map = exec->eval.map1[0].map;
159 GLfloat uu = (u - map->u1) * map->du;
162 ASSIGN_4V(vertex, 0, 0, 0, 1);
164 _math_horner_bezier_curve(map->Points, vertex, uu,
165 exec->eval.map1[0].sz,
168 if (exec->eval.map1[0].sz == 4)
169 CALL_Vertex4fv(GET_DISPATCH(), ( vertex ));
171 CALL_Vertex3fv(GET_DISPATCH(), ( vertex ));
177 void vbo_exec_do_EvalCoord2f( struct vbo_exec_context *exec,
178 GLfloat u, GLfloat v )
182 for (attr = 1; attr <= VBO_ATTRIB_TEX7; attr++) {
183 struct gl_2d_map *map = exec->eval.map2[attr].map;
185 GLfloat uu = (u - map->u1) * map->du;
186 GLfloat vv = (v - map->v1) * map->dv;
189 ASSIGN_4V(data, 0, 0, 0, 1);
191 _math_horner_bezier_surf(map->Points,
194 exec->eval.map2[attr].sz,
195 map->Uorder, map->Vorder);
197 COPY_SZ_4V( exec->vtx.attrptr[attr],
198 exec->vtx.attrsz[attr],
203 /** Vertex -- EvalCoord2f is a noop if this map not enabled:
205 if (exec->eval.map2[0].map) {
206 struct gl_2d_map *map = exec->eval.map2[0].map;
207 GLfloat uu = (u - map->u1) * map->du;
208 GLfloat vv = (v - map->v1) * map->dv;
211 ASSIGN_4V(vertex, 0, 0, 0, 1);
213 if (exec->ctx->Eval.AutoNormal) {
215 GLfloat du[4], dv[4];
217 _math_de_casteljau_surf(map->Points, vertex, du, dv, uu, vv,
218 exec->eval.map2[0].sz,
219 map->Uorder, map->Vorder);
221 if (exec->eval.map2[0].sz == 4) {
222 du[0] = du[0]*vertex[3] - du[3]*vertex[0];
223 du[1] = du[1]*vertex[3] - du[3]*vertex[1];
224 du[2] = du[2]*vertex[3] - du[3]*vertex[2];
226 dv[0] = dv[0]*vertex[3] - dv[3]*vertex[0];
227 dv[1] = dv[1]*vertex[3] - dv[3]*vertex[1];
228 dv[2] = dv[2]*vertex[3] - dv[3]*vertex[2];
232 CROSS3(normal, du, dv);
233 NORMALIZE_3FV(normal);
236 COPY_SZ_4V( exec->vtx.attrptr[VBO_ATTRIB_NORMAL],
237 exec->vtx.attrsz[VBO_ATTRIB_NORMAL],
242 _math_horner_bezier_surf(map->Points, vertex, uu, vv,
243 exec->eval.map2[0].sz,
244 map->Uorder, map->Vorder);
247 if (exec->vtx.attrsz[0] == 4)
248 CALL_Vertex4fv(GET_DISPATCH(), ( vertex ));
250 CALL_Vertex3fv(GET_DISPATCH(), ( vertex ));