14a49301eSmrg/*
24a49301eSmrg * Copyright 2009 VMware, Inc.
34a49301eSmrg * All Rights Reserved.
44a49301eSmrg *
54a49301eSmrg * Permission is hereby granted, free of charge, to any person obtaining a
64a49301eSmrg * copy of this software and associated documentation files (the "Software"),
74a49301eSmrg * to deal in the Software without restriction, including without limitation
84a49301eSmrg * on the rights to use, copy, modify, merge, publish, distribute, sub
94a49301eSmrg * license, and/or sell copies of the Software, and to permit persons to whom
104a49301eSmrg * the Software is furnished to do so, subject to the following conditions:
114a49301eSmrg *
124a49301eSmrg * The above copyright notice and this permission notice (including the next
134a49301eSmrg * paragraph) shall be included in all copies or substantial portions of the
144a49301eSmrg * Software.
154a49301eSmrg *
164a49301eSmrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
174a49301eSmrg * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
184a49301eSmrg * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19af69d88dSmrg * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
204a49301eSmrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
214a49301eSmrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
224a49301eSmrg * USE OR OTHER DEALINGS IN THE SOFTWARE.
234a49301eSmrg */
244a49301eSmrg
254a49301eSmrg#ifndef U_INDICES_H
264a49301eSmrg#define U_INDICES_H
274a49301eSmrg
284a49301eSmrg#include "pipe/p_compiler.h"
2901e04c3fSmrg#include "pipe/p_defines.h"
304a49301eSmrg
3101e04c3fSmrg/* First/last provoking vertex */
324a49301eSmrg#define PV_FIRST      0
334a49301eSmrg#define PV_LAST       1
344a49301eSmrg#define PV_COUNT      2
354a49301eSmrg
3601e04c3fSmrg/* primitive restart disable/enable flags */
3701e04c3fSmrg#define PR_DISABLE 0
3801e04c3fSmrg#define PR_ENABLE 1
3901e04c3fSmrg#define PR_COUNT 2
4001e04c3fSmrg
4101e04c3fSmrg
42af69d88dSmrg/**
43af69d88dSmrg * Index translator function (for glDrawElements() case)
44af69d88dSmrg *
45af69d88dSmrg * \param in     the input index buffer
46af69d88dSmrg * \param start  the index of the first vertex (pipe_draw_info::start)
47af69d88dSmrg * \param nr     the number of vertices (pipe_draw_info::count)
4801e04c3fSmrg * \param out    output buffer big enough for nr vertices (of
49af69d88dSmrg *    @out_index_size bytes each)
50af69d88dSmrg */
514a49301eSmrgtypedef void (*u_translate_func)( const void *in,
52af69d88dSmrg                                  unsigned start,
5301e04c3fSmrg                                  unsigned in_nr,
5401e04c3fSmrg                                  unsigned out_nr,
5501e04c3fSmrg                                  unsigned restart_index,
564a49301eSmrg                                  void *out );
574a49301eSmrg
58af69d88dSmrg/**
59af69d88dSmrg * Index generator function (for glDrawArrays() case)
60af69d88dSmrg *
61af69d88dSmrg * \param start  the index of the first vertex (pipe_draw_info::start)
62af69d88dSmrg * \param nr     the number of vertices (pipe_draw_info::count)
6301e04c3fSmrg * \param out    output buffer big enough for nr vertices (of
64af69d88dSmrg *    @out_index_size bytes each)
65af69d88dSmrg */
66af69d88dSmrgtypedef void (*u_generate_func)( unsigned start,
67af69d88dSmrg                                 unsigned nr,
684a49301eSmrg                                 void *out );
694a49301eSmrg
704a49301eSmrg
714a49301eSmrg/* Return codes describe the translate/generate operation.  Caller may
724a49301eSmrg * be able to reuse translated indices under some circumstances.
734a49301eSmrg */
7401e04c3fSmrgenum indices_mode {
7501e04c3fSmrg   U_TRANSLATE_ERROR = -1,
7601e04c3fSmrg   U_TRANSLATE_NORMAL = 1,
7701e04c3fSmrg   U_TRANSLATE_MEMCPY = 2,
7801e04c3fSmrg   U_GENERATE_LINEAR  = 3,
7901e04c3fSmrg   U_GENERATE_REUSABLE= 4,
8001e04c3fSmrg   U_GENERATE_ONE_OFF = 5,
8101e04c3fSmrg};
824a49301eSmrg
834a49301eSmrgvoid u_index_init( void );
844a49301eSmrg
857ec681f3Smrg/* returns the primitive type resulting from index translation */
867ec681f3Smrgenum pipe_prim_type
877ec681f3Smrgu_index_prim_type_convert(unsigned hw_mask, enum pipe_prim_type prim, bool pv_matches);
887ec681f3Smrg
897ec681f3Smrgstatic inline unsigned
907ec681f3Smrgu_index_size_convert(unsigned index_size)
917ec681f3Smrg{
927ec681f3Smrg   return (index_size == 4) ? 4 : 2;
937ec681f3Smrg}
947ec681f3Smrg
957ec681f3Smrgunsigned
967ec681f3Smrgu_index_count_converted_indices(unsigned hw_mask, bool pv_matches, enum pipe_prim_type prim, unsigned nr);
9701e04c3fSmrg
9801e04c3fSmrg/**
9901e04c3fSmrg * For indexed drawing, this function determines what kind of primitive
10001e04c3fSmrg * transformation is needed (if any) for handling:
10101e04c3fSmrg * - unsupported primitive types (such as PIPE_PRIM_POLYGON)
10201e04c3fSmrg * - changing the provoking vertex
10301e04c3fSmrg * - primitive restart
10401e04c3fSmrg * - index size (1 byte, 2 byte or 4 byte indexes)
10501e04c3fSmrg */
10601e04c3fSmrgenum indices_mode
10701e04c3fSmrgu_index_translator(unsigned hw_mask,
10801e04c3fSmrg                   enum pipe_prim_type prim,
10901e04c3fSmrg                   unsigned in_index_size,
11001e04c3fSmrg                   unsigned nr,
11101e04c3fSmrg                   unsigned in_pv,   /* API */
11201e04c3fSmrg                   unsigned out_pv,  /* hardware */
11301e04c3fSmrg                   unsigned prim_restart,
11401e04c3fSmrg                   enum pipe_prim_type *out_prim,
11501e04c3fSmrg                   unsigned *out_index_size,
11601e04c3fSmrg                   unsigned *out_nr,
11701e04c3fSmrg                   u_translate_func *out_translate);
11801e04c3fSmrg
11901e04c3fSmrg
12001e04c3fSmrg/**
12101e04c3fSmrg * For non-indexed drawing, this function determines what kind of primitive
12201e04c3fSmrg * transformation is needed (see above).
12301e04c3fSmrg *
12401e04c3fSmrg * Note that even when generating it is necessary to know what the
1254a49301eSmrg * API's PV is, as the indices generated will depend on whether it is
1264a49301eSmrg * the same as hardware or not, and in the case of triangle strips,
1274a49301eSmrg * whether it is first or last.
1284a49301eSmrg */
12901e04c3fSmrgenum indices_mode
13001e04c3fSmrgu_index_generator(unsigned hw_mask,
13101e04c3fSmrg                  enum pipe_prim_type prim,
13201e04c3fSmrg                  unsigned start,
13301e04c3fSmrg                  unsigned nr,
13401e04c3fSmrg                  unsigned in_pv,   /* API */
13501e04c3fSmrg                  unsigned out_pv,  /* hardware */
13601e04c3fSmrg                  enum pipe_prim_type *out_prim,
13701e04c3fSmrg                  unsigned *out_index_size,
13801e04c3fSmrg                  unsigned *out_nr,
13901e04c3fSmrg                  u_generate_func *out_generate);
1404a49301eSmrg
1414a49301eSmrg
1424a49301eSmrgvoid u_unfilled_init( void );
1434a49301eSmrg
14401e04c3fSmrg/**
14501e04c3fSmrg * If the driver can't handle "unfilled" primitives (i.e. drawing triangle
14601e04c3fSmrg * primitives as 3 lines or 3 points) this function can be used to translate
14701e04c3fSmrg * an indexed primitive into a new indexed primitive to draw as lines or
14801e04c3fSmrg * points.
14901e04c3fSmrg */
15001e04c3fSmrgenum indices_mode
15101e04c3fSmrgu_unfilled_translator(enum pipe_prim_type prim,
15201e04c3fSmrg                      unsigned in_index_size,
15301e04c3fSmrg                      unsigned nr,
15401e04c3fSmrg                      unsigned unfilled_mode,
15501e04c3fSmrg                      enum pipe_prim_type *out_prim,
15601e04c3fSmrg                      unsigned *out_index_size,
15701e04c3fSmrg                      unsigned *out_nr,
15801e04c3fSmrg                      u_translate_func *out_translate);
1594a49301eSmrg
16001e04c3fSmrg/**
16101e04c3fSmrg * As above, but for non-indexed (array) primitives.
16201e04c3fSmrg */
16301e04c3fSmrgenum indices_mode
16401e04c3fSmrgu_unfilled_generator(enum pipe_prim_type prim,
16501e04c3fSmrg                     unsigned start,
16601e04c3fSmrg                     unsigned nr,
16701e04c3fSmrg                     unsigned unfilled_mode,
16801e04c3fSmrg                     enum pipe_prim_type *out_prim,
16901e04c3fSmrg                     unsigned *out_index_size,
17001e04c3fSmrg                     unsigned *out_nr,
17101e04c3fSmrg                     u_generate_func *out_generate);
1724a49301eSmrg
1734a49301eSmrg#endif
174