1 /**************************************************************************
3 * Copyright 2008 VMware, Inc.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************/
29 #include "pipe/p_context.h"
30 #include "pipe/p_defines.h"
31 #include "util/u_inlines.h"
32 #include "util/u_draw_quad.h"
33 #include "util/u_memory.h"
34 #include "cso_cache/cso_context.h"
38 * Draw a simple vertex buffer / primitive.
39 * Limited to float[4] vertex attribs, tightly packed.
42 util_draw_vertex_buffer(struct pipe_context
*pipe
,
43 struct cso_context
*cso
,
44 struct pipe_resource
*vbuf
,
51 struct pipe_vertex_buffer vbuffer
;
53 assert(num_attribs
<= PIPE_MAX_ATTRIBS
);
55 /* tell pipe about the vertex buffer */
56 memset(&vbuffer
, 0, sizeof(vbuffer
));
57 vbuffer
.buffer
.resource
= vbuf
;
58 vbuffer
.stride
= num_attribs
* 4 * sizeof(float); /* vertex size */
59 vbuffer
.buffer_offset
= offset
;
61 /* note: vertex elements already set by caller */
64 cso_set_vertex_buffers(cso
, vbuf_slot
, 1, &vbuffer
);
65 cso_draw_arrays(cso
, prim_type
, 0, num_verts
);
67 pipe
->set_vertex_buffers(pipe
, vbuf_slot
, 1, &vbuffer
);
68 util_draw_arrays(pipe
, prim_type
, 0, num_verts
);
74 * Draw a simple vertex buffer / primitive.
75 * Limited to float[4] vertex attribs, tightly packed.
78 util_draw_user_vertex_buffer(struct cso_context
*cso
, void *buffer
,
79 uint prim_type
, uint num_verts
, uint num_attribs
)
81 struct pipe_vertex_buffer vbuffer
= {0};
83 assert(num_attribs
<= PIPE_MAX_ATTRIBS
);
85 vbuffer
.is_user_buffer
= true;
86 vbuffer
.buffer
.user
= buffer
;
87 vbuffer
.stride
= num_attribs
* 4 * sizeof(float); /* vertex size */
89 /* note: vertex elements already set by caller */
91 cso_set_vertex_buffers(cso
, 0, 1, &vbuffer
);
92 cso_draw_arrays(cso
, prim_type
, 0, num_verts
);