}
+/**
+ * Draw a simple vertex buffer / primitive.
+ * Limited to float[4] vertex attribs, tightly packed.
+ */
+void
+util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer,
+ uint prim_type, uint num_verts, uint num_attribs)
+{
+ struct pipe_vertex_buffer vbuffer = {0};
+
+ assert(num_attribs <= PIPE_MAX_ATTRIBS);
+
+ vbuffer.user_buffer = buffer;
+ vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */
+
+ /* note: vertex elements already set by caller */
+
+ cso_set_vertex_buffers(cso, 1, &vbuffer);
+ cso_draw_arrays(cso, prim_type, 0, num_verts);
+}
+
/**
* Draw screen-aligned textured quad.
struct pipe_resource *vbuf, uint offset,
uint num_attribs, uint num_verts, uint prim_type);
+void
+util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer,
+ uint prim_type, uint num_verts, uint num_attribs);
extern void
util_draw_texquad(struct pipe_context *pipe, struct cso_context *cso,
VGint num_verts;
VGboolean dirty;
- struct pipe_resource *vbuf;
+ void *user_vbuf;
struct pipe_screen *screen;
};
poly->size = size;
poly->num_verts = 0;
poly->dirty = VG_TRUE;
- poly->vbuf = NULL;
+ poly->user_vbuf = NULL;
return poly;
}
memcpy(poly->data, data, sizeof(float) * COMPONENTS * size);
poly->num_verts = size;
poly->dirty = VG_TRUE;
- poly->vbuf = NULL;
+ poly->user_vbuf = NULL;
return poly;
}
void polygon_destroy(struct polygon *poly)
{
- if (poly->vbuf)
- pipe_resource_reference(&poly->vbuf, NULL);
-
free(poly->data);
free(poly);
}
static void polygon_prepare_buffer(struct vg_context *ctx,
struct polygon *poly)
{
- int vert_size;
struct pipe_context *pipe;
- vert_size = poly->num_verts * COMPONENTS * sizeof(float);
-
/*polygon_print(poly);*/
pipe = ctx->pipe;
- if (poly->vbuf == NULL || poly->dirty) {
- if (poly->vbuf) {
- pipe_resource_reference(&poly->vbuf,
- NULL);
- }
+ if (poly->user_vbuf == NULL || poly->dirty) {
poly->screen = pipe->screen;
- poly->vbuf= pipe_user_buffer_create(poly->screen,
- poly->data,
- vert_size,
- PIPE_BIND_VERTEX_BUFFER);
+ poly->user_vbuf = poly->data;
poly->dirty = VG_FALSE;
}
}
/* tell renderer about the vertex buffer */
memset(&vbuffer, 0, sizeof(vbuffer));
- vbuffer.buffer = poly->vbuf;
+ vbuffer.user_buffer = poly->user_vbuf;
vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */
- vbuffer.buffer_offset = 0;
renderer_polygon_stencil_begin(ctx->renderer,
&velement, ctx->state.vg.fill_rule, VG_FALSE);
/* tell renderer about the vertex buffer */
memset(&vbuffer, 0, sizeof(vbuffer));
vbuffer.stride = COMPONENTS * sizeof(float); /* vertex size */
- vbuffer.buffer_offset = 0;
/* prepare the stencil buffer */
renderer_polygon_stencil_begin(ctx->renderer,
struct polygon *poly = (((struct polygon**)polys->data)[i]);
polygon_prepare_buffer(ctx, poly);
- vbuffer.buffer = poly->vbuf;
+ vbuffer.user_buffer = poly->user_vbuf;
renderer_polygon_stencil(ctx->renderer, &vbuffer,
PIPE_PRIM_TRIANGLE_FAN, 0, (VGuint) poly->num_verts);
*/
static void renderer_quad_draw(struct renderer *r)
{
- struct pipe_resource *buf;
-
- buf = pipe_user_buffer_create(r->pipe->screen,
- r->vertices,
- sizeof(r->vertices),
- PIPE_BIND_VERTEX_BUFFER);
- if (buf) {
- util_draw_vertex_buffer(r->pipe, r->cso, buf, 0,
- PIPE_PRIM_TRIANGLE_FAN,
- Elements(r->vertices), /* verts */
- Elements(r->vertices[0])); /* attribs/vert */
-
- pipe_resource_reference(&buf, NULL);
- }
+ util_draw_user_vertex_buffer(r->cso, r->vertices, PIPE_PRIM_TRIANGLE_FAN,
+ Elements(r->vertices), /* verts */
+ Elements(r->vertices[0])); /* attribs/vert */
}
/**