1 /* $Id: t_imm_fixup.c,v 1.34 2002/02/13 00:53:20 keithw 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_BIT_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_BIT_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_BIT_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_BIT_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_BIT_END_VB
) break;
138 fixup_first_4f( GLfloat data
[][4], GLuint flag
[], GLuint match
,
139 GLuint start
, GLfloat
*dflt
)
142 match
|= VERT_BIT_END_VB
;
144 while ((flag
[++i
]&match
) == 0)
145 COPY_4FV(data
[i
], dflt
);
150 fixup_first_3f( GLfloat data
[][3], GLuint flag
[], GLuint match
,
151 GLuint start
, GLfloat
*dflt
)
154 match
|= VERT_BIT_END_VB
;
156 /* fprintf(stderr, "fixup_first_3f default: %f %f %f start: %d\n", */
157 /* dflt[0], dflt[1], dflt[2], start); */
159 while ((flag
[++i
]&match
) == 0)
160 COPY_3FV(data
[i
], dflt
);
165 fixup_first_1ui( GLuint data
[], GLuint flag
[], GLuint match
,
166 GLuint start
, GLuint dflt
)
169 match
|= VERT_BIT_END_VB
;
171 while ((flag
[++i
]&match
) == 0)
177 fixup_first_1f( GLfloat data
[], GLuint flag
[], GLuint match
,
178 GLuint start
, GLfloat dflt
)
181 match
|= VERT_BIT_END_VB
;
183 while ((flag
[++i
]&match
) == 0)
189 fixup_first_1ub( GLubyte data
[], GLuint flag
[], GLuint match
,
190 GLuint start
, GLubyte dflt
)
193 match
|= VERT_BIT_END_VB
;
195 while ((flag
[++i
]&match
) == 0)
200 * Copy vertex attributes from the ctx->Current group into the immediate
201 * struct at the given position according to copyMask.
203 static void copy_from_current( GLcontext
*ctx
, struct immediate
*IM
,
204 GLuint pos
, GLuint copyMask
)
206 GLuint attrib
, attribBit
;
208 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
209 _tnl_print_vert_flags("copy from current", copyMask
);
212 if (copyMask
& VERT_BIT_NORMAL
) {
213 COPY_4V(IM
->Attrib
[VERT_ATTRIB_NORMAL
][pos
],
214 ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
]);
217 if (copyMask
& VERT_BIT_COLOR0
) {
218 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR0
][pos
],
219 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
222 if (copyMask
& VERT_BIT_COLOR1
)
223 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR1
][pos
],
224 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
]);
226 if (copyMask
& VERT_BIT_FOG
)
227 IM
->Attrib
[VERT_ATTRIB_FOG
][pos
][0] = ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
][0];
229 if (copyMask
& VERT_BITS_TEX_ANY
) {
231 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
232 if (copyMask
& VERT_BIT_TEX(i
))
233 COPY_4FV(IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
][pos
],
234 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
]);
238 for (attrib
= 0, attribBit
= 1; attrib
< 16; attrib
++, attribBit
<<= 1) {
239 if (copyMask
& attribBit
) {
240 COPY_4FV( IM
->Attrib
[attrib
][pos
], ctx
->Current
.Attrib
[attrib
]);
245 if (copyMask
& VERT_BIT_INDEX
)
246 IM
->Index
[pos
] = ctx
->Current
.Index
;
248 if (copyMask
& VERT_BIT_EDGEFLAG
)
249 IM
->EdgeFlag
[pos
] = ctx
->Current
.EdgeFlag
;
253 void _tnl_fixup_input( GLcontext
*ctx
, struct immediate
*IM
)
255 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
256 GLuint start
= IM
->CopyStart
;
257 GLuint andflag
= IM
->CopyAndFlag
;
258 GLuint orflag
= IM
->CopyOrFlag
| IM
->Evaluated
;
261 IM
->CopyTexSize
= IM
->TexSize
;
263 /* fprintf(stderr, "Fixup input, Start: %u Count: %u LastData: %u\n", */
264 /* IM->Start, IM->Count, IM->LastData); */
265 /* _tnl_print_vert_flags("Orflag", orflag); */
266 /* _tnl_print_vert_flags("Andflag", andflag); */
269 fixup
= ~andflag
& VERT_BITS_FIXUP
;
271 if (!ctx
->CompileFlag
)
272 fixup
&= tnl
->pipeline
.inputs
;
274 if (!ctx
->ExecuteFlag
)
277 if ((orflag
& (VERT_BIT_POS
|VERT_BITS_EVAL_ANY
)) == 0)
281 GLuint copy
= fixup
& ~IM
->Flag
[start
];
284 /* Equivalent to a lazy copy-from-current when setting up the
287 if (ctx
->ExecuteFlag
&& copy
)
288 copy_from_current( ctx
, IM
, start
, copy
);
290 if (MESA_VERBOSE
&VERBOSE_IMMEDIATE
)
291 _tnl_print_vert_flags("fixup", fixup
);
293 /* XXX replace these conditionals with a loop over the 16
297 if (fixup
& VERT_BITS_TEX_ANY
) {
299 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
300 if (fixup
& VERT_BIT_TEX(i
)) {
301 if (orflag
& VERT_BIT_TEX(i
))
302 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
303 start
, VERT_BIT_TEX(i
) );
305 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
306 VERT_BIT_END_VB
, start
,
307 IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
][start
]);
313 if (fixup
& VERT_BIT_EDGEFLAG
) {
314 if (orflag
& VERT_BIT_EDGEFLAG
)
315 _tnl_fixup_1ub( IM
->EdgeFlag
, IM
->Flag
, start
, VERT_BIT_EDGEFLAG
);
317 fixup_first_1ub( IM
->EdgeFlag
, IM
->Flag
, VERT_BIT_END_VB
, start
,
318 IM
->EdgeFlag
[start
] );
321 if (fixup
& VERT_BIT_INDEX
) {
322 if (orflag
& VERT_BIT_INDEX
)
323 _tnl_fixup_1ui( IM
->Index
, IM
->Flag
, start
, VERT_BIT_INDEX
);
325 fixup_first_1ui( IM
->Index
, IM
->Flag
, VERT_BIT_END_VB
, start
,
329 if (fixup
& VERT_BIT_COLOR0
) {
330 if (orflag
& VERT_BIT_COLOR0
)
331 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
, start
,
333 /* No need for else case as the drivers understand stride
334 * zero here. (TODO - propogate this)
338 if (fixup
& VERT_BIT_COLOR1
) {
339 if (orflag
& VERT_BIT_COLOR1
)
340 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
, start
,
343 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
, VERT_BIT_END_VB
, start
,
344 IM
->Attrib
[VERT_ATTRIB_COLOR1
][start
] );
347 if (fixup
& VERT_BIT_FOG
) {
348 if (orflag
& VERT_BIT_FOG
)
349 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
,
350 start
, VERT_BIT_FOG
);
352 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
, VERT_BIT_END_VB
,
353 start
, IM
->Attrib
[VERT_ATTRIB_FOG
][start
] );
356 if (fixup
& VERT_BIT_NORMAL
) {
357 if (orflag
& VERT_BIT_NORMAL
)
358 _tnl_fixup_4f( IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
, start
,
361 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
,
362 VERT_BIT_END_VB
, start
,
363 IM
->Attrib
[VERT_ATTRIB_NORMAL
][start
] );
367 /* Prune possible half-filled slot.
369 IM
->Flag
[IM
->LastData
+1] &= ~VERT_BIT_END_VB
;
370 IM
->Flag
[IM
->Count
] |= VERT_BIT_END_VB
;
375 if (IM
->MaterialOrMask
& ~IM
->MaterialAndMask
) {
376 GLuint vulnerable
= IM
->MaterialOrMask
;
377 GLuint i
= IM
->Start
;
380 while (!(IM
->Flag
[i
] & VERT_BIT_MATERIAL
))
383 vulnerable
&= ~IM
->MaterialMask
[i
];
384 _mesa_copy_material_pairs( IM
->Material
[i
],
389 } while (vulnerable
);
395 copy_material( struct immediate
*next
,
396 struct immediate
*prev
,
397 GLuint dst
, GLuint src
)
399 /* fprintf(stderr, "%s\n", __FUNCTION__); */
401 if (next
->Material
== 0) {
402 next
->Material
= (struct gl_material (*)[2])
403 MALLOC( sizeof(struct gl_material
) * IMM_SIZE
* 2 );
404 next
->MaterialMask
= (GLuint
*) MALLOC( sizeof(GLuint
) * IMM_SIZE
);
407 next
->MaterialMask
[dst
] = prev
->MaterialOrMask
;
408 MEMCPY(next
->Material
[dst
], prev
->Material
[src
],
409 2 * sizeof(struct gl_material
));
414 static GLboolean is_fan_like
[GL_POLYGON
+1] = {
417 GL_TRUE
, /* line loop */
421 GL_TRUE
, /* tri fan */
424 GL_TRUE
/* polygon */
428 /* Copy the untransformed data from the shared vertices of a primitive
429 * that wraps over two immediate structs. This is done prior to
430 * set_immediate so that prev and next may point to the same
431 * structure. In general it's difficult to avoid this copy on long
434 * Have to be careful with the transitions between display list
435 * replay, compile and normal execute modes.
437 void _tnl_copy_immediate_vertices( GLcontext
*ctx
, struct immediate
*next
)
439 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
440 struct immediate
*prev
= tnl
->ExecCopySource
;
441 struct vertex_arrays
*inputs
= &tnl
->imm_inputs
;
442 GLuint count
= tnl
->ExecCopyCount
;
443 GLuint
*elts
= tnl
->ExecCopyElts
;
444 GLuint offset
= IMM_MAX_COPIED_VERTS
- count
;
448 ASSERT(tnl
->ExecCopyCount
== 0);
452 next
->CopyStart
= next
->Start
- count
;
454 if ((prev
->CopyOrFlag
& VERT_BITS_DATA
) == VERT_BIT_ELT
&&
455 ctx
->Array
.LockCount
&&
456 ctx
->Array
.Vertex
.Enabled
)
458 /* Copy Elt values only
460 for (i
= 0 ; i
< count
; i
++)
462 GLuint src
= elts
[i
+offset
];
463 GLuint dst
= next
->CopyStart
+i
;
464 next
->Elt
[dst
] = prev
->Elt
[src
];
465 next
->Flag
[dst
] = VERT_BIT_ELT
;
466 elts
[i
+offset
] = dst
;
468 /* fprintf(stderr, "ADDING VERT_BIT_ELT!\n"); */
469 next
->CopyOrFlag
|= VERT_BIT_ELT
;
470 next
->CopyAndFlag
&= VERT_BIT_ELT
;
473 GLuint copy
= tnl
->pipeline
.inputs
& (prev
->CopyOrFlag
|prev
->Evaluated
);
476 if (is_fan_like
[ctx
->Driver
.CurrentExecPrimitive
]) {
477 flag
= ((prev
->CopyOrFlag
|prev
->Evaluated
) & VERT_BITS_FIXUP
);
478 next
->CopyOrFlag
|= flag
;
481 /* Don't let an early 'glColor', etc. poison the elt path.
483 flag
= ((prev
->OrFlag
|prev
->Evaluated
) & VERT_BITS_FIXUP
);
486 next
->TexSize
|= tnl
->ExecCopyTexSize
;
487 next
->CopyAndFlag
&= flag
;
490 /* _tnl_print_vert_flags("copy vertex components", copy); */
491 /* _tnl_print_vert_flags("prev copyorflag", prev->CopyOrFlag); */
492 /* _tnl_print_vert_flags("flag", flag); */
494 /* Copy whole vertices
496 for (i
= 0 ; i
< count
; i
++)
498 GLuint src
= elts
[i
+offset
];
499 GLuint isrc
= src
- prev
->CopyStart
;
500 GLuint dst
= next
->CopyStart
+i
;
502 /* Values subject to eval must be copied out of the 'inputs'
503 * struct. (Copied rows should not be evaluated twice).
505 * Note these pointers are null when inactive.
507 COPY_4FV( next
->Attrib
[VERT_ATTRIB_POS
][dst
],
508 inputs
->Obj
.data
[isrc
] );
510 if (copy
& VERT_BIT_NORMAL
) {
511 /* fprintf(stderr, "copy vert norm %d to %d (%p): %f %f %f\n", */
513 /* next->Normal[dst], */
514 /* inputs->Normal.data[isrc][0], */
515 /* inputs->Normal.data[isrc][1], */
516 /* inputs->Normal.data[isrc][2]); */
517 COPY_3FV( next
->Attrib
[VERT_ATTRIB_NORMAL
][dst
], inputs
->Normal
.data
[isrc
] );
520 if (copy
& VERT_BIT_COLOR0
)
521 COPY_4FV( next
->Attrib
[VERT_ATTRIB_COLOR0
][dst
],
522 ((GLfloat (*)[4])inputs
->Color
.Ptr
)[isrc
] );
524 if (copy
& VERT_BIT_INDEX
)
525 next
->Index
[dst
] = inputs
->Index
.data
[isrc
];
527 if (copy
& VERT_BITS_TEX_ANY
) {
529 for (i
= 0 ; i
< prev
->MaxTextureUnits
; i
++) {
530 if (copy
& VERT_BIT_TEX(i
))
531 COPY_4FV( next
->Attrib
[VERT_ATTRIB_TEX0
+ i
][dst
],
532 inputs
->TexCoord
[i
].data
[isrc
] );
536 /* Remaining values should be the same in the 'input' struct and the
537 * original immediate.
539 if (copy
& (VERT_BIT_ELT
|VERT_BIT_EDGEFLAG
|VERT_BIT_COLOR1
|VERT_BIT_FOG
|
540 VERT_BIT_MATERIAL
)) {
542 if (prev
->Flag
[src
] & VERT_BIT_MATERIAL
)
543 copy_material(next
, prev
, dst
, src
);
545 next
->Elt
[dst
] = prev
->Elt
[src
];
546 next
->EdgeFlag
[dst
] = prev
->EdgeFlag
[src
];
547 COPY_4FV( next
->Attrib
[VERT_ATTRIB_COLOR1
][dst
],
548 prev
->Attrib
[VERT_ATTRIB_COLOR1
][src
] );
549 COPY_4FV( next
->Attrib
[VERT_ATTRIB_FOG
][dst
],
550 prev
->Attrib
[VERT_ATTRIB_FOG
][src
] );
553 next
->Flag
[dst
] = flag
;
554 next
->CopyOrFlag
|= prev
->Flag
[src
] & (VERT_BITS_FIXUP
|
557 elts
[i
+offset
] = dst
;
561 if (--tnl
->ExecCopySource
->ref_count
== 0)
562 _tnl_free_immediate( tnl
->ExecCopySource
);
564 tnl
->ExecCopySource
= next
; next
->ref_count
++;
569 /* Revive a compiled immediate struct - propogate new 'Current'
570 * values. Often this is redundant because the current values were
571 * known and fixed up at compile time (or in the first execution of
574 void _tnl_fixup_compiled_cassette( GLcontext
*ctx
, struct immediate
*IM
)
576 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
578 GLuint start
= IM
->Start
;
580 /* fprintf(stderr, "%s\n", __FUNCTION__); */
583 IM
->CopyOrFlag
= IM
->OrFlag
;
584 IM
->CopyAndFlag
= IM
->AndFlag
;
585 IM
->CopyTexSize
= IM
->TexSize
| tnl
->ExecCopyTexSize
;
587 _tnl_copy_immediate_vertices( ctx
, IM
);
589 if (ctx
->Driver
.CurrentExecPrimitive
== GL_POLYGON
+1) {
590 ASSERT(IM
->CopyStart
== IM
->Start
);
593 /* Naked array elements can be copied into the first cassette in a
594 * display list. Need to translate them away:
596 if (IM
->CopyOrFlag
& VERT_BIT_ELT
) {
597 GLuint copy
= tnl
->pipeline
.inputs
& ~ctx
->Array
._Enabled
;
600 ASSERT(IM
->CopyStart
< IM
->Start
);
602 _tnl_translate_array_elts( ctx
, IM
, IM
->CopyStart
, IM
->Start
);
604 for (i
= IM
->CopyStart
; i
< IM
->Start
; i
++)
605 copy_from_current( ctx
, IM
, i
, copy
);
607 _tnl_copy_to_current( ctx
, IM
, ctx
->Array
._Enabled
, IM
->Start
);
610 fixup
= tnl
->pipeline
.inputs
& ~IM
->Flag
[start
] & VERT_BITS_FIXUP
;
612 /* _tnl_print_vert_flags("fixup compiled", fixup); */
616 /* XXX try to replace this code with a loop over the 16 vertex
620 if (fixup
& VERT_BIT_NORMAL
) {
621 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_NORMAL
], IM
->Flag
,
622 VERT_BIT_NORMAL
, start
,
623 ctx
->Current
.Attrib
[VERT_ATTRIB_NORMAL
] );
626 if (fixup
& VERT_BIT_COLOR0
) {
627 if (IM
->CopyOrFlag
& VERT_BIT_COLOR0
)
628 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
,
629 VERT_BIT_COLOR0
, start
,
630 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
] );
632 fixup
&= ~VERT_BIT_COLOR0
;
635 if (fixup
& VERT_BIT_COLOR1
)
636 fixup_first_4f(IM
->Attrib
[VERT_ATTRIB_COLOR1
], IM
->Flag
,
637 VERT_BIT_COLOR1
, start
,
638 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR1
] );
640 if (fixup
& VERT_BIT_FOG
)
641 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_FOG
], IM
->Flag
,
643 ctx
->Current
.Attrib
[VERT_ATTRIB_FOG
] );
645 if (fixup
& VERT_BITS_TEX_ANY
) {
647 for (i
= 0 ; i
< ctx
->Const
.MaxTextureUnits
; i
++) {
648 if (fixup
& VERT_BIT_TEX(i
))
649 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_TEX0
+ i
], IM
->Flag
,
650 VERT_BIT_TEX(i
), start
,
651 ctx
->Current
.Attrib
[VERT_ATTRIB_TEX0
+ i
] );
655 if (fixup
& VERT_BIT_EDGEFLAG
)
656 fixup_first_1ub(IM
->EdgeFlag
, IM
->Flag
, VERT_BIT_EDGEFLAG
, start
,
657 ctx
->Current
.EdgeFlag
);
659 if (fixup
& VERT_BIT_INDEX
)
660 fixup_first_1ui(IM
->Index
, IM
->Flag
, VERT_BIT_INDEX
, start
,
661 ctx
->Current
.Index
);
663 IM
->CopyOrFlag
|= fixup
;
669 if (IM
->MaterialOrMask
& ~IM
->MaterialAndMask
) {
670 GLuint vulnerable
= IM
->MaterialOrMask
;
671 GLuint i
= IM
->Start
;
674 while (!(IM
->Flag
[i
] & VERT_BIT_MATERIAL
))
677 vulnerable
&= ~IM
->MaterialMask
[i
];
678 _mesa_copy_material_pairs( IM
->Material
[i
],
683 } while (vulnerable
);
692 static void copy_none( TNLcontext
*tnl
, GLuint start
, GLuint count
, GLuint ovf
)
694 (void) (start
&& ovf
&& tnl
&& count
);
697 static void copy_last( TNLcontext
*tnl
, GLuint start
, GLuint count
, GLuint ovf
)
699 (void) start
; (void) ovf
;
700 tnl
->ExecCopyCount
= 1;
701 tnl
->ExecCopyElts
[2] = count
-1;
704 static void copy_first_and_last( TNLcontext
*tnl
, GLuint start
, GLuint count
,
708 tnl
->ExecCopyCount
= 2;
709 tnl
->ExecCopyElts
[1] = start
;
710 tnl
->ExecCopyElts
[2] = count
-1;
713 static void copy_last_two( TNLcontext
*tnl
, GLuint start
, GLuint count
,
717 tnl
->ExecCopyCount
= 2+ovf
;
718 tnl
->ExecCopyElts
[0] = count
-3;
719 tnl
->ExecCopyElts
[1] = count
-2;
720 tnl
->ExecCopyElts
[2] = count
-1;
723 static void copy_overflow( TNLcontext
*tnl
, GLuint start
, GLuint count
,
727 tnl
->ExecCopyCount
= ovf
;
728 tnl
->ExecCopyElts
[0] = count
-3;
729 tnl
->ExecCopyElts
[1] = count
-2;
730 tnl
->ExecCopyElts
[2] = count
-1;
734 typedef void (*copy_func
)( TNLcontext
*tnl
, GLuint start
, GLuint count
,
737 static copy_func copy_tab
[GL_POLYGON
+2] =
756 /* Figure out what vertices need to be copied next time.
759 _tnl_get_exec_copy_verts( GLcontext
*ctx
, struct immediate
*IM
)
762 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
763 GLuint last
= IM
->LastPrimitive
;
764 GLuint prim
= ctx
->Driver
.CurrentExecPrimitive
;
765 GLuint pincr
= increment
[prim
];
766 GLuint pintro
= intro
[prim
];
769 /* fprintf(stderr, "_tnl_get_exec_copy_verts %s\n", */
770 /* _mesa_lookup_enum_by_nr(prim)); */
772 if (tnl
->ExecCopySource
)
773 if (--tnl
->ExecCopySource
->ref_count
== 0)
774 _tnl_free_immediate( tnl
->ExecCopySource
);
776 if (prim
== GL_POLYGON
+1) {
777 tnl
->ExecCopySource
= 0;
778 tnl
->ExecCopyCount
= 0;
779 tnl
->ExecCopyTexSize
= 0;
782 /* Remember this immediate as the one to copy from.
784 tnl
->ExecCopySource
= IM
; IM
->ref_count
++;
785 tnl
->ExecCopyCount
= 0;
786 tnl
->ExecCopyTexSize
= IM
->CopyTexSize
;
788 if (IM
->LastPrimitive
!= IM
->CopyStart
)
791 tnl
->ExecParity
^= IM
->PrimitiveLength
[IM
->LastPrimitive
] & 1;
794 if (pincr
!= 1 && (IM
->Count
- last
- pintro
))
795 ovf
= (IM
->Count
- last
- pintro
) % pincr
;
797 if (last
< IM
->Count
)
798 copy_tab
[prim
]( tnl
, last
, IM
->Count
, ovf
);
803 /* Recalculate ExecCopyElts, ExecParity, etc.
806 _tnl_get_purged_copy_verts( GLcontext
*ctx
, struct immediate
*IM
)
808 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
810 if (ctx
->Driver
.CurrentExecPrimitive
!= GL_POLYGON
+1) {
811 GLuint last
= IM
->LastPrimitive
;
812 GLenum prim
= IM
->Primitive
[last
];
813 GLuint pincr
= increment
[prim
];
814 GLuint pintro
= intro
[prim
];
817 tnl
->ExecCopyCount
= 0;
818 if (IM
->LastPrimitive
!= IM
->CopyStart
)
821 tnl
->ExecParity
^= IM
->PrimitiveLength
[IM
->LastPrimitive
] & 1;
823 if (pincr
!= 1 && (IM
->Count
- last
- pintro
))
824 ovf
= (IM
->Count
- last
- pintro
) % pincr
;
826 if (last
< IM
->Count
)
827 copy_tab
[prim
]( tnl
, last
, IM
->Count
, ovf
);
829 for (i
= 0 ; i
< tnl
->ExecCopyCount
; i
++)
830 tnl
->ExecCopyElts
[i
] = IM
->Elt
[tnl
->ExecCopyElts
[i
]];
835 void _tnl_upgrade_current_data( GLcontext
*ctx
,
839 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
840 struct vertex_buffer
*VB
= &tnl
->vb
;
841 struct immediate
*IM
= (struct immediate
*)VB
->import_source
;
845 /* _tnl_print_vert_flags("_tnl_upgrade_client_data", required); */
847 if ((required
& VERT_BIT_COLOR0
) && (VB
->ColorPtr
[0]->Flags
& CA_CLIENT_DATA
)) {
848 struct gl_client_array
*tmp
= &tnl
->imm_inputs
.Color
;
849 GLuint start
= IM
->CopyStart
;
851 tmp
->Ptr
= IM
->Attrib
[VERT_ATTRIB_COLOR0
] + start
;
852 tmp
->StrideB
= 4 * sizeof(GLfloat
);
855 COPY_4FV( IM
->Attrib
[VERT_ATTRIB_COLOR0
][start
],
856 ctx
->Current
.Attrib
[VERT_ATTRIB_COLOR0
]);
859 ASSERT(IM->Flag[IM->LastData+1] & VERT_BIT_END_VB);
862 fixup_first_4f( IM
->Attrib
[VERT_ATTRIB_COLOR0
], IM
->Flag
,
864 start
, IM
->Attrib
[VERT_ATTRIB_COLOR0
][start
] );
866 VB
->importable_data
&= ~VERT_BIT_COLOR0
;