1 /************************************************************************** 2 * 3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. 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 TUNGSTEN GRAPHICS 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, uint mode, uint start, uint count) 53 { 54 struct pipe_draw_info info; 55 56 util_draw_init_info(&info); 57 info.mode = mode; 58 info.start = start; 59 info.count = count; 60 info.min_index = start; 61 info.max_index = start + count - 1; 62 63 pipe->draw_vbo(pipe, &info); 64 } 65 66 static INLINE void 67 util_draw_elements(struct pipe_context *pipe, int index_bias, 68 uint mode, uint start, uint count) 69 { 70 struct pipe_draw_info info; 71 72 util_draw_init_info(&info); 73 info.indexed = TRUE; 74 info.mode = mode; 75 info.start = start; 76 info.count = count; 77 info.index_bias = index_bias; 78 79 pipe->draw_vbo(pipe, &info); 80 } 81 82 static INLINE void 83 util_draw_arrays_instanced(struct pipe_context *pipe, 84 uint mode, uint start, uint count, 85 uint start_instance, 86 uint instance_count) 87 { 88 struct pipe_draw_info info; 89 90 util_draw_init_info(&info); 91 info.mode = mode; 92 info.start = start; 93 info.count = count; 94 info.start_instance = start_instance; 95 info.instance_count = instance_count; 96 info.min_index = start; 97 info.max_index = start + count - 1; 98 99 pipe->draw_vbo(pipe, &info); 100 } 101 102 static INLINE void 103 util_draw_elements_instanced(struct pipe_context *pipe, 104 int index_bias, 105 uint mode, uint start, uint count, 106 uint start_instance, 107 uint instance_count) 108 { 109 struct pipe_draw_info info; 110 111 util_draw_init_info(&info); 112 info.indexed = TRUE; 113 info.mode = mode; 114 info.start = start; 115 info.count = count; 116 info.index_bias = index_bias; 117 info.start_instance = start_instance; 118 info.instance_count = instance_count; 119 120 pipe->draw_vbo(pipe, &info); 121 } 122 123 static INLINE void 124 util_draw_range_elements(struct pipe_context *pipe, 125 int index_bias, 126 uint min_index, 127 uint max_index, 128 uint mode, uint start, uint count) 129 { 130 struct pipe_draw_info info; 131 132 util_draw_init_info(&info); 133 info.indexed = TRUE; 134 info.mode = mode; 135 info.start = start; 136 info.count = count; 137 info.index_bias = index_bias; 138 info.min_index = min_index; 139 info.max_index = max_index; 140 141 pipe->draw_vbo(pipe, &info); 142 } 143 144 145 unsigned 146 util_draw_max_index( 147 const struct pipe_vertex_buffer *vertex_buffers, 148 const struct pipe_vertex_element *vertex_elements, 149 unsigned nr_vertex_elements, 150 const struct pipe_draw_info *info); 151 152 153 #ifdef __cplusplus 154 } 155 #endif 156 157 #endif /* !U_DRAW_H */ 158