Merge branch 'mesa_7_5_branch' into mesa_7_6_branch
[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 #include "pipe/p_inlines.h"
5
6 #include "nv04_context.h"
7 #include "nv04_state.h"
8
9 #include "nouveau/nouveau_channel.h"
10 #include "nouveau/nouveau_pushbuf.h"
11
12 boolean nv04_draw_elements( struct pipe_context *pipe,
13 struct pipe_buffer *indexBuffer,
14 unsigned indexSize,
15 unsigned prim, unsigned start, unsigned count)
16 {
17 struct pipe_screen *pscreen = pipe->screen;
18 struct nv04_context *nv04 = nv04_context( pipe );
19 struct draw_context *draw = nv04->draw;
20 unsigned i;
21
22 nv04_emit_hw_state(nv04);
23
24 /*
25 * Map vertex buffers
26 */
27 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
28 if (nv04->vtxbuf[i].buffer) {
29 void *buf
30 = pipe_buffer_map(pscreen,
31 nv04->vtxbuf[i].buffer,
32 PIPE_BUFFER_USAGE_CPU_READ);
33 draw_set_mapped_vertex_buffer(draw, i, buf);
34 }
35 }
36 /* Map index buffer, if present */
37 if (indexBuffer) {
38 void *mapped_indexes
39 = pipe_buffer_map(pscreen, indexBuffer,
40 PIPE_BUFFER_USAGE_CPU_READ);
41 draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
42 }
43 else {
44 /* no index/element buffer */
45 draw_set_mapped_element_buffer(draw, 0, NULL);
46 }
47
48 draw_set_mapped_constant_buffer(draw,
49 nv04->constbuf[PIPE_SHADER_VERTEX],
50 nv04->constbuf_nr[PIPE_SHADER_VERTEX]);
51
52 /* draw! */
53 draw_arrays(nv04->draw, prim, start, count);
54
55 /*
56 * unmap vertex/index buffers
57 */
58 for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
59 if (nv04->vtxbuf[i].buffer) {
60 pipe_buffer_unmap(pscreen, nv04->vtxbuf[i].buffer);
61 draw_set_mapped_vertex_buffer(draw, i, NULL);
62 }
63 }
64 if (indexBuffer) {
65 pipe_buffer_unmap(pscreen, indexBuffer);
66 draw_set_mapped_element_buffer(draw, 0, NULL);
67 }
68
69 return TRUE;
70 }
71
72 boolean nv04_draw_arrays( struct pipe_context *pipe,
73 unsigned prim, unsigned start, unsigned count)
74 {
75 printf("coucou in draw arrays\n");
76 return nv04_draw_elements(pipe, NULL, 0, prim, start, count);
77 }
78
79
80