Path: blob/21.2-virgl/src/gallium/auxiliary/util/u_draw.h
4561 views
/**************************************************************************1*2* Copyright 2008 VMware, Inc.3* All Rights Reserved.4*5* Permission is hereby granted, free of charge, to any person obtaining a6* copy of this software and associated documentation files (the7* "Software"), to deal in the Software without restriction, including8* without limitation the rights to use, copy, modify, merge, publish,9* distribute, sub license, and/or sell copies of the Software, and to10* permit persons to whom the Software is furnished to do so, subject to11* the following conditions:12*13* The above copyright notice and this permission notice (including the14* next paragraph) shall be included in all copies or substantial portions15* of the Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS18* OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF19* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT.20* IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR21* ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,22* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE23* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.24*25**************************************************************************/2627#ifndef U_DRAW_H28#define U_DRAW_H293031#include "pipe/p_compiler.h"32#include "pipe/p_context.h"33#include "pipe/p_state.h"343536#ifdef __cplusplus37extern "C" {38#endif394041static inline void42util_draw_init_info(struct pipe_draw_info *info)43{44memset(info, 0, sizeof(*info));45info->instance_count = 1;46info->max_index = 0xffffffff;47}484950static inline void51util_draw_arrays(struct pipe_context *pipe,52enum pipe_prim_type mode,53uint start,54uint count)55{56struct pipe_draw_info info;57struct pipe_draw_start_count_bias draw;5859util_draw_init_info(&info);60info.mode = mode;61info.min_index = start;62info.max_index = start + count - 1;6364draw.start = start;65draw.count = count;66draw.index_bias = 0;6768pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);69}7071static inline void72util_draw_elements(struct pipe_context *pipe,73void *indices,74unsigned index_size,75int index_bias, enum pipe_prim_type mode,76uint start,77uint count)78{79struct pipe_draw_info info;80struct pipe_draw_start_count_bias draw;8182util_draw_init_info(&info);83info.index.user = indices;84info.has_user_indices = true;85info.index_size = index_size;86info.mode = mode;87draw.index_bias = index_bias;8889draw.start = start;90draw.count = count;9192pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);93}9495static inline void96util_draw_arrays_instanced(struct pipe_context *pipe,97enum pipe_prim_type mode,98uint start,99uint count,100uint start_instance,101uint instance_count)102{103struct pipe_draw_info info;104struct pipe_draw_start_count_bias draw;105106util_draw_init_info(&info);107info.mode = mode;108info.start_instance = start_instance;109info.instance_count = instance_count;110info.index_bounds_valid = true;111info.min_index = start;112info.max_index = start + count - 1;113114draw.start = start;115draw.count = count;116draw.index_bias = 0;117118pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);119}120121static inline void122util_draw_elements_instanced(struct pipe_context *pipe,123void *indices,124unsigned index_size,125int index_bias,126enum pipe_prim_type mode,127uint start,128uint count,129uint start_instance,130uint instance_count)131{132struct pipe_draw_info info;133struct pipe_draw_start_count_bias draw;134135util_draw_init_info(&info);136info.index.user = indices;137info.has_user_indices = true;138info.index_size = index_size;139info.mode = mode;140draw.index_bias = index_bias;141info.start_instance = start_instance;142info.instance_count = instance_count;143144draw.start = start;145draw.count = count;146147pipe->draw_vbo(pipe, &info, 0, NULL, &draw, 1);148}149150struct u_indirect_params {151struct pipe_draw_info info;152struct pipe_draw_start_count_bias draw;153};154155/* caller must free the return value */156struct u_indirect_params *157util_draw_indirect_read(struct pipe_context *pipe,158const struct pipe_draw_info *info_in,159const struct pipe_draw_indirect_info *indirect,160unsigned *num_draws);161162/* This converts an indirect draw into a direct draw by mapping the indirect163* buffer, extracting its arguments, and calling pipe->draw_vbo.164*/165void166util_draw_indirect(struct pipe_context *pipe,167const struct pipe_draw_info *info,168const struct pipe_draw_indirect_info *indirect);169170/* Helper to handle multi-draw by splitting into individual draws. You171* don't want to call this if num_draws==1172*/173void174util_draw_multi(struct pipe_context *pctx, const struct pipe_draw_info *info,175unsigned drawid_offset,176const struct pipe_draw_indirect_info *indirect,177const struct pipe_draw_start_count_bias *draws,178unsigned num_draws);179180unsigned181util_draw_max_index(182const struct pipe_vertex_buffer *vertex_buffers,183const struct pipe_vertex_element *vertex_elements,184unsigned nr_vertex_elements,185const struct pipe_draw_info *info);186187188#ifdef __cplusplus189}190#endif191192#endif /* !U_DRAW_H */193194195