1 /* $Id: t_imm_fixup.c,v 1.31 2002/01/05 20:51:13 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.
29 * Keith Whitwell <keithw@valinux.com>
45 #include "math/m_matrix.h"
46 #include "math/m_xform.h"
48 #include "t_context.h"
49 #include "t_imm_alloc.h"
50 #include "t_imm_debug.h"
51 #include "t_imm_elt.h"
52 #include "t_imm_fixup.h"
53 #include "t_imm_exec.h"
54 #include "t_pipeline.h"
57 static const GLuint increment
[GL_POLYGON
+2] = { 1,2,1,1,3,1,1,4,2,1,1 };
58 static const GLuint intro
[GL_POLYGON
+2] = { 0,0,2,2,0,2,2,0,2,2,0 };
61 _tnl_fixup_4f( GLfloat data
[][4], GLuint flag
[], GLuint start
, GLuint match
)
66 if ((flag
[++i
] & match
) == 0) {
67 COPY_4FV(data
[i
], data
[i
-1]);
68 if (flag
[i
] & VERT_END_VB
) break;
74 _tnl_fixup_3f( float data
[][3], GLuint flag
[], GLuint start
, GLuint match
)
80 if ((flag
[++i
] & match
) == 0) {
81 /* fprintf(stderr, "_tnl_fixup_3f copy to %p values %f %f %f\n", */
86 COPY_3V(data
[i
], data
[i
-1]);
87 if (flag
[i
] & VERT_END_VB
) break;
94 _tnl_fixup_1ui( GLuint
*data
, GLuint flag
[], GLuint start
, GLuint match
)
99 if ((flag
[++i
] & match
) == 0) {
101 if (flag
[i
] & VERT_END_VB
) break;
109 _tnl_fixup_1f( GLfloat
*data
, GLuint flag
[], GLuint start
, GLuint match
)
114 if ((flag
[++i
] & match
) == 0) {
116 if (flag
[i
] & VERT_END_VB
) break;
123 _tnl_fixup_1ub( GLubyte
*data
, GLuint flag
[], GLuint start
, GLuint match
)
128 if ((flag
[++i
] & match
) == 0) {
130 if (flag
[i
] & VERT_END_VB
) break;
138 fixup_first_4f( GLfloat data
[][4], GLuint flag
[], GLuint match
,
139 GLuint start
, GLfloat
*dflt
)
142 match
|= VERT_END_VB
;
144 while ((flag
[++i
]&match
) == 0)
145 COPY_4FV(data
[i
], dflt
);
149 fixup_first_3f( GLfloat data
[][3], GLuint flag
[], GLuint match
,
150 GLuint start
, GLfloat
*dflt
)
153 match
|= VERT_END_VB
;
155 /* fprintf(stderr, "fixup_first_3f default: %f %f %f start: %d\n", */
156 /* dflt[0], dflt[1], dflt[2], start); */
158 while ((flag
[++i
]&match
) == 0)
159 COPY_3FV(data
[i
], dflt
);
164 fixup_first_1ui( GLuint data
[], GLuint flag
[], GLuint match
,
165 GLuint start
, GLuint dflt
)
168 match
|= VERT_END_VB
;
170 while ((flag
[++i
]&match
) == 0)
176 fixup_first_1f( GLfloat data
[], GLuint flag
[], GLuint match
,
177 GLuint start
, GLfloat dflt
)
180 match
|= VERT_END_VB
;
182 while ((flag
[++i
]&match
) == 0)
188 fixup_first_1ub( GLubyte data
[], GLuint flag
[], GLuint match
,
189 GLuint start
, GLubyte dflt
)
192 match
|= VERT_END_VB
;
194 while ((flag
[++i
]&match
) == 0)
199 * Copy vertex attributes from the ctx->Current group into the immediate
200 * struct at the given position according to copyMask.
202 static void copy_from_current( GLcontext
*ctx
, struct immediate
*IM
,
203 GLuint pos
, GLuint copyMask
)
205 GLuint attrib
, attribBit
;
207 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
208 _tnl_print_vert_flags("copy from current", copyMask
);
211 if (copyMask
& VERT_NORMAL_BIT
) {
212 COPY_4V(IM
->Attrib
[VERT_ATTRIB_NORMAL
][pos
],
213 ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
]);
216 if (copyMask
& VERT_COLOR0_BIT
) {
217 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR0
][pos
],
218 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
221 if (copyMask
& VERT_COLOR1_BIT
)
222 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR1
][pos
],
223 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
]);
225 if (copyMask
& VERT_FOG_BIT
)
226 IM
->Attrib
[VERT_ATTRIB_FOG
][pos
][0] = ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
228 if (copyMask
& VERT_TEX_ANY
) {
230 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
231 if (copyMask
& VERT_TEX(i
))
232 COPY_4FV(IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
][pos
],
233 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
]);
237 for (attrib
= 0, attribBit
= 1; attrib
< 16; attrib
++, attribBit
<<= 1) {
238 if (copyMask
& attribBit
) {
239 COPY_4FV( IM
->Attrib
[attrib
][pos
], ctx
->Current
.Attrib
[attrib
]);
244 if (copyMask
& VERT_INDEX_BIT
)
245 IM
->Index
[pos
] = ctx
->Current
.Index
;
247 if (copyMask
& VERT_EDGEFLAG_BIT
)
248 IM
->EdgeFlag
[pos
] = ctx
->Current
.EdgeFlag
;
252 void _tnl_fixup_input( GLcontext
*ctx
, struct immediate
*IM
)
254 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
255 GLuint start
= IM
->CopyStart
;
256 GLuint andflag
= IM
->CopyAndFlag
;
257 GLuint orflag
= IM
->CopyOrFlag
| IM
->Evaluated
;
260 IM
->CopyTexSize
= IM
->TexSize
;
262 /* fprintf(stderr, "Fixup input, Start: %u Count: %u LastData: %u\n", */
263 /* IM->Start, IM->Count, IM->LastData); */
264 /* _tnl_print_vert_flags("Orflag", orflag); */
265 /* _tnl_print_vert_flags("Andflag", andflag); */
268 fixup
= ~andflag
& VERT_FIXUP
;
270 if (!ctx
->CompileFlag
)
271 fixup
&= tnl
->pipeline
.inputs
;
273 if (!ctx
->ExecuteFlag
)
276 if ((orflag
& (VERT_OBJ_BIT
|VERT_EVAL_ANY
)) == 0)
280 GLuint copy
= fixup
& ~IM
->Flag
[start
];
283 /* Equivalent to a lazy copy-from-current when setting up the
286 if (ctx
->ExecuteFlag
&& copy
)
287 copy_from_current( ctx
, IM
, start
, copy
);
289 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
290 _tnl_print_vert_flags("fixup", fixup
);
292 /* XXX replace these conditionals with a loop over the 16
296 if (fixup
& VERT_TEX_ANY
) {
298 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
299 if (fixup
& VERT_TEX(i
)) {
300 if (orflag
& VERT_TEX(i
))
301 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
302 start
, VERT_TEX(i
) );
304 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
306 IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
][start
]);
312 if (fixup
& VERT_EDGEFLAG_BIT
) {
313 if (orflag
& VERT_EDGEFLAG_BIT
)
314 _tnl_fixup_1ub( IM
->EdgeFlag
, IM
->Flag
, start
, VERT_EDGEFLAG_BIT
);
316 fixup_first_1ub( IM
->EdgeFlag
, IM
->Flag
, VERT_END_VB
, start
,
317 IM
->EdgeFlag
[start
] );
320 if (fixup
& VERT_INDEX_BIT
) {
321 if (orflag
& VERT_INDEX_BIT
)
322 _tnl_fixup_1ui( IM
->Index
, IM
->Flag
, start
, VERT_INDEX_BIT
);
324 fixup_first_1ui( IM
->Index
, IM
->Flag
, VERT_END_VB
, start
,
328 if (fixup
& VERT_COLOR0_BIT
) {
329 if (orflag
& VERT_COLOR0_BIT
)
330 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
, start
,
332 /* No need for else case as the drivers understand stride
333 * zero here. (TODO - propogate this)
337 if (fixup
& VERT_COLOR1_BIT
) {
338 if (orflag
& VERT_COLOR1_BIT
)
339 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
, start
,
342 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
, VERT_END_VB
, start
,
343 IM
->Attrib
[VERT_ATTRIB_COLOR1
][start
] );
346 if (fixup
& VERT_FOG_BIT
) {
347 if (orflag
& VERT_FOG_BIT
)
348 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
,
349 start
, VERT_FOG_BIT
);
351 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
, VERT_END_VB
,
352 start
, IM
->Attrib
[VERT_ATTRIB_FOG
][start
] );
355 if (fixup
& VERT_NORMAL_BIT
) {
356 if (orflag
& VERT_NORMAL_BIT
)
357 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
, start
,
360 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
,
362 IM
->Attrib
[VERT_ATTRIB_NORMAL
][start
] );
366 /* Prune possible half-filled slot.
368 IM
->Flag
[IM
->LastData
+1] &= ~VERT_END_VB
;
369 IM
->Flag
[IM
->Count
] |= VERT_END_VB
;
374 if (IM
->MaterialOrMask
& ~IM
->MaterialAndMask
) {
375 GLuint vulnerable
= IM
->MaterialOrMask
;
376 GLuint i
= IM
->Start
;
379 while (!(IM
->Flag
[i
] & VERT_MATERIAL
))
382 vulnerable
&= ~IM
->MaterialMask
[i
];
383 _mesa_copy_material_pairs( IM
->Material
[i
],
388 } while (vulnerable
);
395 static void copy_material( struct immediate
*next
,
396 struct immediate
*prev
,
397 GLuint dst
, GLuint src
)
399 if (next
->Material
== 0) {
400 next
->Material
= (GLmaterial (*)[2]) MALLOC( sizeof(GLmaterial
) *
402 next
->MaterialMask
= (GLuint
*) MALLOC( sizeof(GLuint
) * IMM_SIZE
);
405 next
->MaterialMask
[dst
] = prev
->MaterialOrMask
;
406 MEMCPY(next
->Material
[dst
], prev
->Material
[src
], 2*sizeof(GLmaterial
));
409 static GLboolean is_fan_like
[GL_POLYGON
+1] = {
412 GL_TRUE
, /* line loop */
416 GL_TRUE
, /* tri fan */
419 GL_TRUE
/* polygon */
423 /* Copy the untransformed data from the shared vertices of a primitive
424 * that wraps over two immediate structs. This is done prior to
425 * set_immediate so that prev and next may point to the same
426 * structure. In general it's difficult to avoid this copy on long
429 * Have to be careful with the transitions between display list
430 * replay, compile and normal execute modes.
432 void _tnl_copy_immediate_vertices( GLcontext
*ctx
, struct immediate
*next
)
434 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
435 struct immediate
*prev
= tnl
->ExecCopySource
;
436 struct vertex_arrays
*inputs
= &tnl
->imm_inputs
;
437 GLuint count
= tnl
->ExecCopyCount
;
438 GLuint
*elts
= tnl
->ExecCopyElts
;
439 GLuint offset
= IMM_MAX_COPIED_VERTS
- count
;
443 ASSERT(tnl
->ExecCopyCount
== 0);
447 next
->CopyStart
= next
->Start
- count
;
449 if ((prev
->CopyOrFlag
& VERT_DATA
) == VERT_ELT
&&
450 ctx
->Array
.LockCount
&&
451 ctx
->Array
.Vertex
.Enabled
)
453 /* Copy Elt values only
455 for (i
= 0 ; i
< count
; i
++)
457 GLuint src
= elts
[i
+offset
];
458 GLuint dst
= next
->CopyStart
+i
;
459 next
->Elt
[dst
] = prev
->Elt
[src
];
460 next
->Flag
[dst
] = VERT_ELT
;
462 /* fprintf(stderr, "ADDING VERT_ELT!\n"); */
463 next
->CopyOrFlag
|= VERT_ELT
;
464 next
->CopyAndFlag
&= VERT_ELT
;
467 GLuint copy
= tnl
->pipeline
.inputs
& (prev
->CopyOrFlag
|prev
->Evaluated
);
470 if (is_fan_like
[ctx
->Driver
.CurrentExecPrimitive
]) {
471 flag
= ((prev
->CopyOrFlag
|prev
->Evaluated
) & VERT_FIXUP
);
472 next
->CopyOrFlag
|= flag
;
475 /* Don't let an early 'glColor', etc. poison the elt path.
477 flag
= ((prev
->OrFlag
|prev
->Evaluated
) & VERT_FIXUP
);
480 next
->TexSize
|= tnl
->ExecCopyTexSize
;
481 next
->CopyAndFlag
&= flag
;
484 /* _tnl_print_vert_flags("copy vertex components", copy); */
485 /* _tnl_print_vert_flags("prev copyorflag", prev->CopyOrFlag); */
486 /* _tnl_print_vert_flags("flag", flag); */
488 /* Copy whole vertices
490 for (i
= 0 ; i
< count
; i
++)
492 GLuint src
= elts
[i
+offset
];
493 GLuint isrc
= src
- prev
->CopyStart
;
494 GLuint dst
= next
->CopyStart
+i
;
496 /* Values subject to eval must be copied out of the 'inputs'
497 * struct. (Copied rows should not be evaluated twice).
499 * Note these pointers are null when inactive.
501 COPY_4FV( next
->Attrib
[VERT_ATTRIB_POS
][dst
],
502 inputs
->Obj
.data
[isrc
] );
504 if (copy
& VERT_NORMAL_BIT
) {
505 /* fprintf(stderr, "copy vert norm %d to %d (%p): %f %f %f\n", */
507 /* next->Normal[dst], */
508 /* inputs->Normal.data[isrc][0], */
509 /* inputs->Normal.data[isrc][1], */
510 /* inputs->Normal.data[isrc][2]); */
511 COPY_3FV( next
->Attrib
[VERT_ATTRIB_NORMAL
][dst
], inputs
->Normal
.data
[isrc
] );
514 if (copy
& VERT_COLOR0_BIT
)
515 COPY_4FV( next
->Attrib
[VERT_ATTRIB_COLOR0
][dst
],
516 ((GLfloat (*)[4])inputs
->Color
.Ptr
)[isrc
] );
518 if (copy
& VERT_INDEX_BIT
)
519 next
->Index
[dst
] = inputs
->Index
.data
[isrc
];
521 if (copy
& VERT_TEX_ANY
) {
523 for (i
= 0 ; i
< prev
->MaxTextureUnits
; i
++) {
524 if (copy
& VERT_TEX(i
))
525 COPY_4FV( next
->Attrib
[VERT_ATTRIB_TEX0
+ i
][dst
],
526 inputs
->TexCoord
[i
].data
[isrc
] );
530 /* Remaining values should be the same in the 'input' struct and the
531 * original immediate.
533 if (copy
& (VERT_ELT
|VERT_EDGEFLAG_BIT
|VERT_COLOR1_BIT
|VERT_FOG_BIT
|
536 if (prev
->Flag
[src
] & VERT_MATERIAL
)
537 copy_material(next
, prev
, dst
, src
);
539 next
->Elt
[dst
] = prev
->Elt
[src
];
540 next
->EdgeFlag
[dst
] = prev
->EdgeFlag
[src
];
541 COPY_4FV( next
->Attrib
[VERT_ATTRIB_COLOR1
][dst
],
542 prev
->Attrib
[VERT_ATTRIB_COLOR1
][src
] );
543 COPY_4FV( next
->Attrib
[VERT_ATTRIB_FOG
][dst
],
544 prev
->Attrib
[VERT_ATTRIB_FOG
][src
] );
547 next
->Flag
[dst
] = flag
;
548 next
->CopyOrFlag
|= prev
->Flag
[src
] & (VERT_FIXUP
|
554 if (--tnl
->ExecCopySource
->ref_count
== 0)
555 _tnl_free_immediate( tnl
->ExecCopySource
);
557 tnl
->ExecCopySource
= 0;
558 tnl
->ExecCopyCount
= 0;
563 /* Revive a compiled immediate struct - propogate new 'Current'
564 * values. Often this is redundant because the current values were
565 * known and fixed up at compile time (or in the first execution of
568 void _tnl_fixup_compiled_cassette( GLcontext
*ctx
, struct immediate
*IM
)
570 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
572 GLuint start
= IM
->Start
;
574 /* fprintf(stderr, "%s\n", __FUNCTION__); */
577 IM
->CopyOrFlag
= IM
->OrFlag
;
578 IM
->CopyAndFlag
= IM
->AndFlag
;
579 IM
->CopyTexSize
= IM
->TexSize
| tnl
->ExecCopyTexSize
;
581 _tnl_copy_immediate_vertices( ctx
, IM
);
583 if (ctx
->Driver
.CurrentExecPrimitive
== GL_POLYGON
+1) {
584 ASSERT(IM
->CopyStart
== IM
->Start
);
587 /* Naked array elements can be copied into the first cassette in a
588 * display list. Need to translate them away:
590 if (IM
->CopyOrFlag
& VERT_ELT
) {
591 GLuint copy
= tnl
->pipeline
.inputs
& ~ctx
->Array
._Enabled
;
594 ASSERT(IM
->CopyStart
< IM
->Start
);
596 _tnl_translate_array_elts( ctx
, IM
, IM
->CopyStart
, IM
->Start
);
598 for (i
= IM
->CopyStart
; i
< IM
->Start
; i
++)
599 copy_from_current( ctx
, IM
, i
, copy
);
601 _tnl_copy_to_current( ctx
, IM
, ctx
->Array
._Enabled
, IM
->Start
);
604 fixup
= tnl
->pipeline
.inputs
& ~IM
->Flag
[start
] & VERT_FIXUP
;
606 /* _tnl_print_vert_flags("fixup compiled", fixup); */
610 /* XXX try to replace this code with a loop over the 16 vertex
614 if (fixup
& VERT_NORMAL_BIT
) {
615 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
,
616 VERT_NORMAL_BIT
, start
,
617 ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
] );
620 if (fixup
& VERT_COLOR0_BIT
) {
621 if (IM
->CopyOrFlag
& VERT_COLOR0_BIT
)
622 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
,
623 VERT_COLOR0_BIT
, start
,
624 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
626 fixup
&= ~VERT_COLOR0_BIT
;
629 if (fixup
& VERT_COLOR1_BIT
)
630 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
,
631 VERT_COLOR1_BIT
, start
,
632 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
] );
634 if (fixup
& VERT_FOG_BIT
)
635 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
,
637 ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
] );
639 if (fixup
& VERT_TEX_ANY
) {
641 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
642 if (fixup
& VERT_TEX(i
))
643 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
645 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
] );
649 if (fixup
& VERT_EDGEFLAG_BIT
)
650 fixup_first_1ub(IM
->EdgeFlag
, IM
->Flag
, VERT_EDGEFLAG_BIT
, start
,
651 ctx
->Current
.EdgeFlag
);
653 if (fixup
& VERT_INDEX_BIT
)
654 fixup_first_1ui(IM
->Index
, IM
->Flag
, VERT_INDEX_BIT
, start
,
655 ctx
->Current
.Index
);
657 IM
->CopyOrFlag
|= fixup
;
663 if (IM
->MaterialOrMask
& ~IM
->MaterialAndMask
) {
664 GLuint vulnerable
= IM
->MaterialOrMask
;
665 GLuint i
= IM
->Start
;
668 while (!(IM
->Flag
[i
] & VERT_MATERIAL
))
671 vulnerable
&= ~IM
->MaterialMask
[i
];
672 _mesa_copy_material_pairs( IM
->Material
[i
],
677 } while (vulnerable
);
686 static void copy_none( TNLcontext
*tnl
, GLuint start
, GLuint count
, GLuint ovf
)
688 (void) (start
&& ovf
&& tnl
&& count
);
691 static void copy_last( TNLcontext
*tnl
, GLuint start
, GLuint count
, GLuint ovf
)
693 (void) start
; (void) ovf
;
694 tnl
->ExecCopyCount
= 1;
695 tnl
->ExecCopyElts
[2] = count
-1;
698 static void copy_first_and_last( TNLcontext
*tnl
, GLuint start
, GLuint count
,
702 tnl
->ExecCopyCount
= 2;
703 tnl
->ExecCopyElts
[1] = start
;
704 tnl
->ExecCopyElts
[2] = count
-1;
707 static void copy_last_two( TNLcontext
*tnl
, GLuint start
, GLuint count
,
711 tnl
->ExecCopyCount
= 2+ovf
;
712 tnl
->ExecCopyElts
[0] = count
-3;
713 tnl
->ExecCopyElts
[1] = count
-2;
714 tnl
->ExecCopyElts
[2] = count
-1;
717 static void copy_overflow( TNLcontext
*tnl
, GLuint start
, GLuint count
,
721 tnl
->ExecCopyCount
= ovf
;
722 tnl
->ExecCopyElts
[0] = count
-3;
723 tnl
->ExecCopyElts
[1] = count
-2;
724 tnl
->ExecCopyElts
[2] = count
-1;
728 typedef void (*copy_func
)( TNLcontext
*tnl
, GLuint start
, GLuint count
,
731 static copy_func copy_tab
[GL_POLYGON
+2] =
750 /* Figure out what vertices need to be copied next time.
753 _tnl_get_exec_copy_verts( GLcontext
*ctx
, struct immediate
*IM
)
756 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
757 GLuint last
= IM
->LastPrimitive
;
758 GLuint prim
= ctx
->Driver
.CurrentExecPrimitive
;
759 GLuint pincr
= increment
[prim
];
760 GLuint pintro
= intro
[prim
];
763 /* fprintf(stderr, "_tnl_get_exec_copy_verts %s\n", */
764 /* _mesa_lookup_enum_by_nr(prim)); */
766 ASSERT(tnl
->ExecCopySource
== 0);
768 if (prim
== GL_POLYGON
+1) {
769 tnl
->ExecCopyCount
= 0;
770 tnl
->ExecCopyTexSize
= 0;
773 /* Remember this immediate as the one to copy from.
776 tnl
->ExecCopySource
= IM
;
777 tnl
->ExecCopyCount
= 0;
778 tnl
->ExecCopyTexSize
= IM
->CopyTexSize
;
780 if (IM
->LastPrimitive
!= IM
->CopyStart
)
783 tnl
->ExecParity
^= IM
->PrimitiveLength
[IM
->LastPrimitive
] & 1;
786 if (pincr
!= 1 && (IM
->Count
- last
- pintro
))
787 ovf
= (IM
->Count
- last
- pintro
) % pincr
;
789 if (last
< IM
->Count
)
790 copy_tab
[prim
]( tnl
, last
, IM
->Count
, ovf
);
795 /* Recalculate ExecCopyElts, ExecParity, etc.
798 _tnl_get_purged_copy_verts( GLcontext
*ctx
, struct immediate
*IM
)
800 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
802 if (ctx
->Driver
.CurrentExecPrimitive
!= GL_POLYGON
+1) {
803 GLuint last
= IM
->LastPrimitive
;
804 GLenum prim
= IM
->Primitive
[last
];
805 GLuint pincr
= increment
[prim
];
806 GLuint pintro
= intro
[prim
];
809 tnl
->ExecCopyCount
= 0;
810 if (IM
->LastPrimitive
!= IM
->CopyStart
)
813 tnl
->ExecParity
^= IM
->PrimitiveLength
[IM
->LastPrimitive
] & 1;
815 if (pincr
!= 1 && (IM
->Count
- last
- pintro
))
816 ovf
= (IM
->Count
- last
- pintro
) % pincr
;
818 if (last
< IM
->Count
)
819 copy_tab
[prim
]( tnl
, last
, IM
->Count
, ovf
);
821 for (i
= 0 ; i
< tnl
->ExecCopyCount
; i
++)
822 tnl
->ExecCopyElts
[i
] = IM
->Elt
[tnl
->ExecCopyElts
[i
]];
827 void _tnl_upgrade_current_data( GLcontext
*ctx
,
831 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
832 struct vertex_buffer
*VB
= &tnl
->vb
;
833 struct immediate
*IM
= (struct immediate
*)VB
->import_source
;
837 /* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
839 if ((required
& VERT_COLOR0_BIT
) && (VB
->ColorPtr
[0]->Flags
& CA_CLIENT_DATA
)) {
840 struct gl_client_array
*tmp
= &tnl
->imm_inputs
.Color
;
841 GLuint start
= IM
->CopyStart
;
843 tmp
->Ptr
= IM
->Attrib
[VERT_ATTRIB_COLOR0
] + start
;
844 tmp
->StrideB
= 4 * sizeof(GLfloat
);
847 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR0
][start
],
848 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
851 ASSERT(IM->Flag[IM->LastData+1] & VERT_END_VB);
854 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
, VERT_END_VB
,
855 start
, IM
->Attrib
[VERT_ATTRIB_COLOR0
][start
] );
857 VB
->importable_data
&= ~VERT_COLOR0_BIT
;