1 /************************************************************************** 2 * 3 * Copyright 2008 VMware, Inc. 4 * All Rights Reserved. 5 * 6 * Permission is hereby granted, free of charge, to any person obtaining a 7 * copy of this software and associated documentation files (the 8 * "Software"), to deal in the Software without restriction, including 9 * without limitation the rights to use, copy, modify, merge, publish, 10 * distribute, sub license, and/or sell copies of the Software, and to 11 * permit persons to whom the Software is furnished to do so, subject to 12 * the following conditions: 13 * 14 * The above copyright notice and this permission notice (including the 15 * next paragraph) shall be included in all copies or substantial portions 16 * of the Software. 17 * 18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 19 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 20 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 21 * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR 22 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 23 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 24 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 25 * 26 **************************************************************************/ 27 28 #ifndef U_DRAW_H 29 #define U_DRAW_H 30 31 32 #include "pipe/p_compiler.h" 33 #include "pipe/p_context.h" 34 #include "pipe/p_state.h" 35 36 37 #ifdef __cplusplus 38 extern "C" { 39 #endif 40 41 42 static inline void 43 util_draw_init_info(struct pipe_draw_info *info) 44 { 45 memset(info, 0, sizeof(*info)); 46 info->instance_count = 1; 47 info->max_index = 0xffffffff; 48 } 49 50 51 static inline void 52 util_draw_arrays(struct pipe_context *pipe, 53 enum pipe_prim_type mode, 54 uint start, 55 uint count) 56 { 57 struct pipe_draw_info info; 58 59 util_draw_init_info(&info); 60 info.mode = mode; 61 info.start = start; 62 info.count = count; 63 info.min_index = start; 64 info.max_index = start + count - 1; 65 66 pipe->draw_vbo(pipe, &info); 67 } 68 69 static inline void 70 util_draw_elements(struct pipe_context *pipe, unsigned index_size, 71 int index_bias, enum pipe_prim_type mode, 72 uint start, 73 uint count) 74 { 75 struct pipe_draw_info info; 76 77 util_draw_init_info(&info); 78 info.index_size = index_size; 79 info.mode = mode; 80 info.start = start; 81 info.count = count; 82 info.index_bias = index_bias; 83 84 pipe->draw_vbo(pipe, &info); 85 } 86 87 static inline void 88 util_draw_arrays_instanced(struct pipe_context *pipe, 89 enum pipe_prim_type mode, 90 uint start, 91 uint count, 92 uint start_instance, 93 uint instance_count) 94 { 95 struct pipe_draw_info info; 96 97 util_draw_init_info(&info); 98 info.mode = mode; 99 info.start = start; 100 info.count = count; 101 info.start_instance = start_instance; 102 info.instance_count = instance_count; 103 info.min_index = start; 104 info.max_index = start + count - 1; 105 106 pipe->draw_vbo(pipe, &info); 107 } 108 109 static inline void 110 util_draw_elements_instanced(struct pipe_context *pipe, 111 unsigned index_size, 112 int index_bias, 113 enum pipe_prim_type mode, 114 uint start, 115 uint count, 116 uint start_instance, 117 uint instance_count) 118 { 119 struct pipe_draw_info info; 120 121 util_draw_init_info(&info); 122 info.index_size = index_size; 123 info.mode = mode; 124 info.start = start; 125 info.count = count; 126 info.index_bias = index_bias; 127 info.start_instance = start_instance; 128 info.instance_count = instance_count; 129 130 pipe->draw_vbo(pipe, &info); 131 } 132 133 134 /* This converts an indirect draw into a direct draw by mapping the indirect 135 * buffer, extracting its arguments, and calling pipe->draw_vbo. 136 */ 137 void 138 util_draw_indirect(struct pipe_context *pipe, 139 const struct pipe_draw_info *info); 140 141 142 unsigned 143 util_draw_max_index( 144 const struct pipe_vertex_buffer *vertex_buffers, 145 const struct pipe_vertex_element *vertex_elements, 146 unsigned nr_vertex_elements, 147 const struct pipe_draw_info *info); 148 149 150 #ifdef __cplusplus 151 } 152 #endif 153 154 #endif /* !U_DRAW_H */ 155