1848b8605Smrg/**************************************************************************
2848b8605Smrg *
3848b8605Smrg * Copyright 2008 VMware, Inc.
4848b8605Smrg * All Rights Reserved.
5848b8605Smrg *
6848b8605Smrg * Permission is hereby granted, free of charge, to any person obtaining a
7848b8605Smrg * copy of this software and associated documentation files (the
8848b8605Smrg * "Software"), to deal in the Software without restriction, including
9848b8605Smrg * without limitation the rights to use, copy, modify, merge, publish,
10848b8605Smrg * distribute, sub license, and/or sell copies of the Software, and to
11848b8605Smrg * permit persons to whom the Software is furnished to do so, subject to
12848b8605Smrg * the following conditions:
13848b8605Smrg *
14848b8605Smrg * The above copyright notice and this permission notice (including the
15848b8605Smrg * next paragraph) shall be included in all copies or substantial portions
16848b8605Smrg * of the Software.
17848b8605Smrg *
18848b8605Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
19848b8605Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
20848b8605Smrg * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21848b8605Smrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
22848b8605Smrg * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
23848b8605Smrg * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
24848b8605Smrg * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25848b8605Smrg *
26848b8605Smrg **************************************************************************/
27848b8605Smrg
28848b8605Smrg#ifndef U_DRAW_H
29848b8605Smrg#define U_DRAW_H
30848b8605Smrg
31848b8605Smrg
32848b8605Smrg#include "pipe/p_compiler.h"
33848b8605Smrg#include "pipe/p_context.h"
34848b8605Smrg#include "pipe/p_state.h"
35848b8605Smrg
36848b8605Smrg
37848b8605Smrg#ifdef __cplusplus
38848b8605Smrgextern "C" {
39848b8605Smrg#endif
40848b8605Smrg
41848b8605Smrg
42b8e80941Smrgstatic inline void
43848b8605Smrgutil_draw_init_info(struct pipe_draw_info *info)
44848b8605Smrg{
45848b8605Smrg   memset(info, 0, sizeof(*info));
46848b8605Smrg   info->instance_count = 1;
47848b8605Smrg   info->max_index = 0xffffffff;
48848b8605Smrg}
49848b8605Smrg
50848b8605Smrg
51b8e80941Smrgstatic inline void
52b8e80941Smrgutil_draw_arrays(struct pipe_context *pipe,
53b8e80941Smrg                 enum pipe_prim_type mode,
54b8e80941Smrg                 uint start,
55b8e80941Smrg                 uint count)
56848b8605Smrg{
57848b8605Smrg   struct pipe_draw_info info;
58848b8605Smrg
59848b8605Smrg   util_draw_init_info(&info);
60848b8605Smrg   info.mode = mode;
61848b8605Smrg   info.start = start;
62848b8605Smrg   info.count = count;
63848b8605Smrg   info.min_index = start;
64848b8605Smrg   info.max_index = start + count - 1;
65848b8605Smrg
66848b8605Smrg   pipe->draw_vbo(pipe, &info);
67848b8605Smrg}
68848b8605Smrg
69b8e80941Smrgstatic inline void
70b8e80941Smrgutil_draw_elements(struct pipe_context *pipe,
71b8e80941Smrg                   void *indices,
72b8e80941Smrg                   unsigned index_size,
73b8e80941Smrg                   int index_bias, enum pipe_prim_type mode,
74b8e80941Smrg                   uint start,
75b8e80941Smrg                   uint count)
76848b8605Smrg{
77848b8605Smrg   struct pipe_draw_info info;
78848b8605Smrg
79848b8605Smrg   util_draw_init_info(&info);
80b8e80941Smrg   info.index.user = indices;
81b8e80941Smrg   info.has_user_indices = true;
82b8e80941Smrg   info.index_size = index_size;
83848b8605Smrg   info.mode = mode;
84848b8605Smrg   info.start = start;
85848b8605Smrg   info.count = count;
86848b8605Smrg   info.index_bias = index_bias;
87848b8605Smrg
88848b8605Smrg   pipe->draw_vbo(pipe, &info);
89848b8605Smrg}
90848b8605Smrg
91b8e80941Smrgstatic inline void
92848b8605Smrgutil_draw_arrays_instanced(struct pipe_context *pipe,
93b8e80941Smrg                           enum pipe_prim_type mode,
94b8e80941Smrg                           uint start,
95b8e80941Smrg                           uint count,
96848b8605Smrg                           uint start_instance,
97848b8605Smrg                           uint instance_count)
98848b8605Smrg{
99848b8605Smrg   struct pipe_draw_info info;
100848b8605Smrg
101848b8605Smrg   util_draw_init_info(&info);
102848b8605Smrg   info.mode = mode;
103848b8605Smrg   info.start = start;
104848b8605Smrg   info.count = count;
105848b8605Smrg   info.start_instance = start_instance;
106848b8605Smrg   info.instance_count = instance_count;
107848b8605Smrg   info.min_index = start;
108848b8605Smrg   info.max_index = start + count - 1;
109848b8605Smrg
110848b8605Smrg   pipe->draw_vbo(pipe, &info);
111848b8605Smrg}
112848b8605Smrg
113b8e80941Smrgstatic inline void
114848b8605Smrgutil_draw_elements_instanced(struct pipe_context *pipe,
115b8e80941Smrg                             void *indices,
116b8e80941Smrg                             unsigned index_size,
117848b8605Smrg                             int index_bias,
118b8e80941Smrg                             enum pipe_prim_type mode,
119b8e80941Smrg                             uint start,
120b8e80941Smrg                             uint count,
121848b8605Smrg                             uint start_instance,
122848b8605Smrg                             uint instance_count)
123848b8605Smrg{
124848b8605Smrg   struct pipe_draw_info info;
125848b8605Smrg
126848b8605Smrg   util_draw_init_info(&info);
127b8e80941Smrg   info.index.user = indices;
128b8e80941Smrg   info.has_user_indices = true;
129b8e80941Smrg   info.index_size = index_size;
130848b8605Smrg   info.mode = mode;
131848b8605Smrg   info.start = start;
132848b8605Smrg   info.count = count;
133848b8605Smrg   info.index_bias = index_bias;
134848b8605Smrg   info.start_instance = start_instance;
135848b8605Smrg   info.instance_count = instance_count;
136848b8605Smrg
137848b8605Smrg   pipe->draw_vbo(pipe, &info);
138848b8605Smrg}
139848b8605Smrg
140848b8605Smrg
141848b8605Smrg/* This converts an indirect draw into a direct draw by mapping the indirect
142848b8605Smrg * buffer, extracting its arguments, and calling pipe->draw_vbo.
143848b8605Smrg */
144848b8605Smrgvoid
145848b8605Smrgutil_draw_indirect(struct pipe_context *pipe,
146848b8605Smrg                   const struct pipe_draw_info *info);
147848b8605Smrg
148848b8605Smrg
149848b8605Smrgunsigned
150848b8605Smrgutil_draw_max_index(
151848b8605Smrg      const struct pipe_vertex_buffer *vertex_buffers,
152848b8605Smrg      const struct pipe_vertex_element *vertex_elements,
153848b8605Smrg      unsigned nr_vertex_elements,
154848b8605Smrg      const struct pipe_draw_info *info);
155848b8605Smrg
156848b8605Smrg
157848b8605Smrg#ifdef __cplusplus
158848b8605Smrg}
159848b8605Smrg#endif
160848b8605Smrg
161848b8605Smrg#endif /* !U_DRAW_H */
162