From e7f1ac39be5ab8c627f66a4a8488697c274079e6 Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Mon, 11 Aug 2008 14:06:24 +0100 Subject: python: Split the interface definition file in smaller ones. --- src/gallium/state_trackers/python/p_state.i | 103 ++++++++++++++++++++++++++++ 1 file changed, 103 insertions(+) create mode 100644 src/gallium/state_trackers/python/p_state.i (limited to 'src/gallium/state_trackers/python/p_state.i') diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i new file mode 100644 index 0000000000..9834229b4b --- /dev/null +++ b/src/gallium/state_trackers/python/p_state.i @@ -0,0 +1,103 @@ + /************************************************************************** + * + * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas. + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL TUNGSTEN GRAPHICS AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +/** + * @file + * SWIG interface definion for Gallium types. + * + * @author Jose Fonseca + */ + +%module gallium; + +%include "pipe/p_state.h"; + + +%extend pipe_framebuffer_state { + + pipe_framebuffer_state(void) { + return CALLOC_STRUCT(pipe_framebuffer_state); + } + + ~pipe_framebuffer_state() { + unsigned index; + for(index = 0; index < PIPE_MAX_COLOR_BUFS; ++index) + pipe_surface_reference(&$self->cbufs[index], NULL); + pipe_surface_reference(&$self->zsbuf, NULL); + FREE($self); + } + + void + set_cbuf(unsigned index, struct pipe_surface *surface) { + pipe_surface_reference(&$self->cbufs[index], surface); + } + + void + set_zsbuf(struct pipe_surface *surface) { + pipe_surface_reference(&$self->zsbuf, surface); + } + +}; + + +%extend pipe_shader_state { + + pipe_shader_state(const char *text, unsigned num_tokens = 1024) { + struct tgsi_token *tokens; + struct pipe_shader_state *shader; + + tokens = MALLOC(num_tokens * sizeof(struct tgsi_token)); + if(!tokens) + goto error1; + + if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE) + goto error2; + + shader = CALLOC_STRUCT(pipe_shader_state); + if(!shader) + goto error3; + + shader->tokens = tokens; + + return shader; + +error3: +error2: + FREE(tokens); +error1: + return NULL; + } + + ~pipe_shader_state() { + FREE((void*)$self->tokens); + FREE($self); + } + + void dump(unsigned flags = 0) { + tgsi_dump($self->tokens, flags); + } +} -- cgit v1.2.3 From 0ecaa37e49ff3a745b821ba7027eebeed938547a Mon Sep 17 00:00:00 2001 From: José Fonseca Date: Wed, 13 Aug 2008 12:31:53 +0100 Subject: python: Bindings fixes. --- src/gallium/state_trackers/python/gallium.i | 2 ++ src/gallium/state_trackers/python/p_context.i | 32 ++++++++++++++++++--------- src/gallium/state_trackers/python/p_state.i | 6 +++++ src/gallium/state_trackers/python/st_device.h | 4 ++++ 4 files changed, 34 insertions(+), 10 deletions(-) (limited to 'src/gallium/state_trackers/python/p_state.i') diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index 8d7a49cee7..641b19e940 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -55,6 +55,8 @@ %} +%include "typemaps.i" + %include "carrays.i" %array_class(unsigned char, ByteArray); %array_class(int, IntArray); diff --git a/src/gallium/state_trackers/python/p_context.i b/src/gallium/state_trackers/python/p_context.i index 521a2dee07..a23c805852 100644 --- a/src/gallium/state_trackers/python/p_context.i +++ b/src/gallium/state_trackers/python/p_context.i @@ -110,7 +110,7 @@ struct st_context { { struct pipe_constant_buffer state; memset(&state, 0, sizeof(state)); - state.buffer = buffer->buffer; + state.buffer = buffer ? buffer->buffer : NULL; state.size = buffer->buffer->size; $self->pipe->set_constant_buffer($self->pipe, shader, index, &state); } @@ -154,23 +154,31 @@ struct st_context { state.pitch = pitch; state.max_index = max_index; state.buffer_offset = buffer_offset; - state.buffer = buffer->buffer; + state.buffer = buffer ? buffer->buffer : NULL; memcpy(&$self->vertex_buffers[index], &state, sizeof(state)); for(i = 0; i < PIPE_MAX_ATTRIBS; ++i) if(self->vertex_buffers[i].buffer) - num_vertex_buffers = i + 1; + $self->num_vertex_buffers = i + 1; $self->pipe->set_vertex_buffers($self->pipe, - num_vertex_buffers, + $self->num_vertex_buffers, $self->vertex_buffers); } void set_vertex_element(unsigned index, - const struct pipe_vertex_element *element) { + const struct pipe_vertex_element *element) + { memcpy(&$self->vertex_elements[index], element, sizeof(*element)); - $self->pipe->set_vertex_elements($self->pipe, PIPE_MAX_ATTRIBS, $self->vertex_elements); + } + + void set_vertex_elements(unsigned num) + { + $self->num_vertex_elements = num; + $self->pipe->set_vertex_elements($self->pipe, + $self->num_vertex_elements, + $self->vertex_elements); } /* @@ -183,8 +191,12 @@ struct st_context { void draw_elements( struct st_buffer *indexBuffer, unsigned indexSize, - unsigned mode, unsigned start, unsigned count) { - $self->pipe->draw_elements($self->pipe, indexBuffer->buffer, indexSize, mode, start, count); + unsigned mode, unsigned start, unsigned count) + { + $self->pipe->draw_elements($self->pipe, + indexBuffer->buffer, + indexSize, + mode, start, count); } void draw_vertices(unsigned prim, @@ -222,9 +234,9 @@ error1: } void - flush(void) { + flush(unsigned flags = 0) { struct pipe_fence_handle *fence = NULL; - $self->pipe->flush($self->pipe, PIPE_FLUSH_RENDER_CACHE, &fence); + $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence); /* TODO: allow asynchronous operation */ $self->pipe->winsys->fence_finish( $self->pipe->winsys, fence, 0 ); $self->pipe->winsys->fence_reference( $self->pipe->winsys, &fence, NULL ); diff --git a/src/gallium/state_trackers/python/p_state.i b/src/gallium/state_trackers/python/p_state.i index 9834229b4b..7f5760b3b6 100644 --- a/src/gallium/state_trackers/python/p_state.i +++ b/src/gallium/state_trackers/python/p_state.i @@ -34,9 +34,15 @@ %module gallium; +%ignore winsys; +%ignore pipe_vertex_buffer::buffer; + %include "pipe/p_state.h"; +%array_class(struct pipe_stencil_state, StencilArray); + + %extend pipe_framebuffer_state { pipe_framebuffer_state(void) { diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index 5b7adbe1a0..644c263b53 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -57,7 +57,11 @@ struct st_context { struct pipe_texture *default_texture; struct pipe_texture *sampler_textures[PIPE_MAX_SAMPLERS]; + + unsigned num_vertex_buffers; struct pipe_vertex_buffer vertex_buffers[PIPE_MAX_ATTRIBS]; + + unsigned num_vertex_elements; struct pipe_vertex_element vertex_elements[PIPE_MAX_ATTRIBS]; }; -- cgit v1.2.3