2 * Mesa 3-D graphics library
4 * Copyright (C) 1999-2004 Brian Paul All Rights Reserved.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included
14 * in all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 * 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 "main/dispatch.h"
36 static void clear_active_eval1( struct vbo_exec_context
*exec
, GLuint attr
)
38 assert(attr
< Elements(exec
->eval
.map1
));
39 exec
->eval
.map1
[attr
].map
= NULL
;
42 static void clear_active_eval2( struct vbo_exec_context
*exec
, GLuint attr
)
44 assert(attr
< Elements(exec
->eval
.map2
));
45 exec
->eval
.map2
[attr
].map
= NULL
;
48 static void set_active_eval1( struct vbo_exec_context
*exec
, GLuint attr
, GLuint dim
,
49 struct gl_1d_map
*map
)
51 assert(attr
< Elements(exec
->eval
.map1
));
52 if (!exec
->eval
.map1
[attr
].map
) {
53 exec
->eval
.map1
[attr
].map
= map
;
54 exec
->eval
.map1
[attr
].sz
= dim
;
58 static void set_active_eval2( struct vbo_exec_context
*exec
, GLuint attr
, GLuint dim
,
59 struct gl_2d_map
*map
)
61 assert(attr
< Elements(exec
->eval
.map2
));
62 if (!exec
->eval
.map2
[attr
].map
) {
63 exec
->eval
.map2
[attr
].map
= map
;
64 exec
->eval
.map2
[attr
].sz
= dim
;
68 void vbo_exec_eval_update( struct vbo_exec_context
*exec
)
70 struct gl_context
*ctx
= exec
->ctx
;
73 /* Vertex program maps have priority over conventional attribs */
75 for (attr
= 0; attr
< VBO_ATTRIB_FIRST_MATERIAL
; attr
++) {
76 clear_active_eval1( exec
, attr
);
77 clear_active_eval2( exec
, attr
);
80 if (ctx
->Eval
.Map1Color4
)
81 set_active_eval1( exec
, VBO_ATTRIB_COLOR0
, 4, &ctx
->EvalMap
.Map1Color4
);
83 if (ctx
->Eval
.Map2Color4
)
84 set_active_eval2( exec
, VBO_ATTRIB_COLOR0
, 4, &ctx
->EvalMap
.Map2Color4
);
86 if (ctx
->Eval
.Map1TextureCoord4
)
87 set_active_eval1( exec
, VBO_ATTRIB_TEX0
, 4, &ctx
->EvalMap
.Map1Texture4
);
88 else if (ctx
->Eval
.Map1TextureCoord3
)
89 set_active_eval1( exec
, VBO_ATTRIB_TEX0
, 3, &ctx
->EvalMap
.Map1Texture3
);
90 else if (ctx
->Eval
.Map1TextureCoord2
)
91 set_active_eval1( exec
, VBO_ATTRIB_TEX0
, 2, &ctx
->EvalMap
.Map1Texture2
);
92 else if (ctx
->Eval
.Map1TextureCoord1
)
93 set_active_eval1( exec
, VBO_ATTRIB_TEX0
, 1, &ctx
->EvalMap
.Map1Texture1
);
95 if (ctx
->Eval
.Map2TextureCoord4
)
96 set_active_eval2( exec
, VBO_ATTRIB_TEX0
, 4, &ctx
->EvalMap
.Map2Texture4
);
97 else if (ctx
->Eval
.Map2TextureCoord3
)
98 set_active_eval2( exec
, VBO_ATTRIB_TEX0
, 3, &ctx
->EvalMap
.Map2Texture3
);
99 else if (ctx
->Eval
.Map2TextureCoord2
)
100 set_active_eval2( exec
, VBO_ATTRIB_TEX0
, 2, &ctx
->EvalMap
.Map2Texture2
);
101 else if (ctx
->Eval
.Map2TextureCoord1
)
102 set_active_eval2( exec
, VBO_ATTRIB_TEX0
, 1, &ctx
->EvalMap
.Map2Texture1
);
104 if (ctx
->Eval
.Map1Normal
)
105 set_active_eval1( exec
, VBO_ATTRIB_NORMAL
, 3, &ctx
->EvalMap
.Map1Normal
);
107 if (ctx
->Eval
.Map2Normal
)
108 set_active_eval2( exec
, VBO_ATTRIB_NORMAL
, 3, &ctx
->EvalMap
.Map2Normal
);
110 if (ctx
->Eval
.Map1Vertex4
)
111 set_active_eval1( exec
, VBO_ATTRIB_POS
, 4, &ctx
->EvalMap
.Map1Vertex4
);
112 else if (ctx
->Eval
.Map1Vertex3
)
113 set_active_eval1( exec
, VBO_ATTRIB_POS
, 3, &ctx
->EvalMap
.Map1Vertex3
);
115 if (ctx
->Eval
.Map2Vertex4
)
116 set_active_eval2( exec
, VBO_ATTRIB_POS
, 4, &ctx
->EvalMap
.Map2Vertex4
);
117 else if (ctx
->Eval
.Map2Vertex3
)
118 set_active_eval2( exec
, VBO_ATTRIB_POS
, 3, &ctx
->EvalMap
.Map2Vertex3
);
120 exec
->eval
.recalculate_maps
= 0;
125 void vbo_exec_do_EvalCoord1f(struct vbo_exec_context
*exec
, GLfloat u
)
129 for (attr
= 1; attr
<= VBO_ATTRIB_TEX7
; attr
++) {
130 struct gl_1d_map
*map
= exec
->eval
.map1
[attr
].map
;
132 GLfloat uu
= (u
- map
->u1
) * map
->du
;
135 ASSIGN_4V(data
, 0, 0, 0, 1);
137 _math_horner_bezier_curve(map
->Points
, data
, uu
,
138 exec
->eval
.map1
[attr
].sz
,
141 COPY_SZ_4V( exec
->vtx
.attrptr
[attr
],
142 exec
->vtx
.attrsz
[attr
],
147 /** Vertex -- EvalCoord1f is a noop if this map not enabled:
149 if (exec
->eval
.map1
[0].map
) {
150 struct gl_1d_map
*map
= exec
->eval
.map1
[0].map
;
151 GLfloat uu
= (u
- map
->u1
) * map
->du
;
154 ASSIGN_4V(vertex
, 0, 0, 0, 1);
156 _math_horner_bezier_curve(map
->Points
, vertex
, uu
,
157 exec
->eval
.map1
[0].sz
,
160 if (exec
->eval
.map1
[0].sz
== 4)
161 CALL_Vertex4fv(GET_DISPATCH(), ( vertex
));
163 CALL_Vertex3fv(GET_DISPATCH(), ( vertex
));
169 void vbo_exec_do_EvalCoord2f( struct vbo_exec_context
*exec
,
170 GLfloat u
, GLfloat v
)
174 for (attr
= 1; attr
<= VBO_ATTRIB_TEX7
; attr
++) {
175 struct gl_2d_map
*map
= exec
->eval
.map2
[attr
].map
;
177 GLfloat uu
= (u
- map
->u1
) * map
->du
;
178 GLfloat vv
= (v
- map
->v1
) * map
->dv
;
181 ASSIGN_4V(data
, 0, 0, 0, 1);
183 _math_horner_bezier_surf(map
->Points
,
186 exec
->eval
.map2
[attr
].sz
,
187 map
->Uorder
, map
->Vorder
);
189 COPY_SZ_4V( exec
->vtx
.attrptr
[attr
],
190 exec
->vtx
.attrsz
[attr
],
195 /** Vertex -- EvalCoord2f is a noop if this map not enabled:
197 if (exec
->eval
.map2
[0].map
) {
198 struct gl_2d_map
*map
= exec
->eval
.map2
[0].map
;
199 GLfloat uu
= (u
- map
->u1
) * map
->du
;
200 GLfloat vv
= (v
- map
->v1
) * map
->dv
;
203 ASSIGN_4V(vertex
, 0, 0, 0, 1);
205 if (exec
->ctx
->Eval
.AutoNormal
) {
207 GLfloat du
[4], dv
[4];
209 _math_de_casteljau_surf(map
->Points
, vertex
, du
, dv
, uu
, vv
,
210 exec
->eval
.map2
[0].sz
,
211 map
->Uorder
, map
->Vorder
);
213 if (exec
->eval
.map2
[0].sz
== 4) {
214 du
[0] = du
[0]*vertex
[3] - du
[3]*vertex
[0];
215 du
[1] = du
[1]*vertex
[3] - du
[3]*vertex
[1];
216 du
[2] = du
[2]*vertex
[3] - du
[3]*vertex
[2];
218 dv
[0] = dv
[0]*vertex
[3] - dv
[3]*vertex
[0];
219 dv
[1] = dv
[1]*vertex
[3] - dv
[3]*vertex
[1];
220 dv
[2] = dv
[2]*vertex
[3] - dv
[3]*vertex
[2];
224 CROSS3(normal
, du
, dv
);
225 NORMALIZE_3FV(normal
);
228 COPY_SZ_4V( exec
->vtx
.attrptr
[VBO_ATTRIB_NORMAL
],
229 exec
->vtx
.attrsz
[VBO_ATTRIB_NORMAL
],
234 _math_horner_bezier_surf(map
->Points
, vertex
, uu
, vv
,
235 exec
->eval
.map2
[0].sz
,
236 map
->Uorder
, map
->Vorder
);
239 if (exec
->vtx
.attrsz
[0] == 4)
240 CALL_Vertex4fv(GET_DISPATCH(), ( vertex
));
242 CALL_Vertex3fv(GET_DISPATCH(), ( vertex
));