gallium: add target-helpers/wrap_screen.c to C_SOURCES
[mesa/mesa-lb.git] / src / gallium / auxiliary / indices / u_unfilled_indices.c
blob26c5d4d4c72cad1fc664658973dab87a7f2a4563
1 /*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
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
14 * Software.
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 * VMWARE 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 #include "u_indices.h"
26 #include "u_indices_priv.h"
29 static void translate_ubyte_ushort( const void *in,
30 unsigned nr,
31 void *out )
33 const ubyte *in_ub = (const ubyte *)in;
34 ushort *out_us = (ushort *)out;
35 unsigned i;
36 for (i = 0; i < nr; i++)
37 out_us[i] = (ushort) in_ub[i];
40 static void translate_memcpy_ushort( const void *in,
41 unsigned nr,
42 void *out )
44 memcpy(out, in, nr*sizeof(short));
47 static void translate_memcpy_uint( const void *in,
48 unsigned nr,
49 void *out )
51 memcpy(out, in, nr*sizeof(int));
55 static void generate_linear_ushort( unsigned nr,
56 void *out )
58 ushort *out_us = (ushort *)out;
59 unsigned i;
60 for (i = 0; i < nr; i++)
61 out_us[i] = (ushort) i;
64 static void generate_linear_uint( unsigned nr,
65 void *out )
67 unsigned *out_ui = (unsigned *)out;
68 unsigned i;
69 for (i = 0; i < nr; i++)
70 out_ui[i] = i;
74 static unsigned nr_lines( unsigned prim,
75 unsigned nr )
77 switch (prim) {
78 case PIPE_PRIM_TRIANGLES:
79 return (nr / 3) * 6;
80 case PIPE_PRIM_TRIANGLE_STRIP:
81 return (nr - 2) * 6;
82 case PIPE_PRIM_TRIANGLE_FAN:
83 return (nr - 2) * 6;
84 case PIPE_PRIM_QUADS:
85 return (nr / 4) * 8;
86 case PIPE_PRIM_QUAD_STRIP:
87 return (nr - 2) / 2 * 8;
88 case PIPE_PRIM_POLYGON:
89 return (nr - 2) * 6;
90 default:
91 assert(0);
92 return 0;
98 int u_unfilled_translator( unsigned prim,
99 unsigned in_index_size,
100 unsigned nr,
101 unsigned unfilled_mode,
102 unsigned *out_prim,
103 unsigned *out_index_size,
104 unsigned *out_nr,
105 u_translate_func *out_translate )
107 unsigned in_idx;
108 unsigned out_idx;
110 u_unfilled_init();
112 in_idx = in_size_idx(in_index_size);
113 *out_index_size = (in_index_size == 4) ? 4 : 2;
114 out_idx = out_size_idx(*out_index_size);
116 if (unfilled_mode == PIPE_POLYGON_MODE_POINT)
118 *out_prim = PIPE_PRIM_POINTS;
119 *out_nr = nr;
121 switch (in_index_size)
123 case 1:
124 *out_translate = translate_ubyte_ushort;
125 return U_TRANSLATE_NORMAL;
126 case 2:
127 *out_translate = translate_memcpy_uint;
128 return U_TRANSLATE_MEMCPY;
129 case 4:
130 *out_translate = translate_memcpy_ushort;
131 return U_TRANSLATE_MEMCPY;
132 default:
133 *out_translate = translate_memcpy_uint;
134 *out_nr = 0;
135 assert(0);
136 return U_TRANSLATE_ERROR;
139 else {
140 assert(unfilled_mode == PIPE_POLYGON_MODE_LINE);
141 *out_prim = PIPE_PRIM_LINES;
142 *out_translate = translate_line[in_idx][out_idx][prim];
143 *out_nr = nr_lines( prim, nr );
144 return U_TRANSLATE_NORMAL;
150 int u_unfilled_generator( unsigned prim,
151 unsigned start,
152 unsigned nr,
153 unsigned unfilled_mode,
154 unsigned *out_prim,
155 unsigned *out_index_size,
156 unsigned *out_nr,
157 u_generate_func *out_generate )
159 unsigned out_idx;
161 u_unfilled_init();
163 *out_index_size = ((start + nr) > 0xfffe) ? 4 : 2;
164 out_idx = out_size_idx(*out_index_size);
166 if (unfilled_mode == PIPE_POLYGON_MODE_POINT) {
168 if (*out_index_size == 4)
169 *out_generate = generate_linear_uint;
170 else
171 *out_generate = generate_linear_ushort;
173 *out_prim = PIPE_PRIM_POINTS;
174 *out_nr = nr;
175 return U_GENERATE_LINEAR;
177 else {
178 assert(unfilled_mode == PIPE_POLYGON_MODE_LINE);
179 *out_prim = PIPE_PRIM_LINES;
180 *out_generate = generate_line[out_idx][prim];
181 *out_nr = nr_lines( prim, nr );
183 return U_GENERATE_REUSABLE;