gallium/util: replace pipe_mutex_lock() with mtx_lock()
[mesa.git] / src / gallium / auxiliary / util / u_draw.h
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 #ifndef U_DRAW_H
29 #define U_DRAW_H
30
31
32 #include "pipe/p_compiler.h"
33 #include "pipe/p_context.h"
34 #include "pipe/p_state.h"
35
36
37 #ifdef __cplusplus
38 extern "C" {
39 #endif
40
41
42 static inline void
43 util_draw_init_info(struct pipe_draw_info *info)
44 {
45 memset(info, 0, sizeof(*info));
46 info->instance_count = 1;
47 info->max_index = 0xffffffff;
48 }
49
50
51 static inline void
52 util_draw_arrays(struct pipe_context *pipe,
53 enum pipe_prim_type mode,
54 uint start,
55 uint count)
56 {
57 struct pipe_draw_info info;
58
59 util_draw_init_info(&info);
60 info.mode = mode;
61 info.start = start;
62 info.count = count;
63 info.min_index = start;
64 info.max_index = start + count - 1;
65
66 pipe->draw_vbo(pipe, &info);
67 }
68
69 static inline void
70 util_draw_elements(struct pipe_context *pipe, int index_bias,
71 enum pipe_prim_type mode,
72 uint start,
73 uint count)
74 {
75 struct pipe_draw_info info;
76
77 util_draw_init_info(&info);
78 info.indexed = TRUE;
79 info.mode = mode;
80 info.start = start;
81 info.count = count;
82 info.index_bias = index_bias;
83
84 pipe->draw_vbo(pipe, &info);
85 }
86
87 static inline void
88 util_draw_arrays_instanced(struct pipe_context *pipe,
89 enum pipe_prim_type mode,
90 uint start,
91 uint count,
92 uint start_instance,
93 uint instance_count)
94 {
95 struct pipe_draw_info info;
96
97 util_draw_init_info(&info);
98 info.mode = mode;
99 info.start = start;
100 info.count = count;
101 info.start_instance = start_instance;
102 info.instance_count = instance_count;
103 info.min_index = start;
104 info.max_index = start + count - 1;
105
106 pipe->draw_vbo(pipe, &info);
107 }
108
109 static inline void
110 util_draw_elements_instanced(struct pipe_context *pipe,
111 int index_bias,
112 enum pipe_prim_type mode,
113 uint start,
114 uint count,
115 uint start_instance,
116 uint instance_count)
117 {
118 struct pipe_draw_info info;
119
120 util_draw_init_info(&info);
121 info.indexed = TRUE;
122 info.mode = mode;
123 info.start = start;
124 info.count = count;
125 info.index_bias = index_bias;
126 info.start_instance = start_instance;
127 info.instance_count = instance_count;
128
129 pipe->draw_vbo(pipe, &info);
130 }
131
132 static inline void
133 util_draw_range_elements(struct pipe_context *pipe,
134 int index_bias,
135 uint min_index,
136 uint max_index,
137 enum pipe_prim_type mode,
138 uint start,
139 uint count)
140 {
141 struct pipe_draw_info info;
142
143 util_draw_init_info(&info);
144 info.indexed = TRUE;
145 info.mode = mode;
146 info.start = start;
147 info.count = count;
148 info.index_bias = index_bias;
149 info.min_index = min_index;
150 info.max_index = max_index;
151
152 pipe->draw_vbo(pipe, &info);
153 }
154
155
156 /* This converts an indirect draw into a direct draw by mapping the indirect
157 * buffer, extracting its arguments, and calling pipe->draw_vbo.
158 */
159 void
160 util_draw_indirect(struct pipe_context *pipe,
161 const struct pipe_draw_info *info);
162
163
164 unsigned
165 util_draw_max_index(
166 const struct pipe_vertex_buffer *vertex_buffers,
167 const struct pipe_vertex_element *vertex_elements,
168 unsigned nr_vertex_elements,
169 const struct pipe_draw_info *info);
170
171
172 #ifdef __cplusplus
173 }
174 #endif
175
176 #endif /* !U_DRAW_H */