}
-void
-draw_set_index_buffer(struct draw_context *draw,
- const struct pipe_index_buffer *ib)
-{
- if (ib)
- memcpy(&draw->pt.index_buffer, ib, sizeof(draw->pt.index_buffer));
- else
- memset(&draw->pt.index_buffer, 0, sizeof(draw->pt.index_buffer));
-}
-
-
/**
- * Tell drawing context where to find mapped index/element buffer.
+ * Tell the draw module where vertex indexes/elements are located, and
+ * their size (in bytes).
+ *
+ * Note: the caller must apply the pipe_index_buffer::offset value to
+ * the address. The draw module doesn't do that.
*/
void
-draw_set_mapped_index_buffer(struct draw_context *draw,
- const void *elements)
-{
- draw->pt.user.elts = elements;
+draw_set_indexes(struct draw_context *draw,
+ const void *elements, unsigned elem_size)
+{
+ assert(elem_size == 0 ||
+ elem_size == 1 ||
+ elem_size == 2 ||
+ elem_size == 4);
+ draw->pt.user.elts = elements;
+ draw->pt.user.eltSize = elem_size;
}
unsigned count,
const struct pipe_vertex_element *elements);
-void draw_set_index_buffer(struct draw_context *draw,
- const struct pipe_index_buffer *ib);
-
-void draw_set_mapped_index_buffer(struct draw_context *draw,
- const void *elements);
+void draw_set_indexes(struct draw_context *draw,
+ const void *elements, unsigned elem_size);
void draw_set_mapped_vertex_buffer(struct draw_context *draw,
unsigned attr, const void *buffer);
struct pipe_vertex_element vertex_element[PIPE_MAX_ATTRIBS];
unsigned nr_vertex_elements;
- struct pipe_index_buffer index_buffer;
-
/* user-space vertex data, buffers */
struct {
/** vertex element/index buffer (ex: glDrawElements) */
uint j;
if (draw->pt.user.eltSize) {
- const char *elts;
-
/* indexed arrays */
- elts = (const char *) draw->pt.user.elts;
- elts += draw->pt.index_buffer.offset;
switch (draw->pt.user.eltSize) {
case 1:
{
- const ubyte *elem = (const ubyte *) elts;
+ const ubyte *elem = (const ubyte *) draw->pt.user.elts;
ii = elem[start + i];
}
break;
case 2:
{
- const ushort *elem = (const ushort *) elts;
+ const ushort *elem = (const ushort *) draw->pt.user.elts;
ii = elem[start + i];
}
break;
case 4:
{
- const uint *elem = (const uint *) elts;
+ const uint *elem = (const uint *) draw->pt.user.elts;
ii = elem[start + i];
}
break;
if (draw->pt.user.elts) {
/* indexed prims (draw_elements) */
- const char *elts =
- (const char *) draw->pt.user.elts + draw->pt.index_buffer.offset;
-
cur_start = start;
cur_count = 0;
switch (draw->pt.user.eltSize) {
case 1:
{
- const ubyte *elt_ub = (const ubyte *) elts;
+ const ubyte *elt_ub = (const ubyte *) draw->pt.user.elts;
PRIM_RESTART_LOOP(elt_ub);
}
break;
case 2:
{
- const ushort *elt_us = (const ushort *) elts;
+ const ushort *elt_us = (const ushort *) draw->pt.user.elts;
PRIM_RESTART_LOOP(elt_us);
}
break;
case 4:
{
- const uint *elt_ui = (const uint *) elts;
+ const uint *elt_ui = (const uint *) draw->pt.user.elts;
PRIM_RESTART_LOOP(elt_ui);
}
break;
if (info->indexed)
assert(draw->pt.user.elts);
- draw->pt.user.eltSize =
- (info->indexed) ? draw->pt.index_buffer.index_size : 0;
-
draw->pt.user.eltBias = info->index_bias;
draw->pt.user.min_index = info->min_index;
draw->pt.user.max_index = info->max_index;
unsigned istart, unsigned icount)
{
struct draw_context *draw = vsplit->draw;
- const ELT_TYPE *ib = (const ELT_TYPE *)
- ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
+ const ELT_TYPE *ib = (const ELT_TYPE *) draw->pt.user.elts;
const unsigned min_index = draw->pt.user.min_index;
const unsigned max_index = draw->pt.user.max_index;
const int elt_bias = draw->pt.user.eltBias;
boolean close, unsigned iclose)
{
struct draw_context *draw = vsplit->draw;
- const ELT_TYPE *ib = (const ELT_TYPE *)
- ((const char *) draw->pt.user.elts + draw->pt.index_buffer.offset);
+ const ELT_TYPE *ib = (const ELT_TYPE *) draw->pt.user.elts;
const int ibias = draw->pt.user.eltBias;
unsigned i;
mapped_indices = i915->index_buffer.user_buffer;
if (!mapped_indices)
mapped_indices = i915_buffer(i915->index_buffer.buffer)->data;
+ draw_set_indexes(draw,
+ (ubyte *) mapped_indices + i915->index_buffer.offset,
+ i915->index_buffer.index_size);
}
- draw_set_mapped_index_buffer(draw, mapped_indices);
if (i915->constants[PIPE_SHADER_VERTEX])
draw_set_mapped_constant_buffer(draw, PIPE_SHADER_VERTEX, 0,
draw_vbo(i915->draw, info);
if (mapped_indices)
- draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_indexes(draw, NULL, 0);
if (i915->num_vertex_sampler_views > 0)
i915_cleanup_vertex_sampling(i915);
memcpy(&i915->index_buffer, ib, sizeof(i915->index_buffer));
else
memset(&i915->index_buffer, 0, sizeof(i915->index_buffer));
-
- /* pass-through to draw module */
- draw_set_index_buffer(i915->draw, ib);
}
static void
mapped_indices = lp->index_buffer.user_buffer;
if (!mapped_indices)
mapped_indices = llvmpipe_resource_data(lp->index_buffer.buffer);
- }
- draw_set_mapped_index_buffer(draw, mapped_indices);
+ draw_set_indexes(draw,
+ (ubyte *) mapped_indices + lp->index_buffer.offset,
+ lp->index_buffer.index_size);
+ }
llvmpipe_prepare_vertex_sampling(lp,
lp->num_vertex_sampler_views,
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
- draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_indexes(draw, NULL, 0);
}
llvmpipe_cleanup_vertex_sampling(lp);
memcpy(&llvmpipe->index_buffer, ib, sizeof(llvmpipe->index_buffer));
else
memset(&llvmpipe->index_buffer, 0, sizeof(llvmpipe->index_buffer));
-
- draw_set_index_buffer(llvmpipe->draw, ib);
}
void
pipe_buffer_map(pipe, nv30->idxbuf.buffer,
PIPE_TRANSFER_UNSYNCHRONIZED |
PIPE_TRANSFER_READ, &transferi);
- draw_set_index_buffer(draw, &nv30->idxbuf);
- draw_set_mapped_index_buffer(draw, map);
+ draw_set_indexes(draw,
+ (ubyte *) map + nv30->idxbuf.offset,
+ nv30->idxbuf.index_size);
} else {
- draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_indexes(draw, NULL, 0);
}
draw_vbo(draw, info);
{
struct r300_context* r300 = r300_context(pipe);
- draw_set_index_buffer(r300->draw, ib);
-
if (ib) {
+ const void *buf = NULL;
if (ib->user_buffer) {
- draw_set_mapped_index_buffer(r300->draw,
- ib->user_buffer);
+ buf = ib->user_buffer;
} else if (ib->buffer) {
- draw_set_mapped_index_buffer(r300->draw,
- r300_resource(ib->buffer)->malloced_buffer);
+ buf = r300_resource(ib->buffer)->malloced_buffer;
}
+ draw_set_indexes(r300->draw,
+ (const ubyte *) buf + ib->offset,
+ ib->index_size);
}
}
mapped_indices = sp->index_buffer.user_buffer;
if (!mapped_indices)
mapped_indices = softpipe_resource(sp->index_buffer.buffer)->data;
+
+ draw_set_indexes(draw,
+ (ubyte *) mapped_indices + sp->index_buffer.offset,
+ sp->index_buffer.index_size);
}
- draw_set_mapped_index_buffer(draw, mapped_indices);
for (i = 0; i < sp->num_so_targets; i++) {
void *buf = softpipe_resource(sp->so_targets[i]->target.buffer)->data;
draw_set_mapped_vertex_buffer(draw, i, NULL);
}
if (mapped_indices) {
- draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_indexes(draw, NULL, 0);
}
draw_set_mapped_so_targets(draw, 0, NULL);
memcpy(&softpipe->index_buffer, ib, sizeof(softpipe->index_buffer));
else
memset(&softpipe->index_buffer, 0, sizeof(softpipe->index_buffer));
-
- draw_set_index_buffer(softpipe->draw, ib);
}
}
}
- /* TODO move this to update_swtnl_draw */
- draw_set_index_buffer(draw, &svga->curr.ib);
-
/* Map index buffer, if present */
map = NULL;
if (info->indexed && svga->curr.ib.buffer) {
map = pipe_buffer_map(&svga->pipe, svga->curr.ib.buffer,
PIPE_TRANSFER_READ,
&ib_transfer);
+ draw_set_indexes(draw,
+ (const ubyte *) map + svga->curr.ib.offset,
+ svga->curr.ib.index_size);
}
- draw_set_mapped_index_buffer(draw, map);
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
map = pipe_buffer_map(&svga->pipe,
if (ib_transfer) {
pipe_buffer_unmap(&svga->pipe, ib_transfer);
- draw_set_mapped_index_buffer(draw, NULL);
+ draw_set_indexes(draw, NULL, 0);
}
if (svga->curr.cb[PIPE_SHADER_VERTEX]) {
mapped_indices = ib->ptr;
}
- draw_set_index_buffer(draw, &ibuffer);
- draw_set_mapped_index_buffer(draw, mapped_indices);
+ draw_set_indexes(draw,
+ (ubyte *) mapped_indices + ibuffer.offset,
+ ibuffer.index_size);
}
/* set the constant buffer */
* unmap vertex/index buffers
*/
if (ib) {
- draw_set_mapped_index_buffer(draw, NULL);
- draw_set_index_buffer(draw, NULL);
-
+ draw_set_indexes(draw, NULL, 0);
if (ib_transfer)
pipe_buffer_unmap(pipe, ib_transfer);
pipe_resource_reference(&ibuffer.buffer, NULL);