gallium: added util_draw_vertex_buffer()
authorBrian <brian.paul@tungstengraphics.com>
Thu, 20 Mar 2008 16:44:27 +0000 (10:44 -0600)
committerBrian <brian.paul@tungstengraphics.com>
Thu, 20 Mar 2008 16:44:27 +0000 (10:44 -0600)
src/gallium/auxiliary/util/u_draw_quad.c
src/gallium/auxiliary/util/u_draw_quad.h

index 79a69de633dc60e95bcc68bc15b0e722c5126a45..37e85336091dad21a388ef6fe6124677b5c8d745 100644 (file)
 #include "util/u_draw_quad.h"
 
 
+/**
+ * Draw a simple vertex buffer / primitive.
+ * Limited to float[4] vertex attribs, tightly packed.
+ */
+void 
+util_draw_vertex_buffer(struct pipe_context *pipe,
+                        struct pipe_buffer *vbuf,
+                        uint prim_type,
+                        uint num_verts,
+                        uint num_attribs)
+{
+   struct pipe_vertex_buffer vbuffer;
+   struct pipe_vertex_element velement;
+   uint i;
+
+   /* tell pipe about the vertex buffer */
+   vbuffer.buffer = vbuf;
+   vbuffer.pitch = num_attribs * 4 * sizeof(float);  /* vertex size */
+   vbuffer.buffer_offset = 0;
+   pipe->set_vertex_buffer(pipe, 0, &vbuffer);
+
+   /* tell pipe about the vertex attributes */
+   for (i = 0; i < num_attribs; i++) {
+      velement.src_offset = i * 4 * sizeof(float);
+      velement.vertex_buffer_index = 0;
+      velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
+      velement.nr_components = 4;
+      pipe->set_vertex_element(pipe, i, &velement);
+   }
+
+   /* draw */
+   pipe->draw_arrays(pipe, prim_type, 0, num_verts);
+}
+
+
+
 /**
  * Draw screen-aligned textured quad.
+ * Note: this function allocs/destroys a vertex buffer and isn't especially
+ * efficient.
  */
 void 
 util_draw_texquad(struct pipe_context *pipe,
                   float x0, float y0, float x1, float y1, float z)
 {
    struct pipe_buffer *vbuf;
-   struct pipe_vertex_buffer vbuffer;
-   struct pipe_vertex_element velement;
    uint numAttribs = 2, vertexBytes, i, j;
    float *v;
 
@@ -89,24 +125,7 @@ util_draw_texquad(struct pipe_context *pipe,
 
    pipe->winsys->buffer_unmap(pipe->winsys, vbuf);
 
-   /* tell pipe about the vertex buffer */
-   vbuffer.buffer = vbuf;
-   vbuffer.pitch = numAttribs * 4 * sizeof(float);  /* vertex size */
-   vbuffer.buffer_offset = 0;
-   pipe->set_vertex_buffer(pipe, 0, &vbuffer);
-
-   /* tell pipe about the vertex attributes */
-   for (i = 0; i < numAttribs; i++) {
-      velement.src_offset = i * 4 * sizeof(float);
-      velement.vertex_buffer_index = 0;
-      velement.src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
-      velement.nr_components = 4;
-      pipe->set_vertex_element(pipe, i, &velement);
-   }
-
-   /* draw */
-   pipe->draw_arrays(pipe, PIPE_PRIM_TRIANGLE_FAN, 0, 4);
+   util_draw_vertex_buffer(pipe, vbuf, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
 
-   /* XXX: do one-time */
    pipe_buffer_reference(pipe->winsys, &vbuf, NULL);
 }
index a97f55d2efdfdf80c86e47faaa70a75869f51757..5b6539a99ca71d10582677e9d35bfb332b8d62b8 100644 (file)
 #define U_DRAWQUAD_H
 
 
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern void 
+util_draw_vertex_buffer(struct pipe_context *pipe,
+                        struct pipe_buffer *vbuf,
+                        uint num_attribs, uint num_verts, uint prim_type);
+
+
 extern void 
 util_draw_texquad(struct pipe_context *pipe,
                   float x0, float y0, float x1, float y1, float z);
 
 
+#ifdef __cplusplus
+}
+#endif
+
+
 #endif