remove old/used code
[mesa.git] / src / mesa / pipe / draw / draw_vertex.c
1 /**************************************************************************
2 *
3 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 *
26 **************************************************************************/
27
28 /*
29 * Functions for specifying the post-transformation vertex layout.
30 *
31 * Author:
32 * Brian Paul
33 * Keith Whitwell
34 */
35
36
37 #include "pipe/p_defines.h"
38 #include "pipe/p_context.h"
39 #include "pipe/p_winsys.h"
40 #include "pipe/p_util.h"
41
42 #include "pipe/draw/draw_private.h"
43 #include "pipe/draw/draw_context.h"
44 #include "pipe/draw/draw_vertex.h"
45
46
47 static INLINE void
48 emit_vertex_attr(struct vertex_info *vinfo,
49 attrib_format format, interp_mode interp)
50 {
51 const uint n = vinfo->num_attribs;
52 vinfo->interp_mode[n] = interp;
53 vinfo->format[n] = format;
54 vinfo->num_attribs++;
55 }
56
57
58 /**
59 * Compute the size of a vertex, in dwords/floats, to update the
60 * vinfo->size field.
61 */
62 void
63 draw_compute_vertex_size(struct vertex_info *vinfo)
64 {
65 uint i;
66
67 vinfo->size = 0;
68 for (i = 0; i < vinfo->num_attribs; i++) {
69 switch (vinfo->format[i]) {
70 case FORMAT_OMIT:
71 break;
72 case FORMAT_4UB:
73 /* fall-through */
74 case FORMAT_1F:
75 vinfo->size += 1;
76 break;
77 case FORMAT_2F:
78 vinfo->size += 2;
79 break;
80 case FORMAT_3F:
81 vinfo->size += 3;
82 break;
83 case FORMAT_4F:
84 case FORMAT_4F_VIEWPORT:
85 vinfo->size += 4;
86 break;
87 default:
88 assert(0);
89 }
90 }
91 }
92
93
94 /**
95 * Tell the drawing module about the layout of post-transformation vertices
96 */
97 void
98 draw_set_vertex_attributes( struct draw_context *draw,
99 const uint *slot_to_vf_attr,
100 const interp_mode *interps,
101 unsigned nr_attrs )
102 {
103 struct vertex_info *vinfo = &draw->vertex_info;
104 unsigned i;
105
106 #if 0
107 assert(slot_to_vf_attr[0] == TGSI_ATTRIB_POS);
108 #endif
109
110 memset(vinfo, 0, sizeof(*vinfo));
111
112 /*
113 * First three attribs are always the same: header, clip pos, winpos
114 */
115 emit_vertex_attr(vinfo, FORMAT_1F, INTERP_NONE);
116 emit_vertex_attr(vinfo, FORMAT_4F, INTERP_LINEAR);
117 emit_vertex_attr(vinfo, FORMAT_4F_VIEWPORT, INTERP_LINEAR);
118
119 /*
120 * Remaining attribs (color, texcoords, etc)
121 */
122 for (i = 1; i < nr_attrs; i++) {
123 emit_vertex_attr(vinfo, FORMAT_4F, interps[i]);
124 }
125
126 draw_compute_vertex_size(vinfo);
127 }
128
129
130 /**
131 * This function is used to tell the draw module about attributes
132 * (like colors) that need to be selected based on front/back face
133 * orientation.
134 *
135 * The logic is:
136 * if (polygon is back-facing) {
137 * vertex->attrib[front0] = vertex->attrib[back0];
138 * vertex->attrib[front1] = vertex->attrib[back1];
139 * }
140 *
141 * \param front0 first attrib to replace if the polygon is back-facing
142 * \param back0 first attrib to copy if the polygon is back-facing
143 * \param front1 second attrib to replace if the polygon is back-facing
144 * \param back1 second attrib to copy if the polygon is back-facing
145 *
146 * Pass -1 to disable two-sided attributes.
147 */
148 void
149 draw_set_twoside_attributes(struct draw_context *draw,
150 uint front0, uint back0,
151 uint front1, uint back1)
152 {
153 /* XXX we could alternately pass an array of front/back attribs if there's
154 * ever need for more than two. One could imagine a shader extension
155 * that allows arbitrary attributes to be selected based on polygon
156 * orientation...
157 */
158 draw->attrib_front0 = front0;
159 draw->attrib_back0 = back0;
160 draw->attrib_front1 = front1;
161 draw->attrib_back1 = back1;
162 }