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
util_draw_init_info(struct pipe_draw_info * info)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
util_draw_arrays(struct pipe_context * pipe,enum pipe_prim_type mode,uint start,uint count)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
util_draw_elements(struct pipe_context * pipe,void * indices,unsigned index_size,int index_bias,enum pipe_prim_type mode,uint start,uint count)70 util_draw_elements(struct pipe_context *pipe,
71 void *indices,
72 unsigned index_size,
73 int index_bias, enum pipe_prim_type mode,
74 uint start,
75 uint count)
76 {
77 struct pipe_draw_info info;
78
79 util_draw_init_info(&info);
80 info.index.user = indices;
81 info.has_user_indices = true;
82 info.index_size = index_size;
83 info.mode = mode;
84 info.start = start;
85 info.count = count;
86 info.index_bias = index_bias;
87
88 pipe->draw_vbo(pipe, &info);
89 }
90
91 static inline void
util_draw_arrays_instanced(struct pipe_context * pipe,enum pipe_prim_type mode,uint start,uint count,uint start_instance,uint instance_count)92 util_draw_arrays_instanced(struct pipe_context *pipe,
93 enum pipe_prim_type mode,
94 uint start,
95 uint count,
96 uint start_instance,
97 uint instance_count)
98 {
99 struct pipe_draw_info info;
100
101 util_draw_init_info(&info);
102 info.mode = mode;
103 info.start = start;
104 info.count = count;
105 info.start_instance = start_instance;
106 info.instance_count = instance_count;
107 info.min_index = start;
108 info.max_index = start + count - 1;
109
110 pipe->draw_vbo(pipe, &info);
111 }
112
113 static inline void
util_draw_elements_instanced(struct pipe_context * pipe,void * indices,unsigned index_size,int index_bias,enum pipe_prim_type mode,uint start,uint count,uint start_instance,uint instance_count)114 util_draw_elements_instanced(struct pipe_context *pipe,
115 void *indices,
116 unsigned index_size,
117 int index_bias,
118 enum pipe_prim_type mode,
119 uint start,
120 uint count,
121 uint start_instance,
122 uint instance_count)
123 {
124 struct pipe_draw_info info;
125
126 util_draw_init_info(&info);
127 info.index.user = indices;
128 info.has_user_indices = true;
129 info.index_size = index_size;
130 info.mode = mode;
131 info.start = start;
132 info.count = count;
133 info.index_bias = index_bias;
134 info.start_instance = start_instance;
135 info.instance_count = instance_count;
136
137 pipe->draw_vbo(pipe, &info);
138 }
139
140
141 /* This converts an indirect draw into a direct draw by mapping the indirect
142 * buffer, extracting its arguments, and calling pipe->draw_vbo.
143 */
144 void
145 util_draw_indirect(struct pipe_context *pipe,
146 const struct pipe_draw_info *info);
147
148
149 unsigned
150 util_draw_max_index(
151 const struct pipe_vertex_buffer *vertex_buffers,
152 const struct pipe_vertex_element *vertex_elements,
153 unsigned nr_vertex_elements,
154 const struct pipe_draw_info *info);
155
156
157 #ifdef __cplusplus
158 }
159 #endif
160
161 #endif /* !U_DRAW_H */
162