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_*.
49 * These functions take the NDC coordinates pointed to by 'in', apply the
50 * NDC->Viewport mapping and store the results at 'v'.
54 insert_4f_viewport_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
57 GLfloat
*out
= (GLfloat
*)v
;
58 const GLfloat
* const vp
= a
->vp
;
60 out
[0] = vp
[0] * in
[0] + vp
[12];
61 out
[1] = vp
[5] * in
[1] + vp
[13];
62 out
[2] = vp
[10] * in
[2] + vp
[14];
66 static void insert_4f_viewport_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
69 GLfloat
*out
= (GLfloat
*)v
;
70 const GLfloat
* const vp
= a
->vp
;
72 out
[0] = vp
[0] * in
[0] + vp
[12];
73 out
[1] = vp
[5] * in
[1] + vp
[13];
74 out
[2] = vp
[10] * in
[2] + vp
[14];
78 static void insert_4f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
81 GLfloat
*out
= (GLfloat
*)v
;
82 const GLfloat
* const vp
= a
->vp
;
84 out
[0] = vp
[0] * in
[0] + vp
[12];
85 out
[1] = vp
[5] * in
[1] + vp
[13];
90 static void insert_4f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
93 GLfloat
*out
= (GLfloat
*)v
;
94 const GLfloat
* const vp
= a
->vp
;
96 out
[0] = vp
[0] * in
[0] + vp
[12];
102 static void insert_3f_viewport_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
105 GLfloat
*out
= (GLfloat
*)v
;
106 const GLfloat
* const vp
= a
->vp
;
108 out
[0] = vp
[0] * in
[0] + vp
[12];
109 out
[1] = vp
[5] * in
[1] + vp
[13];
110 out
[2] = vp
[10] * in
[2] + vp
[14];
113 static void insert_3f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
116 GLfloat
*out
= (GLfloat
*)v
;
117 const GLfloat
* const vp
= a
->vp
;
119 out
[0] = vp
[0] * in
[0] + vp
[12];
120 out
[1] = vp
[5] * in
[1] + vp
[13];
121 out
[2] = vp
[10] * in
[2] + vp
[14];
124 static void insert_3f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
127 GLfloat
*out
= (GLfloat
*)v
;
128 const GLfloat
* const vp
= a
->vp
;
130 out
[0] = vp
[0] * in
[0] + vp
[12];
135 static void insert_2f_viewport_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
138 GLfloat
*out
= (GLfloat
*)v
;
139 const GLfloat
* const vp
= a
->vp
;
141 out
[0] = vp
[0] * in
[0] + vp
[12];
142 out
[1] = vp
[5] * in
[1] + vp
[13];
145 static void insert_2f_viewport_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
148 GLfloat
*out
= (GLfloat
*)v
;
149 const GLfloat
* const vp
= a
->vp
;
151 out
[0] = vp
[0] * in
[0] + vp
[12];
157 * These functions do the same as above, except for the viewport mapping.
160 static void insert_4f_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
162 GLfloat
*out
= (GLfloat
*)(v
);
171 static void insert_4f_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
173 GLfloat
*out
= (GLfloat
*)(v
);
182 static void insert_4f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
184 GLfloat
*out
= (GLfloat
*)(v
);
193 static void insert_4f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
195 GLfloat
*out
= (GLfloat
*)(v
);
204 static void insert_3f_xyw_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
206 GLfloat
*out
= (GLfloat
*)(v
);
214 static void insert_3f_xyw_err( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
216 (void) a
; (void) v
; (void) in
;
220 static void insert_3f_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
222 GLfloat
*out
= (GLfloat
*)(v
);
230 static void insert_3f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
232 GLfloat
*out
= (GLfloat
*)(v
);
240 static void insert_3f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
242 GLfloat
*out
= (GLfloat
*)(v
);
251 static void insert_2f_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
253 GLfloat
*out
= (GLfloat
*)(v
);
260 static void insert_2f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
262 GLfloat
*out
= (GLfloat
*)(v
);
269 static void insert_1f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
, const GLfloat
*in
)
271 GLfloat
*out
= (GLfloat
*)(v
);
277 static void insert_4chan_4f_rgba_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
280 GLchan
*c
= (GLchan
*)v
;
282 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
283 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
284 UNCLAMPED_FLOAT_TO_CHAN(c
[2], in
[2]);
285 UNCLAMPED_FLOAT_TO_CHAN(c
[3], in
[3]);
288 static void insert_4chan_4f_rgba_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
291 GLchan
*c
= (GLchan
*)v
;
293 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
294 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
295 UNCLAMPED_FLOAT_TO_CHAN(c
[2], in
[2]);
299 static void insert_4chan_4f_rgba_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
302 GLchan
*c
= (GLchan
*)v
;
304 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
305 UNCLAMPED_FLOAT_TO_CHAN(c
[1], in
[1]);
310 static void insert_4chan_4f_rgba_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
313 GLchan
*c
= (GLchan
*)v
;
315 UNCLAMPED_FLOAT_TO_CHAN(c
[0], in
[0]);
321 static void insert_4ub_4f_rgba_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
325 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
326 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
327 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
328 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], in
[3]);
331 static void insert_4ub_4f_rgba_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
335 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
336 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
337 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
341 static void insert_4ub_4f_rgba_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
345 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
346 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
351 static void insert_4ub_4f_rgba_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
355 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
361 static void insert_4ub_4f_bgra_4( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
365 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
366 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
367 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
368 UNCLAMPED_FLOAT_TO_UBYTE(v
[3], in
[3]);
371 static void insert_4ub_4f_bgra_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
375 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
376 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
377 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
381 static void insert_4ub_4f_bgra_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
385 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
386 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
391 static void insert_4ub_4f_bgra_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
395 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
401 static void insert_3ub_3f_rgb_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
405 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
406 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
407 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[2]);
410 static void insert_3ub_3f_rgb_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
414 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
415 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
419 static void insert_3ub_3f_rgb_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
423 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
428 static void insert_3ub_3f_bgr_3( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
432 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
433 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
434 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[2]);
437 static void insert_3ub_3f_bgr_2( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
441 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
442 UNCLAMPED_FLOAT_TO_UBYTE(v
[1], in
[1]);
446 static void insert_3ub_3f_bgr_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
450 UNCLAMPED_FLOAT_TO_UBYTE(v
[2], in
[0]);
456 static void insert_1ub_1f_1( const struct tnl_clipspace_attr
*a
, GLubyte
*v
,
460 UNCLAMPED_FLOAT_TO_UBYTE(v
[0], in
[0]);
464 /***********************************************************************
465 * Functions to perform the reverse operations to the above, for
466 * swrast translation and clip-interpolation.
468 * Currently always extracts a full 4 floats.
471 static void extract_4f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
474 const GLfloat
*in
= (const GLfloat
*)v
;
475 const GLfloat
* const vp
= a
->vp
;
477 /* Although included for completeness, the position coordinate is
478 * usually handled differently during clipping.
480 out
[0] = (in
[0] - vp
[12]) / vp
[0];
481 out
[1] = (in
[1] - vp
[13]) / vp
[5];
482 out
[2] = (in
[2] - vp
[14]) / vp
[10];
486 static void extract_3f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
489 const GLfloat
*in
= (const GLfloat
*)v
;
490 const GLfloat
* const vp
= a
->vp
;
492 out
[0] = (in
[0] - vp
[12]) / vp
[0];
493 out
[1] = (in
[1] - vp
[13]) / vp
[5];
494 out
[2] = (in
[2] - vp
[14]) / vp
[10];
499 static void extract_2f_viewport( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
502 const GLfloat
*in
= (const GLfloat
*)v
;
503 const GLfloat
* const vp
= a
->vp
;
505 out
[0] = (in
[0] - vp
[12]) / vp
[0];
506 out
[1] = (in
[1] - vp
[13]) / vp
[5];
512 static void extract_4f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
514 const GLfloat
*in
= (const GLfloat
*)v
;
523 static void extract_3f_xyw( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
525 const GLfloat
*in
= (const GLfloat
*)v
;
535 static void extract_3f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
537 const GLfloat
*in
= (const GLfloat
*)v
;
547 static void extract_2f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
549 const GLfloat
*in
= (const GLfloat
*)v
;
558 static void extract_1f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
560 const GLfloat
*in
= (const GLfloat
*)v
;
569 static void extract_4chan_4f_rgba( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
572 GLchan
*c
= (GLchan
*)v
;
575 out
[0] = CHAN_TO_FLOAT(c
[0]);
576 out
[1] = CHAN_TO_FLOAT(c
[1]);
577 out
[2] = CHAN_TO_FLOAT(c
[2]);
578 out
[3] = CHAN_TO_FLOAT(c
[3]);
581 static void extract_4ub_4f_rgba( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
585 out
[0] = UBYTE_TO_FLOAT(v
[0]);
586 out
[1] = UBYTE_TO_FLOAT(v
[1]);
587 out
[2] = UBYTE_TO_FLOAT(v
[2]);
588 out
[3] = UBYTE_TO_FLOAT(v
[3]);
591 static void extract_4ub_4f_bgra( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
595 out
[2] = UBYTE_TO_FLOAT(v
[0]);
596 out
[1] = UBYTE_TO_FLOAT(v
[1]);
597 out
[0] = UBYTE_TO_FLOAT(v
[2]);
598 out
[3] = UBYTE_TO_FLOAT(v
[3]);
601 static void extract_3ub_3f_rgb( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
605 out
[0] = UBYTE_TO_FLOAT(v
[0]);
606 out
[1] = UBYTE_TO_FLOAT(v
[1]);
607 out
[2] = UBYTE_TO_FLOAT(v
[2]);
611 static void extract_3ub_3f_bgr( const struct tnl_clipspace_attr
*a
, GLfloat
*out
,
615 out
[2] = UBYTE_TO_FLOAT(v
[0]);
616 out
[1] = UBYTE_TO_FLOAT(v
[1]);
617 out
[0] = UBYTE_TO_FLOAT(v
[2]);
621 static void extract_1ub_1f( const struct tnl_clipspace_attr
*a
, GLfloat
*out
, const GLubyte
*v
)
624 out
[0] = UBYTE_TO_FLOAT(v
[0]);
633 tnl_extract_func extract
;
634 tnl_insert_func insert
[4];
635 const GLuint attrsize
;
636 } format_info
[EMIT_MAX
] = {
640 { insert_1f_1
, insert_1f_1
, insert_1f_1
, insert_1f_1
},
645 { insert_2f_1
, insert_2f_2
, insert_2f_2
, insert_2f_2
},
646 2 * sizeof(GLfloat
) },
650 { insert_3f_1
, insert_3f_2
, insert_3f_3
, insert_3f_3
},
651 3 * sizeof(GLfloat
) },
655 { insert_4f_1
, insert_4f_2
, insert_4f_3
, insert_4f_4
},
656 4 * sizeof(GLfloat
) },
660 { insert_2f_viewport_1
, insert_2f_viewport_2
, insert_2f_viewport_2
,
661 insert_2f_viewport_2
},
662 2 * sizeof(GLfloat
) },
666 { insert_3f_viewport_1
, insert_3f_viewport_2
, insert_3f_viewport_3
,
667 insert_3f_viewport_3
},
668 3 * sizeof(GLfloat
) },
672 { insert_4f_viewport_1
, insert_4f_viewport_2
, insert_4f_viewport_3
,
673 insert_4f_viewport_4
},
674 4 * sizeof(GLfloat
) },
678 { insert_3f_xyw_err
, insert_3f_xyw_err
, insert_3f_xyw_err
,
680 3 * sizeof(GLfloat
) },
684 { insert_1ub_1f_1
, insert_1ub_1f_1
, insert_1ub_1f_1
, insert_1ub_1f_1
},
689 { insert_3ub_3f_rgb_1
, insert_3ub_3f_rgb_2
, insert_3ub_3f_rgb_3
,
690 insert_3ub_3f_rgb_3
},
691 3 * sizeof(GLubyte
) },
695 { insert_3ub_3f_bgr_1
, insert_3ub_3f_bgr_2
, insert_3ub_3f_bgr_3
,
696 insert_3ub_3f_bgr_3
},
697 3 * sizeof(GLubyte
) },
701 { insert_4ub_4f_rgba_1
, insert_4ub_4f_rgba_2
, insert_4ub_4f_rgba_3
,
702 insert_4ub_4f_rgba_4
},
703 4 * sizeof(GLubyte
) },
707 { insert_4ub_4f_bgra_1
, insert_4ub_4f_bgra_2
, insert_4ub_4f_bgra_3
,
708 insert_4ub_4f_bgra_4
},
709 4 * sizeof(GLubyte
) },
712 extract_4chan_4f_rgba
,
713 { insert_4chan_4f_rgba_1
, insert_4chan_4f_rgba_2
, insert_4chan_4f_rgba_3
,
714 insert_4chan_4f_rgba_4
},
715 4 * sizeof(GLchan
) },
725 /***********************************************************************
726 * Generic (non-codegen) functions for whole vertices or groups of
730 static void generic_emit( GLcontext
*ctx
,
731 GLuint start
, GLuint end
,
734 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
735 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
736 struct tnl_clipspace_attr
*a
= vtx
->attr
;
737 GLubyte
*v
= (GLubyte
*)dest
;
739 const GLuint count
= vtx
->attr_count
;
742 for (j
= 0; j
< count
; j
++) {
743 GLvector4f
*vptr
= VB
->AttribPtr
[a
[j
].attrib
];
744 a
[j
].inputstride
= vptr
->stride
;
745 a
[j
].inputptr
= ((GLubyte
*)vptr
->data
) + start
* vptr
->stride
;
746 a
[j
].emit
= a
[j
].insert
[vptr
->size
- 1];
750 stride
= vtx
->vertex_size
;
752 for (i
= 0 ; i
< end
; i
++, v
+= stride
) {
753 for (j
= 0; j
< count
; j
++) {
754 GLfloat
*in
= (GLfloat
*)a
[j
].inputptr
;
755 a
[j
].inputptr
+= a
[j
].inputstride
;
756 a
[j
].emit( &a
[j
], v
+ a
[j
].vertoffset
, in
);
762 static void generic_interp( GLcontext
*ctx
,
764 GLuint edst
, GLuint eout
, GLuint ein
,
765 GLboolean force_boundary
)
767 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
768 struct vertex_buffer
*VB
= &tnl
->vb
;
769 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
770 const GLubyte
*vin
= vtx
->vertex_buf
+ ein
* vtx
->vertex_size
;
771 const GLubyte
*vout
= vtx
->vertex_buf
+ eout
* vtx
->vertex_size
;
772 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
773 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
774 const GLuint attr_count
= vtx
->attr_count
;
776 (void) force_boundary
;
778 if (tnl
->NeedNdcCoords
) {
779 const GLfloat
*dstclip
= VB
->ClipPtr
->data
[edst
];
780 if (dstclip
[3] != 0.0) {
781 const GLfloat w
= 1.0f
/ dstclip
[3];
784 pos
[0] = dstclip
[0] * w
;
785 pos
[1] = dstclip
[1] * w
;
786 pos
[2] = dstclip
[2] * w
;
789 a
[0].insert
[4-1]( &a
[0], vdst
, pos
);
793 a
[0].insert
[4-1]( &a
[0], vdst
, VB
->ClipPtr
->data
[edst
] );
797 for (j
= 1; j
< attr_count
; j
++) {
798 GLfloat fin
[4], fout
[4], fdst
[4];
800 a
[j
].extract( &a
[j
], fin
, vin
+ a
[j
].vertoffset
);
801 a
[j
].extract( &a
[j
], fout
, vout
+ a
[j
].vertoffset
);
803 INTERP_F( t
, fdst
[3], fout
[3], fin
[3] );
804 INTERP_F( t
, fdst
[2], fout
[2], fin
[2] );
805 INTERP_F( t
, fdst
[1], fout
[1], fin
[1] );
806 INTERP_F( t
, fdst
[0], fout
[0], fin
[0] );
808 a
[j
].insert
[4-1]( &a
[j
], vdst
+ a
[j
].vertoffset
, fdst
);
813 /* Extract color attributes from one vertex and insert them into
814 * another. (Shortcircuit extract/insert with memcpy).
816 static void generic_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
818 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
819 GLubyte
*vsrc
= vtx
->vertex_buf
+ esrc
* vtx
->vertex_size
;
820 GLubyte
*vdst
= vtx
->vertex_buf
+ edst
* vtx
->vertex_size
;
821 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
822 const GLuint attr_count
= vtx
->attr_count
;
825 for (j
= 0; j
< attr_count
; j
++) {
826 if (a
[j
].attrib
== VERT_ATTRIB_COLOR0
||
827 a
[j
].attrib
== VERT_ATTRIB_COLOR1
) {
829 _mesa_memcpy( vdst
+ a
[j
].vertoffset
,
830 vsrc
+ a
[j
].vertoffset
,
837 /* Helper functions for hardware which doesn't put back colors and/or
838 * edgeflags into vertices.
840 static void generic_interp_extras( GLcontext
*ctx
,
842 GLuint dst
, GLuint out
, GLuint in
,
843 GLboolean force_boundary
)
845 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
847 if (VB
->ColorPtr
[1]) {
848 assert(VB
->ColorPtr
[1]->stride
== 4 * sizeof(GLfloat
));
851 VB
->ColorPtr
[1]->data
[dst
],
852 VB
->ColorPtr
[1]->data
[out
],
853 VB
->ColorPtr
[1]->data
[in
] );
855 if (VB
->SecondaryColorPtr
[1]) {
857 VB
->SecondaryColorPtr
[1]->data
[dst
],
858 VB
->SecondaryColorPtr
[1]->data
[out
],
859 VB
->SecondaryColorPtr
[1]->data
[in
] );
862 else if (VB
->IndexPtr
[1]) {
863 VB
->IndexPtr
[1]->data
[dst
][0] = LINTERP( t
,
864 VB
->IndexPtr
[1]->data
[out
][0],
865 VB
->IndexPtr
[1]->data
[in
][0] );
869 VB
->EdgeFlag
[dst
] = VB
->EdgeFlag
[out
] || force_boundary
;
872 generic_interp(ctx
, t
, dst
, out
, in
, force_boundary
);
875 static void generic_copy_pv_extras( GLcontext
*ctx
,
876 GLuint dst
, GLuint src
)
878 struct vertex_buffer
*VB
= &TNL_CONTEXT(ctx
)->vb
;
880 if (VB
->ColorPtr
[1]) {
881 COPY_4FV( VB
->ColorPtr
[1]->data
[dst
],
882 VB
->ColorPtr
[1]->data
[src
] );
884 if (VB
->SecondaryColorPtr
[1]) {
885 COPY_4FV( VB
->SecondaryColorPtr
[1]->data
[dst
],
886 VB
->SecondaryColorPtr
[1]->data
[src
] );
889 else if (VB
->IndexPtr
[1]) {
890 VB
->IndexPtr
[1]->data
[dst
][0] = VB
->IndexPtr
[1]->data
[src
][0];
893 generic_copy_pv(ctx
, dst
, src
);
899 /***********************************************************************
900 * Build codegen functions or return generic ones:
904 static void do_emit( GLcontext
*ctx
, GLuint start
, GLuint end
,
907 TNLcontext
*tnl
= TNL_CONTEXT(ctx
);
908 struct vertex_buffer
*VB
= &tnl
->vb
;
909 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
910 struct tnl_clipspace_attr
*a
= vtx
->attr
;
911 const GLuint count
= vtx
->attr_count
;
914 for (j
= 0; j
< count
; j
++) {
915 GLvector4f
*vptr
= VB
->AttribPtr
[a
[j
].attrib
];
916 a
[j
].inputstride
= vptr
->stride
;
917 a
[j
].inputptr
= ((GLubyte
*)vptr
->data
) + start
* vptr
->stride
;
918 a
[j
].emit
= a
[j
].insert
[vptr
->size
- 1];
924 vtx
->emit
= _tnl_codegen_emit(ctx
);
927 vtx
->emit
= generic_emit
;
929 vtx
->emit( ctx
, start
, end
, dest
);
934 static void choose_interp_func( GLcontext
*ctx
,
936 GLuint edst
, GLuint eout
, GLuint ein
,
937 GLboolean force_boundary
)
939 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
941 if (vtx
->need_extras
&&
942 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
943 vtx
->interp
= generic_interp_extras
;
945 vtx
->interp
= generic_interp
;
948 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
952 static void choose_copy_pv_func( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
954 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
956 if (vtx
->need_extras
&&
957 (ctx
->_TriangleCaps
& (DD_TRI_LIGHT_TWOSIDE
|DD_TRI_UNFILLED
))) {
958 vtx
->copy_pv
= generic_copy_pv_extras
;
960 vtx
->copy_pv
= generic_copy_pv
;
963 vtx
->copy_pv( ctx
, edst
, esrc
);
967 /***********************************************************************
968 * Public entrypoints, mostly dispatch to the above:
972 /* Interpolate between two vertices to produce a third:
974 void _tnl_interp( GLcontext
*ctx
,
976 GLuint edst
, GLuint eout
, GLuint ein
,
977 GLboolean force_boundary
)
979 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
980 vtx
->interp( ctx
, t
, edst
, eout
, ein
, force_boundary
);
983 /* Copy colors from one vertex to another:
985 void _tnl_copy_pv( GLcontext
*ctx
, GLuint edst
, GLuint esrc
)
987 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
988 vtx
->copy_pv( ctx
, edst
, esrc
);
992 /* Extract a named attribute from a hardware vertex. Will have to
993 * reverse any viewport transformation, swizzling or other conversions
994 * which may have been applied:
996 void _tnl_get_attr( GLcontext
*ctx
, const void *vin
,
997 GLenum attr
, GLfloat
*dest
)
999 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1000 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
1001 const GLuint attr_count
= vtx
->attr_count
;
1004 for (j
= 0; j
< attr_count
; j
++) {
1005 if (a
[j
].attrib
== attr
) {
1006 a
[j
].extract( &a
[j
], dest
, (GLubyte
*)vin
+ a
[j
].vertoffset
);
1011 /* Else return the value from ctx->Current -- dangerous???
1013 _mesa_memcpy( dest
, ctx
->Current
.Attrib
[attr
], 4*sizeof(GLfloat
));
1017 /* Complementary operation to the above.
1019 void _tnl_set_attr( GLcontext
*ctx
, void *vout
,
1020 GLenum attr
, const GLfloat
*src
)
1022 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1023 const struct tnl_clipspace_attr
*a
= vtx
->attr
;
1024 const GLuint attr_count
= vtx
->attr_count
;
1027 for (j
= 0; j
< attr_count
; j
++) {
1028 if (a
[j
].attrib
== attr
) {
1029 a
[j
].insert
[4-1]( &a
[j
], (GLubyte
*)vout
+ a
[j
].vertoffset
, src
);
1036 void *_tnl_get_vertex( GLcontext
*ctx
, GLuint nr
)
1038 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1040 return vtx
->vertex_buf
+ nr
* vtx
->vertex_size
;
1043 void _tnl_invalidate_vertex_state( GLcontext
*ctx
, GLuint new_state
)
1045 if (new_state
& (_DD_NEW_TRI_LIGHT_TWOSIDE
|_DD_NEW_TRI_UNFILLED
) ) {
1046 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1047 vtx
->new_inputs
= ~0;
1048 vtx
->interp
= choose_interp_func
;
1049 vtx
->copy_pv
= choose_copy_pv_func
;
1054 GLuint
_tnl_install_attrs( GLcontext
*ctx
, const struct tnl_attr_map
*map
,
1055 GLuint nr
, const GLfloat
*vp
,
1056 GLuint unpacked_size
)
1058 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1062 assert(nr
< _TNL_ATTRIB_MAX
);
1063 assert(nr
== 0 || map
[0].attrib
== VERT_ATTRIB_POS
);
1066 vtx
->interp
= choose_interp_func
;
1067 vtx
->copy_pv
= choose_copy_pv_func
;
1068 vtx
->new_inputs
= ~0;
1070 for (j
= 0, i
= 0; i
< nr
; i
++) {
1071 const GLuint format
= map
[i
].format
;
1072 if (format
== EMIT_PAD
) {
1074 fprintf(stderr, "%d: pad %d, offset %d\n", i,
1075 map[i].offset, offset);
1077 offset
+= map
[i
].offset
;
1081 vtx
->attr
[j
].attrib
= map
[i
].attrib
;
1082 vtx
->attr
[j
].format
= format
;
1083 vtx
->attr
[j
].vp
= vp
;
1084 vtx
->attr
[j
].insert
= format_info
[format
].insert
;
1085 vtx
->attr
[j
].extract
= format_info
[format
].extract
;
1086 vtx
->attr
[j
].vertattrsize
= format_info
[format
].attrsize
;
1089 vtx
->attr
[j
].vertoffset
= map
[i
].offset
;
1091 vtx
->attr
[j
].vertoffset
= offset
;
1094 fprintf(stderr, "%d: %s, vp %p, offset %d\n", i,
1095 format_info[format].name, (void *)vp,
1096 vtx->attr[j].vertoffset);
1098 offset
+= format_info
[format
].attrsize
;
1103 vtx
->attr_count
= j
;
1106 vtx
->vertex_size
= unpacked_size
;
1108 vtx
->vertex_size
= offset
;
1110 assert(vtx
->vertex_size
<= vtx
->max_vertex_size
);
1112 return vtx
->vertex_size
;
1117 void _tnl_invalidate_vertices( GLcontext
*ctx
, GLuint newinputs
)
1119 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1120 vtx
->new_inputs
|= newinputs
;
1124 void _tnl_build_vertices( GLcontext
*ctx
,
1129 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1130 const GLuint stride
= vtx
->vertex_size
;
1131 GLubyte
*vDest
= ((GLubyte
*)vtx
->vertex_buf
+ (start
*stride
));
1133 newinputs
|= vtx
->new_inputs
;
1134 vtx
->new_inputs
= 0;
1137 do_emit( ctx
, start
, end
, vDest
);
1141 void *_tnl_emit_vertices_to_buffer( GLcontext
*ctx
,
1146 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1147 do_emit( ctx
, start
, end
, dest
);
1148 return (void *)((GLubyte
*)dest
+ vtx
->vertex_size
* (end
- start
));
1152 void _tnl_init_vertices( GLcontext
*ctx
,
1154 GLuint max_vertex_size
)
1156 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1158 _tnl_install_attrs( ctx
, 0, 0, 0, 0 );
1160 vtx
->need_extras
= GL_TRUE
;
1161 if (max_vertex_size
> vtx
->max_vertex_size
) {
1162 _tnl_free_vertices( ctx
);
1163 vtx
->max_vertex_size
= max_vertex_size
;
1164 vtx
->vertex_buf
= (GLubyte
*)ALIGN_CALLOC(vb_size
* max_vertex_size
, 32 );
1167 _tnl_init_c_codegen( &vtx
->codegen
);
1171 void _tnl_free_vertices( GLcontext
*ctx
)
1173 struct tnl_clipspace
*vtx
= GET_VERTEX_STATE(ctx
);
1174 if (vtx
->vertex_buf
) {
1175 ALIGN_FREE(vtx
->vertex_buf
);
1176 vtx
->vertex_buf
= 0;