Merge remote branch 'origin/7.8'
[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::face;
46 %immutable st_surface::level;
47 %immutable st_surface::zslice;
48
49 %newobject pipe_resource::get_surface;
50
51 /* Avoid naming conflict with p_inlines.h's pipe_buffer_read/write */
52 %rename(read) read_;
53 %rename(write) write_;
54
55 %extend pipe_resource {
56
57 ~pipe_resource() {
58 struct pipe_resource *ptr = $self;
59 pipe_resource_reference(&ptr, NULL);
60 }
61
62 unsigned get_width(unsigned level=0) {
63 return u_minify($self->width0, level);
64 }
65
66 unsigned get_height(unsigned level=0) {
67 return u_minify($self->height0, level);
68 }
69
70 unsigned get_depth(unsigned level=0) {
71 return u_minify($self->depth0, level);
72 }
73
74 /** Get a surface which is a "view" into a texture */
75 struct st_surface *
76 get_surface(unsigned face=0, unsigned level=0, unsigned zslice=0)
77 {
78 struct st_surface *surface;
79
80 if(face >= ($self->target == PIPE_TEXTURE_CUBE ? 6U : 1U))
81 SWIG_exception(SWIG_ValueError, "face out of bounds");
82 if(level > $self->last_level)
83 SWIG_exception(SWIG_ValueError, "level out of bounds");
84 if(zslice >= u_minify($self->depth0, level))
85 SWIG_exception(SWIG_ValueError, "zslice out of bounds");
86
87 surface = CALLOC_STRUCT(st_surface);
88 if(!surface)
89 return NULL;
90
91 pipe_resource_reference(&surface->texture, $self);
92 surface->face = face;
93 surface->level = level;
94 surface->zslice = zslice;
95
96 return surface;
97
98 fail:
99 return NULL;
100 }
101
102 unsigned __len__(void)
103 {
104 assert($self->target == PIPE_BUFFER);
105 assert(p_atomic_read(&$self->reference.count) > 0);
106 return $self->width0;
107 }
108
109 };
110
111 struct st_surface
112 {
113 %immutable;
114
115 struct pipe_resource *texture;
116 unsigned face;
117 unsigned level;
118 unsigned zslice;
119
120 };
121
122 %extend st_surface {
123
124 %immutable;
125
126 unsigned format;
127 unsigned width;
128 unsigned height;
129
130 ~st_surface() {
131 pipe_resource_reference(&$self->texture, NULL);
132 FREE($self);
133 }
134
135
136 };
137
138 %{
139 static enum pipe_format
140 st_surface_format_get(struct st_surface *surface)
141 {
142 return surface->texture->format;
143 }
144
145 static unsigned
146 st_surface_width_get(struct st_surface *surface)
147 {
148 return u_minify(surface->texture->width0, surface->level);
149 }
150
151 static unsigned
152 st_surface_height_get(struct st_surface *surface)
153 {
154 return u_minify(surface->texture->height0, surface->level);
155 }
156 %}