cso: add set_index_buffer and draw_vbo passthrough functions
[mesa.git] / src / gallium / auxiliary / cso_cache / cso_context.c
index 60a6e0262e0bc0bfb45145c66a169bf4715ec73f..9ec7a2a9676108fbf0c9254b059d3966761da4e9 100644 (file)
@@ -36,6 +36,7 @@
   */
 
 #include "pipe/p_state.h"
+#include "util/u_draw.h"
 #include "util/u_framebuffer.h"
 #include "util/u_inlines.h"
 #include "util/u_math.h"
@@ -863,10 +864,18 @@ void cso_save_vertex_buffers(struct cso_context *ctx)
 
 void cso_restore_vertex_buffers(struct cso_context *ctx)
 {
+   unsigned i;
+
    util_copy_vertex_buffers(ctx->vertex_buffers,
                             &ctx->nr_vertex_buffers,
                             ctx->vertex_buffers_saved,
                             ctx->nr_vertex_buffers_saved);
+
+   for (i = 0; i < ctx->nr_vertex_buffers_saved; i++) {
+      pipe_resource_reference(&ctx->vertex_buffers_saved[i].buffer, NULL);
+   }
+   ctx->nr_vertex_buffers_saved = 0;
+
    ctx->pipe->set_vertex_buffers(ctx->pipe, ctx->nr_vertex_buffers,
                                  ctx->vertex_buffers);
 }
@@ -1282,3 +1291,37 @@ cso_restore_stream_outputs(struct cso_context *ctx)
    ctx->nr_so_targets = ctx->nr_so_targets_saved;
    ctx->nr_so_targets_saved = 0;
 }
+
+/* drawing */
+
+void
+cso_set_index_buffer(struct cso_context *cso,
+                     const struct pipe_index_buffer *ib)
+{
+   struct pipe_context *pipe = cso->pipe;
+   pipe->set_index_buffer(pipe, ib);
+}
+
+void
+cso_draw_vbo(struct cso_context *cso,
+             const struct pipe_draw_info *info)
+{
+   struct pipe_context *pipe = cso->pipe;
+   pipe->draw_vbo(pipe, info);
+}
+
+void
+cso_draw_arrays(struct cso_context *cso, uint mode, uint start, uint count)
+{
+   struct pipe_draw_info info;
+
+   util_draw_init_info(&info);
+
+   info.mode = mode;
+   info.start = start;
+   info.count = count;
+   info.min_index = start;
+   info.max_index = start + count - 1;
+
+   cso_draw_vbo(cso, &info);
+}