1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
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"
38 struct draw_context
*draw
;
40 struct translate
*translate
;
42 struct translate_cache
*cache
;
45 void draw_pt_emit_prepare( struct pt_emit
*emit
,
48 struct draw_context
*draw
= emit
->draw
;
49 const struct vertex_info
*vinfo
;
51 struct translate_key hw_key
;
55 ok
= draw
->render
->set_primitive(draw
->render
, prim
);
61 memset(&hw_key
, 0, sizeof(hw_key
));
63 /* Must do this after set_primitive() above:
65 vinfo
= draw
->render
->get_vertex_info(draw
->render
);
68 /* Translate from pipeline vertices to hw vertices.
71 for (i
= 0; i
< vinfo
->num_attribs
; i
++) {
73 unsigned src_buffer
= 0;
74 unsigned output_format
;
75 unsigned src_offset
= (vinfo
->src_index
[i
] * 4 * sizeof(float) );
79 switch (vinfo
->emit
[i
]) {
81 output_format
= PIPE_FORMAT_R32G32B32A32_FLOAT
;
82 emit_sz
= 4 * sizeof(float);
85 output_format
= PIPE_FORMAT_R32G32B32_FLOAT
;
86 emit_sz
= 3 * sizeof(float);
89 output_format
= PIPE_FORMAT_R32G32_FLOAT
;
90 emit_sz
= 2 * sizeof(float);
93 output_format
= PIPE_FORMAT_R32_FLOAT
;
94 emit_sz
= 1 * sizeof(float);
97 output_format
= PIPE_FORMAT_R32_FLOAT
;
98 emit_sz
= 1 * sizeof(float);
103 output_format
= PIPE_FORMAT_B8G8R8A8_UNORM
;
104 emit_sz
= 4 * sizeof(ubyte
);
107 output_format
= PIPE_FORMAT_NONE
;
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
;
118 dst_offset
+= emit_sz
;
121 hw_key
.nr_elements
= vinfo
->num_attribs
;
122 hw_key
.output_stride
= vinfo
->size
* 4;
124 if (!emit
->translate
||
125 memcmp(&emit
->translate
->key
, &hw_key
, sizeof(hw_key
)) != 0)
127 emit
->translate
= translate_cache_find(emit
->cache
, &hw_key
);
132 void draw_pt_emit( struct pt_emit
*emit
,
133 const float (*vertex_data
)[4],
134 unsigned vertex_count
,
139 struct draw_context
*draw
= emit
->draw
;
140 struct translate
*translate
= emit
->translate
;
141 struct vbuf_render
*render
= draw
->render
;
144 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
146 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
148 hw_verts
= render
->allocate_vertices(render
,
149 (ushort
)translate
->key
.output_stride
,
156 translate
->set_buffer(translate
,
161 translate
->set_buffer(translate
,
163 &draw
->rasterizer
->point_size
,
166 translate
->run( translate
,
175 render
->release_vertices(render
,
177 translate
->key
.output_stride
,
182 void draw_pt_emit_linear(struct pt_emit
*emit
,
183 const float (*vertex_data
)[4],
184 unsigned vertex_count
,
189 struct draw_context
*draw
= emit
->draw
;
190 struct translate
*translate
= emit
->translate
;
191 struct vbuf_render
*render
= draw
->render
;
195 debug_printf("Linear emit\n");
197 /* XXX: need to flush to get prim_vbuf.c to release its allocation??
199 draw_do_flush( draw
, DRAW_FLUSH_BACKEND
);
201 hw_verts
= render
->allocate_vertices(render
,
202 (ushort
)translate
->key
.output_stride
,
209 translate
->set_buffer(translate
, 0,
210 vertex_data
, stride
);
212 translate
->set_buffer(translate
, 1,
213 &draw
->rasterizer
->point_size
,
216 translate
->run(translate
,
221 render
->draw_arrays(render
, start
, count
);
223 render
->release_vertices(render
,
225 translate
->key
.output_stride
,
229 struct pt_emit
*draw_pt_emit_create( struct draw_context
*draw
)
231 struct pt_emit
*emit
= CALLOC_STRUCT(pt_emit
);
236 emit
->cache
= translate_cache_create();
245 void draw_pt_emit_destroy( struct pt_emit
*emit
)
247 translate_cache_destroy(emit
->cache
);