util: don't define isfinite(), isnan() for MSVC >= 1800
[mesa.git] / src / gallium / auxiliary / util / u_draw_quad.c
index 1fbe12171c5eb48cfa3668a4a0e7a07f55253ba9..03784bf2ccf79ff6a4a0865f5a45c776fa0cb03f 100644 (file)
@@ -1,6 +1,6 @@
 /**************************************************************************
  *
- * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
+ * Copyright 2008 VMware, Inc.
  * All Rights Reserved.
  *
  * Permission is hereby granted, free of charge, to any person obtaining a
@@ -18,7 +18,7 @@
  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
- * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR
+ * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
  * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -42,6 +42,7 @@ void
 util_draw_vertex_buffer(struct pipe_context *pipe,
                         struct cso_context *cso,
                         struct pipe_resource *vbuf,
+                        uint vbuf_slot,
                         uint offset,
                         uint prim_type,
                         uint num_verts,
@@ -60,15 +61,36 @@ util_draw_vertex_buffer(struct pipe_context *pipe,
    /* note: vertex elements already set by caller */
 
    if (cso) {
-      cso_set_vertex_buffers(cso, 1, &vbuffer);
+      cso_set_vertex_buffers(cso, vbuf_slot, 1, &vbuffer);
       cso_draw_arrays(cso, prim_type, 0, num_verts);
    } else {
-      pipe->set_vertex_buffers(pipe, 1, &vbuffer);
+      pipe->set_vertex_buffers(pipe, vbuf_slot, 1, &vbuffer);
       util_draw_arrays(pipe, prim_type, 0, num_verts);
    }
 }
 
 
+/**
+ * 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, 0, 1, &vbuffer);
+   cso_draw_arrays(cso, prim_type, 0, num_verts);
+}
+
 
 /**
  * Draw screen-aligned textured quad.
@@ -76,6 +98,7 @@ util_draw_vertex_buffer(struct pipe_context *pipe,
  */
 void 
 util_draw_texquad(struct pipe_context *pipe, struct cso_context *cso,
+                  uint vbuf_slot,
                   float x0, float y0, float x1, float y1, float z)
 {
    uint numAttribs = 2, i, j;
@@ -124,12 +147,12 @@ util_draw_texquad(struct pipe_context *pipe, struct cso_context *cso,
       goto out;
    pipe_buffer_write(pipe, vbuf, 0, vertexBytes, v);
 
-   util_draw_vertex_buffer(pipe, cso, vbuf, 0, PIPE_PRIM_TRIANGLE_FAN, 4, 2);
+   util_draw_vertex_buffer(pipe, cso, vbuf, vbuf_slot, 0,
+                           PIPE_PRIM_TRIANGLE_FAN, 4, 2);
 
 out:
    if (vbuf)
       pipe_resource_reference(&vbuf, NULL);
    
-   if (v)
-      FREE(v);
+   FREE(v);
 }