Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 1 | #include "draw/draw_context.h" |
| 2 | #include "pipe/p_context.h" |
| 3 | #include "pipe/p_state.h" |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 4 | #include "pipe/p_inlines.h" |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 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; |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 19 | struct pipe_screen *pscreen = pipe->screen; |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 20 | unsigned i; |
| 21 | |
Stephane Marchesin | fb19b33 | 2008-04-02 18:26:49 +0200 | [diff] [blame] | 22 | nv10_emit_hw_state(nv10); |
| 23 | |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 24 | /* |
| 25 | * Map vertex buffers |
| 26 | */ |
Ben Skeggs | 7d2085b | 2008-04-15 13:25:28 +1000 | [diff] [blame] | 27 | for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 28 | if (nv10->vtxbuf[i].buffer) { |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 29 | void *buf = |
| 30 | pipe_buffer_map(pscreen, nv10->vtxbuf[i].buffer, |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 31 | PIPE_BUFFER_USAGE_CPU_READ); |
| 32 | draw_set_mapped_vertex_buffer(draw, i, buf); |
| 33 | } |
| 34 | } |
| 35 | /* Map index buffer, if present */ |
| 36 | if (indexBuffer) { |
| 37 | void *mapped_indexes |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 38 | = pipe_buffer_map(pscreen, indexBuffer, |
| 39 | PIPE_BUFFER_USAGE_CPU_READ); |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 40 | draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes); |
| 41 | } |
| 42 | else { |
| 43 | /* no index/element buffer */ |
| 44 | draw_set_mapped_element_buffer(draw, 0, NULL); |
| 45 | } |
| 46 | |
Ben Skeggs | 5a01060 | 2008-06-23 00:14:21 +1000 | [diff] [blame] | 47 | draw_set_mapped_constant_buffer(draw, |
| 48 | nv10->constbuf[PIPE_SHADER_VERTEX], |
| 49 | nv10->constbuf_nr[PIPE_SHADER_VERTEX]); |
Stephane Marchesin | 7f21b63 | 2008-04-03 04:07:16 +0200 | [diff] [blame] | 50 | |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 51 | /* draw! */ |
| 52 | draw_arrays(nv10->draw, prim, start, count); |
| 53 | |
| 54 | /* |
| 55 | * unmap vertex/index buffers |
| 56 | */ |
Ben Skeggs | 7d2085b | 2008-04-15 13:25:28 +1000 | [diff] [blame] | 57 | for (i = 0; i < PIPE_MAX_ATTRIBS; i++) { |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 58 | if (nv10->vtxbuf[i].buffer) { |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 59 | pipe_buffer_unmap(pscreen, nv10->vtxbuf[i].buffer); |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 60 | draw_set_mapped_vertex_buffer(draw, i, NULL); |
| 61 | } |
| 62 | } |
| 63 | if (indexBuffer) { |
Ben Skeggs | 6b3ca67 | 2009-06-05 11:21:08 +1000 | [diff] [blame] | 64 | pipe_buffer_unmap(pscreen, indexBuffer); |
Stephane Marchesin | d493203 | 2008-03-15 05:37:57 +0100 | [diff] [blame] | 65 | draw_set_mapped_element_buffer(draw, 0, NULL); |
| 66 | } |
| 67 | |
| 68 | return TRUE; |
| 69 | } |
| 70 | |
| 71 | boolean nv10_draw_arrays( struct pipe_context *pipe, |
| 72 | unsigned prim, unsigned start, unsigned count) |
| 73 | { |
| 74 | return nv10_draw_elements(pipe, NULL, 0, prim, start, count); |
| 75 | } |
| 76 | |
| 77 | |
| 78 | |