gallium: adapt state trackers etc. to pipe_constant_buffer removal
[mesa.git] / src / gallium / state_trackers / python / p_context.i
1 /**************************************************************************
2 *
3 * Copyright 2008 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 * @file
30 * SWIG interface definion for Gallium types.
31 *
32 * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
33 */
34
35 %nodefaultctor st_context;
36 %nodefaultdtor st_context;
37
38 struct st_context {
39 };
40
41 %extend st_context {
42
43 ~st_context() {
44 st_context_destroy($self);
45 }
46
47 /*
48 * State functions (create/bind/destroy state objects)
49 */
50
51 void set_blend( const struct pipe_blend_state *state ) {
52 cso_set_blend($self->cso, state);
53 }
54
55 void set_sampler( unsigned index, const struct pipe_sampler_state *state ) {
56 cso_single_sampler($self->cso, index, state);
57 cso_single_sampler_done($self->cso);
58 }
59
60 void set_rasterizer( const struct pipe_rasterizer_state *state ) {
61 cso_set_rasterizer($self->cso, state);
62 }
63
64 void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) {
65 cso_set_depth_stencil_alpha($self->cso, state);
66 }
67
68 void set_fragment_shader( const struct pipe_shader_state *state ) {
69 void *fs;
70
71 if(!state) {
72 cso_set_fragment_shader_handle($self->cso, NULL);
73 return;
74 }
75
76 fs = $self->pipe->create_fs_state($self->pipe, state);
77 if(!fs)
78 return;
79
80 if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
81 return;
82
83 cso_delete_fragment_shader($self->cso, $self->fs);
84 $self->fs = fs;
85 }
86
87 void set_vertex_shader( const struct pipe_shader_state *state ) {
88 void *vs;
89
90 if(!state) {
91 cso_set_vertex_shader_handle($self->cso, NULL);
92 return;
93 }
94
95 vs = $self->pipe->create_vs_state($self->pipe, state);
96 if(!vs)
97 return;
98
99 if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
100 return;
101
102 cso_delete_vertex_shader($self->cso, $self->vs);
103 $self->vs = vs;
104 }
105
106 /*
107 * Parameter-like state (or properties)
108 */
109
110 void set_blend_color(const struct pipe_blend_color *state ) {
111 cso_set_blend_color($self->cso, state);
112 }
113
114 void set_clip(const struct pipe_clip_state *state ) {
115 $self->pipe->set_clip_state($self->pipe, state);
116 }
117
118 void set_constant_buffer(unsigned shader, unsigned index,
119 struct pipe_buffer *buffer )
120 {
121 $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
122 }
123
124 void set_framebuffer(const struct pipe_framebuffer_state *state )
125 {
126 memcpy(&$self->framebuffer, state, sizeof *state);
127 cso_set_framebuffer($self->cso, state);
128 }
129
130 void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
131 $self->pipe->set_polygon_stipple($self->pipe, state);
132 }
133
134 void set_scissor(const struct pipe_scissor_state *state ) {
135 $self->pipe->set_scissor_state($self->pipe, state);
136 }
137
138 void set_viewport(const struct pipe_viewport_state *state) {
139 cso_set_viewport($self->cso, state);
140 }
141
142 void set_sampler_texture(unsigned index,
143 struct pipe_texture *texture) {
144 if(!texture)
145 texture = $self->default_texture;
146 pipe_texture_reference(&$self->sampler_textures[index], texture);
147 $self->pipe->set_fragment_sampler_textures($self->pipe,
148 PIPE_MAX_SAMPLERS,
149 $self->sampler_textures);
150 }
151
152 void set_vertex_buffer(unsigned index,
153 unsigned stride,
154 unsigned max_index,
155 unsigned buffer_offset,
156 struct pipe_buffer *buffer)
157 {
158 unsigned i;
159 struct pipe_vertex_buffer state;
160
161 memset(&state, 0, sizeof(state));
162 state.stride = stride;
163 state.max_index = max_index;
164 state.buffer_offset = buffer_offset;
165 state.buffer = buffer;
166
167 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
168
169 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
170 if(self->vertex_buffers[i].buffer)
171 $self->num_vertex_buffers = i + 1;
172
173 $self->pipe->set_vertex_buffers($self->pipe,
174 $self->num_vertex_buffers,
175 $self->vertex_buffers);
176 }
177
178 void set_vertex_element(unsigned index,
179 const struct pipe_vertex_element *element)
180 {
181 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
182 }
183
184 void set_vertex_elements(unsigned num)
185 {
186 $self->num_vertex_elements = num;
187 $self->pipe->set_vertex_elements($self->pipe,
188 $self->num_vertex_elements,
189 $self->vertex_elements);
190 }
191
192 /*
193 * Draw functions
194 */
195
196 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
197 $self->pipe->draw_arrays($self->pipe, mode, start, count);
198 }
199
200 void draw_elements( struct pipe_buffer *indexBuffer,
201 unsigned indexSize,
202 unsigned mode, unsigned start, unsigned count)
203 {
204 $self->pipe->draw_elements($self->pipe,
205 indexBuffer,
206 indexSize,
207 mode, start, count);
208 }
209
210 void draw_range_elements( struct pipe_buffer *indexBuffer,
211 unsigned indexSize, unsigned minIndex, unsigned maxIndex,
212 unsigned mode, unsigned start, unsigned count)
213 {
214 $self->pipe->draw_range_elements($self->pipe,
215 indexBuffer,
216 indexSize, minIndex, maxIndex,
217 mode, start, count);
218 }
219
220 void draw_vertices(unsigned prim,
221 unsigned num_verts,
222 unsigned num_attribs,
223 const float *vertices)
224 {
225 struct pipe_context *pipe = $self->pipe;
226 struct pipe_screen *screen = pipe->screen;
227 struct pipe_buffer *vbuf;
228 float *map;
229 unsigned size;
230
231 size = num_verts * num_attribs * 4 * sizeof(float);
232
233 vbuf = pipe_buffer_create(screen,
234 32,
235 PIPE_BUFFER_USAGE_VERTEX,
236 size);
237 if(!vbuf)
238 goto error1;
239
240 map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
241 if (!map)
242 goto error2;
243 memcpy(map, vertices, size);
244 pipe_buffer_unmap(screen, vbuf);
245
246 util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs);
247
248 error2:
249 pipe_buffer_reference(&vbuf, NULL);
250 error1:
251 ;
252 }
253
254 void
255 flush(unsigned flags = 0) {
256 struct pipe_fence_handle *fence = NULL;
257 $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
258 if(fence) {
259 /* TODO: allow asynchronous operation */
260 $self->pipe->screen->fence_finish( $self->pipe->screen, fence, 0 );
261 $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
262 }
263 }
264
265 /*
266 * Surface functions
267 */
268
269 void surface_copy(struct st_surface *dst,
270 unsigned destx, unsigned desty,
271 struct st_surface *src,
272 unsigned srcx, unsigned srcy,
273 unsigned width, unsigned height)
274 {
275 struct pipe_surface *_dst = NULL;
276 struct pipe_surface *_src = NULL;
277
278 _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
279 if(!_dst)
280 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
281
282 _src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ);
283 if(!_src)
284 SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading");
285
286 $self->pipe->surface_copy($self->pipe, _dst, destx, desty, _src, srcx, srcy, width, height);
287
288 fail:
289 pipe_surface_reference(&_src, NULL);
290 pipe_surface_reference(&_dst, NULL);
291 }
292
293 void surface_fill(struct st_surface *dst,
294 unsigned x, unsigned y,
295 unsigned width, unsigned height,
296 unsigned value)
297 {
298 struct pipe_surface *_dst = NULL;
299
300 _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
301 if(!_dst)
302 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
303
304 $self->pipe->surface_fill($self->pipe, _dst, x, y, width, height, value);
305
306 fail:
307 pipe_surface_reference(&_dst, NULL);
308 }
309
310 void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
311 unsigned stencil = 0)
312 {
313 $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
314 }
315
316 };