u_indices.h revision 848b8605
1/*
2 * Copyright 2009 VMware, Inc.
3 * All Rights Reserved.
4 *
5 * Permission is hereby granted, free of charge, to any person obtaining a
6 * copy of this software and associated documentation files (the "Software"),
7 * to deal in the Software without restriction, including without limitation
8 * on the rights to use, copy, modify, merge, publish, distribute, sub
9 * license, and/or sell copies of the Software, and to permit persons to whom
10 * the Software is furnished to do so, subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice (including the next
13 * paragraph) shall be included in all copies or substantial portions of the
14 * Software.
15 *
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.  IN NO EVENT SHALL
19 * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,
20 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
21 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
22 * USE OR OTHER DEALINGS IN THE SOFTWARE.
23 */
24
25#ifndef U_INDICES_H
26#define U_INDICES_H
27
28#include "pipe/p_compiler.h"
29
30#define PV_FIRST      0
31#define PV_LAST       1
32#define PV_COUNT      2
33
34/**
35 * Index translator function (for glDrawElements() case)
36 *
37 * \param in     the input index buffer
38 * \param start  the index of the first vertex (pipe_draw_info::start)
39 * \param nr     the number of vertices (pipe_draw_info::count)
40 * \param out    output buffer big enough or nr vertices (of
41 *    @out_index_size bytes each)
42 */
43typedef void (*u_translate_func)( const void *in,
44                                  unsigned start,
45                                  unsigned nr,
46                                  void *out );
47
48/**
49 * Index generator function (for glDrawArrays() case)
50 *
51 * \param start  the index of the first vertex (pipe_draw_info::start)
52 * \param nr     the number of vertices (pipe_draw_info::count)
53 * \param out    output buffer big enough or nr vertices (of
54 *    @out_index_size bytes each)
55 */
56typedef void (*u_generate_func)( unsigned start,
57                                 unsigned nr,
58                                 void *out );
59
60
61/* Return codes describe the translate/generate operation.  Caller may
62 * be able to reuse translated indices under some circumstances.
63 */
64#define U_TRANSLATE_ERROR  -1
65#define U_TRANSLATE_NORMAL  1
66#define U_TRANSLATE_MEMCPY  2
67#define U_GENERATE_LINEAR   3
68#define U_GENERATE_REUSABLE 4
69#define U_GENERATE_ONE_OFF  5
70
71
72void u_index_init( void );
73
74int u_index_translator( unsigned hw_mask,
75                        unsigned prim,
76                        unsigned in_index_size,
77                        unsigned nr,
78                        unsigned in_pv,   /* API */
79                        unsigned out_pv,  /* hardware */
80                        unsigned *out_prim,
81                        unsigned *out_index_size,
82                        unsigned *out_nr,
83                        u_translate_func *out_translate );
84
85/* Note that even when generating it is necessary to know what the
86 * API's PV is, as the indices generated will depend on whether it is
87 * the same as hardware or not, and in the case of triangle strips,
88 * whether it is first or last.
89 */
90int u_index_generator( unsigned hw_mask,
91                       unsigned prim,
92                       unsigned start,
93                       unsigned nr,
94                       unsigned in_pv,   /* API */
95                       unsigned out_pv,  /* hardware */
96                       unsigned *out_prim,
97                       unsigned *out_index_size,
98                       unsigned *out_nr,
99                       u_generate_func *out_generate );
100
101
102void u_unfilled_init( void );
103
104int u_unfilled_translator( unsigned prim,
105                           unsigned in_index_size,
106                           unsigned nr,
107                           unsigned unfilled_mode,
108                           unsigned *out_prim,
109                           unsigned *out_index_size,
110                           unsigned *out_nr,
111                           u_translate_func *out_translate );
112
113int u_unfilled_generator( unsigned prim,
114                          unsigned start,
115                          unsigned nr,
116                          unsigned unfilled_mode,
117                          unsigned *out_prim,
118                          unsigned *out_index_size,
119                          unsigned *out_nr,
120                          u_generate_func *out_generate );
121
122
123
124
125#endif
126