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>
36 %nodefaultctor pipe_texture;
37 %nodefaultctor pipe_surface;
38 %nodefaultctor st_buffer;
40 %nodefaultdtor pipe_texture;
41 %nodefaultdtor pipe_surface;
42 %nodefaultdtor st_buffer;
44 %ignore pipe_texture::screen;
46 %ignore pipe_surface::winsys;
47 %immutable pipe_surface::texture;
48 %immutable pipe_surface::buffer;
50 %newobject pipe_texture::get_surface;
53 %extend pipe_texture {
56 struct pipe_texture *ptr = $self;
57 pipe_texture_reference(&ptr, NULL);
60 unsigned get_width(unsigned level=0) {
61 return $self->width[level];
64 unsigned get_height(unsigned level=0) {
65 return $self->height[level];
68 unsigned get_depth(unsigned level=0) {
69 return $self->depth[level];
72 unsigned get_nblocksx(unsigned level=0) {
73 return $self->nblocksx[level];
76 unsigned get_nblocksy(unsigned level=0) {
77 return $self->nblocksy[level];
80 /** Get a surface which is a "view" into a texture */
82 get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0, unsigned usage=0 )
84 struct pipe_screen *screen = $self->screen;
85 return screen->get_tex_surface(screen, $self, face, level, zslice, usage);
91 %extend pipe_surface {
94 struct pipe_surface *ptr = $self;
95 pipe_surface_reference(&ptr, NULL);
98 // gets mapped to pipe_surface_map automatically
99 void * map( unsigned flags );
101 // gets mapped to pipe_surface_unmap automatically
105 get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char *raw, unsigned stride) {
106 pipe_get_tile_raw($self, x, y, w, h, raw, stride);
110 put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *raw, unsigned stride) {
111 pipe_put_tile_raw($self, x, y, w, h, raw, stride);
115 get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba) {
116 pipe_get_tile_rgba($self, x, y, w, h, rgba);
120 put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba) {
121 pipe_put_tile_rgba($self, x, y, w, h, rgba);
125 get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z) {
126 pipe_get_tile_z($self, x, y, w, h, z);
130 put_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z) {
131 pipe_put_tile_z($self, x, y, w, h, z);
135 sample_rgba(float *rgba) {
136 st_sample_surface($self, rgba);
140 compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0)
147 rgba2 = MALLOC(h*w*4*sizeof(float));
151 pipe_get_tile_rgba($self, x, y, w, h, rgba2);
156 for(i = h*w; i; --i) {
157 unsigned differs = 0;
159 float delta = *p2++ - *p1++;
160 if (delta < -tol || delta > tol)
179 st_buffer_destroy($self);
182 void write( const char *STRING, unsigned LENGTH, unsigned offset = 0) {
183 struct pipe_winsys *winsys = $self->st_dev->screen->winsys;
186 assert($self->buffer->refcount);
188 if(offset > $self->buffer->size) {
189 PyErr_SetString(PyExc_ValueError, "offset must be smaller than buffer size");
193 if(offset + LENGTH > $self->buffer->size) {
194 PyErr_SetString(PyExc_ValueError, "data length must fit inside the buffer");
198 map = winsys->buffer_map(winsys, $self->buffer, PIPE_BUFFER_USAGE_CPU_WRITE);
200 memcpy(map + offset, STRING, LENGTH);
201 winsys->buffer_unmap(winsys, $self->buffer);