draw_context.h revision 185ed2105829d6f5eb19edb9abbf0d7977e157c3
1 2/************************************************************************** 3 * 4 * Copyright 2007 Tungsten Graphics, Inc., Cedar Park, Texas. 5 * All Rights Reserved. 6 * 7 * Permission is hereby granted, free of charge, to any person obtaining a 8 * copy of this software and associated documentation files (the 9 * "Software"), to deal in the Software without restriction, including 10 * without limitation the rights to use, copy, modify, merge, publish, 11 * distribute, sub license, and/or sell copies of the Software, and to 12 * permit persons to whom the Software is furnished to do so, subject to 13 * the following conditions: 14 * 15 * The above copyright notice and this permission notice (including the 16 * next paragraph) shall be included in all copies or substantial portions 17 * of the Software. 18 * 19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 22 * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR 23 * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 24 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 25 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 * 27 **************************************************************************/ 28 29/** 30 * \brief Public interface into the drawing module. 31 */ 32 33/* Authors: Keith Whitwell <keith@tungstengraphics.com> 34 */ 35 36 37#ifndef DRAW_CONTEXT_H 38#define DRAW_CONTEXT_H 39 40 41#include "pipe/p_state.h" 42#include "tgsi/tgsi_exec.h" 43 44struct pipe_context; 45struct draw_context; 46struct draw_stage; 47struct draw_vertex_shader; 48struct draw_geometry_shader; 49struct draw_fragment_shader; 50struct tgsi_sampler; 51struct gallivm_state; 52 53/* 54 * structure to contain driver internal information 55 * for stream out support. mapping stores the pointer 56 * to the buffer contents, and internal offset stores 57 * stores an internal counter to how much of the stream 58 * out buffer is used (in bytes). 59 */ 60struct draw_so_target { 61 struct pipe_stream_output_target target; 62 void *mapping; 63 int internal_offset; 64}; 65 66struct draw_context *draw_create( struct pipe_context *pipe ); 67 68struct draw_context *draw_create_no_llvm(struct pipe_context *pipe); 69 70struct draw_context * 71draw_create_gallivm(struct pipe_context *pipe, struct gallivm_state *gallivm); 72 73void draw_destroy( struct draw_context *draw ); 74 75void draw_flush(struct draw_context *draw); 76 77void draw_set_viewport_state( struct draw_context *draw, 78 const struct pipe_viewport_state *viewport ); 79 80void draw_set_clip_state( struct draw_context *pipe, 81 const struct pipe_clip_state *clip ); 82 83/** 84 * Sets the rasterization state used by the draw module. 85 * The rast_handle is used to pass the driver specific representation 86 * of the rasterization state. It's going to be used when the 87 * draw module sets the state back on the driver itself using the 88 * pipe::bind_rasterizer_state method. 89 * 90 * NOTE: if you're calling this function from within the pipe's 91 * bind_rasterizer_state you should always call it before binding 92 * the actual state - that's because the draw module can try to 93 * bind its own rasterizer state which would reset your newly 94 * set state. i.e. always do 95 * draw_set_rasterizer_state(driver->draw, state->pipe_state, state); 96 * driver->state.raster = state; 97 */ 98void draw_set_rasterizer_state( struct draw_context *draw, 99 const struct pipe_rasterizer_state *raster, 100 void *rast_handle ); 101 102void draw_set_rasterize_stage( struct draw_context *draw, 103 struct draw_stage *stage ); 104 105void draw_wide_point_threshold(struct draw_context *draw, float threshold); 106 107void draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite); 108 109void draw_wide_line_threshold(struct draw_context *draw, float threshold); 110 111void draw_enable_line_stipple(struct draw_context *draw, boolean enable); 112 113void draw_enable_point_sprites(struct draw_context *draw, boolean enable); 114 115void draw_set_mrd(struct draw_context *draw, double mrd); 116 117boolean 118draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe); 119 120boolean 121draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe); 122 123boolean 124draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe); 125 126 127struct tgsi_shader_info * 128draw_get_shader_info(const struct draw_context *draw); 129 130int 131draw_find_shader_output(const struct draw_context *draw, 132 uint semantic_name, uint semantic_index); 133 134uint 135draw_num_shader_outputs(const struct draw_context *draw); 136 137 138void 139draw_texture_samplers(struct draw_context *draw, 140 uint shader_type, 141 uint num_samplers, 142 struct tgsi_sampler **samplers); 143 144void 145draw_set_sampler_views(struct draw_context *draw, 146 struct pipe_sampler_view **views, 147 unsigned num); 148void 149draw_set_samplers(struct draw_context *draw, 150 struct pipe_sampler_state **samplers, 151 unsigned num); 152 153void 154draw_set_mapped_texture(struct draw_context *draw, 155 unsigned sampler_idx, 156 uint32_t width, uint32_t height, uint32_t depth, 157 uint32_t first_level, uint32_t last_level, 158 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], 159 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], 160 const void *data[PIPE_MAX_TEXTURE_LEVELS]); 161 162 163/* 164 * Vertex shader functions 165 */ 166 167struct draw_vertex_shader * 168draw_create_vertex_shader(struct draw_context *draw, 169 const struct pipe_shader_state *shader); 170void draw_bind_vertex_shader(struct draw_context *draw, 171 struct draw_vertex_shader *dvs); 172void draw_delete_vertex_shader(struct draw_context *draw, 173 struct draw_vertex_shader *dvs); 174 175 176/* 177 * Fragment shader functions 178 */ 179struct draw_fragment_shader * 180draw_create_fragment_shader(struct draw_context *draw, 181 const struct pipe_shader_state *shader); 182void draw_bind_fragment_shader(struct draw_context *draw, 183 struct draw_fragment_shader *dvs); 184void draw_delete_fragment_shader(struct draw_context *draw, 185 struct draw_fragment_shader *dvs); 186 187/* 188 * Geometry shader functions 189 */ 190struct draw_geometry_shader * 191draw_create_geometry_shader(struct draw_context *draw, 192 const struct pipe_shader_state *shader); 193void draw_bind_geometry_shader(struct draw_context *draw, 194 struct draw_geometry_shader *dvs); 195void draw_delete_geometry_shader(struct draw_context *draw, 196 struct draw_geometry_shader *dvs); 197 198 199/* 200 * Vertex data functions 201 */ 202 203void draw_set_vertex_buffers(struct draw_context *draw, 204 unsigned count, 205 const struct pipe_vertex_buffer *buffers); 206 207void draw_set_vertex_elements(struct draw_context *draw, 208 unsigned count, 209 const struct pipe_vertex_element *elements); 210 211void draw_set_indexes(struct draw_context *draw, 212 const void *elements, unsigned elem_size); 213 214void draw_set_mapped_vertex_buffer(struct draw_context *draw, 215 unsigned attr, const void *buffer); 216 217void 218draw_set_mapped_constant_buffer(struct draw_context *draw, 219 unsigned shader_type, 220 unsigned slot, 221 const void *buffer, 222 unsigned size); 223 224void 225draw_set_mapped_so_buffers(struct draw_context *draw, 226 void *buffers[PIPE_MAX_SO_BUFFERS], 227 unsigned num_buffers); 228 229void 230draw_set_mapped_so_targets(struct draw_context *draw, 231 int num_targets, 232 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]); 233 234void 235draw_set_so_state(struct draw_context *draw, 236 struct pipe_stream_output_info *state); 237 238 239/*********************************************************************** 240 * draw_pt.c 241 */ 242 243void draw_vbo(struct draw_context *draw, 244 const struct pipe_draw_info *info); 245 246void draw_arrays(struct draw_context *draw, unsigned prim, 247 unsigned start, unsigned count); 248 249void 250draw_arrays_instanced(struct draw_context *draw, 251 unsigned mode, 252 unsigned start, 253 unsigned count, 254 unsigned startInstance, 255 unsigned instanceCount); 256 257 258/******************************************************************************* 259 * Driver backend interface 260 */ 261struct vbuf_render; 262void draw_set_render( struct draw_context *draw, 263 struct vbuf_render *render ); 264 265void draw_set_driver_clipping( struct draw_context *draw, 266 boolean bypass_clip_xy, 267 boolean bypass_clip_z, 268 boolean guard_band_xy); 269 270void draw_set_force_passthrough( struct draw_context *draw, 271 boolean enable ); 272 273/******************************************************************************* 274 * Draw pipeline 275 */ 276boolean draw_need_pipeline(const struct draw_context *draw, 277 const struct pipe_rasterizer_state *rasterizer, 278 unsigned prim ); 279 280static INLINE int 281draw_get_shader_param(unsigned shader, enum pipe_shader_cap param) 282{ 283 switch(shader) { 284 case PIPE_SHADER_VERTEX: 285 case PIPE_SHADER_GEOMETRY: 286 return tgsi_exec_get_shader_param(param); 287 default: 288 return 0; 289 } 290} 291 292#endif /* DRAW_CONTEXT_H */ 293