5033209323feb5cd18014321a541d96dd11189d6
[mesa.git] / src / mesa / pipe / p_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 #ifndef PIPE_CONTEXT_H
29 #define PIPE_CONTEXT_H
30
31 #include "p_state.h"
32
33 struct pipe_state_cache;
34
35
36 /**
37 * Gallium rendering context. Basically:
38 * - state setting functions
39 * - VBO drawing functions
40 * - memory region function
41 * - device queries
42 */
43 struct pipe_context {
44 struct pipe_winsys *winsys;
45
46 void *priv; /** context private data (for DRI for example) */
47
48 void (*destroy)( struct pipe_context * );
49
50 /*
51 * Queries
52 */
53 boolean (*is_format_supported)( struct pipe_context *pipe,
54 uint format );
55
56 const char *(*get_name)( struct pipe_context *pipe );
57
58 const char *(*get_vendor)( struct pipe_context *pipe );
59
60 int (*get_param)( struct pipe_context *pipe, int param );
61 float (*get_paramf)( struct pipe_context *pipe, int param );
62
63
64 /*
65 * Drawing.
66 * Return false on fallbacks (temporary??)
67 */
68 boolean (*draw_arrays)( struct pipe_context *pipe,
69 unsigned mode, unsigned start, unsigned count);
70
71 boolean (*draw_elements)( struct pipe_context *pipe,
72 struct pipe_buffer_handle *indexBuffer,
73 unsigned indexSize,
74 unsigned mode, unsigned start, unsigned count);
75
76 /** Clear a surface to given value (no scissor; clear whole surface) */
77 void (*clear)(struct pipe_context *pipe, struct pipe_surface *ps,
78 unsigned clearValue);
79
80 /**
81 * Query objects
82 */
83 void (*begin_query)(struct pipe_context *pipe, struct pipe_query_object *q);
84 void (*end_query)(struct pipe_context *pipe, struct pipe_query_object *q);
85 void (*wait_query)(struct pipe_context *pipe, struct pipe_query_object *q);
86
87 /*
88 * State functions
89 */
90 void * (*create_alpha_test_state)(struct pipe_context *,
91 const struct pipe_alpha_test_state *);
92 void (*bind_alpha_test_state)(struct pipe_context *, void *);
93 void (*delete_alpha_test_state)(struct pipe_context *, void *);
94
95 void * (*create_blend_state)(struct pipe_context *,
96 const struct pipe_blend_state *);
97 void (*bind_blend_state)(struct pipe_context *, void *);
98 void (*delete_blend_state)(struct pipe_context *, void *);
99
100 void * (*create_sampler_state)(struct pipe_context *,
101 const struct pipe_sampler_state *);
102 void (*bind_sampler_state)(struct pipe_context *, unsigned unit, void *);
103 void (*delete_sampler_state)(struct pipe_context *, void *);
104
105 void * (*create_rasterizer_state)(struct pipe_context *,
106 const struct pipe_rasterizer_state *);
107 void (*bind_rasterizer_state)(struct pipe_context *, void *);
108 void (*delete_rasterizer_state)(struct pipe_context *, void *);
109
110 void * (*create_depth_stencil_state)(struct pipe_context *,
111 const struct pipe_depth_stencil_state *);
112 void (*bind_depth_stencil_state)(struct pipe_context *, void *);
113 void (*delete_depth_stencil_state)(struct pipe_context *, void *);
114
115 void * (*create_fs_state)(struct pipe_context *,
116 const struct pipe_shader_state *);
117 void (*bind_fs_state)(struct pipe_context *, void *);
118 void (*delete_fs_state)(struct pipe_context *, void *);
119
120 void * (*create_vs_state)(struct pipe_context *,
121 const struct pipe_shader_state *);
122 void (*bind_vs_state)(struct pipe_context *, void *);
123 void (*delete_vs_state)(struct pipe_context *, void *);
124
125 /* The following look more properties than states.
126 * maybe combine a few of them into states or pass them
127 * in the bind calls to the state */
128 void (*set_blend_color)( struct pipe_context *,
129 const struct pipe_blend_color * );
130
131 void (*set_clip_state)( struct pipe_context *,
132 const struct pipe_clip_state * );
133
134 void (*set_clear_color_state)( struct pipe_context *,
135 const struct pipe_clear_color_state * );
136
137 void (*set_constant_buffer)( struct pipe_context *,
138 uint shader, uint index,
139 const struct pipe_constant_buffer *buf );
140
141 void (*set_feedback_state)( struct pipe_context *,
142 const struct pipe_feedback_state *);
143
144 void (*set_framebuffer_state)( struct pipe_context *,
145 const struct pipe_framebuffer_state * );
146
147 void (*set_polygon_stipple)( struct pipe_context *,
148 const struct pipe_poly_stipple * );
149
150 void (*set_sampler_units)( struct pipe_context *,
151 uint num_samplers, const uint *units );
152
153 void (*set_scissor_state)( struct pipe_context *,
154 const struct pipe_scissor_state * );
155
156 void (*set_texture_state)( struct pipe_context *,
157 unsigned unit,
158 struct pipe_texture * );
159
160 void (*set_viewport_state)( struct pipe_context *,
161 const struct pipe_viewport_state * );
162
163 /*
164 * Vertex arrays
165 */
166 void (*set_vertex_buffer)( struct pipe_context *,
167 unsigned index,
168 const struct pipe_vertex_buffer * );
169
170 void (*set_vertex_element)( struct pipe_context *,
171 unsigned index,
172 const struct pipe_vertex_element * );
173
174 /*
175 * Vertex feedback
176 */
177 void (*set_feedback_buffer)(struct pipe_context *,
178 unsigned index,
179 const struct pipe_feedback_buffer *);
180
181 /** Get a surface which is a "view" into a texture */
182 struct pipe_surface *(*get_tex_surface)(struct pipe_context *pipe,
183 struct pipe_texture *texture,
184 unsigned face, unsigned level,
185 unsigned zslice);
186
187 /** Get a block of raw pixel data from a surface */
188 void (*get_tile)(struct pipe_context *pipe,
189 struct pipe_surface *ps,
190 uint x, uint y, uint w, uint h,
191 void *p, int dst_stride);
192 /** Put a block of raw pixel data into a surface */
193 void (*put_tile)(struct pipe_context *pipe,
194 struct pipe_surface *ps,
195 uint x, uint y, uint w, uint h,
196 const void *p, int src_stride);
197 /* XXX temporary here, move these to softpipe */
198 void (*get_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps,
199 uint x, uint y, uint w, uint h, float *p);
200 void (*put_tile_rgba)(struct pipe_context *pipe, struct pipe_surface *ps,
201 uint x, uint y, uint w, uint h, const float *p);
202
203
204 /*
205 * Memory region functions
206 */
207 ubyte *(*region_map)(struct pipe_context *pipe, struct pipe_region *r);
208
209 void (*region_unmap)(struct pipe_context *pipe, struct pipe_region *r);
210
211
212 /*
213 * Surface functions
214 */
215 void (*surface_data)(struct pipe_context *pipe,
216 struct pipe_surface *dest,
217 unsigned destx, unsigned desty,
218 const void *src, unsigned src_stride,
219 unsigned srcx, unsigned srcy,
220 unsigned width, unsigned height);
221
222 void (*surface_copy)(struct pipe_context *pipe,
223 struct pipe_surface *dest,
224 unsigned destx, unsigned desty,
225 struct pipe_surface *src, /* don't make this const -
226 need to map/unmap */
227 unsigned srcx, unsigned srcy,
228 unsigned width, unsigned height);
229
230 void (*surface_fill)(struct pipe_context *pipe,
231 struct pipe_surface *dst,
232 unsigned dstx, unsigned dsty,
233 unsigned width, unsigned height,
234 unsigned value);
235
236
237 /*
238 * Texture functions
239 */
240 void (*texture_create)(struct pipe_context *pipe,
241 struct pipe_texture **pt);
242
243 void (*texture_release)(struct pipe_context *pipe,
244 struct pipe_texture **pt);
245
246
247 /* Flush rendering:
248 */
249 void (*flush)( struct pipe_context *pipe,
250 unsigned flags );
251 };
252
253 #endif /* PIPE_CONTEXT_H */