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#include "pipe/p_defines.h" 30 31/* First/last provoking vertex */ 32#define PV_FIRST 0 33#define PV_LAST 1 34#define PV_COUNT 2 35 36/* primitive restart disable/enable flags */ 37#define PR_DISABLE 0 38#define PR_ENABLE 1 39#define PR_COUNT 2 40 41 42/** 43 * Index translator function (for glDrawElements() case) 44 * 45 * \param in the input index buffer 46 * \param start the index of the first vertex (pipe_draw_info::start) 47 * \param nr the number of vertices (pipe_draw_info::count) 48 * \param out output buffer big enough for nr vertices (of 49 * @out_index_size bytes each) 50 */ 51typedef void (*u_translate_func)( const void *in, 52 unsigned start, 53 unsigned in_nr, 54 unsigned out_nr, 55 unsigned restart_index, 56 void *out ); 57 58/** 59 * Index generator function (for glDrawArrays() case) 60 * 61 * \param start the index of the first vertex (pipe_draw_info::start) 62 * \param nr the number of vertices (pipe_draw_info::count) 63 * \param out output buffer big enough for nr vertices (of 64 * @out_index_size bytes each) 65 */ 66typedef void (*u_generate_func)( unsigned start, 67 unsigned nr, 68 void *out ); 69 70 71/* Return codes describe the translate/generate operation. Caller may 72 * be able to reuse translated indices under some circumstances. 73 */ 74enum indices_mode { 75 U_TRANSLATE_ERROR = -1, 76 U_TRANSLATE_NORMAL = 1, 77 U_TRANSLATE_MEMCPY = 2, 78 U_GENERATE_LINEAR = 3, 79 U_GENERATE_REUSABLE= 4, 80 U_GENERATE_ONE_OFF = 5, 81}; 82 83void u_index_init( void ); 84 85/* returns the primitive type resulting from index translation */ 86enum pipe_prim_type 87u_index_prim_type_convert(unsigned hw_mask, enum pipe_prim_type prim, bool pv_matches); 88 89static inline unsigned 90u_index_size_convert(unsigned index_size) 91{ 92 return (index_size == 4) ? 4 : 2; 93} 94 95unsigned 96u_index_count_converted_indices(unsigned hw_mask, bool pv_matches, enum pipe_prim_type prim, unsigned nr); 97 98/** 99 * For indexed drawing, this function determines what kind of primitive 100 * transformation is needed (if any) for handling: 101 * - unsupported primitive types (such as PIPE_PRIM_POLYGON) 102 * - changing the provoking vertex 103 * - primitive restart 104 * - index size (1 byte, 2 byte or 4 byte indexes) 105 */ 106enum indices_mode 107u_index_translator(unsigned hw_mask, 108 enum pipe_prim_type prim, 109 unsigned in_index_size, 110 unsigned nr, 111 unsigned in_pv, /* API */ 112 unsigned out_pv, /* hardware */ 113 unsigned prim_restart, 114 enum pipe_prim_type *out_prim, 115 unsigned *out_index_size, 116 unsigned *out_nr, 117 u_translate_func *out_translate); 118 119 120/** 121 * For non-indexed drawing, this function determines what kind of primitive 122 * transformation is needed (see above). 123 * 124 * Note that even when generating it is necessary to know what the 125 * API's PV is, as the indices generated will depend on whether it is 126 * the same as hardware or not, and in the case of triangle strips, 127 * whether it is first or last. 128 */ 129enum indices_mode 130u_index_generator(unsigned hw_mask, 131 enum pipe_prim_type prim, 132 unsigned start, 133 unsigned nr, 134 unsigned in_pv, /* API */ 135 unsigned out_pv, /* hardware */ 136 enum pipe_prim_type *out_prim, 137 unsigned *out_index_size, 138 unsigned *out_nr, 139 u_generate_func *out_generate); 140 141 142void u_unfilled_init( void ); 143 144/** 145 * If the driver can't handle "unfilled" primitives (i.e. drawing triangle 146 * primitives as 3 lines or 3 points) this function can be used to translate 147 * an indexed primitive into a new indexed primitive to draw as lines or 148 * points. 149 */ 150enum indices_mode 151u_unfilled_translator(enum pipe_prim_type prim, 152 unsigned in_index_size, 153 unsigned nr, 154 unsigned unfilled_mode, 155 enum pipe_prim_type *out_prim, 156 unsigned *out_index_size, 157 unsigned *out_nr, 158 u_translate_func *out_translate); 159 160/** 161 * As above, but for non-indexed (array) primitives. 162 */ 163enum indices_mode 164u_unfilled_generator(enum pipe_prim_type prim, 165 unsigned start, 166 unsigned nr, 167 unsigned unfilled_mode, 168 enum pipe_prim_type *out_prim, 169 unsigned *out_index_size, 170 unsigned *out_nr, 171 u_generate_func *out_generate); 172 173#endif 174