diff options
author | José Fonseca <[email protected]> | 2008-08-10 18:52:00 +0100 |
---|---|---|
committer | José Fonseca <[email protected]> | 2008-08-12 11:34:40 +0100 |
commit | a304d271185af935974850055da74ec8263b00e2 (patch) | |
tree | e9bb1f947ea408e60ccd2c0828529c394bb49e13 /src/gallium | |
parent | e5a606883f24980dd8e2378c25e6fb3b8f1937ce (diff) |
python: Allow writing to buffers.
Diffstat (limited to 'src/gallium')
-rw-r--r-- | src/gallium/state_trackers/python/gallium.i | 37 | ||||
-rw-r--r-- | src/gallium/state_trackers/python/st_device.c | 33 | ||||
-rw-r--r-- | src/gallium/state_trackers/python/st_device.h | 14 |
3 files changed, 76 insertions, 8 deletions
diff --git a/src/gallium/state_trackers/python/gallium.i b/src/gallium/state_trackers/python/gallium.i index 284ecb827df..8f731ca9054 100644 --- a/src/gallium/state_trackers/python/gallium.i +++ b/src/gallium/state_trackers/python/gallium.i @@ -65,8 +65,7 @@ %rename(Context) st_context; %rename(Texture) pipe_texture; %rename(Surface) pipe_surface; - -%rename(Buffer) pipe_buffer; +%rename(Buffer) st_buffer; %rename(BlendColor) pipe_blend_color; %rename(Blend) pipe_blend_state; @@ -88,13 +87,13 @@ %nodefaultctor st_context; %nodefaultctor pipe_texture; %nodefaultctor pipe_surface; -%nodefaultctor pipe_buffer; +%nodefaultctor st_buffer; %nodefaultdtor st_device; %nodefaultdtor st_context; %nodefaultdtor pipe_texture; %nodefaultdtor pipe_surface; -%nodefaultdtor pipe_buffer; +%nodefaultdtor st_buffer; %ignore pipe_texture::screen; @@ -114,6 +113,9 @@ struct st_device { struct st_context { }; +struct st_buffer { +}; + %newobject st_device::texture_create; %newobject st_device::context_create; @@ -197,9 +199,9 @@ struct st_context { return $self->screen->texture_create($self->screen, &templat); } - struct pipe_buffer * + struct st_buffer * buffer_create(unsigned size, unsigned alignment = 0, unsigned usage = 0) { - return $self->screen->winsys->buffer_create($self->screen->winsys, alignment, usage, size); + return st_buffer_create($self, alignment, usage, size); } }; @@ -323,10 +325,10 @@ struct st_context { $self->pipe->draw_arrays($self->pipe, mode, start, count); } - void draw_elements( struct pipe_buffer *indexBuffer, + void draw_elements( struct st_buffer *indexBuffer, unsigned indexSize, unsigned mode, unsigned start, unsigned count) { - $self->pipe->draw_elements($self->pipe, indexBuffer, indexSize, mode, start, count); + $self->pipe->draw_elements($self->pipe, indexBuffer->buffer, indexSize, mode, start, count); } void draw_vertices(unsigned prim, @@ -522,6 +524,25 @@ error1: }; +%extend st_buffer { + + ~st_buffer() { + st_buffer_destroy($self); + } + + void write( const char *STRING, unsigned LENGTH, unsigned offset = 0) { + struct pipe_winsys *winsys = $self->st_dev->screen->winsys; + char *map; + + map = winsys->buffer_map(winsys, $self->buffer, PIPE_BUFFER_USAGE_CPU_WRITE); + if(!map) { + memcpy(map + offset, STRING, LENGTH); + winsys->buffer_unmap(winsys, $self->buffer); + } + } +}; + + %extend pipe_framebuffer_state { pipe_framebuffer_state(void) { diff --git a/src/gallium/state_trackers/python/st_device.c b/src/gallium/state_trackers/python/st_device.c index 2e53a83eea9..fbd56712e01 100644 --- a/src/gallium/state_trackers/python/st_device.c +++ b/src/gallium/state_trackers/python/st_device.c @@ -266,3 +266,36 @@ st_context_create(struct st_device *st_dev) return st_ctx; } + + +void +st_buffer_destroy(struct st_buffer *st_buf) +{ + if(st_buf) { + struct pipe_winsys *winsys = st_buf->st_dev->screen->winsys; + pipe_buffer_reference(winsys, &st_buf->buffer, NULL); + FREE(st_buf); + } +} + + +struct st_buffer * +st_buffer_create(struct st_device *st_dev, + unsigned alignment, unsigned usage, unsigned size) +{ + struct pipe_winsys *winsys = st_dev->screen->winsys; + struct st_buffer *st_buf; + + st_buf = CALLOC_STRUCT(st_buffer); + if(!st_buf) + return NULL; + + st_buf->st_dev = st_dev; + + st_buf->buffer = winsys->buffer_create(winsys, alignment, usage, size); + if(!st_buf->buffer) + st_buffer_destroy(st_buf); + + return st_buf; +} + diff --git a/src/gallium/state_trackers/python/st_device.h b/src/gallium/state_trackers/python/st_device.h index 2d95c2da731..5b7adbe1a0b 100644 --- a/src/gallium/state_trackers/python/st_device.h +++ b/src/gallium/state_trackers/python/st_device.h @@ -38,6 +38,13 @@ struct pipe_context; struct st_winsys; +struct st_buffer { + struct st_device *st_dev; + + struct pipe_buffer *buffer; +}; + + struct st_context { struct st_device *st_dev; @@ -65,6 +72,13 @@ struct st_device { }; +struct st_buffer * +st_buffer_create(struct st_device *st_dev, + unsigned alignment, unsigned usage, unsigned size); + +void +st_buffer_destroy(struct st_buffer *st_buf); + struct st_context * st_context_create(struct st_device *st_dev); |