3c379c9091add1e5f04f2ae6a48b0e7310574f2b
[mesa.git] / src / mesa / pipe / softpipe / sp_context.h
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 /* Authors: Keith Whitwell <keith@tungstengraphics.com>
29 */
30
31 #ifndef SP_CONTEXT_H
32 #define SP_CONTEXT_H
33
34 #include "glheader.h"
35
36 #include "pipe/p_state.h"
37 #include "pipe/p_context.h"
38
39 #include "sp_quad.h"
40
41
42 struct softpipe_surface;
43 struct draw_context;
44 struct draw_stage;
45
46
47 enum interp_mode {
48 INTERP_CONSTANT,
49 INTERP_LINEAR,
50 INTERP_PERSPECTIVE
51 };
52
53
54 #define SP_NEW_VIEWPORT 0x1
55 #define SP_NEW_SETUP 0x2
56 #define SP_NEW_FS 0x4
57 #define SP_NEW_BLEND 0x8
58 #define SP_NEW_CLIP 0x10
59 #define SP_NEW_SCISSOR 0x20
60 #define SP_NEW_STIPPLE 0x40
61 #define SP_NEW_FRAMEBUFFER 0x80
62 #define SP_NEW_ALPHA_TEST 0x100
63 #define SP_NEW_DEPTH_TEST 0x200
64 #define SP_NEW_SAMPLER 0x400
65 #define SP_NEW_TEXTURE 0x800
66 #define SP_NEW_STENCIL 0x1000
67
68
69 struct softpipe_context {
70 struct pipe_context pipe; /**< base class */
71
72 /* The most recent drawing state as set by the driver:
73 */
74 struct pipe_alpha_test_state alpha_test;
75 struct pipe_blend_state blend;
76 struct pipe_blend_color blend_color;
77 struct pipe_clear_color_state clear_color;
78 struct pipe_clip_state clip;
79 struct pipe_depth_state depth_test;
80 struct pipe_framebuffer_state framebuffer;
81 struct pipe_fs_state fs;
82 struct pipe_poly_stipple poly_stipple;
83 struct pipe_scissor_state scissor;
84 struct pipe_sampler_state sampler[PIPE_MAX_SAMPLERS];
85 struct pipe_setup_state setup;
86 struct pipe_stencil_state stencil;
87 struct pipe_texture_object *texture[PIPE_MAX_SAMPLERS];
88 struct pipe_viewport_state viewport;
89 GLuint dirty;
90
91 /* Setup derived state. TODO: this should be passed in the program
92 * tokens as parameters to DECL instructions.
93 *
94 * For now we just set colors to CONST on flatshade, textures to
95 * perspective always and everything else to linear.
96 */
97 enum interp_mode interp[PIPE_ATTRIB_MAX];
98
99
100 /* FS + setup derived state:
101 */
102
103 /** Map fragment program attribute to quad/coef array slot */
104 GLuint fp_attr_to_slot[PIPE_ATTRIB_MAX];
105 /** Map vertex format attribute to a vertex attribute slot */
106 GLuint vf_attr_to_slot[PIPE_ATTRIB_MAX];
107 GLuint nr_attrs;
108 GLuint nr_frag_attrs; /**< number of active fragment attribs */
109 GLbitfield attr_mask; /**< bitfield of VF_ATTRIB_ indexes/bits */
110
111 GLboolean need_z; /**< produce quad/fragment Z values? */
112 GLboolean need_w; /**< produce quad/fragment W values? */
113
114 #if 0
115 /* Stipple derived state:
116 */
117 GLubyte stipple_masks[16][16];
118 #endif
119
120 /** Derived from scissor and surface bounds: */
121 struct pipe_scissor_state cliprect;
122
123 GLuint occlusion_counter;
124
125 GLuint line_stipple_counter;
126
127 /** Software quad rendering pipeline */
128 struct {
129 struct quad_stage *polygon_stipple;
130 struct quad_stage *shade;
131 struct quad_stage *alpha_test;
132 struct quad_stage *stencil_test;
133 struct quad_stage *depth_test;
134 struct quad_stage *occlusion;
135 struct quad_stage *coverage;
136 struct quad_stage *bufloop;
137 struct quad_stage *blend;
138 struct quad_stage *colormask;
139 struct quad_stage *output;
140
141 struct quad_stage *first; /**< points to one of the above stages */
142 } quad;
143
144 /** The primitive drawing context */
145 struct draw_context *draw;
146
147 struct pipe_surface *cbuf; /**< current color buffer (one of cbufs) */
148 };
149
150
151
152
153 static INLINE struct softpipe_context *
154 softpipe_context( struct pipe_context *pipe )
155 {
156 return (struct softpipe_context *)pipe;
157 }
158
159
160 #endif /* SP_CONTEXT_H */