025ad6de4bdeb360005b24f98744636166acfe95
[mesa.git] / src / gallium / drivers / nv10 / nv10_vbo.c
1 #include "draw/draw_context.h"
2 #include "pipe/p_context.h"
3 #include "pipe/p_state.h"
4 #include "pipe/p_util.h"
5
6 #include "nv10_context.h"
7 #include "nv10_state.h"
8
9 #include "nouveau/nouveau_channel.h"
10 #include "nouveau/nouveau_pushbuf.h"
11
12 boolean nv10_draw_elements( struct pipe_context *pipe,
13 struct pipe_buffer *indexBuffer,
14 unsigned indexSize,
15 unsigned prim, unsigned start, unsigned count)
16 {
17 struct nv10_context *nv10 = nv10_context( pipe );
18 struct draw_context *draw = nv10->draw;
19 unsigned i;
20
21 /*
22 * Map vertex buffers
23 */
24 for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
25 if (nv10->vtxbuf[i].buffer) {
26 void *buf
27 = pipe->winsys->buffer_map(pipe->winsys,
28 nv10->vtxbuf[i].buffer,
29 PIPE_BUFFER_USAGE_CPU_READ);
30 draw_set_mapped_vertex_buffer(draw, i, buf);
31 }
32 }
33 /* Map index buffer, if present */
34 if (indexBuffer) {
35 void *mapped_indexes
36 = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
37 PIPE_BUFFER_USAGE_CPU_READ);
38 draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
39 }
40 else {
41 /* no index/element buffer */
42 draw_set_mapped_element_buffer(draw, 0, NULL);
43 }
44
45 /* draw! */
46 draw_arrays(nv10->draw, prim, start, count);
47
48 /*
49 * unmap vertex/index buffers
50 */
51 for (i = 0; i < PIPE_ATTRIB_MAX; i++) {
52 if (nv10->vtxbuf[i].buffer) {
53 pipe->winsys->buffer_unmap(pipe->winsys, nv10->vtxbuf[i].buffer);
54 draw_set_mapped_vertex_buffer(draw, i, NULL);
55 }
56 }
57 if (indexBuffer) {
58 pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
59 draw_set_mapped_element_buffer(draw, 0, NULL);
60 }
61
62 return TRUE;
63 }
64
65 boolean nv10_draw_arrays( struct pipe_context *pipe,
66 unsigned prim, unsigned start, unsigned count)
67 {
68 return nv10_draw_elements(pipe, NULL, 0, prim, start, count);
69 }
70
71
72