python: Bindings fixes.
[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 fs = $self->pipe->create_fs_state($self->pipe, state);
72 if(!fs)
73 return;
74
75 if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
76 return;
77
78 cso_delete_fragment_shader($self->cso, $self->fs);
79 $self->fs = fs;
80 }
81
82 void set_vertex_shader( const struct pipe_shader_state *state ) {
83 void *vs;
84
85 vs = $self->pipe->create_vs_state($self->pipe, state);
86 if(!vs)
87 return;
88
89 if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
90 return;
91
92 cso_delete_vertex_shader($self->cso, $self->vs);
93 $self->vs = vs;
94 }
95
96 /*
97 * Parameter-like state (or properties)
98 */
99
100 void set_blend_color(const struct pipe_blend_color *state ) {
101 cso_set_blend_color($self->cso, state);
102 }
103
104 void set_clip(const struct pipe_clip_state *state ) {
105 $self->pipe->set_clip_state($self->pipe, state);
106 }
107
108 void set_constant_buffer(unsigned shader, unsigned index,
109 struct st_buffer *buffer )
110 {
111 struct pipe_constant_buffer state;
112 memset(&state, 0, sizeof(state));
113 state.buffer = buffer ? buffer->buffer : NULL;
114 state.size = buffer->buffer->size;
115 $self->pipe->set_constant_buffer($self->pipe, shader, index, &state);
116 }
117
118 void set_framebuffer(const struct pipe_framebuffer_state *state ) {
119 cso_set_framebuffer($self->cso, state);
120 }
121
122 void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
123 $self->pipe->set_polygon_stipple($self->pipe, state);
124 }
125
126 void set_scissor(const struct pipe_scissor_state *state ) {
127 $self->pipe->set_scissor_state($self->pipe, state);
128 }
129
130 void set_viewport(const struct pipe_viewport_state *state) {
131 cso_set_viewport($self->cso, state);
132 }
133
134 void set_sampler_texture(unsigned index,
135 struct pipe_texture *texture) {
136 if(!texture)
137 texture = $self->default_texture;
138 pipe_texture_reference(&$self->sampler_textures[index], texture);
139 $self->pipe->set_sampler_textures($self->pipe,
140 PIPE_MAX_SAMPLERS,
141 $self->sampler_textures);
142 }
143
144 void set_vertex_buffer(unsigned index,
145 unsigned pitch,
146 unsigned max_index,
147 unsigned buffer_offset,
148 struct st_buffer *buffer)
149 {
150 unsigned i, num_vertex_buffers;
151 struct pipe_vertex_buffer state;
152
153 memset(&state, 0, sizeof(state));
154 state.pitch = pitch;
155 state.max_index = max_index;
156 state.buffer_offset = buffer_offset;
157 state.buffer = buffer ? buffer->buffer : NULL;
158
159 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
160
161 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
162 if(self->vertex_buffers[i].buffer)
163 $self->num_vertex_buffers = i + 1;
164
165 $self->pipe->set_vertex_buffers($self->pipe,
166 $self->num_vertex_buffers,
167 $self->vertex_buffers);
168 }
169
170 void set_vertex_element(unsigned index,
171 const struct pipe_vertex_element *element)
172 {
173 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
174 }
175
176 void set_vertex_elements(unsigned num)
177 {
178 $self->num_vertex_elements = num;
179 $self->pipe->set_vertex_elements($self->pipe,
180 $self->num_vertex_elements,
181 $self->vertex_elements);
182 }
183
184 /*
185 * Draw functions
186 */
187
188 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
189 $self->pipe->draw_arrays($self->pipe, mode, start, count);
190 }
191
192 void draw_elements( struct st_buffer *indexBuffer,
193 unsigned indexSize,
194 unsigned mode, unsigned start, unsigned count)
195 {
196 $self->pipe->draw_elements($self->pipe,
197 indexBuffer->buffer,
198 indexSize,
199 mode, start, count);
200 }
201
202 void draw_vertices(unsigned prim,
203 unsigned num_verts,
204 unsigned num_attribs,
205 const float *vertices)
206 {
207 struct pipe_context *pipe = $self->pipe;
208 struct pipe_winsys *winsys = pipe->winsys;
209 struct pipe_buffer *vbuf;
210 float *map;
211 unsigned size;
212
213 size = num_verts * num_attribs * 4 * sizeof(float);
214
215 vbuf = winsys->buffer_create(winsys,
216 32,
217 PIPE_BUFFER_USAGE_VERTEX,
218 size);
219 if(!vbuf)
220 goto error1;
221
222 map = winsys->buffer_map(winsys, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
223 if (!map)
224 goto error2;
225 memcpy(map, vertices, size);
226 pipe->winsys->buffer_unmap(pipe->winsys, vbuf);
227
228 util_draw_vertex_buffer(pipe, vbuf, prim, num_verts, num_attribs);
229
230 error2:
231 pipe_buffer_reference(pipe->winsys, &vbuf, NULL);
232 error1:
233 ;
234 }
235
236 void
237 flush(unsigned flags = 0) {
238 struct pipe_fence_handle *fence = NULL;
239 $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
240 /* TODO: allow asynchronous operation */
241 $self->pipe->winsys->fence_finish( $self->pipe->winsys, fence, 0 );
242 $self->pipe->winsys->fence_reference( $self->pipe->winsys, &fence, NULL );
243 }
244
245 /*
246 * Surface functions
247 */
248
249 void surface_copy(int do_flip,
250 struct pipe_surface *dest,
251 unsigned destx, unsigned desty,
252 struct pipe_surface *src,
253 unsigned srcx, unsigned srcy,
254 unsigned width, unsigned height) {
255 $self->pipe->surface_copy($self->pipe, do_flip, dest, destx, desty, src, srcx, srcy, width, height);
256 }
257
258 void surface_fill(struct pipe_surface *dst,
259 unsigned x, unsigned y,
260 unsigned width, unsigned height,
261 unsigned value) {
262 $self->pipe->surface_fill($self->pipe, dst, x, y, width, height, value);
263 }
264
265 void surface_clear(struct pipe_surface *surface, unsigned value = 0) {
266 $self->pipe->clear($self->pipe, surface, value);
267 }
268
269 };