p_state.h revision 1c5f27a18b775b3784fcd265d60e0affa0b31581
1/************************************************************************** 2 * 3 * Copyright 2007 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 29/** 30 * Abstract graphics pipe state objects. 31 * 32 * Basic notes: 33 * 1. Want compact representations, so we use bitfields. 34 * 2. Put bitfields before other (GLfloat) fields. 35 */ 36 37 38#ifndef PIPE_STATE_H 39#define PIPE_STATE_H 40 41#include "p_compiler.h" 42#include "p_defines.h" 43#include "p_format.h" 44 45/** 46 * Implementation limits 47 */ 48#define PIPE_MAX_SAMPLERS 8 49#define PIPE_MAX_CLIP_PLANES 6 50#define PIPE_MAX_CONSTANT 32 51#define PIPE_ATTRIB_MAX 32 52#define PIPE_MAX_COLOR_BUFS 8 53#define PIPE_MAX_TEXTURE_LEVELS 16 54#define PIPE_MAX_FEEDBACK_ATTRIBS 16 55#define PIPE_MAX_SHADER_INPUTS 16 56#define PIPE_MAX_SHADER_OUTPUTS 16 57 58 59/* fwd decl */ 60struct pipe_surface; 61 62/* opaque type */ 63struct pipe_buffer_handle; 64 65struct pipe_winsys; 66 67 68/*** 69 *** State objects 70 ***/ 71 72 73/** 74 * Primitive (point/line/tri) rasterization info 75 */ 76struct pipe_rasterizer_state 77{ 78 unsigned flatshade:1; 79 unsigned light_twoside:1; 80 unsigned front_winding:2; /**< PIPE_WINDING_x */ 81 unsigned cull_mode:2; /**< PIPE_WINDING_x */ 82 unsigned fill_cw:2; /**< PIPE_POLYGON_MODE_x */ 83 unsigned fill_ccw:2; /**< PIPE_POLYGON_MODE_x */ 84 unsigned offset_cw:1; 85 unsigned offset_ccw:1; 86 unsigned scissor:1; 87 unsigned poly_smooth:1; 88 unsigned poly_stipple_enable:1; 89 unsigned point_smooth:1; 90 unsigned point_sprite:1; 91 unsigned point_size_per_vertex:1; /**< size computed in vertex shader */ 92 unsigned multisample:1; /* XXX maybe more ms state in future */ 93 unsigned line_smooth:1; 94 unsigned line_stipple_enable:1; 95 unsigned line_stipple_factor:8; /**< [1..256] actually */ 96 unsigned line_stipple_pattern:16; 97 unsigned bypass_clipping:1; 98 unsigned origin_lower_left:1; /**< Is (0,0) the lower-left corner? */ 99 100 float line_width; 101 float point_size; /**< used when no per-vertex size */ 102 float offset_units; 103 float offset_scale; 104 ubyte sprite_coord_mode[PIPE_MAX_SHADER_OUTPUTS]; /**< PIPE_SPRITE_COORD_ */ 105}; 106 107 108struct pipe_poly_stipple { 109 unsigned stipple[32]; 110}; 111 112 113struct pipe_viewport_state { 114 float scale[4]; 115 float translate[4]; 116}; 117 118struct pipe_scissor_state { 119 unsigned minx:16; 120 unsigned miny:16; 121 unsigned maxx:16; 122 unsigned maxy:16; 123}; 124 125struct pipe_clip_state { 126 float ucp[PIPE_MAX_CLIP_PLANES][4]; 127 unsigned nr; 128}; 129 130 131/** 132 * Constants for vertex/fragment shaders 133 */ 134struct pipe_constant_buffer { 135 struct pipe_buffer_handle *buffer; 136 unsigned size; /** in bytes */ 137}; 138 139 140struct pipe_shader_state { 141 const struct tgsi_token *tokens; 142 ubyte num_inputs; 143 ubyte num_outputs; 144 ubyte input_map[PIPE_MAX_SHADER_INPUTS]; /* XXX this may be temporary */ 145 ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */ 146 ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS]; 147 ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */ 148 ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS]; 149}; 150 151struct pipe_depth_stencil_alpha_state 152{ 153 struct { 154 unsigned enabled:1; /**< depth test enabled? */ 155 unsigned writemask:1; /**< allow depth buffer writes? */ 156 unsigned func:3; /**< depth test func (PIPE_FUNC_x) */ 157 unsigned occlusion_count:1; /**< XXX move this elsewhere? */ 158 } depth; 159 struct { 160 unsigned enabled:1; 161 unsigned func:3; /**< PIPE_FUNC_x */ 162 unsigned fail_op:3; /**< PIPE_STENCIL_OP_x */ 163 unsigned zpass_op:3; /**< PIPE_STENCIL_OP_x */ 164 unsigned zfail_op:3; /**< PIPE_STENCIL_OP_x */ 165 ubyte ref_value; 166 ubyte value_mask; 167 ubyte write_mask; 168 } stencil[2]; /**< [0] = front, [1] = back */ 169 170 struct { 171 unsigned enabled:1; 172 unsigned func:3; /**< PIPE_FUNC_x */ 173 float ref; /**< reference value */ 174 } alpha; 175}; 176 177 178struct pipe_blend_state { 179 unsigned blend_enable:1; 180 181 unsigned rgb_func:3; /**< PIPE_BLEND_x */ 182 unsigned rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */ 183 unsigned rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */ 184 185 unsigned alpha_func:3; /**< PIPE_BLEND_x */ 186 unsigned alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */ 187 unsigned alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */ 188 189 unsigned logicop_enable:1; 190 unsigned logicop_func:4; /**< PIPE_LOGICOP_x */ 191 192 unsigned colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */ 193 unsigned dither:1; 194}; 195 196struct pipe_blend_color { 197 float color[4]; 198}; 199 200struct pipe_framebuffer_state 201{ 202 /** multiple colorbuffers for multiple render targets */ 203 unsigned num_cbufs; 204 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS]; 205 206 struct pipe_surface *zbuf; /**< Z buffer */ 207 struct pipe_surface *sbuf; /**< Stencil buffer */ 208}; 209 210 211/** 212 * Texture sampler state. 213 */ 214struct pipe_sampler_state 215{ 216 unsigned wrap_s:3; /**< PIPE_TEX_WRAP_x */ 217 unsigned wrap_t:3; /**< PIPE_TEX_WRAP_x */ 218 unsigned wrap_r:3; /**< PIPE_TEX_WRAP_x */ 219 unsigned min_img_filter:2; /**< PIPE_TEX_FILTER_x */ 220 unsigned min_mip_filter:2; /**< PIPE_TEX_MIPFILTER_x */ 221 unsigned mag_img_filter:2; /**< PIPE_TEX_FILTER_x */ 222 unsigned compare:1; /**< shadow/depth compare enabled? */ 223 unsigned compare_mode:1; /**< PIPE_TEX_COMPARE_x */ 224 unsigned compare_func:3; /**< PIPE_FUNC_x */ 225 unsigned normalized_coords:1; /**< Are coords normalized to [0,1]? */ 226 float shadow_ambient; /**< shadow test fail color/intensity */ 227 float min_lod; 228 float max_lod; 229 float lod_bias; 230#if 0 /* need these? */ 231 int BaseLevel; /**< min mipmap level, OpenGL 1.2 */ 232 int MaxLevel; /**< max mipmap level, OpenGL 1.2 */ 233#endif 234 float border_color[4]; 235 float max_anisotropy; 236}; 237 238 239/** 240 * 2D surface. This is basically a view into a memory buffer. 241 * May be a renderbuffer, texture mipmap level, etc. 242 */ 243struct pipe_surface 244{ 245 struct pipe_buffer_handle *buffer; /**< driver private buffer handle */ 246 ubyte *map; /**< only non-NULL when surface is actually mapped */ 247 unsigned map_refcount; /**< Reference count for mapping */ 248 enum pipe_format format; /**< PIPE_FORMAT_x */ 249 unsigned cpp; /**< bytes per pixel */ 250 unsigned width, height; 251 unsigned pitch; /**< in pixels */ 252 unsigned offset; /**< offset from start of buffer, in bytes */ 253 unsigned refcount; 254 struct pipe_winsys *winsys; /**< winsys which owns/created the surface */ 255}; 256 257 258/** 259 * Texture. Represents one or several texture images on one or several mipmap 260 * levels. 261 */ 262struct pipe_texture 263{ 264 /* Effectively the key: 265 */ 266 enum pipe_texture_target target; /**< PIPE_TEXTURE_x */ 267 enum pipe_format format; /**< PIPE_FORMAT_x */ 268 269 unsigned first_level; 270 unsigned last_level; 271 272 unsigned width[PIPE_MAX_TEXTURE_LEVELS]; 273 unsigned height[PIPE_MAX_TEXTURE_LEVELS]; 274 unsigned depth[PIPE_MAX_TEXTURE_LEVELS]; 275 unsigned cpp; 276 277 unsigned compressed:1; 278 279 /* These are also refcounted: 280 */ 281 unsigned refcount; 282}; 283 284 285/** 286 * A vertex buffer. Typically, all the vertex data/attributes for 287 * drawing something will be in one buffer. But it's also possible, for 288 * example, to put colors in one buffer and texcoords in another. 289 */ 290struct pipe_vertex_buffer 291{ 292 unsigned pitch:11; /**< stride to same attrib in next vertex, in bytes */ 293 unsigned max_index; /**< number of vertices in this buffer */ 294 unsigned buffer_offset; /**< offset to start of data in buffer, in bytes */ 295 struct pipe_buffer_handle *buffer; /**< the actual buffer */ 296}; 297 298 299/** 300 * Information to describe a vertex attribute (position, color, etc) 301 */ 302struct pipe_vertex_element 303{ 304 /** Offset of this attribute, in bytes, from the start of the vertex */ 305 unsigned src_offset:11; 306 307 /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does 308 * this attribute live in? 309 */ 310 unsigned vertex_buffer_index:5; 311 unsigned nr_components:3; 312 313 enum pipe_format src_format; /**< PIPE_FORMAT_* */ 314}; 315 316 317 318#endif 319