draw_context.h revision ec8cbd79ac4065111365a6720c9564de56855cc8
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 83void draw_set_rasterizer_state( struct draw_context *draw, 84 const struct pipe_rasterizer_state *raster, 85 void *rast_handle ); 86 87void draw_set_rasterize_stage( struct draw_context *draw, 88 struct draw_stage *stage ); 89 90void draw_wide_point_threshold(struct draw_context *draw, float threshold); 91 92void draw_wide_point_sprites(struct draw_context *draw, boolean draw_sprite); 93 94void draw_wide_line_threshold(struct draw_context *draw, float threshold); 95 96void draw_enable_line_stipple(struct draw_context *draw, boolean enable); 97 98void draw_enable_point_sprites(struct draw_context *draw, boolean enable); 99 100void draw_set_mrd(struct draw_context *draw, double mrd); 101 102boolean 103draw_install_aaline_stage(struct draw_context *draw, struct pipe_context *pipe); 104 105boolean 106draw_install_aapoint_stage(struct draw_context *draw, struct pipe_context *pipe); 107 108boolean 109draw_install_pstipple_stage(struct draw_context *draw, struct pipe_context *pipe); 110 111 112struct tgsi_shader_info * 113draw_get_shader_info(const struct draw_context *draw); 114 115int 116draw_find_shader_output(const struct draw_context *draw, 117 uint semantic_name, uint semantic_index); 118 119uint 120draw_num_shader_outputs(const struct draw_context *draw); 121 122 123void 124draw_texture_samplers(struct draw_context *draw, 125 uint shader_type, 126 uint num_samplers, 127 struct tgsi_sampler **samplers); 128 129void 130draw_set_sampler_views(struct draw_context *draw, 131 struct pipe_sampler_view **views, 132 unsigned num); 133void 134draw_set_samplers(struct draw_context *draw, 135 struct pipe_sampler_state **samplers, 136 unsigned num); 137 138void 139draw_set_mapped_texture(struct draw_context *draw, 140 unsigned sampler_idx, 141 uint32_t width, uint32_t height, uint32_t depth, 142 uint32_t first_level, uint32_t last_level, 143 uint32_t row_stride[PIPE_MAX_TEXTURE_LEVELS], 144 uint32_t img_stride[PIPE_MAX_TEXTURE_LEVELS], 145 const void *data[PIPE_MAX_TEXTURE_LEVELS]); 146 147 148/* 149 * Vertex shader functions 150 */ 151 152struct draw_vertex_shader * 153draw_create_vertex_shader(struct draw_context *draw, 154 const struct pipe_shader_state *shader); 155void draw_bind_vertex_shader(struct draw_context *draw, 156 struct draw_vertex_shader *dvs); 157void draw_delete_vertex_shader(struct draw_context *draw, 158 struct draw_vertex_shader *dvs); 159 160 161/* 162 * Fragment shader functions 163 */ 164struct draw_fragment_shader * 165draw_create_fragment_shader(struct draw_context *draw, 166 const struct pipe_shader_state *shader); 167void draw_bind_fragment_shader(struct draw_context *draw, 168 struct draw_fragment_shader *dvs); 169void draw_delete_fragment_shader(struct draw_context *draw, 170 struct draw_fragment_shader *dvs); 171 172/* 173 * Geometry shader functions 174 */ 175struct draw_geometry_shader * 176draw_create_geometry_shader(struct draw_context *draw, 177 const struct pipe_shader_state *shader); 178void draw_bind_geometry_shader(struct draw_context *draw, 179 struct draw_geometry_shader *dvs); 180void draw_delete_geometry_shader(struct draw_context *draw, 181 struct draw_geometry_shader *dvs); 182 183 184/* 185 * Vertex data functions 186 */ 187 188void draw_set_vertex_buffers(struct draw_context *draw, 189 unsigned count, 190 const struct pipe_vertex_buffer *buffers); 191 192void draw_set_vertex_elements(struct draw_context *draw, 193 unsigned count, 194 const struct pipe_vertex_element *elements); 195 196void draw_set_index_buffer(struct draw_context *draw, 197 const struct pipe_index_buffer *ib); 198 199void draw_set_mapped_index_buffer(struct draw_context *draw, 200 const void *elements); 201 202void draw_set_mapped_vertex_buffer(struct draw_context *draw, 203 unsigned attr, const void *buffer); 204 205void 206draw_set_mapped_constant_buffer(struct draw_context *draw, 207 unsigned shader_type, 208 unsigned slot, 209 const void *buffer, 210 unsigned size); 211 212void 213draw_set_mapped_so_buffers(struct draw_context *draw, 214 void *buffers[PIPE_MAX_SO_BUFFERS], 215 unsigned num_buffers); 216 217void 218draw_set_mapped_so_targets(struct draw_context *draw, 219 int num_targets, 220 struct draw_so_target *targets[PIPE_MAX_SO_BUFFERS]); 221 222void 223draw_set_so_state(struct draw_context *draw, 224 struct pipe_stream_output_info *state); 225 226 227/*********************************************************************** 228 * draw_pt.c 229 */ 230 231void draw_vbo(struct draw_context *draw, 232 const struct pipe_draw_info *info); 233 234void draw_arrays(struct draw_context *draw, unsigned prim, 235 unsigned start, unsigned count); 236 237void 238draw_arrays_instanced(struct draw_context *draw, 239 unsigned mode, 240 unsigned start, 241 unsigned count, 242 unsigned startInstance, 243 unsigned instanceCount); 244 245 246/******************************************************************************* 247 * Driver backend interface 248 */ 249struct vbuf_render; 250void draw_set_render( struct draw_context *draw, 251 struct vbuf_render *render ); 252 253void draw_set_driver_clipping( struct draw_context *draw, 254 boolean bypass_clip_xy, 255 boolean bypass_clip_z, 256 boolean guard_band_xy); 257 258void draw_set_force_passthrough( struct draw_context *draw, 259 boolean enable ); 260 261/******************************************************************************* 262 * Draw pipeline 263 */ 264boolean draw_need_pipeline(const struct draw_context *draw, 265 const struct pipe_rasterizer_state *rasterizer, 266 unsigned prim ); 267 268static INLINE int 269draw_get_shader_param(unsigned shader, enum pipe_shader_cap param) 270{ 271 switch(shader) { 272 case PIPE_SHADER_VERTEX: 273 case PIPE_SHADER_GEOMETRY: 274 return tgsi_exec_get_shader_param(param); 275 default: 276 return 0; 277 } 278} 279 280#endif /* DRAW_CONTEXT_H */ 281