Merge commit 'origin/gallium-master-merge'
[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 nv04_emit_hw_state(nv04);
21
22 /*
23 * Map vertex buffers
24 */
25 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
26 if (nv04->vtxbuf[i].buffer) {
27 void *buf
28 = pipe->winsys->buffer_map(pipe->winsys,
29 nv04->vtxbuf[i].buffer,
30 PIPE_BUFFER_USAGE_CPU_READ);
31 draw_set_mapped_vertex_buffer(draw, i, buf);
32 }
33 }
34 /* Map index buffer, if present */
35 if (indexBuffer) {
36 void *mapped_indexes
37 = pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
38 PIPE_BUFFER_USAGE_CPU_READ);
39 draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
40 }
41 else {
42 /* no index/element buffer */
43 draw_set_mapped_element_buffer(draw, 0, NULL);
44 }
45
46 draw_set_mapped_constant_buffer(draw,
47 nv04->constbuf[PIPE_SHADER_VERTEX],
48 nv04->constbuf_nr[PIPE_SHADER_VERTEX]);
49
50 /* draw! */
51 draw_arrays(nv04->draw, prim, start, count);
52
53 /*
54 * unmap vertex/index buffers
55 */
56 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
57 if (nv04->vtxbuf[i].buffer) {
58 pipe->winsys->buffer_unmap(pipe->winsys, nv04->vtxbuf[i].buffer);
59 draw_set_mapped_vertex_buffer(draw, i, NULL);
60 }
61 }
62 if (indexBuffer) {
63 pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
64 draw_set_mapped_element_buffer(draw, 0, NULL);
65 }
66
67 return TRUE;
68 }
69
70 boolean nv04_draw_arrays( struct pipe_context *pipe,
71 unsigned prim, unsigned start, unsigned count)
72 {
73 printf("coucou in draw arrays\n");
74 return nv04_draw_elements(pipe, NULL, 0, prim, start, count);
75 }
76
77
78