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 st_surface;
38 %nodefaultctor pipe_buffer;
40 %nodefaultdtor pipe_texture;
41 %nodefaultdtor st_surface;
42 %nodefaultdtor pipe_buffer;
44 %ignore pipe_texture::screen;
46 %immutable st_surface::texture;
47 %immutable st_surface::face;
48 %immutable st_surface::level;
49 %immutable st_surface::zslice;
51 %newobject pipe_texture::get_surface;
54 %extend pipe_texture {
57 struct pipe_texture *ptr = $self;
58 pipe_texture_reference(&ptr, NULL);
61 unsigned get_width(unsigned level=0) {
62 return $self->width[level];
65 unsigned get_height(unsigned level=0) {
66 return $self->height[level];
69 unsigned get_depth(unsigned level=0) {
70 return $self->depth[level];
73 unsigned get_nblocksx(unsigned level=0) {
74 return $self->nblocksx[level];
77 unsigned get_nblocksy(unsigned level=0) {
78 return $self->nblocksy[level];
81 /** Get a surface which is a "view" into a texture */
83 get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0)
85 struct st_surface *surface;
87 if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
88 SWIG_exception(SWIG_ValueError, "face out of bounds");
89 if(level > $self->last_level)
90 SWIG_exception(SWIG_ValueError, "level out of bounds");
91 if(zslice >= $self->depth[level])
92 SWIG_exception(SWIG_ValueError, "zslice out of bounds");
94 surface = CALLOC_STRUCT(st_surface);
98 pipe_texture_reference(&surface->texture, $self);
100 surface->level = level;
101 surface->zslice = zslice;
115 struct pipe_texture *texture;
131 pipe_texture_reference(&$self->texture, NULL);
136 get_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, char *raw, unsigned stride)
138 struct pipe_screen *screen = $self->texture->screen;
139 struct pipe_transfer *transfer;
140 transfer = screen->get_tex_transfer(screen,
148 pipe_get_tile_raw(transfer, 0, 0, w, h, raw, stride);
149 screen->tex_transfer_destroy(transfer);
154 put_tile_raw(unsigned x, unsigned y, unsigned w, unsigned h, const char *raw, unsigned stride)
156 struct pipe_screen *screen = $self->texture->screen;
157 struct pipe_transfer *transfer;
158 transfer = screen->get_tex_transfer(screen,
166 pipe_put_tile_raw(transfer, 0, 0, w, h, raw, stride);
167 screen->tex_transfer_destroy(transfer);
172 get_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, float *rgba)
174 struct pipe_screen *screen = $self->texture->screen;
175 struct pipe_transfer *transfer;
176 transfer = screen->get_tex_transfer(screen,
184 pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba);
185 screen->tex_transfer_destroy(transfer);
190 put_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba)
192 struct pipe_screen *screen = $self->texture->screen;
193 struct pipe_transfer *transfer;
194 transfer = screen->get_tex_transfer(screen,
202 pipe_put_tile_rgba(transfer, 0, 0, w, h, rgba);
203 screen->tex_transfer_destroy(transfer);
207 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
209 get_tile_rgba8(unsigned x, unsigned y, unsigned w, unsigned h, char **STRING, int *LENGTH)
211 struct pipe_screen *screen = $self->texture->screen;
212 struct pipe_transfer *transfer;
214 unsigned char *rgba8;
224 *STRING = (char *) malloc(*LENGTH);
228 rgba = malloc(h*w*4*sizeof(float));
232 rgba8 = (unsigned char *) *STRING;
234 transfer = screen->get_tex_transfer(screen,
243 pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba);
244 for(j = 0; j < h; ++j) {
245 for(i = 0; i < w; ++i)
246 for(k = 0; k <4; ++k)
247 rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
249 screen->tex_transfer_destroy(transfer);
256 get_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, unsigned *z)
258 struct pipe_screen *screen = $self->texture->screen;
259 struct pipe_transfer *transfer;
260 transfer = screen->get_tex_transfer(screen,
268 pipe_get_tile_z(transfer, 0, 0, w, h, z);
269 screen->tex_transfer_destroy(transfer);
274 put_tile_z(unsigned x, unsigned y, unsigned w, unsigned h, const unsigned *z)
276 struct pipe_screen *screen = $self->texture->screen;
277 struct pipe_transfer *transfer;
278 transfer = screen->get_tex_transfer(screen,
286 pipe_put_tile_z(transfer, 0, 0, w, h, z);
287 screen->tex_transfer_destroy(transfer);
292 sample_rgba(float *rgba) {
293 st_sample_surface($self, rgba);
297 compare_tile_rgba(unsigned x, unsigned y, unsigned w, unsigned h, const float *rgba, float tol = 0.0)
299 struct pipe_screen *screen = $self->texture->screen;
300 struct pipe_transfer *transfer;
306 rgba2 = MALLOC(h*w*4*sizeof(float));
310 transfer = screen->get_tex_transfer(screen,
322 pipe_get_tile_rgba(transfer, 0, 0, w, h, rgba2);
323 screen->tex_transfer_destroy(transfer);
328 for(i = h*w; i; --i) {
329 unsigned differs = 0;
331 float delta = *p2++ - *p1++;
332 if (delta < -tol || delta > tol)
346 static enum pipe_format
347 st_surface_format_get(struct st_surface *surface)
349 return surface->texture->format;
353 st_surface_width_get(struct st_surface *surface)
355 return surface->texture->width[surface->level];
359 st_surface_height_get(struct st_surface *surface)
361 return surface->texture->height[surface->level];
365 /* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
366 %rename(read) pipe_buffer_read_;
367 %rename(write) pipe_buffer_write_;
369 %extend pipe_buffer {
372 struct pipe_buffer *ptr = $self;
373 pipe_buffer_reference(&ptr, NULL);
376 unsigned __len__(void)
378 assert(p_atomic_read(&$self->reference.count) > 0);
382 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
383 void read_(char **STRING, int *LENGTH)
385 struct pipe_screen *screen = $self->screen;
387 assert(p_atomic_read(&$self->reference.count) > 0);
389 *LENGTH = $self->size;
390 *STRING = (char *) malloc($self->size);
394 pipe_buffer_read(screen, $self, 0, $self->size, STRING);
397 %cstring_input_binary(const char *STRING, unsigned LENGTH);
398 void write_(const char *STRING, unsigned LENGTH, unsigned offset = 0)
400 struct pipe_screen *screen = $self->screen;
402 assert(p_atomic_read(&$self->reference.count) > 0);
404 if(offset > $self->size)
405 SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
407 if(offset + LENGTH > $self->size)
408 SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
410 pipe_buffer_write(screen, $self, offset, LENGTH, STRING);