silence debugging output
[mesa.git] / src / gallium / auxiliary / draw / draw_pt_emit.c
1 /**************************************************************************
2 *
3 * Copyright 2008 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 #include "pipe/p_util.h"
29 #include "draw/draw_context.h"
30 #include "draw/draw_private.h"
31 #include "draw/draw_vbuf.h"
32 #include "draw/draw_vertex.h"
33 #include "draw/draw_pt.h"
34 #include "translate/translate.h"
35 #include "translate/translate_cache.h"
36
37 struct pt_emit {
38 struct draw_context *draw;
39
40 struct translate *translate;
41
42 struct translate_cache *cache;
43 };
44
45 void draw_pt_emit_prepare( struct pt_emit *emit,
46 unsigned prim )
47 {
48 struct draw_context *draw = emit->draw;
49 const struct vertex_info *vinfo;
50 unsigned dst_offset;
51 struct translate_key hw_key;
52 unsigned i;
53 boolean ok;
54
55 ok = draw->render->set_primitive(draw->render, prim);
56 if (!ok) {
57 assert(0);
58 return;
59 }
60
61 memset(&hw_key, 0, sizeof(hw_key));
62
63 /* Must do this after set_primitive() above:
64 */
65 vinfo = draw->render->get_vertex_info(draw->render);
66
67
68 /* Translate from pipeline vertices to hw vertices.
69 */
70 dst_offset = 0;
71 for (i = 0; i < vinfo->num_attribs; i++) {
72 unsigned emit_sz = 0;
73 unsigned src_buffer = 0;
74 unsigned output_format;
75 unsigned src_offset = (vinfo->src_index[i] * 4 * sizeof(float) );
76
77
78
79 switch (vinfo->emit[i]) {
80 case EMIT_4F:
81 output_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
82 emit_sz = 4 * sizeof(float);
83 break;
84 case EMIT_3F:
85 output_format = PIPE_FORMAT_R32G32B32_FLOAT;
86 emit_sz = 3 * sizeof(float);
87 break;
88 case EMIT_2F:
89 output_format = PIPE_FORMAT_R32G32_FLOAT;
90 emit_sz = 2 * sizeof(float);
91 break;
92 case EMIT_1F:
93 output_format = PIPE_FORMAT_R32_FLOAT;
94 emit_sz = 1 * sizeof(float);
95 break;
96 case EMIT_1F_PSIZE:
97 output_format = PIPE_FORMAT_R32_FLOAT;
98 emit_sz = 1 * sizeof(float);
99 src_buffer = 1;
100 src_offset = 0;
101 break;
102 case EMIT_4UB:
103 output_format = PIPE_FORMAT_B8G8R8A8_UNORM;
104 emit_sz = 4 * sizeof(ubyte);
105 default:
106 assert(0);
107 output_format = PIPE_FORMAT_NONE;
108 emit_sz = 0;
109 break;
110 }
111
112 hw_key.element[i].input_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
113 hw_key.element[i].input_buffer = src_buffer;
114 hw_key.element[i].input_offset = src_offset;
115 hw_key.element[i].output_format = output_format;
116 hw_key.element[i].output_offset = dst_offset;
117
118 dst_offset += emit_sz;
119 }
120
121 hw_key.nr_elements = vinfo->num_attribs;
122 hw_key.output_stride = vinfo->size * 4;
123
124 if (!emit->translate ||
125 memcmp(&emit->translate->key, &hw_key, sizeof(hw_key)) != 0)
126 {
127 emit->translate = translate_cache_find(emit->cache, &hw_key);
128 }
129 }
130
131
132 void draw_pt_emit( struct pt_emit *emit,
133 const float (*vertex_data)[4],
134 unsigned vertex_count,
135 unsigned stride,
136 const ushort *elts,
137 unsigned count )
138 {
139 struct draw_context *draw = emit->draw;
140 struct translate *translate = emit->translate;
141 struct vbuf_render *render = draw->render;
142 void *hw_verts;
143
144 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
145 */
146 draw_do_flush( draw, DRAW_FLUSH_BACKEND );
147
148 hw_verts = render->allocate_vertices(render,
149 (ushort)translate->key.output_stride,
150 (ushort)count);
151 if (!hw_verts) {
152 assert(0);
153 return;
154 }
155
156 translate->set_buffer(translate,
157 0,
158 vertex_data,
159 stride );
160
161 translate->set_buffer(translate,
162 1,
163 &draw->rasterizer->point_size,
164 0);
165
166 translate->run( translate,
167 0,
168 vertex_count,
169 hw_verts );
170
171 render->draw(render,
172 elts,
173 count);
174
175 render->release_vertices(render,
176 hw_verts,
177 translate->key.output_stride,
178 vertex_count);
179 }
180
181
182 void draw_pt_emit_linear(struct pt_emit *emit,
183 const float (*vertex_data)[4],
184 unsigned vertex_count,
185 unsigned stride,
186 unsigned start,
187 unsigned count)
188 {
189 struct draw_context *draw = emit->draw;
190 struct translate *translate = emit->translate;
191 struct vbuf_render *render = draw->render;
192 void *hw_verts;
193
194 #if 0
195 debug_printf("Linear emit\n");
196 #endif
197 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
198 */
199 draw_do_flush( draw, DRAW_FLUSH_BACKEND );
200
201 hw_verts = render->allocate_vertices(render,
202 (ushort)translate->key.output_stride,
203 (ushort)count);
204 if (!hw_verts) {
205 assert(0);
206 return;
207 }
208
209 translate->set_buffer(translate, 0,
210 vertex_data, stride);
211
212 translate->set_buffer(translate, 1,
213 &draw->rasterizer->point_size,
214 0);
215
216 translate->run(translate,
217 0,
218 vertex_count,
219 hw_verts);
220
221 render->draw_arrays(render, start, count);
222
223 render->release_vertices(render,
224 hw_verts,
225 translate->key.output_stride,
226 vertex_count);
227 }
228
229 struct pt_emit *draw_pt_emit_create( struct draw_context *draw )
230 {
231 struct pt_emit *emit = CALLOC_STRUCT(pt_emit);
232 if (!emit)
233 return NULL;
234
235 emit->draw = draw;
236 emit->cache = translate_cache_create();
237 if (!emit->cache) {
238 FREE(emit);
239 return NULL;
240 }
241
242 return emit;
243 }
244
245 void draw_pt_emit_destroy( struct pt_emit *emit )
246 {
247 translate_cache_destroy(emit->cache);
248
249 FREE(emit);
250 }