Added origin_lower_left field to pipe_rasterizer_state
[mesa.git] / src / mesa / pipe / p_state.h
index b841181cf01151bc92c4e37f12e529569d3f83ce..af65d365bf0b6a79dc4fc6a324f6765aae4d12b9 100644 (file)
 #ifndef PIPE_STATE_H
 #define PIPE_STATE_H
 
-#include "mtypes.h"
-
+#include "p_compiler.h"
+#include "p_format.h"
 
 /**
- * Primitive (point/line/tri) setup info
+ * Implementation limits
  */
-struct pipe_setup_state
-{
-   GLuint flatshade:1;
-   GLuint light_twoside:1;
+#define PIPE_MAX_SAMPLERS     8
+#define PIPE_MAX_CLIP_PLANES  6
+#define PIPE_MAX_CONSTANT    32
+#define PIPE_ATTRIB_MAX      32
+#define PIPE_MAX_COLOR_BUFS   8
+#define PIPE_MAX_TEXTURE_LEVELS  16
+#define PIPE_MAX_FEEDBACK_ATTRIBS 16
+#define PIPE_MAX_SHADER_INPUTS 16
+#define PIPE_MAX_SHADER_OUTPUTS 16
+
+
+/* fwd decl */
+struct pipe_surface;
 
-   GLuint front_winding:2;  /**< PIPE_WINDING_x */
+/* opaque type */
+struct pipe_buffer_handle;
 
-   GLuint cull_mode:2;      /**< PIPE_WINDING_x */
+struct pipe_winsys;
 
-   GLuint fill_cw:2;        /**< PIPE_POLYGON_MODE_x */
-   GLuint fill_ccw:2;       /**< PIPE_POLYGON_MODE_x */
 
-   GLuint offset_cw:1;
-   GLuint offset_ccw:1;
+/***
+ *** State objects
+ ***/
 
-   GLuint scissor:1;
-   GLuint poly_stipple:1;
-   GLuint poly_smooth:1;
 
-   GLfloat offset_units;
-   GLfloat offset_scale;
+/**
+ * Primitive (point/line/tri) rasterization info
+ */
+struct pipe_rasterizer_state
+{
+   unsigned flatshade:1;
+   unsigned light_twoside:1;
+   unsigned front_winding:2;  /**< PIPE_WINDING_x */
+   unsigned cull_mode:2;      /**< PIPE_WINDING_x */
+   unsigned fill_cw:2;        /**< PIPE_POLYGON_MODE_x */
+   unsigned fill_ccw:2;       /**< PIPE_POLYGON_MODE_x */
+   unsigned offset_cw:1;
+   unsigned offset_ccw:1;
+   unsigned scissor:1;
+   unsigned poly_smooth:1;
+   unsigned poly_stipple_enable:1;
+   unsigned point_smooth:1;
+   unsigned point_sprite:1;
+   unsigned point_size_per_vertex:1; /**< size computed in vertex shader */
+   unsigned multisample:1;         /* XXX maybe more ms state in future */
+   unsigned line_smooth:1;
+   unsigned line_stipple_enable:1;
+   unsigned line_stipple_factor:8;  /**< [1..256] actually */
+   unsigned line_stipple_pattern:16;
+   unsigned bypass_clipping:1;
+   unsigned origin_lower_left:1;  /**< Is (0,0) the lower-left corner? */
+
+   float line_width;
+   float point_size;           /**< used when no per-vertex size */
+   float offset_units;
+   float offset_scale;
+   ubyte sprite_coord_mode[PIPE_MAX_SHADER_OUTPUTS]; /**< PIPE_SPRITE_COORD_ */
 };
 
+
 struct pipe_poly_stipple {
-   GLuint stipple[32];
+   unsigned stipple[32];
 };
 
 
-struct pipe_viewport {
-   GLfloat scale[4];
-   GLfloat translate[4];
+struct pipe_viewport_state {
+   float scale[4];
+   float translate[4];
 };
 
-struct pipe_scissor_rect {
-   GLshort minx;
-   GLshort miny;
-   GLshort maxx;
-   GLshort maxy;
+struct pipe_scissor_state {
+   unsigned minx:16;
+   unsigned miny:16;
+   unsigned maxx:16;
+   unsigned maxy:16;
 };
 
-
-#define PIPE_MAX_CLIP_PLANES 6
-
 struct pipe_clip_state {
-   GLfloat ucp[PIPE_MAX_CLIP_PLANES][4];
-   GLuint nr;
+   float ucp[PIPE_MAX_CLIP_PLANES][4];
+   unsigned nr;
 };
 
-struct pipe_fs_state {
-   struct gl_fragment_program *fp;
-};
-
-#define PIPE_MAX_CONSTANT 32
 
+/**
+ * Constants for vertex/fragment shaders
+ */
 struct pipe_constant_buffer {
-   GLfloat constant[PIPE_MAX_CONSTANT][4];
-   GLuint nr_constants;
+   struct pipe_buffer_handle *buffer;
+   unsigned size;    /** in bytes */
 };
 
 
-struct pipe_depth_state
+struct pipe_shader_state {
+   const struct tgsi_token *tokens;
+   ubyte num_inputs;
+   ubyte num_outputs;
+   ubyte input_map[PIPE_MAX_SHADER_INPUTS]; /* XXX this may be temporary */
+   ubyte input_semantic_name[PIPE_MAX_SHADER_INPUTS]; /**< TGSI_SEMANTIC_x */
+   ubyte input_semantic_index[PIPE_MAX_SHADER_INPUTS];
+   ubyte output_semantic_name[PIPE_MAX_SHADER_OUTPUTS]; /**< TGSI_SEMANTIC_x */
+   ubyte output_semantic_index[PIPE_MAX_SHADER_OUTPUTS];
+};
+
+struct pipe_depth_stencil_state
 {
-   GLuint enabled:1;   /**< depth test enabled? */
-   GLuint writemask:1; /**< allow depth buffer writes? */
-   GLuint func:3;      /**< depth test func (PIPE_FUNC_x) */
-   GLfloat clear;      /**< Clear value in [0,1] (XXX correct place?) */
+   struct {
+      unsigned enabled:1;   /**< depth test enabled? */
+      unsigned writemask:1; /**< allow depth buffer writes? */
+      unsigned func:3;      /**< depth test func (PIPE_FUNC_x) */
+      unsigned occlusion_count:1; /**< XXX move this elsewhere? */
+   } depth;
+   struct {
+      unsigned front_enabled:1;
+      unsigned front_func:3;     /**< PIPE_FUNC_x */
+      unsigned front_fail_op:3;  /**< PIPE_STENCIL_OP_x */
+      unsigned front_zpass_op:3; /**< PIPE_STENCIL_OP_x */
+      unsigned front_zfail_op:3; /**< PIPE_STENCIL_OP_x */
+      unsigned back_enabled:1;
+      unsigned back_func:3;      /**< PIPE_FUNC_x */
+      unsigned back_fail_op:3;   /**< PIPE_STENCIL_OP_x */
+      unsigned back_zpass_op:3;  /**< PIPE_STENCIL_OP_x */
+      unsigned back_zfail_op:3;  /**< PIPE_STENCIL_OP_x */
+      ubyte ref_value[2];    /**< [0] = front, [1] = back */
+      ubyte value_mask[2];
+      ubyte write_mask[2];
+   } stencil;
 };
 
 struct pipe_alpha_test_state {
-   GLuint enabled:1;
-   GLuint func:3;    /**< PIPE_FUNC_x */
-   GLfloat ref;      /**< reference value */
+   unsigned enabled:1;
+   unsigned func:3;    /**< PIPE_FUNC_x */
+   float ref;      /**< reference value */
 };
 
 struct pipe_blend_state {
-   GLuint blend_enable:1;
+   unsigned blend_enable:1;
 
-   GLuint rgb_func:3;
-   GLuint rgb_src_factor:5;
-   GLuint rgb_dst_factor:5;
+   unsigned rgb_func:3;          /**< PIPE_BLEND_x */
+   unsigned rgb_src_factor:5;    /**< PIPE_BLENDFACTOR_x */
+   unsigned rgb_dst_factor:5;    /**< PIPE_BLENDFACTOR_x */
 
-   GLuint alpha_func:3;
-   GLuint alpha_src_factor:5;
-   GLuint alpha_dst_factor:5;
+   unsigned alpha_func:3;        /**< PIPE_BLEND_x */
+   unsigned alpha_src_factor:5;  /**< PIPE_BLENDFACTOR_x */
+   unsigned alpha_dst_factor:5;  /**< PIPE_BLENDFACTOR_x */
 
-   GLuint logicop_enable:1;
-   GLuint logicop_func:4;
+   unsigned logicop_enable:1;
+   unsigned logicop_func:4;      /**< PIPE_LOGICOP_x */
+
+   unsigned colormask:4;         /**< bitmask of PIPE_MASK_R/G/B/A */
+   unsigned dither:1;
 };
 
 struct pipe_blend_color {
-   GLfloat color[4];
+   float color[4];
 };
 
-struct pipe_clear_color_state
+struct pipe_framebuffer_state
 {
-   GLfloat color[4];
+   /** multiple colorbuffers for multiple render targets */
+   unsigned num_cbufs;
+   struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
+
+   struct pipe_surface *zbuf;      /**< Z buffer */
+   struct pipe_surface *sbuf;      /**< Stencil buffer */
 };
 
-/** XXXX probably merge into pipe_setup_state */
-struct pipe_line_state
+
+/**
+ * Texture sampler state.
+ */
+struct pipe_sampler_state
 {
-   GLuint smooth:1;
-   GLuint stipple:1;
-   GLushort stipple_pattern;
-   GLint stipple_factor;
-   GLfloat width;
+   unsigned wrap_s:3;        /**< PIPE_TEX_WRAP_x */
+   unsigned wrap_t:3;        /**< PIPE_TEX_WRAP_x */
+   unsigned wrap_r:3;        /**< PIPE_TEX_WRAP_x */
+   unsigned min_img_filter:2;    /**< PIPE_TEX_FILTER_x */
+   unsigned min_mip_filter:2;    /**< PIPE_TEX_MIPFILTER_x */
+   unsigned mag_img_filter:2;    /**< PIPE_TEX_FILTER_x */
+   unsigned compare:1;       /**< shadow/depth compare enabled? */
+   unsigned compare_mode:1;  /**< PIPE_TEX_COMPARE_x */
+   unsigned compare_func:3;  /**< PIPE_FUNC_x */
+   unsigned normalized_coords:1;  /**< Are coords normalized to [0,1]? */
+   float shadow_ambient; /**< shadow test fail color/intensity */
+   float min_lod;
+   float max_lod;
+   float lod_bias;
+#if 0 /* need these? */
+   int BaseLevel;     /**< min mipmap level, OpenGL 1.2 */
+   int MaxLevel;      /**< max mipmap level, OpenGL 1.2 */
+#endif
+   float border_color[4];
+   float max_anisotropy;
 };
 
-/** XXXX probably merge into pipe_setup_state */
-struct pipe_point_state
-{
-   GLuint smooth:1;
-   GLfloat size;
-   GLfloat min_size, max_size;
-   GLfloat attenuation[3];
-};
-
-struct pipe_stencil_state {
-   GLuint front_enabled:1;
-   GLuint front_func:3;     /**< PIPE_FUNC_x */
-   GLuint front_fail_op:3;  /**< PIPE_STENCIL_OP_x */
-   GLuint front_zpass_op:3; /**< PIPE_STENCIL_OP_x */
-   GLuint front_zfail_op:3; /**< PIPE_STENCIL_OP_x */
-   GLuint back_enabled:1;
-   GLuint back_func:3;
-   GLuint back_fail_op:3;
-   GLuint back_zpass_op:3;
-   GLuint back_zfail_op:3;
-   GLubyte ref_value[2];      /**< [0] = front, [1] = back */
-   GLubyte value_mask[2];
-   GLubyte write_mask[2];
-   GLubyte clear_value;
-};
-
-
-/* This will change for hardware pipes...
+
+/**
+ * 2D surface.  This is basically a view into a memory buffer.
+ * May be a renderbuffer, texture mipmap level, etc.
  */
 struct pipe_surface
 {
-   GLuint width, height;
-   GLubyte *ptr;
-   GLint stride;
-   GLuint cpp;
-   GLuint format;
+   struct pipe_buffer_handle *buffer; /**< driver private buffer handle */
+   ubyte *map;    /**< only non-NULL when surface is actually mapped */
+   unsigned map_refcount;  /**< Reference count for mapping */
+   enum pipe_format format;      /**< PIPE_FORMAT_x */
+   unsigned cpp;                 /**< bytes per pixel */
+   unsigned width, height;
+   unsigned pitch;               /**< in pixels */
+   unsigned offset;              /**< offset from start of buffer, in bytes */
+   unsigned refcount;
+   struct pipe_winsys *winsys;   /**< winsys which owns/created the surface */
 };
 
 
-struct pipe_framebuffer_state
+/**
+ * Texture. Represents one or several texture images on one or several mipmap
+ * levels.
+ */
+struct pipe_texture
+{ 
+   /* Effectively the key:
+    */
+   unsigned target;            /**< PIPE_TEXTURE_x */
+   enum pipe_format format;    /**< PIPE_FORMAT_x */
+
+   unsigned first_level;
+   unsigned last_level;
+
+   unsigned width[PIPE_MAX_TEXTURE_LEVELS];
+   unsigned height[PIPE_MAX_TEXTURE_LEVELS];
+   unsigned depth[PIPE_MAX_TEXTURE_LEVELS];
+   unsigned cpp;
+
+   unsigned compressed:1;
+
+   /* These are also refcounted:
+    */
+   unsigned refcount;
+};
+
+
+/**
+ * A vertex buffer.  Typically, all the vertex data/attributes for
+ * drawing something will be in one buffer.  But it's also possible, for
+ * example, to put colors in one buffer and texcoords in another.
+ */
+struct pipe_vertex_buffer
 {
-   GLuint num_cbufs;               /**< Number of color bufs to draw to */
-   struct pipe_surface *cbufs[4];  /**< OpenGL can write to as many as
-                                        4 color buffers at once */
-   struct pipe_surface *zbuf;      /**< Z buffer */
-   struct pipe_surface *sbuf;      /**< Stencil buffer */
-   struct pipe_surface *abuf;      /**< Accum buffer */
+   unsigned pitch:11;    /**< stride to same attrib in next vertex, in bytes */
+   unsigned max_index;   /**< number of vertices in this buffer */
+   unsigned buffer_offset;  /**< offset to start of data in buffer, in bytes */
+   struct pipe_buffer_handle *buffer;  /**< the actual buffer */
 };
 
 
 /**
- * Texture sampler state.
+ * Information to describe a vertex attribute (position, color, etc)
  */
-struct pipe_sampler_state
+struct pipe_vertex_element
 {
-   GLuint wrap_s:3;        /**< PIPE_TEX_WRAP_x */
-   GLuint wrap_t:3;        /**< PIPE_TEX_WRAP_x */
-   GLuint wrap_r:3;        /**< PIPE_TEX_WRAP_x */
-   GLuint min_filter:3;    /**< PIPE_TEX_FILTER_x */
-   GLuint mag_filter:1;    /**< PIPE_TEX_FILTER_LINEAR or _NEAREST */
-   GLuint compare:1;       /**< shadow/depth compare enabled? */
-   GLenum compare_mode:1;  /**< PIPE_TEX_COMPARE_x */
-   GLenum compare_func:3;  /**< PIPE_FUNC_x */
-   GLfloat shadow_ambient; /**< shadow test fail color/intensity */
-   GLfloat min_lod;
-   GLfloat max_lod;
-   GLfloat lod_bias;
-#if 0 /* need these? */
-   GLint BaseLevel;     /**< min mipmap level, OpenGL 1.2 */
-   GLint MaxLevel;      /**< max mipmap level, OpenGL 1.2 */
-#endif
-   GLfloat max_anisotropy;
+   /** Offset of this attribute, in bytes, from the start of the vertex */
+   unsigned src_offset:11;
+
+   /** Which vertex_buffer (as given to pipe->set_vertex_buffer()) does
+    * this attribute live in?
+    */
+   unsigned vertex_buffer_index:5;
+
+   unsigned dst_offset:8; 
+   enum pipe_format src_format;           /**< PIPE_FORMAT_* */
 };
 
+
+
 #endif