Path: blob/21.2-virgl/src/gallium/auxiliary/indices/u_indices.h
4565 views
/*1* Copyright 2009 VMware, Inc.2* All Rights Reserved.3*4* Permission is hereby granted, free of charge, to any person obtaining a5* copy of this software and associated documentation files (the "Software"),6* to deal in the Software without restriction, including without limitation7* on the rights to use, copy, modify, merge, publish, distribute, sub8* license, and/or sell copies of the Software, and to permit persons to whom9* the Software is furnished to do so, subject to the following conditions:10*11* The above copyright notice and this permission notice (including the next12* paragraph) shall be included in all copies or substantial portions of the13* Software.14*15* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR16* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,17* FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL18* VMWARE AND/OR THEIR SUPPLIERS BE LIABLE FOR ANY CLAIM,19* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR20* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE21* USE OR OTHER DEALINGS IN THE SOFTWARE.22*/2324#ifndef U_INDICES_H25#define U_INDICES_H2627#include "pipe/p_compiler.h"28#include "pipe/p_defines.h"2930/* First/last provoking vertex */31#define PV_FIRST 032#define PV_LAST 133#define PV_COUNT 23435/* primitive restart disable/enable flags */36#define PR_DISABLE 037#define PR_ENABLE 138#define PR_COUNT 2394041/**42* Index translator function (for glDrawElements() case)43*44* \param in the input index buffer45* \param start the index of the first vertex (pipe_draw_info::start)46* \param nr the number of vertices (pipe_draw_info::count)47* \param out output buffer big enough for nr vertices (of48* @out_index_size bytes each)49*/50typedef void (*u_translate_func)( const void *in,51unsigned start,52unsigned in_nr,53unsigned out_nr,54unsigned restart_index,55void *out );5657/**58* Index generator function (for glDrawArrays() case)59*60* \param start the index of the first vertex (pipe_draw_info::start)61* \param nr the number of vertices (pipe_draw_info::count)62* \param out output buffer big enough for nr vertices (of63* @out_index_size bytes each)64*/65typedef void (*u_generate_func)( unsigned start,66unsigned nr,67void *out );686970/* Return codes describe the translate/generate operation. Caller may71* be able to reuse translated indices under some circumstances.72*/73enum indices_mode {74U_TRANSLATE_ERROR = -1,75U_TRANSLATE_NORMAL = 1,76U_TRANSLATE_MEMCPY = 2,77U_GENERATE_LINEAR = 3,78U_GENERATE_REUSABLE= 4,79U_GENERATE_ONE_OFF = 5,80};8182void u_index_init( void );8384/* returns the primitive type resulting from index translation */85enum pipe_prim_type86u_index_prim_type_convert(unsigned hw_mask, enum pipe_prim_type prim, bool pv_matches);8788static inline unsigned89u_index_size_convert(unsigned index_size)90{91return (index_size == 4) ? 4 : 2;92}9394unsigned95u_index_count_converted_indices(unsigned hw_mask, bool pv_matches, enum pipe_prim_type prim, unsigned nr);9697/**98* For indexed drawing, this function determines what kind of primitive99* transformation is needed (if any) for handling:100* - unsupported primitive types (such as PIPE_PRIM_POLYGON)101* - changing the provoking vertex102* - primitive restart103* - index size (1 byte, 2 byte or 4 byte indexes)104*/105enum indices_mode106u_index_translator(unsigned hw_mask,107enum pipe_prim_type prim,108unsigned in_index_size,109unsigned nr,110unsigned in_pv, /* API */111unsigned out_pv, /* hardware */112unsigned prim_restart,113enum pipe_prim_type *out_prim,114unsigned *out_index_size,115unsigned *out_nr,116u_translate_func *out_translate);117118119/**120* For non-indexed drawing, this function determines what kind of primitive121* transformation is needed (see above).122*123* Note that even when generating it is necessary to know what the124* API's PV is, as the indices generated will depend on whether it is125* the same as hardware or not, and in the case of triangle strips,126* whether it is first or last.127*/128enum indices_mode129u_index_generator(unsigned hw_mask,130enum pipe_prim_type prim,131unsigned start,132unsigned nr,133unsigned in_pv, /* API */134unsigned out_pv, /* hardware */135enum pipe_prim_type *out_prim,136unsigned *out_index_size,137unsigned *out_nr,138u_generate_func *out_generate);139140141void u_unfilled_init( void );142143/**144* If the driver can't handle "unfilled" primitives (i.e. drawing triangle145* primitives as 3 lines or 3 points) this function can be used to translate146* an indexed primitive into a new indexed primitive to draw as lines or147* points.148*/149enum indices_mode150u_unfilled_translator(enum pipe_prim_type prim,151unsigned in_index_size,152unsigned nr,153unsigned unfilled_mode,154enum pipe_prim_type *out_prim,155unsigned *out_index_size,156unsigned *out_nr,157u_translate_func *out_translate);158159/**160* As above, but for non-indexed (array) primitives.161*/162enum indices_mode163u_unfilled_generator(enum pipe_prim_type prim,164unsigned start,165unsigned nr,166unsigned unfilled_mode,167enum pipe_prim_type *out_prim,168unsigned *out_index_size,169unsigned *out_nr,170u_generate_func *out_generate);171172#endif173174175