13464ebd5Sriastradh/**************************************************************************
23464ebd5Sriastradh *
3af69d88dSmrg * Copyright 2008 VMware, Inc.
43464ebd5Sriastradh * All Rights Reserved.
53464ebd5Sriastradh *
63464ebd5Sriastradh * Permission is hereby granted, free of charge, to any person obtaining a
73464ebd5Sriastradh * copy of this software and associated documentation files (the
83464ebd5Sriastradh * "Software"), to deal in the Software without restriction, including
93464ebd5Sriastradh * without limitation the rights to use, copy, modify, merge, publish,
103464ebd5Sriastradh * distribute, sub license, and/or sell copies of the Software, and to
113464ebd5Sriastradh * permit persons to whom the Software is furnished to do so, subject to
123464ebd5Sriastradh * the following conditions:
133464ebd5Sriastradh *
143464ebd5Sriastradh * The above copyright notice and this permission notice (including the
153464ebd5Sriastradh * next paragraph) shall be included in all copies or substantial portions
163464ebd5Sriastradh * of the Software.
173464ebd5Sriastradh *
183464ebd5Sriastradh * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
193464ebd5Sriastradh * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
203464ebd5Sriastradh * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.
21af69d88dSmrg * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR
223464ebd5Sriastradh * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
233464ebd5Sriastradh * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
243464ebd5Sriastradh * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
253464ebd5Sriastradh *
263464ebd5Sriastradh **************************************************************************/
273464ebd5Sriastradh
283464ebd5Sriastradh#ifndef U_DRAW_H
293464ebd5Sriastradh#define U_DRAW_H
303464ebd5Sriastradh
313464ebd5Sriastradh
323464ebd5Sriastradh#include "pipe/p_compiler.h"
333464ebd5Sriastradh#include "pipe/p_context.h"
343464ebd5Sriastradh#include "pipe/p_state.h"
353464ebd5Sriastradh
363464ebd5Sriastradh
373464ebd5Sriastradh#ifdef __cplusplus
383464ebd5Sriastradhextern "C" {
393464ebd5Sriastradh#endif
403464ebd5Sriastradh
413464ebd5Sriastradh
4201e04c3fSmrgstatic inline void
433464ebd5Sriastradhutil_draw_init_info(struct pipe_draw_info *info)
443464ebd5Sriastradh{
453464ebd5Sriastradh   memset(info, 0, sizeof(*info));
463464ebd5Sriastradh   info->instance_count = 1;
473464ebd5Sriastradh   info->max_index = 0xffffffff;
483464ebd5Sriastradh}
493464ebd5Sriastradh
503464ebd5Sriastradh
5101e04c3fSmrgstatic inline void
5201e04c3fSmrgutil_draw_arrays(struct pipe_context *pipe,
5301e04c3fSmrg                 enum pipe_prim_type mode,
5401e04c3fSmrg                 uint start,
5501e04c3fSmrg                 uint count)
563464ebd5Sriastradh{
573464ebd5Sriastradh   struct pipe_draw_info info;
587ec681f3Smrg   struct pipe_draw_start_count_bias draw;
593464ebd5Sriastradh
603464ebd5Sriastradh   util_draw_init_info(&info);
613464ebd5Sriastradh   info.mode = mode;
623464ebd5Sriastradh   info.min_index = start;
633464ebd5Sriastradh   info.max_index = start + count - 1;
643464ebd5Sriastradh
657ec681f3Smrg   draw.start = start;
667ec681f3Smrg   draw.count = count;
677ec681f3Smrg   draw.index_bias = 0;
687ec681f3Smrg
697ec681f3Smrg   pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);
703464ebd5Sriastradh}
713464ebd5Sriastradh
7201e04c3fSmrgstatic inline void
7301e04c3fSmrgutil_draw_elements(struct pipe_context *pipe,
7401e04c3fSmrg                   void *indices,
7501e04c3fSmrg                   unsigned index_size,
7601e04c3fSmrg                   int index_bias, enum pipe_prim_type mode,
7701e04c3fSmrg                   uint start,
7801e04c3fSmrg                   uint count)
793464ebd5Sriastradh{
803464ebd5Sriastradh   struct pipe_draw_info info;
817ec681f3Smrg   struct pipe_draw_start_count_bias draw;
823464ebd5Sriastradh
833464ebd5Sriastradh   util_draw_init_info(&info);
8401e04c3fSmrg   info.index.user = indices;
8501e04c3fSmrg   info.has_user_indices = true;
8601e04c3fSmrg   info.index_size = index_size;
873464ebd5Sriastradh   info.mode = mode;
887ec681f3Smrg   draw.index_bias = index_bias;
897ec681f3Smrg
907ec681f3Smrg   draw.start = start;
917ec681f3Smrg   draw.count = count;
923464ebd5Sriastradh
937ec681f3Smrg   pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);
943464ebd5Sriastradh}
953464ebd5Sriastradh
9601e04c3fSmrgstatic inline void
973464ebd5Sriastradhutil_draw_arrays_instanced(struct pipe_context *pipe,
9801e04c3fSmrg                           enum pipe_prim_type mode,
9901e04c3fSmrg                           uint start,
10001e04c3fSmrg                           uint count,
1013464ebd5Sriastradh                           uint start_instance,
1023464ebd5Sriastradh                           uint instance_count)
1033464ebd5Sriastradh{
1043464ebd5Sriastradh   struct pipe_draw_info info;
1057ec681f3Smrg   struct pipe_draw_start_count_bias draw;
1063464ebd5Sriastradh
1073464ebd5Sriastradh   util_draw_init_info(&info);
1083464ebd5Sriastradh   info.mode = mode;
1093464ebd5Sriastradh   info.start_instance = start_instance;
1103464ebd5Sriastradh   info.instance_count = instance_count;
1117ec681f3Smrg   info.index_bounds_valid = true;
1123464ebd5Sriastradh   info.min_index = start;
1133464ebd5Sriastradh   info.max_index = start + count - 1;
1143464ebd5Sriastradh
1157ec681f3Smrg   draw.start = start;
1167ec681f3Smrg   draw.count = count;
1177ec681f3Smrg   draw.index_bias = 0;
1187ec681f3Smrg
1197ec681f3Smrg   pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);
1203464ebd5Sriastradh}
1213464ebd5Sriastradh
12201e04c3fSmrgstatic inline void
1233464ebd5Sriastradhutil_draw_elements_instanced(struct pipe_context *pipe,
12401e04c3fSmrg                             void *indices,
12501e04c3fSmrg                             unsigned index_size,
1263464ebd5Sriastradh                             int index_bias,
12701e04c3fSmrg                             enum pipe_prim_type mode,
12801e04c3fSmrg                             uint start,
12901e04c3fSmrg                             uint count,
1303464ebd5Sriastradh                             uint start_instance,
1313464ebd5Sriastradh                             uint instance_count)
1323464ebd5Sriastradh{
1333464ebd5Sriastradh   struct pipe_draw_info info;
1347ec681f3Smrg   struct pipe_draw_start_count_bias draw;
1353464ebd5Sriastradh
1363464ebd5Sriastradh   util_draw_init_info(&info);
13701e04c3fSmrg   info.index.user = indices;
13801e04c3fSmrg   info.has_user_indices = true;
13901e04c3fSmrg   info.index_size = index_size;
1403464ebd5Sriastradh   info.mode = mode;
1417ec681f3Smrg   draw.index_bias = index_bias;
1423464ebd5Sriastradh   info.start_instance = start_instance;
1433464ebd5Sriastradh   info.instance_count = instance_count;
1443464ebd5Sriastradh
1457ec681f3Smrg   draw.start = start;
1467ec681f3Smrg   draw.count = count;
1477ec681f3Smrg
1487ec681f3Smrg   pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);
1493464ebd5Sriastradh}
1503464ebd5Sriastradh
1517ec681f3Smrgstruct u_indirect_params {
1527ec681f3Smrg   struct pipe_draw_info info;
1537ec681f3Smrg   struct pipe_draw_start_count_bias draw;
1547ec681f3Smrg};
1557ec681f3Smrg
1567ec681f3Smrg/* caller must free the return value */
1577ec681f3Smrgstruct u_indirect_params *
1587ec681f3Smrgutil_draw_indirect_read(struct pipe_context *pipe,
1597ec681f3Smrg                        const struct pipe_draw_info *info_in,
1607ec681f3Smrg                        const struct pipe_draw_indirect_info *indirect,
1617ec681f3Smrg                        unsigned *num_draws);
1623464ebd5Sriastradh
163af69d88dSmrg/* This converts an indirect draw into a direct draw by mapping the indirect
164af69d88dSmrg * buffer, extracting its arguments, and calling pipe->draw_vbo.
165af69d88dSmrg */
166af69d88dSmrgvoid
167af69d88dSmrgutil_draw_indirect(struct pipe_context *pipe,
1687ec681f3Smrg                   const struct pipe_draw_info *info,
1697ec681f3Smrg                   const struct pipe_draw_indirect_info *indirect);
170af69d88dSmrg
1717ec681f3Smrg/* Helper to handle multi-draw by splitting into individual draws.  You
1727ec681f3Smrg * don't want to call this if num_draws==1
1737ec681f3Smrg */
1747ec681f3Smrgvoid
1757ec681f3Smrgutil_draw_multi(struct pipe_context *pctx, const struct pipe_draw_info *info,
1767ec681f3Smrg                unsigned drawid_offset,
1777ec681f3Smrg                const struct pipe_draw_indirect_info *indirect,
1787ec681f3Smrg                const struct pipe_draw_start_count_bias *draws,
1797ec681f3Smrg                unsigned num_draws);
180af69d88dSmrg
1813464ebd5Sriastradhunsigned
1823464ebd5Sriastradhutil_draw_max_index(
1833464ebd5Sriastradh      const struct pipe_vertex_buffer *vertex_buffers,
1843464ebd5Sriastradh      const struct pipe_vertex_element *vertex_elements,
1853464ebd5Sriastradh      unsigned nr_vertex_elements,
1863464ebd5Sriastradh      const struct pipe_draw_info *info);
1873464ebd5Sriastradh
1883464ebd5Sriastradh
1893464ebd5Sriastradh#ifdef __cplusplus
1903464ebd5Sriastradh}
1913464ebd5Sriastradh#endif
1923464ebd5Sriastradh
1933464ebd5Sriastradh#endif /* !U_DRAW_H */
194