New 'draw' module for primitive drawing (clipping, culling, etc).
[mesa.git] / src / mesa / pipe / p_state.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
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 "mtypes.h"
42
43
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
53
54
55 /* fwd decl */
56 struct pipe_surface;
57
58
59 /***
60 *** State objects
61 ***/
62
63
64 /**
65 * Primitive (point/line/tri) setup info
66 */
67 struct pipe_setup_state
68 {
69 GLuint flatshade:1;
70 GLuint light_twoside:1;
71
72 GLuint front_winding:2; /**< PIPE_WINDING_x */
73
74 GLuint cull_mode:2; /**< PIPE_WINDING_x */
75
76 GLuint fill_cw:2; /**< PIPE_POLYGON_MODE_x */
77 GLuint fill_ccw:2; /**< PIPE_POLYGON_MODE_x */
78
79 GLuint offset_cw:1;
80 GLuint offset_ccw:1;
81
82 GLuint scissor:1;
83
84 GLuint poly_smooth:1;
85 GLuint poly_stipple_enable:1;
86
87 GLuint line_smooth:1;
88 GLuint line_stipple_enable:1;
89
90 GLuint point_smooth:1;
91
92 GLubyte line_stipple_factor; /**< [1..256] actually */
93 GLushort line_stipple_pattern;
94 GLfloat line_width;
95 GLfloat point_size; /**< used when no per-vertex size */
96 GLfloat offset_units;
97 GLfloat offset_scale;
98 };
99
100 struct pipe_poly_stipple {
101 GLuint stipple[32];
102 };
103
104
105 struct pipe_viewport_state {
106 GLfloat scale[4];
107 GLfloat translate[4];
108 };
109
110 struct pipe_scissor_state {
111 GLshort minx;
112 GLshort miny;
113 GLshort maxx;
114 GLshort maxy;
115 };
116
117 struct pipe_clip_state {
118 GLfloat ucp[PIPE_MAX_CLIP_PLANES][4];
119 GLuint nr;
120 };
121
122 struct pipe_fs_state {
123 struct gl_fragment_program *fp;
124 };
125
126 struct pipe_constant_buffer {
127 GLfloat constant[PIPE_MAX_CONSTANT][4];
128 GLuint nr_constants;
129 };
130
131
132 struct pipe_depth_state
133 {
134 GLuint enabled:1; /**< depth test enabled? */
135 GLuint writemask:1; /**< allow depth buffer writes? */
136 GLuint func:3; /**< depth test func (PIPE_FUNC_x) */
137 GLfloat clear; /**< Clear value in [0,1] (XXX correct place?) */
138 };
139
140 struct pipe_alpha_test_state {
141 GLuint enabled:1;
142 GLuint func:3; /**< PIPE_FUNC_x */
143 GLfloat ref; /**< reference value */
144 };
145
146 struct pipe_blend_state {
147 GLuint blend_enable:1;
148
149 GLuint rgb_func:3; /**< PIPE_BLEND_x */
150 GLuint rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
151 GLuint rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
152
153 GLuint alpha_func:3; /**< PIPE_BLEND_x */
154 GLuint alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
155 GLuint alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
156
157 GLuint logicop_enable:1;
158 GLuint logicop_func:4; /**< PIPE_LOGICOP_x */
159 };
160
161 struct pipe_blend_color {
162 GLfloat color[4];
163 };
164
165 struct pipe_clear_color_state
166 {
167 GLfloat color[4];
168 };
169
170 struct pipe_stencil_state {
171 GLuint front_enabled:1;
172 GLuint front_func:3; /**< PIPE_FUNC_x */
173 GLuint front_fail_op:3; /**< PIPE_STENCIL_OP_x */
174 GLuint front_zpass_op:3; /**< PIPE_STENCIL_OP_x */
175 GLuint front_zfail_op:3; /**< PIPE_STENCIL_OP_x */
176 GLuint back_enabled:1;
177 GLuint back_func:3; /**< PIPE_FUNC_x */
178 GLuint back_fail_op:3; /**< PIPE_STENCIL_OP_x */
179 GLuint back_zpass_op:3; /**< PIPE_STENCIL_OP_x */
180 GLuint back_zfail_op:3; /**< PIPE_STENCIL_OP_x */
181 GLubyte ref_value[2]; /**< [0] = front, [1] = back */
182 GLubyte value_mask[2];
183 GLubyte write_mask[2];
184 GLubyte clear_value;
185 };
186
187
188 struct pipe_framebuffer_state
189 {
190 GLuint num_cbufs; /**< Number of color bufs to draw to */
191 struct pipe_surface *cbufs[4]; /**< OpenGL can write to as many as
192 4 color buffers at once */
193 struct pipe_surface *zbuf; /**< Z buffer */
194 struct pipe_surface *sbuf; /**< Stencil buffer */
195 struct pipe_surface *abuf; /**< Accum buffer */
196 };
197
198
199 /**
200 * Texture sampler state.
201 */
202 struct pipe_sampler_state
203 {
204 GLuint wrap_s:3; /**< PIPE_TEX_WRAP_x */
205 GLuint wrap_t:3; /**< PIPE_TEX_WRAP_x */
206 GLuint wrap_r:3; /**< PIPE_TEX_WRAP_x */
207 GLuint min_filter:3; /**< PIPE_TEX_FILTER_x */
208 GLuint mag_filter:1; /**< PIPE_TEX_FILTER_LINEAR or _NEAREST */
209 GLuint compare:1; /**< shadow/depth compare enabled? */
210 GLenum compare_mode:1; /**< PIPE_TEX_COMPARE_x */
211 GLenum compare_func:3; /**< PIPE_FUNC_x */
212 GLfloat shadow_ambient; /**< shadow test fail color/intensity */
213 GLfloat min_lod;
214 GLfloat max_lod;
215 GLfloat lod_bias;
216 #if 0 /* need these? */
217 GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
218 GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
219 #endif
220 GLfloat max_anisotropy;
221 };
222
223
224 /***
225 *** Non-state Objects
226 ***/
227
228
229 /**
230 * A mappable buffer (vertex data, pixel data, etc)
231 */
232 struct pipe_buffer
233 {
234 void (*buffer_data)(struct pipe_buffer *pb, GLuint size, const void *src);
235 void (*buffer_sub_data)(struct pipe_buffer *pb, GLuint offset, GLuint size,
236 const void *src);
237 void *(*map)(struct pipe_buffer *pb, GLuint access_mode);
238 void (*unmap)(struct pipe_buffer *pb);
239 void *ptr; /**< address, only valid while mapped */
240 GLuint mode; /**< PIPE_MAP_x, only valid while mapped */
241 };
242
243
244 /**
245 * 2D surface.
246 * May be a renderbuffer, texture mipmap level, etc.
247 */
248 struct pipe_surface
249 {
250 struct pipe_buffer buffer; /**< surfaces can be mapped */
251 GLuint format:5; /**< PIPE_FORMAT_x */
252 GLuint width, height;
253 #if 0
254 GLubyte *ptr;
255 GLint stride;
256 GLuint cpp;
257 GLuint format;
258 #endif
259 };
260
261
262 /**
263 * Texture object.
264 * Mipmap levels, cube faces, 3D slices can be accessed as surfaces.
265 */
266 struct pipe_texture_object
267 {
268 GLuint type:2; /**< PIPE_TEXTURE_x */
269 GLuint format:5; /**< PIPE_FORMAT_x */
270 GLuint width:13; /**< 13 bits = 8K max size */
271 GLuint height:13;
272 GLuint depth:13;
273 GLuint mipmapped:1;
274
275 /** to access a 1D or 2D texture object as a surface */
276 struct pipe_surface *(*get_2d_surface)(struct pipe_texture_object *pto,
277 GLuint level);
278 /** to access a 3D texture object as a surface */
279 struct pipe_surface *(*get_3d_surface)(struct pipe_texture_object *pto,
280 GLuint level, GLuint slice);
281 /** to access a cube texture object as a surface */
282 struct pipe_surface *(*get_cube_surface)(struct pipe_texture_object *pto,
283 GLuint face, GLuint level);
284 /** when finished with surface: */
285 void (*release_surface)(struct pipe_texture_object *pto,
286 struct pipe_surface *ps);
287 };
288
289
290 #endif