1 /* $Id: t_imm_eval.c,v 1.24 2002/06/23 02:47:38 brianp Exp $ */
4 * Mesa 3-D graphics library
7 * Copyright (C) 1999-2002 Brian Paul All Rights Reserved.
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * BRIAN PAUL BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN
23 * AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
24 * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27 * Keith Whitwell <keithw@valinux.com>
28 * Brian Paul - vertex program updates
39 #include "math/m_eval.h"
41 #include "t_context.h"
42 #include "t_imm_debug.h"
43 #include "t_imm_eval.h"
44 #include "t_imm_exec.h"
45 #include "t_imm_fixup.h"
46 #include "t_imm_alloc.h"
49 static void eval_points1( GLfloat outcoord
[][4],
52 GLfloat du
, GLfloat u1
)
55 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
56 if (flags
[i
] & VERT_BITS_EVAL_ANY
) {
57 outcoord
[i
][0] = coord
[i
][0];
58 outcoord
[i
][1] = coord
[i
][1];
59 if (flags
[i
] & VERT_BIT_EVAL_P1
)
60 outcoord
[i
][0] = coord
[i
][0] * du
+ u1
;
64 static void eval_points2( GLfloat outcoord
[][4],
67 GLfloat du
, GLfloat u1
,
68 GLfloat dv
, GLfloat v1
)
71 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++) {
72 if (flags
[i
] & VERT_BITS_EVAL_ANY
) {
73 outcoord
[i
][0] = coord
[i
][0];
74 outcoord
[i
][1] = coord
[i
][1];
75 if (flags
[i
] & VERT_BIT_EVAL_P2
) {
76 outcoord
[i
][0] = coord
[i
][0] * du
+ u1
;
77 outcoord
[i
][1] = coord
[i
][1] * dv
+ v1
;
83 static const GLubyte dirty_flags
[5] = {
92 static void eval1_4f( GLvector4f
*dest
,
96 const struct gl_1d_map
*map
)
98 const GLfloat u1
= map
->u1
;
99 const GLfloat du
= map
->du
;
100 GLfloat (*to
)[4] = dest
->data
;
103 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
104 if (flags
[i
] & (VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
)) {
105 GLfloat u
= (coord
[i
][0] - u1
) * du
;
106 ASSIGN_4V(to
[i
], 0,0,0,1);
107 _math_horner_bezier_curve(map
->Points
, to
[i
], u
,
108 dimension
, map
->Order
);
111 dest
->size
= MAX2(dest
->size
, dimension
);
112 dest
->flags
|= dirty_flags
[dimension
];
116 /* as above, but dest is a gl_client_array */
117 static void eval1_4f_ca( struct gl_client_array
*dest
,
121 const struct gl_1d_map
*map
)
123 const GLfloat u1
= map
->u1
;
124 const GLfloat du
= map
->du
;
125 GLfloat (*to
)[4] = (GLfloat (*)[4])dest
->Ptr
;
128 ASSERT(dest
->Type
== GL_FLOAT
);
129 ASSERT(dest
->StrideB
== 4 * sizeof(GLfloat
));
131 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
132 if (flags
[i
] & (VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
)) {
133 GLfloat u
= (coord
[i
][0] - u1
) * du
;
134 ASSIGN_4V(to
[i
], 0,0,0,1);
135 _math_horner_bezier_curve(map
->Points
, to
[i
], u
,
136 dimension
, map
->Order
);
139 dest
->Size
= MAX2(dest
->Size
, (GLint
) dimension
);
143 static void eval1_1ui( GLvector1ui
*dest
,
146 const struct gl_1d_map
*map
)
148 const GLfloat u1
= map
->u1
;
149 const GLfloat du
= map
->du
;
150 GLuint
*to
= dest
->data
;
153 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
154 if (flags
[i
] & (VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
)) {
155 GLfloat u
= (coord
[i
][0] - u1
) * du
;
157 _math_horner_bezier_curve(map
->Points
, &tmp
, u
, 1, map
->Order
);
158 to
[i
] = (GLuint
) (GLint
) tmp
;
163 static void eval1_norm( GLvector4f
*dest
,
166 const struct gl_1d_map
*map
)
168 const GLfloat u1
= map
->u1
;
169 const GLfloat du
= map
->du
;
170 GLfloat (*to
)[4] = dest
->data
;
173 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
174 if (flags
[i
] & (VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
)) {
175 GLfloat u
= (coord
[i
][0] - u1
) * du
;
176 _math_horner_bezier_curve(map
->Points
, to
[i
], u
, 3, map
->Order
);
181 static void eval2_obj_norm( GLvector4f
*obj_ptr
,
182 GLvector4f
*norm_ptr
,
186 const struct gl_2d_map
*map
)
188 const GLfloat u1
= map
->u1
;
189 const GLfloat du
= map
->du
;
190 const GLfloat v1
= map
->v1
;
191 const GLfloat dv
= map
->dv
;
192 GLfloat (*obj
)[4] = obj_ptr
->data
;
193 GLfloat (*normal
)[4] = norm_ptr
->data
;
196 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
197 if (flags
[i
] & (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
)) {
198 GLfloat u
= (coord
[i
][0] - u1
) * du
;
199 GLfloat v
= (coord
[i
][1] - v1
) * dv
;
200 GLfloat du
[4], dv
[4];
202 ASSIGN_4V(obj
[i
], 0,0,0,1);
203 _math_de_casteljau_surf(map
->Points
, obj
[i
], du
, dv
, u
, v
, dimension
,
204 map
->Uorder
, map
->Vorder
);
206 if (dimension
== 4) {
207 du
[0] = du
[0]*obj
[i
][3] - du
[3]*obj
[i
][0];
208 du
[1] = du
[1]*obj
[i
][3] - du
[3]*obj
[i
][1];
209 du
[2] = du
[2]*obj
[i
][3] - du
[3]*obj
[i
][2];
211 dv
[0] = dv
[0]*obj
[i
][3] - dv
[3]*obj
[i
][0];
212 dv
[1] = dv
[1]*obj
[i
][3] - dv
[3]*obj
[i
][1];
213 dv
[2] = dv
[2]*obj
[i
][3] - dv
[3]*obj
[i
][2];
216 CROSS3(normal
[i
], du
, dv
);
217 NORMALIZE_3FV(normal
[i
]);
220 obj_ptr
->size
= MAX2(obj_ptr
->size
, dimension
);
221 obj_ptr
->flags
|= dirty_flags
[dimension
];
225 static void eval2_4f( GLvector4f
*dest
,
229 const struct gl_2d_map
*map
)
231 const GLfloat u1
= map
->u1
;
232 const GLfloat du
= map
->du
;
233 const GLfloat v1
= map
->v1
;
234 const GLfloat dv
= map
->dv
;
235 GLfloat (*to
)[4] = dest
->data
;
238 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
239 if (flags
[i
] & (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
)) {
240 GLfloat u
= (coord
[i
][0] - u1
) * du
;
241 GLfloat v
= (coord
[i
][1] - v1
) * dv
;
243 _math_horner_bezier_surf(map
->Points
, to
[i
], u
, v
, dimension
,
244 map
->Uorder
, map
->Vorder
);
247 dest
->size
= MAX2(dest
->size
, dimension
);
248 dest
->flags
|= dirty_flags
[dimension
];
252 /* as above, but dest is a gl_client_array */
253 static void eval2_4f_ca( struct gl_client_array
*dest
,
257 const struct gl_2d_map
*map
)
259 const GLfloat u1
= map
->u1
;
260 const GLfloat du
= map
->du
;
261 const GLfloat v1
= map
->v1
;
262 const GLfloat dv
= map
->dv
;
263 GLfloat (*to
)[4] = (GLfloat (*)[4])dest
->Ptr
;
266 ASSERT(dest
->Type
== GL_FLOAT
);
267 ASSERT(dest
->StrideB
== 4 * sizeof(GLfloat
));
269 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
270 if (flags
[i
] & (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
)) {
271 GLfloat u
= (coord
[i
][0] - u1
) * du
;
272 GLfloat v
= (coord
[i
][1] - v1
) * dv
;
273 _math_horner_bezier_surf(map
->Points
, to
[i
], u
, v
, dimension
,
274 map
->Uorder
, map
->Vorder
);
277 dest
->Size
= MAX2(dest
->Size
, (GLint
) dimension
);
281 static void eval2_norm( GLvector4f
*dest
,
284 const struct gl_2d_map
*map
)
286 const GLfloat u1
= map
->u1
;
287 const GLfloat du
= map
->du
;
288 const GLfloat v1
= map
->v1
;
289 const GLfloat dv
= map
->dv
;
290 GLfloat (*to
)[4] = dest
->data
;
293 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++) {
294 if (flags
[i
] & (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
)) {
295 GLfloat u
= (coord
[i
][0] - u1
) * du
;
296 GLfloat v
= (coord
[i
][1] - v1
) * dv
;
297 _math_horner_bezier_surf(map
->Points
, to
[i
], u
, v
, 3,
298 map
->Uorder
, map
->Vorder
);
304 static void eval2_1ui( GLvector1ui
*dest
,
307 const struct gl_2d_map
*map
)
309 const GLfloat u1
= map
->u1
;
310 const GLfloat du
= map
->du
;
311 const GLfloat v1
= map
->v1
;
312 const GLfloat dv
= map
->dv
;
313 GLuint
*to
= dest
->data
;
316 for (i
= 0 ; !(flags
[i
] & VERT_BIT_END_VB
) ; i
++)
317 if (flags
[i
] & (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
)) {
318 GLfloat u
= (coord
[i
][0] - u1
) * du
;
319 GLfloat v
= (coord
[i
][1] - v1
) * dv
;
321 _math_horner_bezier_surf(map
->Points
, &tmp
, u
, v
, 1,
322 map
->Uorder
, map
->Vorder
);
324 to
[i
] = (GLuint
) (GLint
) tmp
;
329 static void copy_4f( GLfloat to
[][4], GLfloat from
[][4], GLuint count
)
331 MEMCPY( to
, from
, count
* sizeof(to
[0]));
334 static void copy_4f_stride( GLfloat to
[][4], const GLfloat
*from
,
335 GLuint stride
, GLuint count
)
337 if (stride
== 4 * sizeof(GLfloat
))
338 MEMCPY( to
, from
, count
* sizeof(to
[0]));
341 for (i
= 0 ; i
< count
; i
++, STRIDE_F(from
, stride
))
342 COPY_4FV( to
[i
], from
);
346 static void copy_3f( GLfloat to
[][4], GLfloat from
[][4], GLuint count
)
349 for (i
= 0 ; i
< count
; i
++) {
350 COPY_3FV(to
[i
], from
[i
]);
355 static void copy_1ui( GLuint to
[], const GLuint from
[], GLuint count
)
357 MEMCPY( to
, from
, (count
) * sizeof(to
[0]));
362 /* Translate eval enabled flags to VERT_* flags.
364 static void update_eval( GLcontext
*ctx
)
366 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
367 GLuint eval1
= 0, eval2
= 0;
370 if (ctx
->Eval
.Map1Index
)
371 eval1
|= VERT_BIT_INDEX
;
373 if (ctx
->Eval
.Map2Index
)
374 eval2
|= VERT_BIT_INDEX
;
376 if (ctx
->Eval
.Map1Color4
)
377 eval1
|= VERT_BIT_COLOR0
;
379 if (ctx
->Eval
.Map2Color4
)
380 eval2
|= VERT_BIT_COLOR0
;
382 if (ctx
->Eval
.Map1Normal
)
383 eval1
|= VERT_BIT_NORMAL
;
385 if (ctx
->Eval
.Map2Normal
)
386 eval2
|= VERT_BIT_NORMAL
;
388 if (ctx
->Eval
.Map1TextureCoord4
||
389 ctx
->Eval
.Map1TextureCoord3
||
390 ctx
->Eval
.Map1TextureCoord2
||
391 ctx
->Eval
.Map1TextureCoord1
)
392 eval1
|= VERT_BIT_TEX0
;
394 if (ctx
->Eval
.Map2TextureCoord4
||
395 ctx
->Eval
.Map2TextureCoord3
||
396 ctx
->Eval
.Map2TextureCoord2
||
397 ctx
->Eval
.Map2TextureCoord1
)
398 eval2
|= VERT_BIT_TEX0
;
400 if (ctx
->Eval
.Map1Vertex4
)
401 eval1
|= VERT_BITS_OBJ_234
;
403 if (ctx
->Eval
.Map1Vertex3
)
404 eval1
|= VERT_BITS_OBJ_23
;
406 if (ctx
->Eval
.Map2Vertex4
) {
407 if (ctx
->Eval
.AutoNormal
)
408 eval2
|= VERT_BITS_OBJ_234
| VERT_BIT_NORMAL
;
410 eval2
|= VERT_BITS_OBJ_234
;
412 else if (ctx
->Eval
.Map2Vertex3
) {
413 if (ctx
->Eval
.AutoNormal
)
414 eval2
|= VERT_BITS_OBJ_23
| VERT_BIT_NORMAL
;
416 eval2
|= VERT_BITS_OBJ_23
;
419 tnl
->eval
.EvalMap1Flags
= eval1
;
420 tnl
->eval
.EvalMap2Flags
= eval2
;
422 /* GL_NV_vertex_program evaluators */
424 for (i
= 0; i
< VERT_ATTRIB_MAX
; i
++) {
425 if (ctx
->Eval
.Map1Attrib
[i
])
427 if (ctx
->Eval
.Map2Attrib
[i
])
430 tnl
->eval
.EvalMap1AttribFlags
= eval1
;
431 tnl
->eval
.EvalMap2AttribFlags
= eval2
;
433 tnl
->eval
.EvalNewState
= 0;
437 /* This looks a lot like a pipeline stage, but for various reasons is
438 * better handled outside the pipeline, and considered the final stage
439 * of fixing up an immediate struct for execution.
441 * Really want to cache the results of this function in display lists,
442 * at least for EvalMesh commands.
444 void _tnl_eval_immediate( GLcontext
*ctx
, struct immediate
*IM
)
446 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
447 struct vertex_arrays
*tmp
= &tnl
->imm_inputs
;
448 struct immediate
*store
= tnl
->eval
.im
;
449 GLuint
*flags
= IM
->Flag
+ IM
->CopyStart
;
451 GLuint orflag
= IM
->OrFlag
;
452 GLuint any_eval1
= orflag
& (VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
);
453 GLuint any_eval2
= orflag
& (VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
);
455 GLuint purge_flags
= 0;
456 GLfloat (*coord
)[4] = IM
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
;
458 if (IM
->AndFlag
& VERT_BITS_EVAL_ANY
)
459 copycount
= IM
->Start
- IM
->CopyStart
; /* just copy copied vertices */
461 copycount
= IM
->Count
- IM
->CopyStart
; /* copy all vertices */
464 store
= tnl
->eval
.im
= _tnl_alloc_immediate( ctx
);
466 if (tnl
->eval
.EvalNewState
& _NEW_EVAL
)
470 req
|= tnl
->pipeline
.inputs
471 & (tnl
->eval
.EvalMap1Flags
| tnl
->eval
.EvalMap1AttribFlags
);
473 if (!ctx
->Eval
.Map1Vertex4
&& !ctx
->Eval
.Map1Vertex3
&&
474 !ctx
->Eval
.Map1Attrib
[0])
475 purge_flags
= (VERT_BIT_EVAL_P1
|VERT_BIT_EVAL_C1
);
477 if (orflag
& VERT_BIT_EVAL_P1
) {
478 eval_points1( store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
,
480 ctx
->Eval
.MapGrid1du
,
481 ctx
->Eval
.MapGrid1u1
);
483 coord
= store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
;
488 req
|= tnl
->pipeline
.inputs
489 & (tnl
->eval
.EvalMap2Flags
| tnl
->eval
.EvalMap2AttribFlags
);
491 if (!ctx
->Eval
.Map2Vertex4
&& !ctx
->Eval
.Map2Vertex3
&&
492 !ctx
->Eval
.Map2Attrib
[0])
493 purge_flags
|= (VERT_BIT_EVAL_P2
|VERT_BIT_EVAL_C2
);
495 if (orflag
& VERT_BIT_EVAL_P2
) {
496 eval_points2( store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
,
498 ctx
->Eval
.MapGrid2du
,
499 ctx
->Eval
.MapGrid2u1
,
500 ctx
->Eval
.MapGrid2dv
,
501 ctx
->Eval
.MapGrid2v1
);
503 coord
= store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
;
507 /* Perform the evaluations on active data elements.
509 if (req
& VERT_BIT_INDEX
) {
510 GLuint generated
= 0;
513 copy_1ui( store
->Index
+ IM
->CopyStart
, tmp
->Index
.data
, copycount
);
515 tmp
->Index
.data
= store
->Index
+ IM
->CopyStart
;
516 tmp
->Index
.start
= store
->Index
+ IM
->CopyStart
;
518 if (ctx
->Eval
.Map1Index
&& any_eval1
) {
519 eval1_1ui( &tmp
->Index
, coord
, flags
, &ctx
->EvalMap
.Map1Index
);
520 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
523 if (ctx
->Eval
.Map2Index
&& any_eval2
) {
524 eval2_1ui( &tmp
->Index
, coord
, flags
, &ctx
->EvalMap
.Map2Index
);
525 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
529 if (req
& VERT_BIT_COLOR0
) {
530 GLuint generated
= 0;
533 copy_4f_stride( store
->Attrib
[VERT_ATTRIB_COLOR0
] + IM
->CopyStart
,
534 (GLfloat
*)tmp
->Color
.Ptr
,
538 tmp
->Color
.Ptr
= store
->Attrib
[VERT_ATTRIB_COLOR0
] + IM
->CopyStart
;
539 tmp
->Color
.StrideB
= 4 * sizeof(GLfloat
);
540 tmp
->Color
.Flags
= 0;
541 tnl
->vb
.importable_data
&= ~VERT_BIT_COLOR0
;
544 /*tmp->Attribs[0].count = count;*/
545 tmp
->Attribs
[3].data
= store
->Attrib
[3] + IM
->CopyStart
;
546 tmp
->Attribs
[3].start
= (GLfloat
*) tmp
->Attribs
[3].data
;
547 tmp
->Attribs
[3].size
= 0;
550 /* Vertex program maps have priority over conventional attribs */
552 if (ctx
->VertexProgram
.Enabled
553 && ctx
->Eval
.Map1Attrib
[VERT_ATTRIB_COLOR0
]) {
554 eval1_4f_ca( &tmp
->Color
, coord
, flags
, 4,
555 &ctx
->EvalMap
.Map1Attrib
[VERT_ATTRIB_COLOR0
] );
556 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
558 else if (ctx
->Eval
.Map1Color4
) {
559 eval1_4f_ca( &tmp
->Color
, coord
, flags
, 4,
560 &ctx
->EvalMap
.Map1Color4
);
561 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
566 if (ctx
->VertexProgram
.Enabled
567 && ctx
->Eval
.Map2Attrib
[VERT_ATTRIB_COLOR0
]) {
568 eval2_4f_ca( &tmp
->Color
, coord
, flags
, 4,
569 &ctx
->EvalMap
.Map2Attrib
[VERT_ATTRIB_COLOR0
] );
570 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
572 else if (ctx
->Eval
.Map2Color4
) {
573 eval2_4f_ca( &tmp
->Color
, coord
, flags
, 4,
574 &ctx
->EvalMap
.Map2Color4
);
575 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
580 if (req
& VERT_BIT_TEX0
) {
581 GLuint generated
= 0;
584 copy_4f( store
->Attrib
[VERT_ATTRIB_TEX0
] + IM
->CopyStart
,
585 tmp
->TexCoord
[0].data
, copycount
);
587 tmp
->TexCoord
[0].size
= 0;
589 tmp
->TexCoord
[0].data
= store
->Attrib
[VERT_ATTRIB_TEX0
] + IM
->CopyStart
;
590 tmp
->TexCoord
[0].start
= (GLfloat
*)tmp
->TexCoord
[0].data
;
592 /* Vertex program maps have priority over conventional attribs */
594 if (ctx
->VertexProgram
.Enabled
595 && ctx
->Eval
.Map1Attrib
[VERT_ATTRIB_TEX0
]) {
596 eval1_4f( &tmp
->TexCoord
[0], coord
, flags
, 4,
597 &ctx
->EvalMap
.Map1Attrib
[VERT_ATTRIB_TEX0
] );
598 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
600 else if (ctx
->Eval
.Map1TextureCoord4
) {
601 eval1_4f( &tmp
->TexCoord
[0], coord
, flags
, 4,
602 &ctx
->EvalMap
.Map1Texture4
);
603 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
605 else if (ctx
->Eval
.Map1TextureCoord3
) {
606 eval1_4f( &tmp
->TexCoord
[0], coord
, flags
, 3,
607 &ctx
->EvalMap
.Map1Texture3
);
608 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
610 else if (ctx
->Eval
.Map1TextureCoord2
) {
611 eval1_4f( &tmp
->TexCoord
[0], coord
, flags
, 2,
612 &ctx
->EvalMap
.Map1Texture2
);
613 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
615 else if (ctx
->Eval
.Map1TextureCoord1
) {
616 eval1_4f( &tmp
->TexCoord
[0], coord
, flags
, 1,
617 &ctx
->EvalMap
.Map1Texture1
);
618 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
623 if (ctx
->VertexProgram
.Enabled
624 && ctx
->Eval
.Map2Attrib
[VERT_ATTRIB_TEX0
]) {
625 eval2_4f( &tmp
->TexCoord
[0], coord
, flags
, 4,
626 &ctx
->EvalMap
.Map2Attrib
[VERT_ATTRIB_TEX0
] );
627 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
629 else if (ctx
->Eval
.Map2TextureCoord4
) {
630 eval2_4f( &tmp
->TexCoord
[0], coord
, flags
, 4,
631 &ctx
->EvalMap
.Map2Texture4
);
632 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
634 else if (ctx
->Eval
.Map2TextureCoord3
) {
635 eval2_4f( &tmp
->TexCoord
[0], coord
, flags
, 3,
636 &ctx
->EvalMap
.Map2Texture3
);
637 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
639 else if (ctx
->Eval
.Map2TextureCoord2
) {
640 eval2_4f( &tmp
->TexCoord
[0], coord
, flags
, 2,
641 &ctx
->EvalMap
.Map2Texture2
);
642 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
644 else if (ctx
->Eval
.Map2TextureCoord1
) {
645 eval2_4f( &tmp
->TexCoord
[0], coord
, flags
, 1,
646 &ctx
->EvalMap
.Map2Texture1
);
647 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
652 if (req
& VERT_BIT_NORMAL
) {
653 GLuint generated
= 0;
656 copy_3f( store
->Attrib
[VERT_ATTRIB_NORMAL
] + IM
->CopyStart
,
657 tmp
->Normal
.data
, copycount
);
660 tmp
->Normal
.data
= store
->Attrib
[VERT_ATTRIB_NORMAL
] + IM
->CopyStart
;
661 tmp
->Normal
.start
= (GLfloat
*)tmp
->Normal
.data
;
664 if (ctx
->VertexProgram
.Enabled
&&
665 ctx
->Eval
.Map1Attrib
[VERT_ATTRIB_NORMAL
]) {
666 eval1_norm( &tmp
->Normal
, coord
, flags
,
667 &ctx
->EvalMap
.Map1Attrib
[VERT_ATTRIB_NORMAL
] );
668 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
670 else if (ctx
->Eval
.Map1Normal
) {
671 eval1_norm( &tmp
->Normal
, coord
, flags
, &ctx
->EvalMap
.Map1Normal
);
672 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
677 if (ctx
->VertexProgram
.Enabled
&&
678 ctx
->Eval
.Map2Attrib
[VERT_ATTRIB_NORMAL
]) {
679 eval2_norm( &tmp
->Normal
, coord
, flags
,
680 &ctx
->EvalMap
.Map2Attrib
[VERT_ATTRIB_NORMAL
] );
681 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
683 else if (ctx
->Eval
.Map2Normal
) {
684 eval2_norm( &tmp
->Normal
, coord
, flags
, &ctx
->EvalMap
.Map2Normal
);
685 generated
|= VERT_BIT_EVAL_C2
|VERT_BIT_EVAL_P2
;
690 /* In the AutoNormal case, the copy and assignment of tmp->NormalPtr
693 if (req
& VERT_BIT_POS
) {
695 /* This copy may already have occurred when eliminating
698 if (coord
!= store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
) {
699 copy_4f( store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
,
700 tmp
->Obj
.data
, copycount
);
707 tmp
->Obj
.data
= store
->Attrib
[VERT_ATTRIB_POS
] + IM
->CopyStart
;
708 tmp
->Obj
.start
= (GLfloat
*) tmp
->Obj
.data
;
711 /*tmp->Attribs[0].count = count;*/
712 tmp
->Attribs
[0].data
= store
->Attrib
[0] + IM
->CopyStart
;
713 tmp
->Attribs
[0].start
= (GLfloat
*) tmp
->Attribs
[0].data
;
714 tmp
->Attribs
[0].size
= 0;
717 /* Note: Normal data is already prepared above.
721 if (ctx
->VertexProgram
.Enabled
&&
722 ctx
->Eval
.Map1Attrib
[VERT_ATTRIB_POS
]) {
723 eval1_4f( &tmp
->Obj
, coord
, flags
, 4,
724 &ctx
->EvalMap
.Map1Attrib
[VERT_ATTRIB_POS
] );
726 else if (ctx
->Eval
.Map1Vertex4
) {
727 eval1_4f( &tmp
->Obj
, coord
, flags
, 4,
728 &ctx
->EvalMap
.Map1Vertex4
);
730 else if (ctx
->Eval
.Map1Vertex3
) {
731 eval1_4f( &tmp
->Obj
, coord
, flags
, 3,
732 &ctx
->EvalMap
.Map1Vertex3
);
737 if (ctx
->VertexProgram
.Enabled
&&
738 ctx
->Eval
.Map2Attrib
[VERT_ATTRIB_POS
]) {
739 if (ctx
->Eval
.AutoNormal
&& (req
& VERT_BIT_NORMAL
))
740 eval2_obj_norm( &tmp
->Obj
, &tmp
->Normal
, coord
, flags
, 4,
741 &ctx
->EvalMap
.Map2Attrib
[VERT_ATTRIB_POS
] );
743 eval2_4f( &tmp
->Obj
, coord
, flags
, 4,
744 &ctx
->EvalMap
.Map2Attrib
[VERT_ATTRIB_POS
] );
746 else if (ctx
->Eval
.Map2Vertex4
) {
747 if (ctx
->Eval
.AutoNormal
&& (req
& VERT_BIT_NORMAL
))
748 eval2_obj_norm( &tmp
->Obj
, &tmp
->Normal
, coord
, flags
, 4,
749 &ctx
->EvalMap
.Map2Vertex4
);
751 eval2_4f( &tmp
->Obj
, coord
, flags
, 4,
752 &ctx
->EvalMap
.Map2Vertex4
);
754 else if (ctx
->Eval
.Map2Vertex3
) {
755 if (ctx
->Eval
.AutoNormal
&& (req
& VERT_BIT_NORMAL
))
756 eval2_obj_norm( &tmp
->Obj
, &tmp
->Normal
, coord
, flags
, 3,
757 &ctx
->EvalMap
.Map2Vertex3
);
759 eval2_4f( &tmp
->Obj
, coord
, flags
, 3,
760 &ctx
->EvalMap
.Map2Vertex3
);
766 if (0/*ctx->VertexProgram.Enabled*/) {
767 /* we already evaluated position, normal, color and texture 0 above */
768 const GLuint skipBits
= (VERT_BIT_POS
|
772 GLuint generated
= 0;
774 for (attr
= 0; attr
< VERT_ATTRIB_MAX
; attr
++) {
775 if ((1 << attr
) & req
& ~skipBits
) {
776 if (any_eval1
&& ctx
->Eval
.Map1Attrib
[attr
]) {
777 /* evaluate 1-D vertex attrib map [i] */
778 eval1_4f( &tmp
->Attribs
[attr
], coord
, flags
, 4,
779 &ctx
->EvalMap
.Map1Attrib
[attr
] );
780 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
782 if (any_eval2
&& ctx
->Eval
.Map2Attrib
[attr
]) {
783 /* evaluate 2-D vertex attrib map [i] */
784 eval2_4f( &tmp
->Attribs
[attr
], coord
, flags
, 4,
785 &ctx
->EvalMap
.Map2Attrib
[attr
] );
786 generated
|= VERT_BIT_EVAL_C1
|VERT_BIT_EVAL_P1
;
792 /* Calculate new IM->Elts, IM->Primitive, IM->PrimitiveLength for
793 * the case where vertex maps are not enabled for some received
794 * eval coordinates. In this case those slots in the immediate
798 const GLuint vertex
= VERT_BIT_POS
|(VERT_BITS_EVAL_ANY
& ~purge_flags
);
799 GLuint last_new_prim
= 0;
800 GLuint new_prim_length
= 0;
801 GLuint next_old_prim
= 0;
802 struct vertex_buffer
*VB
= &tnl
->vb
;
803 const GLuint count
= VB
->Count
;
806 for (i
= 0, j
= 0 ; i
< count
; i
++) {
807 if (flags
[i
] & vertex
) {
811 if (i
== next_old_prim
) {
812 next_old_prim
+= VB
->PrimitiveLength
[i
];
813 VB
->PrimitiveLength
[last_new_prim
] = new_prim_length
;
814 VB
->Primitive
[j
] = VB
->Primitive
[i
];
819 VB
->Elts
= store
->Elt
;
820 _tnl_get_purged_copy_verts( ctx
, store
);
823 /* Produce new flags array:
826 const GLuint count
= tnl
->vb
.Count
+ 1;
829 copy_1ui( store
->Flag
, flags
, count
);
830 tnl
->vb
.Flag
= store
->Flag
;
831 for (i
= 0 ; i
< count
; i
++)
832 store
->Flag
[i
] |= req
;
833 IM
->Evaluated
= req
; /* hack for copying. */