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
},
665 /***********************************************************************
666 * Generic (non-codegen) functions for whole vertices or groups of
670 static void generic_emit( GLcontext
*ctx
,
671 GLuint start
, GLuint end
,
674 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
675 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
676 struct tnl_clipspace_attr
*a
= vtx
->attr
;
677 GLubyte
*v
= (GLubyte
*)dest
;
679 GLuint count
= vtx
->attr_count
;
682 for (j
= 0; j
< count
; j
++) {
683 GLvector4f
*vptr
= VB
->AttribPtr
[a
[j
].attrib
];
684 a
[j
].inputstride
= vptr
->stride
;
685 a
[j
].inputptr
= ((GLubyte
*)vptr
->data
) + start
* vptr
->stride
;
686 a
[j
].emit
= a
[j
].insert
[vptr
->size
- 1];
690 stride
= vtx
->vertex_size
;
692 for (i
= 0 ; i
< end
; i
++, v
+= stride
) {
693 for (j
= 0; j
< count
; j
++) {
694 GLfloat
*in
= (GLfloat
*)a
[j
].inputptr
;
695 a
[j
].inputptr
+= a
[j
].inputstride
;
696 a
[j
].emit( &a
[j
], v
+ a
[j
].vertoffset
, in
);
702 static void generic_interp( GLcontext
*ctx
,
704 GLuint edst
, GLuint eout
, GLuint ein
,
705 GLboolean force_boundary
)
707 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
708 struct vertex_buffer
*VB
= &tnl
->vb
;
709 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
710 GLubyte
*vin
= vtx
->vertex_buf
+ ein
* vtx
->vertex_size
;
711 GLubyte
*vout
= vtx
->vertex_buf
+ eout
* vtx
->vertex_size
;
712 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
713 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
714 int attr_count
= vtx
->attr_count
;
717 if (tnl
->NeedNdcCoords
) {
718 const GLfloat
*dstclip
= VB
->ClipPtr
->data
[edst
];
719 if (dstclip
[3] != 0.0) {
720 const GLfloat w
= 1.0f
/ dstclip
[3];
723 pos
[0] = dstclip
[0] * w
;
724 pos
[1] = dstclip
[1] * w
;
725 pos
[2] = dstclip
[2] * w
;
728 a
[0].insert
[4-1]( &a
[0], vdst
, pos
);
732 a
[0].insert
[4-1]( &a
[0], vdst
, VB
->ClipPtr
->data
[edst
] );
736 for (j
= 1; j
< attr_count
; j
++) {
737 GLfloat fin
[4], fout
[4], fdst
[4];
739 a
[j
].extract( &a
[j
], fin
, vin
+ a
[j
].vertoffset
);
740 a
[j
].extract( &a
[j
], fout
, vout
+ a
[j
].vertoffset
);
742 INTERP_F( t
, fdst
[3], fout
[3], fin
[3] );
743 INTERP_F( t
, fdst
[2], fout
[2], fin
[2] );
744 INTERP_F( t
, fdst
[1], fout
[1], fin
[1] );
745 INTERP_F( t
, fdst
[0], fout
[0], fin
[0] );
747 a
[j
].insert
[4-1]( &a
[j
], vdst
+ a
[j
].vertoffset
, fdst
);
752 /* Extract color attributes from one vertex and insert them into
753 * another. (Shortcircuit extract/insert with memcpy).
755 static void generic_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
757 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
758 GLubyte
*vsrc
= vtx
->vertex_buf
+ esrc
* vtx
->vertex_size
;
759 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
760 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
761 int attr_count
= vtx
->attr_count
;
764 for (j
= 0; j
< attr_count
; j
++) {
765 if (a
[j
].attrib
== VERT_ATTRIB_COLOR0
||
766 a
[j
].attrib
== VERT_ATTRIB_COLOR1
) {
768 memcpy( vdst
+ a
[j
].vertoffset
,
769 vsrc
+ a
[j
].vertoffset
,
776 /* Helper functions for hardware which doesn't put back colors and/or
777 * edgeflags into vertices.
779 static void generic_interp_extras( GLcontext
*ctx
,
781 GLuint dst
, GLuint out
, GLuint in
,
782 GLboolean force_boundary
)
784 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
786 if (VB
->ColorPtr
[1]) {
787 assert(VB
->ColorPtr
[1]->stride
== 4 * sizeof(GLfloat
));
790 VB
->ColorPtr
[1]->data
[dst
],
791 VB
->ColorPtr
[1]->data
[out
],
792 VB
->ColorPtr
[1]->data
[in
] );
794 if (VB
->SecondaryColorPtr
[1]) {
796 VB
->SecondaryColorPtr
[1]->data
[dst
],
797 VB
->SecondaryColorPtr
[1]->data
[out
],
798 VB
->SecondaryColorPtr
[1]->data
[in
] );
801 else if (VB
->IndexPtr
[1]) {
802 VB
->IndexPtr
[1]->data
[dst
][0] = LINTERP( t
,
803 VB
->IndexPtr
[1]->data
[out
][0],
804 VB
->IndexPtr
[1]->data
[in
][0] );
808 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
811 generic_interp(ctx
, t
, dst
, out
, in
, force_boundary
);
814 static void generic_copy_pv_extras( GLcontext
*ctx
,
815 GLuint dst
, GLuint src
)
817 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
819 if (VB
->ColorPtr
[1]) {
820 COPY_4FV( VB
->ColorPtr
[1]->data
[dst
],
821 VB
->ColorPtr
[1]->data
[src
] );
823 if (VB
->SecondaryColorPtr
[1]) {
824 COPY_4FV( VB
->SecondaryColorPtr
[1]->data
[dst
],
825 VB
->SecondaryColorPtr
[1]->data
[src
] );
828 else if (VB
->IndexPtr
[1]) {
829 VB
->IndexPtr
[1]->data
[dst
][0] = VB
->IndexPtr
[1]->data
[src
][0];
832 _tnl_copy_pv(ctx
, dst
, src
);
840 /***********************************************************************
841 * Build codegen functions or return generic ones:
845 static void choose_emit_func( GLcontext
*ctx
,
846 GLuint start
, GLuint end
,
849 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
850 vtx
->emit
= generic_emit
;
851 vtx
->emit( ctx
, start
, end
, dest
);
855 static void choose_interp_func( GLcontext
*ctx
,
857 GLuint edst
, GLuint eout
, GLuint ein
,
858 GLboolean force_boundary
)
860 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
862 if (vtx
->need_extras
&&
863 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
864 vtx
->interp
= generic_interp_extras
;
866 vtx
->interp
= generic_interp
;
869 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
873 static void choose_copy_pv_func( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
875 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
877 if (vtx
->need_extras
&&
878 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
879 vtx
->copy_pv
= generic_copy_pv_extras
;
881 vtx
->copy_pv
= generic_copy_pv
;
884 vtx
->copy_pv( ctx
, edst
, esrc
);
888 /***********************************************************************
889 * Public entrypoints, mostly dispatch to the above:
893 /* Interpolate between two vertices to produce a third:
895 void _tnl_interp( GLcontext
*ctx
,
897 GLuint edst
, GLuint eout
, GLuint ein
,
898 GLboolean force_boundary
)
900 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
901 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
904 /* Copy colors from one vertex to another:
906 void _tnl_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
908 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
909 vtx
->copy_pv( ctx
, edst
, esrc
);
913 /* Extract a named attribute from a hardware vertex. Will have to
914 * reverse any viewport transformation, swizzling or other conversions
915 * which may have been applied:
917 void _tnl_get_attr( GLcontext
*ctx
, const void *vin
,
918 GLenum attr
, GLfloat
*dest
)
920 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
921 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
922 int attr_count
= vtx
->attr_count
;
925 for (j
= 0; j
< attr_count
; j
++) {
926 if (a
[j
].attrib
== (int)attr
) {
927 a
[j
].extract( &a
[j
], dest
, (GLubyte
*)vin
+ a
[j
].vertoffset
);
932 /* Else return the value from ctx->Current
934 memcpy( dest
, ctx
->Current
.Attrib
[attr
], 4*sizeof(GLfloat
));
937 void *_tnl_get_vertex( GLcontext
*ctx
, GLuint nr
)
939 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
941 return vtx
->vertex_buf
+ nr
* vtx
->vertex_size
;
944 void _tnl_invalidate_vertex_state( GLcontext
*ctx
, GLuint new_state
)
946 if (new_state
& (_DD_NEW_TRI_LIGHT_TWOSIDE
|_DD_NEW_TRI_UNFILLED
) ) {
947 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
948 vtx
->new_inputs
= ~0;
949 vtx
->interp
= choose_interp_func
;
950 vtx
->copy_pv
= choose_copy_pv_func
;
955 GLuint
_tnl_install_attrs( GLcontext
*ctx
, const struct tnl_attr_map
*map
,
956 GLuint nr
, const GLfloat
*vp
,
957 GLuint unpacked_size
)
959 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
963 assert(nr
< _TNL_ATTRIB_MAX
);
964 assert(nr
== 0 || map
[0].attrib
== VERT_ATTRIB_POS
);
966 vtx
->attr_count
= nr
;
967 vtx
->emit
= choose_emit_func
;
968 vtx
->interp
= choose_interp_func
;
969 vtx
->copy_pv
= choose_copy_pv_func
;
970 vtx
->new_inputs
= ~0;
972 for (i
= 0; i
< nr
; i
++) {
973 GLuint format
= map
[i
].format
;
974 vtx
->attr
[i
].attrib
= map
[i
].attrib
;
975 vtx
->attr
[i
].vp
= vp
;
976 vtx
->attr
[i
].insert
= format_info
[format
].insert
;
977 vtx
->attr
[i
].extract
= format_info
[format
].extract
;
978 vtx
->attr
[i
].vertattrsize
= format_info
[format
].attrsize
;
981 vtx
->attr
[i
].vertoffset
= map
[i
].offset
;
983 vtx
->attr
[i
].vertoffset
= offset
;
985 /* fprintf(stderr, "%d: %s offset %d\n", i, */
986 /* format_info[format].name, vtx->attr[i].vertoffset); */
988 offset
+= format_info
[format
].attrsize
;
992 vtx
->vertex_size
= unpacked_size
;
994 vtx
->vertex_size
= offset
;
996 assert(vtx
->vertex_size
<= vtx
->max_vertex_size
);
998 return vtx
->vertex_size
;
1003 void _tnl_invalidate_vertices( GLcontext
*ctx
, GLuint newinputs
)
1005 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1006 vtx
->new_inputs
|= newinputs
;
1011 void _tnl_build_vertices( GLcontext
*ctx
,
1016 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1017 GLuint stride
= vtx
->vertex_size
;
1018 GLubyte
*v
= ((GLubyte
*)vtx
->vertex_buf
+ (start
*stride
));
1020 newinputs
|= vtx
->new_inputs
;
1021 vtx
->new_inputs
= 0;
1024 vtx
->emit( ctx
, start
, count
, v
);
1028 void *_tnl_emit_vertices_to_buffer( GLcontext
*ctx
,
1033 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1034 vtx
->emit( ctx
, start
, count
, dest
);
1035 return (void *)((GLubyte
*)dest
+ vtx
->vertex_size
* (count
- start
));
1039 void _tnl_init_vertices( GLcontext
*ctx
,
1041 GLuint max_vertex_size
)
1043 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1045 _tnl_install_attrs( ctx
, 0, 0, 0, 0 );
1047 vtx
->need_extras
= GL_TRUE
;
1048 if (max_vertex_size
> vtx
->max_vertex_size
) {
1049 _tnl_free_vertices( ctx
);
1050 vtx
->max_vertex_size
= max_vertex_size
;
1051 vtx
->vertex_buf
= (GLubyte
*)ALIGN_MALLOC(vb_size
* max_vertex_size
, 32 );
1056 void _tnl_free_vertices( GLcontext
*ctx
)
1058 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1059 if (vtx
->vertex_buf
) {
1060 ALIGN_FREE(vtx
->vertex_buf
);
1061 vtx
->vertex_buf
= 0;