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