Lift region-related functions up to the pipe interface.
[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 #define PIPE_MAX_COLOR_BUFS 8
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 GLuint multisample:1; /* XXX maybe more ms state in future */
93
94 GLubyte line_stipple_factor; /**< [1..256] actually */
95 GLushort line_stipple_pattern;
96 GLfloat line_width;
97 GLfloat point_size; /**< used when no per-vertex size */
98 GLfloat offset_units;
99 GLfloat offset_scale;
100 };
101
102 struct pipe_poly_stipple {
103 GLuint stipple[32];
104 };
105
106
107 struct pipe_viewport_state {
108 GLfloat scale[4];
109 GLfloat translate[4];
110 };
111
112 struct pipe_scissor_state {
113 GLshort minx;
114 GLshort miny;
115 GLshort maxx;
116 GLshort maxy;
117 };
118
119 struct pipe_clip_state {
120 GLfloat ucp[PIPE_MAX_CLIP_PLANES][4];
121 GLuint nr;
122 };
123
124
125 struct pipe_constant_buffer {
126 GLfloat constant[PIPE_MAX_CONSTANT][4];
127 GLuint nr_constants;
128 };
129
130
131 struct pipe_fs_state {
132 GLbitfield inputs_read; /* FRAG_ATTRIB_* */
133 const struct tgsi_token *tokens;
134 struct pipe_constant_buffer *constants; /* XXX temporary? */
135 };
136
137 struct pipe_depth_state
138 {
139 GLuint enabled:1; /**< depth test enabled? */
140 GLuint writemask:1; /**< allow depth buffer writes? */
141 GLuint func:3; /**< depth test func (PIPE_FUNC_x) */
142 GLuint occlusion_count:1; /**< XXX move this elsewhere? */
143 GLfloat clear; /**< Clear value in [0,1] (XXX correct place?) */
144 };
145
146 struct pipe_alpha_test_state {
147 GLuint enabled:1;
148 GLuint func:3; /**< PIPE_FUNC_x */
149 GLfloat ref; /**< reference value */
150 };
151
152 struct pipe_blend_state {
153 GLuint blend_enable:1;
154
155 GLuint rgb_func:3; /**< PIPE_BLEND_x */
156 GLuint rgb_src_factor:5; /**< PIPE_BLENDFACTOR_x */
157 GLuint rgb_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
158
159 GLuint alpha_func:3; /**< PIPE_BLEND_x */
160 GLuint alpha_src_factor:5; /**< PIPE_BLENDFACTOR_x */
161 GLuint alpha_dst_factor:5; /**< PIPE_BLENDFACTOR_x */
162
163 GLuint logicop_enable:1;
164 GLuint logicop_func:4; /**< PIPE_LOGICOP_x */
165
166 GLuint colormask:4; /**< bitmask of PIPE_MASK_R/G/B/A */
167 GLuint dither:1;
168 };
169
170 struct pipe_blend_color {
171 GLfloat color[4];
172 };
173
174 struct pipe_clear_color_state
175 {
176 GLfloat color[4];
177 };
178
179 struct pipe_stencil_state {
180 GLuint front_enabled:1;
181 GLuint front_func:3; /**< PIPE_FUNC_x */
182 GLuint front_fail_op:3; /**< PIPE_STENCIL_OP_x */
183 GLuint front_zpass_op:3; /**< PIPE_STENCIL_OP_x */
184 GLuint front_zfail_op:3; /**< PIPE_STENCIL_OP_x */
185 GLuint back_enabled:1;
186 GLuint back_func:3; /**< PIPE_FUNC_x */
187 GLuint back_fail_op:3; /**< PIPE_STENCIL_OP_x */
188 GLuint back_zpass_op:3; /**< PIPE_STENCIL_OP_x */
189 GLuint back_zfail_op:3; /**< PIPE_STENCIL_OP_x */
190 GLubyte ref_value[2]; /**< [0] = front, [1] = back */
191 GLubyte value_mask[2];
192 GLubyte write_mask[2];
193 GLubyte clear_value;
194 };
195
196
197 struct pipe_framebuffer_state
198 {
199 /** multiple colorbuffers for multiple render targets */
200 GLuint num_cbufs;
201 struct pipe_surface *cbufs[PIPE_MAX_COLOR_BUFS];
202
203 struct pipe_surface *zbuf; /**< Z buffer */
204 struct pipe_surface *sbuf; /**< Stencil buffer */
205 struct pipe_surface *abuf; /**< Accum buffer */
206 };
207
208
209 /**
210 * Texture sampler state.
211 */
212 struct pipe_sampler_state
213 {
214 GLuint wrap_s:3; /**< PIPE_TEX_WRAP_x */
215 GLuint wrap_t:3; /**< PIPE_TEX_WRAP_x */
216 GLuint wrap_r:3; /**< PIPE_TEX_WRAP_x */
217 GLuint min_filter:3; /**< PIPE_TEX_FILTER_x */
218 GLuint mag_filter:1; /**< PIPE_TEX_FILTER_LINEAR or _NEAREST */
219 GLuint compare:1; /**< shadow/depth compare enabled? */
220 GLenum compare_mode:1; /**< PIPE_TEX_COMPARE_x */
221 GLenum compare_func:3; /**< PIPE_FUNC_x */
222 GLfloat shadow_ambient; /**< shadow test fail color/intensity */
223 GLfloat min_lod;
224 GLfloat max_lod;
225 GLfloat lod_bias;
226 #if 0 /* need these? */
227 GLint BaseLevel; /**< min mipmap level, OpenGL 1.2 */
228 GLint MaxLevel; /**< max mipmap level, OpenGL 1.2 */
229 GLfloat border_color[4];
230 #endif
231 GLfloat max_anisotropy;
232 };
233
234
235 /***
236 *** Non-state Objects
237 ***/
238
239
240 /**
241 * A mappable buffer (vertex data, pixel data, etc)
242 * XXX replace with "intel_region".
243 */
244 struct pipe_buffer
245 {
246 void (*buffer_data)(struct pipe_buffer *pb, GLuint size, const void *src);
247 void (*buffer_sub_data)(struct pipe_buffer *pb, GLuint offset, GLuint size,
248 const void *src);
249 void *(*map)(struct pipe_buffer *pb, GLuint access_mode);
250 void (*unmap)(struct pipe_buffer *pb);
251 GLubyte *ptr; /**< address, only valid while mapped */
252 GLuint mode; /**< PIPE_MAP_x, only valid while mapped */
253 };
254
255
256 /**
257 * 2D surface.
258 * May be a renderbuffer, texture mipmap level, etc.
259 */
260 struct pipe_surface
261 {
262 struct pipe_buffer buffer; /**< surfaces can be mapped */
263 GLuint format:5; /**< PIPE_FORMAT_x */
264 GLuint width, height;
265
266 GLint stride, cpp;
267 GLubyte *ptr; /**< only valid while mapped, may not equal buffer->ptr */
268
269 void *rb; /**< Ptr back to renderbuffer (temporary?) */
270
271 void (*resize)(struct pipe_surface *ps, GLuint width, GLuint height);
272 };
273
274
275 struct _DriBufferObject;
276 struct intel_buffer_object;
277
278 struct pipe_region
279 {
280 struct _DriBufferObject *buffer; /**< buffer manager's buffer ID */
281 GLuint refcount; /**< Reference count for region */
282 GLuint cpp; /**< bytes per pixel */
283 GLuint pitch; /**< in pixels */
284 GLuint height; /**< in pixels */
285 GLubyte *map; /**< only non-NULL when region is actually mapped */
286 GLuint map_refcount; /**< Reference count for mapping */
287
288 GLuint draw_offset; /**< Offset of drawing address within the region */
289
290 struct intel_buffer_object *pbo; /* zero-copy uploads */
291 };
292
293 /**
294 * Texture object.
295 * Mipmap levels, cube faces, 3D slices can be accessed as surfaces.
296 */
297 struct pipe_texture_object
298 {
299 GLuint type:2; /**< PIPE_TEXTURE_x */
300 GLuint format:5; /**< PIPE_FORMAT_x */
301 GLuint width:13; /**< 13 bits = 8K max size */
302 GLuint height:13;
303 GLuint depth:13;
304 GLuint mipmapped:1;
305
306 /** to access a 1D or 2D texture object as a surface */
307 struct pipe_surface *(*get_2d_surface)(struct pipe_texture_object *pto,
308 GLuint level);
309 /** to access a 3D texture object as a surface */
310 struct pipe_surface *(*get_3d_surface)(struct pipe_texture_object *pto,
311 GLuint level, GLuint slice);
312 /** to access a cube texture object as a surface */
313 struct pipe_surface *(*get_cube_surface)(struct pipe_texture_object *pto,
314 GLuint face, GLuint level);
315 /** when finished with surface: */
316 void (*release_surface)(struct pipe_texture_object *pto,
317 struct pipe_surface *ps);
318 };
319
320
321 #endif