1f4b4fd596bf1ca4e6228d1037f0d77885939185
[mesa.git] / src / gallium / state_trackers / python / p_texture.i
1 /**************************************************************************
2 *
3 * Copyright 2008 Tungsten Graphics, Inc., Cedar Park, Texas.
4 * All Rights Reserved.
5 *
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:
13 *
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
16 * of the Software.
17 *
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.
25 *
26 **************************************************************************/
27
28 /**
29 * @file
30 * SWIG interface definion for Gallium types.
31 *
32 * @author Jose Fonseca <jrfonseca@tungstengraphics.com>
33 */
34
35
36 %nodefaultctor pipe_resource;
37 %nodefaultctor st_surface;
38
39 %nodefaultdtor pipe_resource;
40 %nodefaultdtor st_surface;
41
42 %ignore pipe_resource::screen;
43
44 %immutable st_surface::texture;
45 %immutable st_surface::level;
46 %immutable st_surface::layer;
47
48 %newobject pipe_resource::get_surface;
49
50 /* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
51 %rename(read) read_;
52 %rename(write) write_;
53
54 %extend pipe_resource {
55
56 ~pipe_resource() {
57 struct pipe_resource *ptr = $self;
58 pipe_resource_reference(&ptr, NULL);
59 }
60
61 unsigned get_width(unsigned level=0) {
62 return u_minify($self->width0, level);
63 }
64
65 unsigned get_height(unsigned level=0) {
66 return u_minify($self->height0, level);
67 }
68
69 unsigned get_depth(unsigned level=0) {
70 return u_minify($self->depth0, level);
71 }
72
73 /** Get a surface which is a "view" into a texture */
74 struct st_surface *
75 get_surface(unsigned level=0, unsigned layer=0)
76 {
77 struct st_surface *surface;
78
79 if(level > $self->last_level)
80 SWIG_exception(SWIG_ValueError, "level out of bounds");
81 if(layer >= ($self->target == PIPE_TEXTURE_3D ?
82 u_minify($self->depth0, level) : $self->depth0))
83 SWIG_exception(SWIG_ValueError, "layer out of bounds");
84
85 surface = CALLOC_STRUCT(st_surface);
86 if(!surface)
87 return NULL;
88
89 pipe_resource_reference(&surface->texture, $self);
90 surface->level = level;
91 surface->layer = layer;
92
93 return surface;
94
95 fail:
96 return NULL;
97 }
98
99 unsigned __len__(void)
100 {
101 assert($self->target == PIPE_BUFFER);
102 assert(p_atomic_read(&$self->reference.count) > 0);
103 return $self->width0;
104 }
105
106 };
107
108 struct st_surface
109 {
110 %immutable;
111
112 struct pipe_resource *texture;
113 unsigned level;
114 unsigned layer;
115
116 };
117
118 %extend st_surface {
119
120 %immutable;
121
122 unsigned format;
123 unsigned width;
124 unsigned height;
125
126 ~st_surface() {
127 pipe_resource_reference(&$self->texture, NULL);
128 FREE($self);
129 }
130
131
132 };
133
134 %{
135 static enum pipe_format
136 st_surface_format_get(struct st_surface *surface)
137 {
138 return surface->texture->format;
139 }
140
141 static unsigned
142 st_surface_width_get(struct st_surface *surface)
143 {
144 return u_minify(surface->texture->width0, surface->level);
145 }
146
147 static unsigned
148 st_surface_height_get(struct st_surface *surface)
149 {
150 return u_minify(surface->texture->height0, surface->level);
151 }
152 %}