util: fix DXT1 RGBA texture compression if the source color is (0, 0, 0, 0)
[mesa.git] / src / gallium / state_trackers / python / p_state.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 %module gallium;
36
37 %ignore winsys;
38 %ignore pipe_vertex_buffer::buffer;
39
40 %include "pipe/p_compiler.h";
41 %include "pipe/p_state.h";
42
43
44 %array_class(struct pipe_stencil_state, StencilArray);
45
46
47 %extend pipe_rt_blend_state
48 {
49 struct pipe_rt_blend_state *
50 __getitem__(int index)
51 {
52 if(index < 0 || index >= PIPE_MAX_COLOR_BUFS)
53 SWIG_exception(SWIG_ValueError, "index out of bounds");
54 return $self + index;
55 fail:
56 return NULL;
57 };
58 };
59
60
61 %extend pipe_blend_state
62 {
63 pipe_blend_state(void)
64 {
65 return CALLOC_STRUCT(pipe_blend_state);
66 }
67
68 %cstring_input_binary(const char *STRING, unsigned LENGTH);
69 pipe_blend_state(const char *STRING, unsigned LENGTH)
70 {
71 struct pipe_blend_state *state;
72 state = CALLOC_STRUCT(pipe_blend_state);
73 if (state) {
74 LENGTH = MIN2(sizeof *state, LENGTH);
75 memcpy(state, STRING, LENGTH);
76 }
77 return state;
78 }
79
80 %cstring_output_allocate_size(char **STRING, int *LENGTH, os_free(*$1));
81 void __str__(char **STRING, int *LENGTH)
82 {
83 struct os_stream *stream;
84
85 stream = os_str_stream_create(1);
86 util_dump_blend_state(stream, $self);
87
88 *STRING = os_str_stream_get_and_close(stream);
89 *LENGTH = strlen(*STRING);
90 }
91 };
92
93
94 %extend pipe_framebuffer_state {
95
96 pipe_framebuffer_state(void) {
97 return CALLOC_STRUCT(pipe_framebuffer_state);
98 }
99
100 ~pipe_framebuffer_state() {
101 unsigned index;
102 for(index = 0; index < PIPE_MAX_COLOR_BUFS; ++index)
103 pipe_surface_reference(&$self->cbufs[index], NULL);
104 pipe_surface_reference(&$self->zsbuf, NULL);
105 FREE($self);
106 }
107
108 void
109 set_cbuf(unsigned index, struct st_surface *surface)
110 {
111 struct pipe_surface *_surface = NULL;
112
113 if(index >= PIPE_MAX_COLOR_BUFS)
114 SWIG_exception(SWIG_ValueError, "index out of bounds");
115
116 if(surface) {
117 /* XXX need a context here */
118 _surface = st_pipe_surface(NULL, surface, PIPE_BIND_RENDER_TARGET);
119 if(!_surface)
120 SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
121 }
122
123 pipe_surface_reference(&$self->cbufs[index], _surface);
124
125 fail:
126 return;
127 }
128
129 void
130 set_zsbuf(struct st_surface *surface)
131 {
132 struct pipe_surface *_surface = NULL;
133
134 if(surface) {
135 /* XXX need a context here */
136 _surface = st_pipe_surface(NULL, surface, PIPE_BIND_DEPTH_STENCIL);
137 if(!_surface)
138 SWIG_exception(SWIG_ValueError, "couldn't acquire surface for writing");
139 }
140
141 pipe_surface_reference(&$self->zsbuf, _surface);
142
143 fail:
144 return;
145 }
146
147 };
148
149
150 %extend pipe_shader_state {
151
152 pipe_shader_state(const char *text, unsigned num_tokens = 1024) {
153 struct tgsi_token *tokens;
154 struct pipe_shader_state *shader;
155
156 tokens = MALLOC(num_tokens * sizeof(struct tgsi_token));
157 if(!tokens)
158 goto error1;
159
160 if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE)
161 goto error2;
162
163 shader = CALLOC_STRUCT(pipe_shader_state);
164 if(!shader)
165 goto error3;
166
167 shader->tokens = tokens;
168
169 return shader;
170
171 error3:
172 error2:
173 FREE(tokens);
174 error1:
175 return NULL;
176 }
177
178 ~pipe_shader_state() {
179 FREE((void*)$self->tokens);
180 FREE($self);
181 }
182
183 void dump(unsigned flags = 0) {
184 tgsi_dump($self->tokens, flags);
185 }
186 }