1 /**************************************************************************
2 *
3 * Copyright 2008 VMware, Inc.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28
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"
35
36
37 /**
38 * Draw a simple vertex buffer / primitive.
39 * Limited to float[4] vertex attribs, tightly packed.
40 */
41 void
util_draw_vertex_buffer(struct pipe_context * pipe,struct cso_context * cso,struct pipe_resource * vbuf,unsigned offset,bool vb_take_ownership,enum mesa_prim prim_type,unsigned num_verts,unsigned num_attribs)42 util_draw_vertex_buffer(struct pipe_context *pipe,
43 struct cso_context *cso,
44 struct pipe_resource *vbuf,
45 unsigned offset,
46 bool vb_take_ownership,
47 enum mesa_prim prim_type,
48 unsigned num_verts,
49 unsigned num_attribs)
50 {
51 struct pipe_vertex_buffer vbuffer;
52
53 assert(num_attribs <= PIPE_MAX_ATTRIBS);
54
55 /* tell pipe about the vertex buffer */
56 memset(&vbuffer, 0, sizeof(vbuffer));
57 vbuffer.buffer.resource = vbuf;
58 vbuffer.buffer_offset = offset;
59
60 /* note: vertex elements already set by caller */
61
62 if (cso) {
63 cso_set_vertex_buffers(cso, 1, vb_take_ownership, &vbuffer);
64 cso_draw_arrays(cso, prim_type, 0, num_verts);
65 } else {
66 util_set_vertex_buffers(pipe, 1, vb_take_ownership, &vbuffer);
67 util_draw_arrays(pipe, prim_type, 0, num_verts);
68 }
69 }
70
71
72 /**
73 * Draw a simple vertex buffer / primitive.
74 * Limited to float[4] vertex attribs, tightly packed.
75 */
76 void
util_draw_user_vertex_buffer(struct cso_context * cso,void * buffer,enum mesa_prim prim_type,unsigned num_verts,unsigned num_attribs)77 util_draw_user_vertex_buffer(struct cso_context *cso, void *buffer,
78 enum mesa_prim prim_type, unsigned num_verts,
79 unsigned num_attribs)
80 {
81 struct pipe_vertex_buffer vbuffer = {0};
82
83 assert(num_attribs <= PIPE_MAX_ATTRIBS);
84
85 vbuffer.is_user_buffer = true;
86 vbuffer.buffer.user = buffer;
87
88 /* note: vertex elements already set by caller */
89
90 cso_set_vertex_buffers(cso, 1, false, &vbuffer);
91 cso_draw_arrays(cso, prim_type, 0, num_verts);
92 }
93
94 /**
95 * Draw a user vertex buffer. This is the correct way.
96 * util_draw_user_vertex_buffer doesn't work with u_vbuf anymore.
97 */
98 void
util_draw_user_vertices(struct cso_context * cso,struct cso_velems_state * ve,void * buffer,enum mesa_prim prim_type,unsigned num_verts)99 util_draw_user_vertices(struct cso_context *cso, struct cso_velems_state *ve,
100 void *buffer, enum mesa_prim prim_type,
101 unsigned num_verts)
102 {
103 struct pipe_vertex_buffer vbuffer = {0};
104
105 vbuffer.is_user_buffer = true;
106 vbuffer.buffer.user = buffer;
107
108 cso_set_vertex_buffers_and_elements(cso, ve, 1, true, &vbuffer);
109 cso_draw_arrays(cso, prim_type, 0, num_verts);
110 }
111