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 const GLfloat w
= 1.0 / dstclip
[3];
722 pos
[0] = dstclip
[0] * w
;
723 pos
[1] = dstclip
[1] * w
;
724 pos
[2] = dstclip
[2] * w
;
727 a
[0].insert
[4-1]( &a
[0], vdst
, pos
);
730 a
[0].insert
[4-1]( &a
[0], vdst
, VB
->ClipPtr
->data
[edst
] );
734 for (j
= 1; j
< attr_count
; j
++) {
735 GLfloat fin
[4], fout
[4], fdst
[4];
737 a
[j
].extract( &a
[j
], fin
, vin
+ a
[j
].vertoffset
);
738 a
[j
].extract( &a
[j
], fout
, vout
+ a
[j
].vertoffset
);
740 INTERP_F( t
, fdst
[3], fout
[3], fin
[3] );
741 INTERP_F( t
, fdst
[2], fout
[2], fin
[2] );
742 INTERP_F( t
, fdst
[1], fout
[1], fin
[1] );
743 INTERP_F( t
, fdst
[0], fout
[0], fin
[0] );
745 a
[j
].insert
[4-1]( &a
[j
], vdst
+ a
[j
].vertoffset
, fdst
);
750 /* Extract color attributes from one vertex and insert them into
751 * another. (Shortcircuit extract/insert with memcpy).
753 static void generic_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
755 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
756 GLubyte
*vsrc
= vtx
->vertex_buf
+ esrc
* vtx
->vertex_size
;
757 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
758 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
759 int attr_count
= vtx
->attr_count
;
762 for (j
= 0; j
< attr_count
; j
++) {
763 if (a
[j
].attrib
== VERT_ATTRIB_COLOR0
||
764 a
[j
].attrib
== VERT_ATTRIB_COLOR1
) {
766 memcpy( vdst
+ a
[j
].vertoffset
,
767 vsrc
+ a
[j
].vertoffset
,
774 /* Helper functions for hardware which doesn't put back colors and/or
775 * edgeflags into vertices.
777 static void generic_interp_extras( GLcontext
*ctx
,
779 GLuint dst
, GLuint out
, GLuint in
,
780 GLboolean force_boundary
)
782 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
784 if (VB
->ColorPtr
[1]) {
785 assert(VB
->ColorPtr
[1]->stride
== 4 * sizeof(GLfloat
));
788 VB
->ColorPtr
[1]->data
[dst
],
789 VB
->ColorPtr
[1]->data
[out
],
790 VB
->ColorPtr
[1]->data
[in
] );
792 if (VB
->SecondaryColorPtr
[1]) {
794 VB
->SecondaryColorPtr
[1]->data
[dst
],
795 VB
->SecondaryColorPtr
[1]->data
[out
],
796 VB
->SecondaryColorPtr
[1]->data
[in
] );
799 else if (VB
->IndexPtr
[1]) {
800 VB
->IndexPtr
[1]->data
[dst
][0] = LINTERP( t
,
801 VB
->IndexPtr
[1]->data
[out
][0],
802 VB
->IndexPtr
[1]->data
[in
][0] );
806 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
809 generic_interp(ctx
, t
, dst
, out
, in
, force_boundary
);
812 static void generic_copy_pv_extras( GLcontext
*ctx
,
813 GLuint dst
, GLuint src
)
815 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
817 if (VB
->ColorPtr
[1]) {
818 COPY_4FV( VB
->ColorPtr
[1]->data
[dst
],
819 VB
->ColorPtr
[1]->data
[src
] );
821 if (VB
->SecondaryColorPtr
[1]) {
822 COPY_4FV( VB
->SecondaryColorPtr
[1]->data
[dst
],
823 VB
->SecondaryColorPtr
[1]->data
[src
] );
826 else if (VB
->IndexPtr
[1]) {
827 VB
->IndexPtr
[1]->data
[dst
][0] = VB
->IndexPtr
[1]->data
[src
][0];
830 _tnl_copy_pv(ctx
, dst
, src
);
838 /***********************************************************************
839 * Build codegen functions or return generic ones:
843 static void choose_emit_func( GLcontext
*ctx
,
844 GLuint start
, GLuint end
,
847 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
848 vtx
->emit
= generic_emit
;
849 vtx
->emit( ctx
, start
, end
, dest
);
853 static void choose_interp_func( GLcontext
*ctx
,
855 GLuint edst
, GLuint eout
, GLuint ein
,
856 GLboolean force_boundary
)
858 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
860 if (vtx
->need_extras
&&
861 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
862 vtx
->interp
= generic_interp_extras
;
864 vtx
->interp
= generic_interp
;
867 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
871 static void choose_copy_pv_func( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
873 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
875 if (vtx
->need_extras
&&
876 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
877 vtx
->copy_pv
= generic_copy_pv_extras
;
879 vtx
->copy_pv
= generic_copy_pv
;
882 vtx
->copy_pv( ctx
, edst
, esrc
);
886 /***********************************************************************
887 * Public entrypoints, mostly dispatch to the above:
891 /* Interpolate between two vertices to produce a third:
893 void _tnl_interp( GLcontext
*ctx
,
895 GLuint edst
, GLuint eout
, GLuint ein
,
896 GLboolean force_boundary
)
898 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
899 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
902 /* Copy colors from one vertex to another:
904 void _tnl_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
906 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
907 vtx
->copy_pv( ctx
, edst
, esrc
);
911 /* Extract a named attribute from a hardware vertex. Will have to
912 * reverse any viewport transformation, swizzling or other conversions
913 * which may have been applied:
915 void _tnl_get_attr( GLcontext
*ctx
, const void *vin
,
916 GLenum attr
, GLfloat
*dest
)
918 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
919 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
920 int attr_count
= vtx
->attr_count
;
923 for (j
= 0; j
< attr_count
; j
++) {
924 if (a
[j
].attrib
== attr
) {
925 a
[j
].extract( &a
[j
], dest
, (GLubyte
*)vin
+ a
[j
].vertoffset
);
930 /* Else return the value from ctx->Current
932 memcpy( dest
, ctx
->Current
.Attrib
[attr
], 4*sizeof(GLfloat
));
935 void *_tnl_get_vertex( GLcontext
*ctx
, GLuint nr
)
937 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
939 return vtx
->vertex_buf
+ nr
* vtx
->vertex_size
;
942 void _tnl_invalidate_vertex_state( GLcontext
*ctx
, GLuint new_state
)
944 if (new_state
& (_DD_NEW_TRI_LIGHT_TWOSIDE
|_DD_NEW_TRI_UNFILLED
) ) {
945 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
946 vtx
->new_inputs
= ~0;
947 vtx
->interp
= choose_interp_func
;
948 vtx
->copy_pv
= choose_copy_pv_func
;
953 GLuint
_tnl_install_attrs( GLcontext
*ctx
, const struct tnl_attr_map
*map
,
954 GLuint nr
, const GLfloat
*vp
,
955 GLuint unpacked_size
)
957 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
961 assert(nr
< _TNL_ATTRIB_MAX
);
962 assert(nr
== 0 || map
[0].attrib
== VERT_ATTRIB_POS
);
964 vtx
->attr_count
= nr
;
965 vtx
->emit
= choose_emit_func
;
966 vtx
->interp
= choose_interp_func
;
967 vtx
->copy_pv
= choose_copy_pv_func
;
968 vtx
->new_inputs
= ~0;
970 for (i
= 0; i
< nr
; i
++) {
971 GLuint format
= map
[i
].format
;
972 vtx
->attr
[i
].attrib
= map
[i
].attrib
;
973 vtx
->attr
[i
].vp
= vp
;
974 vtx
->attr
[i
].insert
= format_info
[format
].insert
;
975 vtx
->attr
[i
].extract
= format_info
[format
].extract
;
976 vtx
->attr
[i
].vertattrsize
= format_info
[format
].attrsize
;
979 vtx
->attr
[i
].vertoffset
= map
[i
].offset
;
981 vtx
->attr
[i
].vertoffset
= offset
;
983 /* fprintf(stderr, "%d: %s offset %d\n", i, */
984 /* format_info[format].name, vtx->attr[i].vertoffset); */
986 offset
+= format_info
[format
].attrsize
;
990 vtx
->vertex_size
= unpacked_size
;
992 vtx
->vertex_size
= offset
;
994 assert(vtx
->vertex_size
<= vtx
->max_vertex_size
);
996 return vtx
->vertex_size
;
1001 void _tnl_invalidate_vertices( GLcontext
*ctx
, GLuint newinputs
)
1003 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1004 vtx
->new_inputs
|= newinputs
;
1009 void _tnl_build_vertices( GLcontext
*ctx
,
1014 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1015 GLuint stride
= vtx
->vertex_size
;
1016 GLubyte
*v
= ((GLubyte
*)vtx
->vertex_buf
+ (start
*stride
));
1018 newinputs
|= vtx
->new_inputs
;
1019 vtx
->new_inputs
= 0;
1022 vtx
->emit( ctx
, start
, count
, v
);
1026 void *_tnl_emit_vertices_to_buffer( GLcontext
*ctx
,
1031 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1032 vtx
->emit( ctx
, start
, count
, dest
);
1033 return (void *)((GLubyte
*)dest
+ vtx
->vertex_size
* (count
- start
));
1037 void _tnl_init_vertices( GLcontext
*ctx
,
1039 GLuint max_vertex_size
)
1041 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1043 _tnl_install_attrs( ctx
, 0, 0, 0, 0 );
1045 vtx
->need_extras
= GL_TRUE
;
1046 if (max_vertex_size
> vtx
->max_vertex_size
) {
1047 _tnl_free_vertices( ctx
);
1048 vtx
->max_vertex_size
= max_vertex_size
;
1049 vtx
->vertex_buf
= (GLubyte
*)ALIGN_MALLOC(vb_size
* max_vertex_size
, 32 );
1054 void _tnl_free_vertices( GLcontext
*ctx
)
1056 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1057 if (vtx
->vertex_buf
) {
1058 ALIGN_FREE(vtx
->vertex_buf
);
1059 vtx
->vertex_buf
= 0;