nv04_vbo.c 1.76 KB
Newer Older
Stéphane Marchesin's avatar
nv04.  
Stéphane Marchesin committed
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
#include "draw/draw_context.h"
#include "pipe/p_context.h"
#include "pipe/p_state.h"

#include "nv04_context.h"
#include "nv04_state.h"

#include "nouveau/nouveau_channel.h"
#include "nouveau/nouveau_pushbuf.h"

boolean nv04_draw_elements( struct pipe_context *pipe,
                    struct pipe_buffer *indexBuffer,
                    unsigned indexSize,
                    unsigned prim, unsigned start, unsigned count)
{
	struct nv04_context *nv04 = nv04_context( pipe );
	struct draw_context *draw = nv04->draw;
	unsigned i;

	/*
	 * Map vertex buffers
	 */
	for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
		if (nv04->vertex_buffer[i].buffer) {
			void *buf
Zack Rusin's avatar
Zack Rusin committed
26
				= pipe->winsys->buffer_map(pipe->winsys,
Stéphane Marchesin's avatar
nv04.  
Stéphane Marchesin committed
27 28 29 30 31 32 33 34
						nv04->vertex_buffer[i].buffer,
						PIPE_BUFFER_USAGE_CPU_READ);
			draw_set_mapped_vertex_buffer(draw, i, buf);
		}
	}
	/* Map index buffer, if present */
	if (indexBuffer) {
		void *mapped_indexes
Zack Rusin's avatar
Zack Rusin committed
35
			= pipe->winsys->buffer_map(pipe->winsys, indexBuffer,
Stéphane Marchesin's avatar
nv04.  
Stéphane Marchesin committed
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
					PIPE_BUFFER_USAGE_CPU_READ);
		draw_set_mapped_element_buffer(draw, indexSize, mapped_indexes);
	}
	else {
		/* no index/element buffer */
		draw_set_mapped_element_buffer(draw, 0, NULL);
	}

	/* draw! */
	draw_arrays(nv04->draw, prim, start, count);

	/*
	 * unmap vertex/index buffers
	 */
	for (i = 0; i < PIPE_MAX_ATTRIBS; i++) {
		if (nv04->vertex_buffer[i].buffer) {
Zack Rusin's avatar
Zack Rusin committed
52
			pipe->winsys->buffer_unmap(pipe->winsys, nv04->vertex_buffer[i].buffer);
Stéphane Marchesin's avatar
nv04.  
Stéphane Marchesin committed
53 54 55 56
			draw_set_mapped_vertex_buffer(draw, i, NULL);
		}
	}
	if (indexBuffer) {
Zack Rusin's avatar
Zack Rusin committed
57
		pipe->winsys->buffer_unmap(pipe->winsys, indexBuffer);
Stéphane Marchesin's avatar
nv04.  
Stéphane Marchesin committed
58 59 60 61 62 63 64 65 66 67 68 69 70 71
		draw_set_mapped_element_buffer(draw, 0, NULL);
	}

	return TRUE;
}

boolean nv04_draw_arrays( struct pipe_context *pipe,
				 unsigned prim, unsigned start, unsigned count)
{
	return nv04_draw_elements(pipe, NULL, 0, prim, start, count);
}