Merge branch 'master' into glsl2
[mesa.git] / src / gallium / auxiliary / util / u_draw.h
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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 TUNGSTEN GRAPHICS 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
35
36 static INLINE void
37 util_draw_init_info(struct pipe_draw_info *info)
38 {
39 memset(info, 0, sizeof(*info));
40 info->instance_count = 1;
41 info->max_index = 0xffffffff;
42 }
43
44
45 static INLINE void
46 util_draw_arrays(struct pipe_context *pipe, uint mode, uint start, uint count)
47 {
48 struct pipe_draw_info info;
49
50 util_draw_init_info(&info);
51 info.mode = mode;
52 info.start = start;
53 info.count = count;
54 info.min_index = start;
55 info.max_index = start + count - 1;
56
57 pipe->draw_vbo(pipe, &info);
58 }
59
60 static INLINE void
61 util_draw_elements(struct pipe_context *pipe, int index_bias,
62 uint mode, uint start, uint count)
63 {
64 struct pipe_draw_info info;
65
66 util_draw_init_info(&info);
67 info.indexed = TRUE;
68 info.mode = mode;
69 info.start = start;
70 info.count = count;
71 info.index_bias = index_bias;
72
73 pipe->draw_vbo(pipe, &info);
74 }
75
76 static INLINE void
77 util_draw_arrays_instanced(struct pipe_context *pipe,
78 uint mode, uint start, uint count,
79 uint start_instance,
80 uint instance_count)
81 {
82 struct pipe_draw_info info;
83
84 util_draw_init_info(&info);
85 info.mode = mode;
86 info.start = start;
87 info.count = count;
88 info.start_instance = start_instance;
89 info.instance_count = instance_count;
90 info.min_index = start;
91 info.max_index = start + count - 1;
92
93 pipe->draw_vbo(pipe, &info);
94 }
95
96 static INLINE void
97 util_draw_elements_instanced(struct pipe_context *pipe,
98 int index_bias,
99 uint mode, uint start, uint count,
100 uint start_instance,
101 uint instance_count)
102 {
103 struct pipe_draw_info info;
104
105 util_draw_init_info(&info);
106 info.indexed = TRUE;
107 info.mode = mode;
108 info.start = start;
109 info.count = count;
110 info.index_bias = index_bias;
111 info.start_instance = start_instance;
112 info.instance_count = instance_count;
113
114 pipe->draw_vbo(pipe, &info);
115 }
116
117 static INLINE void
118 util_draw_range_elements(struct pipe_context *pipe,
119 int index_bias,
120 uint min_index,
121 uint max_index,
122 uint mode, uint start, uint count)
123 {
124 struct pipe_draw_info info;
125
126 util_draw_init_info(&info);
127 info.indexed = TRUE;
128 info.mode = mode;
129 info.start = start;
130 info.count = count;
131 info.index_bias = index_bias;
132 info.min_index = min_index;
133 info.max_index = max_index;
134
135 pipe->draw_vbo(pipe, &info);
136 }
137
138 #endif