1 /**************************************************************************
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
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:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
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.
26 **************************************************************************/
30 * SWIG interface definion for Gallium types.
32 * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
35 %nodefaultctor st_context;
36 %nodefaultdtor st_context;
44 st_context_destroy($self);
48 * State functions (create/bind/destroy state objects)
51 void set_blend( const struct pipe_blend_state *state ) {
52 cso_set_blend($self->cso, state);
55 void set_fragment_sampler( unsigned index, const struct pipe_sampler_state *state ) {
56 cso_single_sampler($self->cso, index, state);
57 cso_single_sampler_done($self->cso);
60 void set_vertex_sampler( unsigned index, const struct pipe_sampler_state *state ) {
61 cso_single_vertex_sampler($self->cso, index, state);
62 cso_single_vertex_sampler_done($self->cso);
65 void set_rasterizer( const struct pipe_rasterizer_state *state ) {
66 cso_set_rasterizer($self->cso, state);
69 void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) {
70 cso_set_depth_stencil_alpha($self->cso, state);
73 void set_fragment_shader( const struct pipe_shader_state *state ) {
77 cso_set_fragment_shader_handle($self->cso, NULL);
81 fs = $self->pipe->create_fs_state($self->pipe, state);
85 if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
88 cso_delete_fragment_shader($self->cso, $self->fs);
92 void set_vertex_shader( const struct pipe_shader_state *state ) {
96 cso_set_vertex_shader_handle($self->cso, NULL);
100 vs = $self->pipe->create_vs_state($self->pipe, state);
104 if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
107 cso_delete_vertex_shader($self->cso, $self->vs);
111 void set_geometry_shader( const struct pipe_shader_state *state ) {
115 cso_set_geometry_shader_handle($self->cso, NULL);
119 gs = $self->pipe->create_gs_state($self->pipe, state);
123 if(cso_set_geometry_shader_handle($self->cso, gs) != PIPE_OK)
126 cso_delete_geometry_shader($self->cso, $self->gs);
131 * Parameter-like state (or properties)
134 void set_blend_color(const struct pipe_blend_color *state ) {
135 cso_set_blend_color($self->cso, state);
138 void set_stencil_ref(const struct pipe_stencil_ref *state ) {
139 cso_set_stencil_ref($self->cso, state);
142 void set_clip(const struct pipe_clip_state *state ) {
143 $self->pipe->set_clip_state($self->pipe, state);
146 void set_constant_buffer(unsigned shader, unsigned index,
147 struct pipe_buffer *buffer )
149 $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
152 void set_framebuffer(const struct pipe_framebuffer_state *state )
154 memcpy(&$self->framebuffer, state, sizeof *state);
155 cso_set_framebuffer($self->cso, state);
158 void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
159 $self->pipe->set_polygon_stipple($self->pipe, state);
162 void set_scissor(const struct pipe_scissor_state *state ) {
163 $self->pipe->set_scissor_state($self->pipe, state);
166 void set_viewport(const struct pipe_viewport_state *state) {
167 cso_set_viewport($self->cso, state);
170 void set_fragment_sampler_texture(unsigned index,
171 struct pipe_texture *texture) {
173 texture = $self->default_texture;
174 pipe_texture_reference(&$self->fragment_sampler_textures[index], texture);
175 $self->pipe->set_fragment_sampler_textures($self->pipe,
177 $self->fragment_sampler_textures);
180 void set_vertex_sampler_texture(unsigned index,
181 struct pipe_texture *texture) {
183 texture = $self->default_texture;
184 pipe_texture_reference(&$self->vertex_sampler_textures[index], texture);
185 $self->pipe->set_vertex_sampler_textures($self->pipe,
186 PIPE_MAX_VERTEX_SAMPLERS,
187 $self->vertex_sampler_textures);
190 void set_vertex_buffer(unsigned index,
193 unsigned buffer_offset,
194 struct pipe_buffer *buffer)
197 struct pipe_vertex_buffer state;
199 memset(&state, 0, sizeof(state));
200 state.stride = stride;
201 state.max_index = max_index;
202 state.buffer_offset = buffer_offset;
203 state.buffer = buffer;
205 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
207 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
208 if(self->vertex_buffers[i].buffer)
209 $self->num_vertex_buffers = i + 1;
211 $self->pipe->set_vertex_buffers($self->pipe,
212 $self->num_vertex_buffers,
213 $self->vertex_buffers);
216 void set_vertex_element(unsigned index,
217 const struct pipe_vertex_element *element)
219 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
222 void set_vertex_elements(unsigned num)
224 $self->num_vertex_elements = num;
225 $self->pipe->set_vertex_elements($self->pipe,
226 $self->num_vertex_elements,
227 $self->vertex_elements);
234 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
235 $self->pipe->draw_arrays($self->pipe, mode, start, count);
238 void draw_elements( struct pipe_buffer *indexBuffer,
240 unsigned mode, unsigned start, unsigned count)
242 $self->pipe->draw_elements($self->pipe,
248 void draw_range_elements( struct pipe_buffer *indexBuffer,
249 unsigned indexSize, unsigned minIndex, unsigned maxIndex,
250 unsigned mode, unsigned start, unsigned count)
252 $self->pipe->draw_range_elements($self->pipe,
254 indexSize, minIndex, maxIndex,
258 void draw_vertices(unsigned prim,
260 unsigned num_attribs,
261 const float *vertices)
263 struct pipe_context *pipe = $self->pipe;
264 struct pipe_screen *screen = pipe->screen;
265 struct pipe_buffer *vbuf;
269 size = num_verts * num_attribs * 4 * sizeof(float);
271 vbuf = pipe_buffer_create(screen,
273 PIPE_BUFFER_USAGE_VERTEX,
278 map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
281 memcpy(map, vertices, size);
282 pipe_buffer_unmap(screen, vbuf);
284 util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs);
287 pipe_buffer_reference(&vbuf, NULL);
293 flush(unsigned flags = 0) {
294 struct pipe_fence_handle *fence = NULL;
295 $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
297 /* TODO: allow asynchronous operation */
298 $self->pipe->screen->fence_finish( $self->pipe->screen, fence, 0 );
299 $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
307 void surface_copy(struct st_surface *dst,
308 unsigned destx, unsigned desty,
309 struct st_surface *src,
310 unsigned srcx, unsigned srcy,
311 unsigned width, unsigned height)
313 struct pipe_surface *_dst = NULL;
314 struct pipe_surface *_src = NULL;
316 _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
318 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
320 _src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ);
322 SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading");
324 $self->pipe->surface_copy($self->pipe, _dst, destx, desty, _src, srcx, srcy, width, height);
327 pipe_surface_reference(&_src, NULL);
328 pipe_surface_reference(&_dst, NULL);
331 void surface_fill(struct st_surface *dst,
332 unsigned x, unsigned y,
333 unsigned width, unsigned height,
336 struct pipe_surface *_dst = NULL;
338 _dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
340 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
342 $self->pipe->surface_fill($self->pipe, _dst, x, y, width, height, value);
345 pipe_surface_reference(&_dst, NULL);
348 void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
349 unsigned stencil = 0)
351 $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);