2 * Copyright 2003 Tungsten Graphics, inc.
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
19 * TUNGSTEN GRAPHICS AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
25 * Keith Whitwell <keithw@tungstengraphics.com>
32 #include "t_context.h"
36 /* Build and manage clipspace/ndc/window vertices.
38 * Another new mechanism designed and crying out for codegen. Before
39 * that, it would be very interesting to investigate the merger of
40 * these vertices and those built in t_vtx_*.
46 #define GET_VERTEX_STATE(ctx) &(TNL_CONTEXT(ctx)->clipspace)
48 static void insert_4f_viewport_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
51 GLfloat
*out
= (GLfloat
*)v
;
52 const GLfloat
* const vp
= a
->vp
;
54 out
[0] = vp
[0] * in
[0] + vp
[12];
55 out
[1] = vp
[5] * in
[1] + vp
[13];
56 out
[2] = vp
[10] * in
[2] + vp
[14];
60 static void insert_4f_viewport_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
63 GLfloat
*out
= (GLfloat
*)v
;
64 const GLfloat
* const vp
= a
->vp
;
66 out
[0] = vp
[0] * in
[0] + vp
[12];
67 out
[1] = vp
[5] * in
[1] + vp
[13];
68 out
[2] = vp
[10] * in
[2] + vp
[14];
72 static void insert_4f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
75 GLfloat
*out
= (GLfloat
*)v
;
76 const GLfloat
* const vp
= a
->vp
;
78 out
[0] = vp
[0] * in
[0] + vp
[12];
79 out
[1] = vp
[5] * in
[1] + vp
[13];
84 static void insert_4f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
87 GLfloat
*out
= (GLfloat
*)v
;
88 const GLfloat
* const vp
= a
->vp
;
90 out
[0] = vp
[0] * in
[0] + vp
[12];
96 static void insert_3f_viewport_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
99 GLfloat
*out
= (GLfloat
*)v
;
100 const GLfloat
* const vp
= a
->vp
;
102 out
[0] = vp
[0] * in
[0] + vp
[12];
103 out
[1] = vp
[5] * in
[1] + vp
[13];
104 out
[2] = vp
[10] * in
[2] + vp
[14];
107 static void insert_3f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
110 GLfloat
*out
= (GLfloat
*)v
;
111 const GLfloat
* const vp
= a
->vp
;
113 out
[0] = vp
[0] * in
[0] + vp
[12];
114 out
[1] = vp
[5] * in
[1] + vp
[13];
115 out
[2] = vp
[10] * in
[2] + vp
[14];
118 static void insert_3f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
121 GLfloat
*out
= (GLfloat
*)v
;
122 const GLfloat
* const vp
= a
->vp
;
124 out
[0] = vp
[0] * in
[0] + vp
[12];
129 static void insert_2f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
132 GLfloat
*out
= (GLfloat
*)v
;
133 const GLfloat
* const vp
= a
->vp
;
135 out
[0] = vp
[0] * in
[0] + vp
[12];
136 out
[1] = vp
[5] * in
[1] + vp
[13];
139 static void insert_2f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
142 GLfloat
*out
= (GLfloat
*)v
;
143 const GLfloat
* const vp
= a
->vp
;
145 out
[0] = vp
[0] * in
[0] + vp
[12];
150 static void insert_4f_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
152 GLfloat
*out
= (GLfloat
*)(v
);
160 static void insert_4f_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
162 GLfloat
*out
= (GLfloat
*)(v
);
170 static void insert_4f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
172 GLfloat
*out
= (GLfloat
*)(v
);
180 static void insert_4f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
182 GLfloat
*out
= (GLfloat
*)(v
);
190 static void insert_3f_xyw_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
192 GLfloat
*out
= (GLfloat
*)(v
);
199 static void insert_3f_xyw_err( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
204 static void insert_3f_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
206 GLfloat
*out
= (GLfloat
*)(v
);
213 static void insert_3f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
215 GLfloat
*out
= (GLfloat
*)(v
);
222 static void insert_3f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
224 GLfloat
*out
= (GLfloat
*)(v
);
232 static void insert_2f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
234 GLfloat
*out
= (GLfloat
*)(v
);
240 static void insert_2f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
242 GLfloat
*out
= (GLfloat
*)(v
);
248 static void insert_1f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
250 GLfloat
*out
= (GLfloat
*)(v
);
255 static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
258 GLchan
*c
= (GLchan
*)v
;
259 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
260 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
261 UNCLAMPED_FLOAT_TO_CHAN(c
[2], in
[2]);
262 UNCLAMPED_FLOAT_TO_CHAN(c
[3], in
[3]);
265 static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
268 GLchan
*c
= (GLchan
*)v
;
269 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
270 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
271 UNCLAMPED_FLOAT_TO_CHAN(c
[2], in
[2]);
275 static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
278 GLchan
*c
= (GLchan
*)v
;
279 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
280 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
285 static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
288 GLchan
*c
= (GLchan
*)v
;
289 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
295 static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
298 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
299 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
300 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
301 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], in
[3]);
304 static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
307 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
308 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
309 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
313 static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
316 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
317 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
322 static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
325 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
331 static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
334 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
335 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
336 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
337 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], in
[3]);
340 static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
343 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
344 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
345 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
349 static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
352 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
353 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
358 static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
361 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
367 static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
370 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
371 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
372 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
375 static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
378 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
379 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
383 static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
386 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
391 static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
394 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
395 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
396 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
399 static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
402 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
403 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
407 static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
410 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
416 static void insert_1ub_1f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
419 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
423 /***********************************************************************
424 * Functions to perform the reverse operations to the above, for
425 * swrast translation and clip-interpolation.
427 * Currently always extracts a full 4 floats.
430 static void extract_4f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
433 const GLfloat
*in
= (const GLfloat
*)v
;
434 const GLfloat
* const vp
= a
->vp
;
436 out
[0] = (in
[0] - vp
[12]) / vp
[0];
437 out
[1] = (in
[1] - vp
[13]) / vp
[5];
438 out
[2] = (in
[2] - vp
[14]) / vp
[10];
442 static void extract_3f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
445 const GLfloat
*in
= (const GLfloat
*)v
;
446 const GLfloat
* const vp
= a
->vp
;
448 out
[0] = (in
[0] - vp
[12]) / vp
[0];
449 out
[1] = (in
[1] - vp
[13]) / vp
[5];
450 out
[2] = (in
[2] - vp
[14]) / vp
[10];
455 static void extract_2f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
458 const GLfloat
*in
= (const GLfloat
*)v
;
459 const GLfloat
* const vp
= a
->vp
;
461 out
[0] = (in
[0] - vp
[12]) / vp
[0];
462 out
[1] = (in
[1] - vp
[13]) / vp
[5];
468 static void extract_4f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
470 const GLfloat
*in
= (const GLfloat
*)v
;
478 static void extract_3f_xyw( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
480 const GLfloat
*in
= (const GLfloat
*)v
;
489 static void extract_3f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
491 const GLfloat
*in
= (const GLfloat
*)v
;
500 static void extract_2f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
502 const GLfloat
*in
= (const GLfloat
*)v
;
510 static void extract_1f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
512 const GLfloat
*in
= (const GLfloat
*)v
;
520 static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
523 GLchan
*c
= (GLchan
*)v
;
525 out
[0] = CHAN_TO_FLOAT(c
[0]);
526 out
[1] = CHAN_TO_FLOAT(c
[1]);
527 out
[2] = CHAN_TO_FLOAT(c
[2]);
528 out
[3] = CHAN_TO_FLOAT(c
[3]);
531 static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
534 out
[0] = UBYTE_TO_FLOAT(v
[0]);
535 out
[1] = UBYTE_TO_FLOAT(v
[1]);
536 out
[2] = UBYTE_TO_FLOAT(v
[2]);
537 out
[3] = UBYTE_TO_FLOAT(v
[3]);
540 static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
543 out
[2] = UBYTE_TO_FLOAT(v
[0]);
544 out
[1] = UBYTE_TO_FLOAT(v
[1]);
545 out
[0] = UBYTE_TO_FLOAT(v
[2]);
546 out
[3] = UBYTE_TO_FLOAT(v
[3]);
549 static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
552 out
[0] = UBYTE_TO_FLOAT(v
[0]);
553 out
[1] = UBYTE_TO_FLOAT(v
[1]);
554 out
[2] = UBYTE_TO_FLOAT(v
[2]);
558 static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
561 out
[2] = UBYTE_TO_FLOAT(v
[0]);
562 out
[1] = UBYTE_TO_FLOAT(v
[1]);
563 out
[0] = UBYTE_TO_FLOAT(v
[2]);
567 static void extract_1ub_1f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
569 out
[0] = UBYTE_TO_FLOAT(v
[0]);
578 extract_func extract
;
579 insert_func insert
[4];
581 } format_info
[EMIT_MAX
] = {
585 { insert_1f_1
, insert_1f_1
, insert_1f_1
, insert_1f_1
},
590 { insert_2f_1
, insert_2f_2
, insert_2f_2
, insert_2f_2
},
591 2 * sizeof(GLfloat
) },
595 { insert_3f_1
, insert_3f_2
, insert_3f_3
, insert_3f_3
},
596 3 * sizeof(GLfloat
) },
600 { insert_4f_1
, insert_4f_2
, insert_4f_3
, insert_4f_4
},
601 4 * sizeof(GLfloat
) },
605 { insert_2f_viewport_1
, insert_2f_viewport_2
, insert_2f_viewport_2
,
606 insert_2f_viewport_2
},
607 2 * sizeof(GLfloat
) },
611 { insert_3f_viewport_1
, insert_3f_viewport_2
, insert_3f_viewport_3
,
612 insert_3f_viewport_3
},
613 3 * sizeof(GLfloat
) },
617 { insert_4f_viewport_1
, insert_4f_viewport_2
, insert_4f_viewport_3
,
618 insert_4f_viewport_4
},
619 4 * sizeof(GLfloat
) },
623 { insert_3f_xyw_err
, insert_3f_xyw_err
, insert_3f_xyw_err
,
625 3 * sizeof(GLfloat
) },
629 { insert_1ub_1f_1
, insert_1ub_1f_1
, insert_1ub_1f_1
, insert_1ub_1f_1
},
634 { insert_3ub_3f_rgb_1
, insert_3ub_3f_rgb_2
, insert_3ub_3f_rgb_3
,
635 insert_3ub_3f_rgb_3
},
636 3 * sizeof(GLubyte
) },
640 { insert_3ub_3f_bgr_1
, insert_3ub_3f_bgr_2
, insert_3ub_3f_bgr_3
,
641 insert_3ub_3f_bgr_3
},
642 3 * sizeof(GLubyte
) },
646 { insert_4ub_4f_rgba_1
, insert_4ub_4f_rgba_2
, insert_4ub_4f_rgba_3
,
647 insert_4ub_4f_rgba_4
},
648 4 * sizeof(GLubyte
) },
652 { insert_4ub_4f_bgra_1
, insert_4ub_4f_bgra_2
, insert_4ub_4f_bgra_3
,
653 insert_4ub_4f_bgra_4
},
654 4 * sizeof(GLubyte
) },
657 extract_4chan_4f_rgba
,
658 { insert_4chan_4f_rgba_1
, insert_4chan_4f_rgba_2
, insert_4chan_4f_rgba_3
,
659 insert_4chan_4f_rgba_4
},
660 4 * sizeof(GLchan
) },
670 /***********************************************************************
671 * Generic (non-codegen) functions for whole vertices or groups of
675 static void generic_emit( GLcontext
*ctx
,
676 GLuint start
, GLuint end
,
679 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
680 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
681 struct tnl_clipspace_attr
*a
= vtx
->attr
;
682 GLubyte
*v
= (GLubyte
*)dest
;
684 GLuint count
= vtx
->attr_count
;
687 for (j
= 0; j
< count
; j
++) {
688 GLvector4f
*vptr
= VB
->AttribPtr
[a
[j
].attrib
];
689 a
[j
].inputstride
= vptr
->stride
;
690 a
[j
].inputptr
= ((GLubyte
*)vptr
->data
) + start
* vptr
->stride
;
691 a
[j
].emit
= a
[j
].insert
[vptr
->size
- 1];
695 stride
= vtx
->vertex_size
;
697 for (i
= 0 ; i
< end
; i
++, v
+= stride
) {
698 for (j
= 0; j
< count
; j
++) {
699 GLfloat
*in
= (GLfloat
*)a
[j
].inputptr
;
700 a
[j
].inputptr
+= a
[j
].inputstride
;
701 a
[j
].emit( &a
[j
], v
+ a
[j
].vertoffset
, in
);
707 static void generic_interp( GLcontext
*ctx
,
709 GLuint edst
, GLuint eout
, GLuint ein
,
710 GLboolean force_boundary
)
712 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
713 struct vertex_buffer
*VB
= &tnl
->vb
;
714 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
715 GLubyte
*vin
= vtx
->vertex_buf
+ ein
* vtx
->vertex_size
;
716 GLubyte
*vout
= vtx
->vertex_buf
+ eout
* vtx
->vertex_size
;
717 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
718 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
719 int attr_count
= vtx
->attr_count
;
722 if (tnl
->NeedNdcCoords
) {
723 const GLfloat
*dstclip
= VB
->ClipPtr
->data
[edst
];
724 if (dstclip
[3] != 0.0) {
725 const GLfloat w
= 1.0f
/ dstclip
[3];
728 pos
[0] = dstclip
[0] * w
;
729 pos
[1] = dstclip
[1] * w
;
730 pos
[2] = dstclip
[2] * w
;
733 a
[0].insert
[4-1]( &a
[0], vdst
, pos
);
737 a
[0].insert
[4-1]( &a
[0], vdst
, VB
->ClipPtr
->data
[edst
] );
741 for (j
= 1; j
< attr_count
; j
++) {
742 GLfloat fin
[4], fout
[4], fdst
[4];
744 a
[j
].extract( &a
[j
], fin
, vin
+ a
[j
].vertoffset
);
745 a
[j
].extract( &a
[j
], fout
, vout
+ a
[j
].vertoffset
);
747 INTERP_F( t
, fdst
[3], fout
[3], fin
[3] );
748 INTERP_F( t
, fdst
[2], fout
[2], fin
[2] );
749 INTERP_F( t
, fdst
[1], fout
[1], fin
[1] );
750 INTERP_F( t
, fdst
[0], fout
[0], fin
[0] );
752 a
[j
].insert
[4-1]( &a
[j
], vdst
+ a
[j
].vertoffset
, fdst
);
757 /* Extract color attributes from one vertex and insert them into
758 * another. (Shortcircuit extract/insert with memcpy).
760 static void generic_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
762 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
763 GLubyte
*vsrc
= vtx
->vertex_buf
+ esrc
* vtx
->vertex_size
;
764 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
765 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
766 int attr_count
= vtx
->attr_count
;
769 for (j
= 0; j
< attr_count
; j
++) {
770 if (a
[j
].attrib
== VERT_ATTRIB_COLOR0
||
771 a
[j
].attrib
== VERT_ATTRIB_COLOR1
) {
773 _mesa_memcpy( vdst
+ a
[j
].vertoffset
,
774 vsrc
+ a
[j
].vertoffset
,
781 /* Helper functions for hardware which doesn't put back colors and/or
782 * edgeflags into vertices.
784 static void generic_interp_extras( GLcontext
*ctx
,
786 GLuint dst
, GLuint out
, GLuint in
,
787 GLboolean force_boundary
)
789 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
791 if (VB
->ColorPtr
[1]) {
792 assert(VB
->ColorPtr
[1]->stride
== 4 * sizeof(GLfloat
));
795 VB
->ColorPtr
[1]->data
[dst
],
796 VB
->ColorPtr
[1]->data
[out
],
797 VB
->ColorPtr
[1]->data
[in
] );
799 if (VB
->SecondaryColorPtr
[1]) {
801 VB
->SecondaryColorPtr
[1]->data
[dst
],
802 VB
->SecondaryColorPtr
[1]->data
[out
],
803 VB
->SecondaryColorPtr
[1]->data
[in
] );
806 else if (VB
->IndexPtr
[1]) {
807 VB
->IndexPtr
[1]->data
[dst
][0] = LINTERP( t
,
808 VB
->IndexPtr
[1]->data
[out
][0],
809 VB
->IndexPtr
[1]->data
[in
][0] );
813 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
816 generic_interp(ctx
, t
, dst
, out
, in
, force_boundary
);
819 static void generic_copy_pv_extras( GLcontext
*ctx
,
820 GLuint dst
, GLuint src
)
822 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
824 if (VB
->ColorPtr
[1]) {
825 COPY_4FV( VB
->ColorPtr
[1]->data
[dst
],
826 VB
->ColorPtr
[1]->data
[src
] );
828 if (VB
->SecondaryColorPtr
[1]) {
829 COPY_4FV( VB
->SecondaryColorPtr
[1]->data
[dst
],
830 VB
->SecondaryColorPtr
[1]->data
[src
] );
833 else if (VB
->IndexPtr
[1]) {
834 VB
->IndexPtr
[1]->data
[dst
][0] = VB
->IndexPtr
[1]->data
[src
][0];
837 _tnl_copy_pv(ctx
, dst
, src
);
845 /***********************************************************************
846 * Build codegen functions or return generic ones:
850 static void choose_emit_func( GLcontext
*ctx
,
851 GLuint start
, GLuint end
,
854 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
855 vtx
->emit
= generic_emit
;
856 vtx
->emit( ctx
, start
, end
, dest
);
860 static void choose_interp_func( GLcontext
*ctx
,
862 GLuint edst
, GLuint eout
, GLuint ein
,
863 GLboolean force_boundary
)
865 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
867 if (vtx
->need_extras
&&
868 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
869 vtx
->interp
= generic_interp_extras
;
871 vtx
->interp
= generic_interp
;
874 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
878 static void choose_copy_pv_func( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
880 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
882 if (vtx
->need_extras
&&
883 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
884 vtx
->copy_pv
= generic_copy_pv_extras
;
886 vtx
->copy_pv
= generic_copy_pv
;
889 vtx
->copy_pv( ctx
, edst
, esrc
);
893 /***********************************************************************
894 * Public entrypoints, mostly dispatch to the above:
898 /* Interpolate between two vertices to produce a third:
900 void _tnl_interp( GLcontext
*ctx
,
902 GLuint edst
, GLuint eout
, GLuint ein
,
903 GLboolean force_boundary
)
905 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
906 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
909 /* Copy colors from one vertex to another:
911 void _tnl_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
913 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
914 vtx
->copy_pv( ctx
, edst
, esrc
);
918 /* Extract a named attribute from a hardware vertex. Will have to
919 * reverse any viewport transformation, swizzling or other conversions
920 * which may have been applied:
922 void _tnl_get_attr( GLcontext
*ctx
, const void *vin
,
923 GLenum attr
, GLfloat
*dest
)
925 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
926 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
927 int attr_count
= vtx
->attr_count
;
930 for (j
= 0; j
< attr_count
; j
++) {
931 if (a
[j
].attrib
== (int)attr
) {
932 a
[j
].extract( &a
[j
], dest
, (GLubyte
*)vin
+ a
[j
].vertoffset
);
937 /* Else return the value from ctx->Current
939 _mesa_memcpy( dest
, ctx
->Current
.Attrib
[attr
], 4*sizeof(GLfloat
));
942 void *_tnl_get_vertex( GLcontext
*ctx
, GLuint nr
)
944 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
946 return vtx
->vertex_buf
+ nr
* vtx
->vertex_size
;
949 void _tnl_invalidate_vertex_state( GLcontext
*ctx
, GLuint new_state
)
951 if (new_state
& (_DD_NEW_TRI_LIGHT_TWOSIDE
|_DD_NEW_TRI_UNFILLED
) ) {
952 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
953 vtx
->new_inputs
= ~0;
954 vtx
->interp
= choose_interp_func
;
955 vtx
->copy_pv
= choose_copy_pv_func
;
960 GLuint
_tnl_install_attrs( GLcontext
*ctx
, const struct tnl_attr_map
*map
,
961 GLuint nr
, const GLfloat
*vp
,
962 GLuint unpacked_size
)
964 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
968 assert(nr
< _TNL_ATTRIB_MAX
);
969 assert(nr
== 0 || map
[0].attrib
== VERT_ATTRIB_POS
);
971 vtx
->emit
= choose_emit_func
;
972 vtx
->interp
= choose_interp_func
;
973 vtx
->copy_pv
= choose_copy_pv_func
;
974 vtx
->new_inputs
= ~0;
976 for (j
= 0, i
= 0; i
< nr
; i
++) {
977 GLuint format
= map
[i
].format
;
978 if (format
== EMIT_PAD
) {
979 offset
+= map
[i
].offset
;
981 /* fprintf(stderr, "%d: pad %d, offset now %d\n", i, */
982 /* map[i].offset, offset); */
986 vtx
->attr
[j
].attrib
= map
[i
].attrib
;
987 vtx
->attr
[j
].vp
= vp
;
988 vtx
->attr
[j
].insert
= format_info
[format
].insert
;
989 vtx
->attr
[j
].extract
= format_info
[format
].extract
;
990 vtx
->attr
[j
].vertattrsize
= format_info
[format
].attrsize
;
993 vtx
->attr
[j
].vertoffset
= map
[i
].offset
;
995 vtx
->attr
[j
].vertoffset
= offset
;
997 /* fprintf(stderr, "%d: %s offset %d\n", i, */
998 /* format_info[format].name, vtx->attr[j].vertoffset); */
1000 offset
+= format_info
[format
].attrsize
;
1005 vtx
->attr_count
= j
;
1008 vtx
->vertex_size
= unpacked_size
;
1010 vtx
->vertex_size
= offset
;
1012 assert(vtx
->vertex_size
<= vtx
->max_vertex_size
);
1014 return vtx
->vertex_size
;
1019 void _tnl_invalidate_vertices( GLcontext
*ctx
, GLuint newinputs
)
1021 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1022 vtx
->new_inputs
|= newinputs
;
1027 void _tnl_build_vertices( GLcontext
*ctx
,
1032 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1033 GLuint stride
= vtx
->vertex_size
;
1034 GLubyte
*v
= ((GLubyte
*)vtx
->vertex_buf
+ (start
*stride
));
1036 newinputs
|= vtx
->new_inputs
;
1037 vtx
->new_inputs
= 0;
1040 vtx
->emit( ctx
, start
, end
, v
);
1044 void *_tnl_emit_vertices_to_buffer( GLcontext
*ctx
,
1049 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1050 vtx
->emit( ctx
, start
, end
, dest
);
1051 return (void *)((GLubyte
*)dest
+ vtx
->vertex_size
* (end
- start
));
1055 void _tnl_init_vertices( GLcontext
*ctx
,
1057 GLuint max_vertex_size
)
1059 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1061 _tnl_install_attrs( ctx
, 0, 0, 0, 0 );
1063 vtx
->need_extras
= GL_TRUE
;
1064 if (max_vertex_size
> vtx
->max_vertex_size
) {
1065 _tnl_free_vertices( ctx
);
1066 vtx
->max_vertex_size
= max_vertex_size
;
1067 vtx
->vertex_buf
= (GLubyte
*)ALIGN_CALLOC(vb_size
* max_vertex_size
, 32 );
1072 void _tnl_free_vertices( GLcontext
*ctx
)
1074 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1075 if (vtx
->vertex_buf
) {
1076 ALIGN_FREE(vtx
->vertex_buf
);
1077 vtx
->vertex_buf
= 0;