1bf215546Sopenharmony_ci/* 2bf215546Sopenharmony_ci * Copyright 2009 VMware, Inc. 3bf215546Sopenharmony_ci * All Rights Reserved. 4bf215546Sopenharmony_ci * 5bf215546Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a 6bf215546Sopenharmony_ci * copy of this software and associated documentation files (the "Software"), 7bf215546Sopenharmony_ci * to deal in the Software without restriction, including without limitation 8bf215546Sopenharmony_ci * on the rights to use, copy, modify, merge, publish, distribute, sub 9bf215546Sopenharmony_ci * license, and/or sell copies of the Software, and to permit persons to whom 10bf215546Sopenharmony_ci * the Software is furnished to do so, subject to the following conditions: 11bf215546Sopenharmony_ci * 12bf215546Sopenharmony_ci * The above copyright notice and this permission notice (including the next 13bf215546Sopenharmony_ci * paragraph) shall be included in all copies or substantial portions of the 14bf215546Sopenharmony_ci * Software. 15bf215546Sopenharmony_ci * 16bf215546Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17bf215546Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18bf215546Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 19bf215546Sopenharmony_ci * VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM, 20bf215546Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 21bf215546Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 22bf215546Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE. 23bf215546Sopenharmony_ci */ 24bf215546Sopenharmony_ci 25bf215546Sopenharmony_ci#ifndef U_INDICES_H 26bf215546Sopenharmony_ci#define U_INDICES_H 27bf215546Sopenharmony_ci 28bf215546Sopenharmony_ci#include "pipe/p_compiler.h" 29bf215546Sopenharmony_ci#include "pipe/p_defines.h" 30bf215546Sopenharmony_ci 31bf215546Sopenharmony_ci/* First/last provoking vertex */ 32bf215546Sopenharmony_ci#define PV_FIRST 0 33bf215546Sopenharmony_ci#define PV_LAST 1 34bf215546Sopenharmony_ci#define PV_COUNT 2 35bf215546Sopenharmony_ci 36bf215546Sopenharmony_ci/* primitive restart disable/enable flags */ 37bf215546Sopenharmony_ci#define PR_DISABLE 0 38bf215546Sopenharmony_ci#define PR_ENABLE 1 39bf215546Sopenharmony_ci#define PR_COUNT 2 40bf215546Sopenharmony_ci 41bf215546Sopenharmony_ci 42bf215546Sopenharmony_ci/** 43bf215546Sopenharmony_ci * Index translator function (for glDrawElements() case) 44bf215546Sopenharmony_ci * 45bf215546Sopenharmony_ci * \param in the input index buffer 46bf215546Sopenharmony_ci * \param start the index of the first vertex (pipe_draw_info::start) 47bf215546Sopenharmony_ci * \param nr the number of vertices (pipe_draw_info::count) 48bf215546Sopenharmony_ci * \param out output buffer big enough for nr vertices (of 49bf215546Sopenharmony_ci * @out_index_size bytes each) 50bf215546Sopenharmony_ci */ 51bf215546Sopenharmony_citypedef void (*u_translate_func)( const void *in, 52bf215546Sopenharmony_ci unsigned start, 53bf215546Sopenharmony_ci unsigned in_nr, 54bf215546Sopenharmony_ci unsigned out_nr, 55bf215546Sopenharmony_ci unsigned restart_index, 56bf215546Sopenharmony_ci void *out ); 57bf215546Sopenharmony_ci 58bf215546Sopenharmony_ci/** 59bf215546Sopenharmony_ci * Index generator function (for glDrawArrays() case) 60bf215546Sopenharmony_ci * 61bf215546Sopenharmony_ci * \param start the index of the first vertex (pipe_draw_info::start) 62bf215546Sopenharmony_ci * \param nr the number of vertices (pipe_draw_info::count) 63bf215546Sopenharmony_ci * \param out output buffer big enough for nr vertices (of 64bf215546Sopenharmony_ci * @out_index_size bytes each) 65bf215546Sopenharmony_ci */ 66bf215546Sopenharmony_citypedef void (*u_generate_func)( unsigned start, 67bf215546Sopenharmony_ci unsigned nr, 68bf215546Sopenharmony_ci void *out ); 69bf215546Sopenharmony_ci 70bf215546Sopenharmony_ci 71bf215546Sopenharmony_ci/* Return codes describe the translate/generate operation. Caller may 72bf215546Sopenharmony_ci * be able to reuse translated indices under some circumstances. 73bf215546Sopenharmony_ci */ 74bf215546Sopenharmony_cienum indices_mode { 75bf215546Sopenharmony_ci U_TRANSLATE_ERROR = -1, 76bf215546Sopenharmony_ci U_TRANSLATE_NORMAL = 1, 77bf215546Sopenharmony_ci U_TRANSLATE_MEMCPY = 2, 78bf215546Sopenharmony_ci U_GENERATE_LINEAR = 3, 79bf215546Sopenharmony_ci U_GENERATE_REUSABLE= 4, 80bf215546Sopenharmony_ci U_GENERATE_ONE_OFF = 5, 81bf215546Sopenharmony_ci}; 82bf215546Sopenharmony_ci 83bf215546Sopenharmony_civoid u_index_init( void ); 84bf215546Sopenharmony_ci 85bf215546Sopenharmony_ci/* returns the primitive type resulting from index translation */ 86bf215546Sopenharmony_cienum pipe_prim_type 87bf215546Sopenharmony_ciu_index_prim_type_convert(unsigned hw_mask, enum pipe_prim_type prim, bool pv_matches); 88bf215546Sopenharmony_ci 89bf215546Sopenharmony_cistatic inline unsigned 90bf215546Sopenharmony_ciu_index_size_convert(unsigned index_size) 91bf215546Sopenharmony_ci{ 92bf215546Sopenharmony_ci return (index_size == 4) ? 4 : 2; 93bf215546Sopenharmony_ci} 94bf215546Sopenharmony_ci 95bf215546Sopenharmony_ciunsigned 96bf215546Sopenharmony_ciu_index_count_converted_indices(unsigned hw_mask, bool pv_matches, enum pipe_prim_type prim, unsigned nr); 97bf215546Sopenharmony_ci 98bf215546Sopenharmony_ci/** 99bf215546Sopenharmony_ci * For indexed drawing, this function determines what kind of primitive 100bf215546Sopenharmony_ci * transformation is needed (if any) for handling: 101bf215546Sopenharmony_ci * - unsupported primitive types (such as PIPE_PRIM_POLYGON) 102bf215546Sopenharmony_ci * - changing the provoking vertex 103bf215546Sopenharmony_ci * - primitive restart 104bf215546Sopenharmony_ci * - index size (1 byte, 2 byte or 4 byte indexes) 105bf215546Sopenharmony_ci */ 106bf215546Sopenharmony_cienum indices_mode 107bf215546Sopenharmony_ciu_index_translator(unsigned hw_mask, 108bf215546Sopenharmony_ci enum pipe_prim_type prim, 109bf215546Sopenharmony_ci unsigned in_index_size, 110bf215546Sopenharmony_ci unsigned nr, 111bf215546Sopenharmony_ci unsigned in_pv, /* API */ 112bf215546Sopenharmony_ci unsigned out_pv, /* hardware */ 113bf215546Sopenharmony_ci unsigned prim_restart, 114bf215546Sopenharmony_ci enum pipe_prim_type *out_prim, 115bf215546Sopenharmony_ci unsigned *out_index_size, 116bf215546Sopenharmony_ci unsigned *out_nr, 117bf215546Sopenharmony_ci u_translate_func *out_translate); 118bf215546Sopenharmony_ci 119bf215546Sopenharmony_ci 120bf215546Sopenharmony_ci/** 121bf215546Sopenharmony_ci * For non-indexed drawing, this function determines what kind of primitive 122bf215546Sopenharmony_ci * transformation is needed (see above). 123bf215546Sopenharmony_ci * 124bf215546Sopenharmony_ci * Note that even when generating it is necessary to know what the 125bf215546Sopenharmony_ci * API's PV is, as the indices generated will depend on whether it is 126bf215546Sopenharmony_ci * the same as hardware or not, and in the case of triangle strips, 127bf215546Sopenharmony_ci * whether it is first or last. 128bf215546Sopenharmony_ci */ 129bf215546Sopenharmony_cienum indices_mode 130bf215546Sopenharmony_ciu_index_generator(unsigned hw_mask, 131bf215546Sopenharmony_ci enum pipe_prim_type prim, 132bf215546Sopenharmony_ci unsigned start, 133bf215546Sopenharmony_ci unsigned nr, 134bf215546Sopenharmony_ci unsigned in_pv, /* API */ 135bf215546Sopenharmony_ci unsigned out_pv, /* hardware */ 136bf215546Sopenharmony_ci enum pipe_prim_type *out_prim, 137bf215546Sopenharmony_ci unsigned *out_index_size, 138bf215546Sopenharmony_ci unsigned *out_nr, 139bf215546Sopenharmony_ci u_generate_func *out_generate); 140bf215546Sopenharmony_ci 141bf215546Sopenharmony_ci 142bf215546Sopenharmony_civoid u_unfilled_init( void ); 143bf215546Sopenharmony_ci 144bf215546Sopenharmony_ci/** 145bf215546Sopenharmony_ci * If the driver can't handle "unfilled" primitives (i.e. drawing triangle 146bf215546Sopenharmony_ci * primitives as 3 lines or 3 points) this function can be used to translate 147bf215546Sopenharmony_ci * an indexed primitive into a new indexed primitive to draw as lines or 148bf215546Sopenharmony_ci * points. 149bf215546Sopenharmony_ci */ 150bf215546Sopenharmony_cienum indices_mode 151bf215546Sopenharmony_ciu_unfilled_translator(enum pipe_prim_type prim, 152bf215546Sopenharmony_ci unsigned in_index_size, 153bf215546Sopenharmony_ci unsigned nr, 154bf215546Sopenharmony_ci unsigned unfilled_mode, 155bf215546Sopenharmony_ci enum pipe_prim_type *out_prim, 156bf215546Sopenharmony_ci unsigned *out_index_size, 157bf215546Sopenharmony_ci unsigned *out_nr, 158bf215546Sopenharmony_ci u_translate_func *out_translate); 159bf215546Sopenharmony_ci 160bf215546Sopenharmony_ci/** 161bf215546Sopenharmony_ci * As above, but for non-indexed (array) primitives. 162bf215546Sopenharmony_ci */ 163bf215546Sopenharmony_cienum indices_mode 164bf215546Sopenharmony_ciu_unfilled_generator(enum pipe_prim_type prim, 165bf215546Sopenharmony_ci unsigned start, 166bf215546Sopenharmony_ci unsigned nr, 167bf215546Sopenharmony_ci unsigned unfilled_mode, 168bf215546Sopenharmony_ci enum pipe_prim_type *out_prim, 169bf215546Sopenharmony_ci unsigned *out_index_size, 170bf215546Sopenharmony_ci unsigned *out_nr, 171bf215546Sopenharmony_ci u_generate_func *out_generate); 172bf215546Sopenharmony_ci 173bf215546Sopenharmony_ci#endif 174