Merge commit 'origin/gallium-master-merge'
[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_state.h";
41
42
43 %array_class(struct pipe_stencil_state, StencilArray);
44
45
46 %extend pipe_framebuffer_state {
47
48 pipe_framebuffer_state(void) {
49 return CALLOC_STRUCT(pipe_framebuffer_state);
50 }
51
52 ~pipe_framebuffer_state() {
53 unsigned index;
54 for(index = 0; index < PIPE_MAX_COLOR_BUFS; ++index)
55 pipe_surface_reference(&$self->cbufs[index], NULL);
56 pipe_surface_reference(&$self->zsbuf, NULL);
57 FREE($self);
58 }
59
60 void
61 set_cbuf(unsigned index, struct pipe_surface *surface) {
62 pipe_surface_reference(&$self->cbufs[index], surface);
63 }
64
65 void
66 set_zsbuf(struct pipe_surface *surface) {
67 pipe_surface_reference(&$self->zsbuf, surface);
68 }
69
70 };
71
72
73 %extend pipe_shader_state {
74
75 pipe_shader_state(const char *text, unsigned num_tokens = 1024) {
76 struct tgsi_token *tokens;
77 struct pipe_shader_state *shader;
78
79 tokens = MALLOC(num_tokens * sizeof(struct tgsi_token));
80 if(!tokens)
81 goto error1;
82
83 if(tgsi_text_translate(text, tokens, num_tokens ) != TRUE)
84 goto error2;
85
86 shader = CALLOC_STRUCT(pipe_shader_state);
87 if(!shader)
88 goto error3;
89
90 shader->tokens = tokens;
91
92 return shader;
93
94 error3:
95 error2:
96 FREE(tokens);
97 error1:
98 return NULL;
99 }
100
101 ~pipe_shader_state() {
102 FREE((void*)$self->tokens);
103 FREE($self);
104 }
105
106 void dump(unsigned flags = 0) {
107 tgsi_dump($self->tokens, flags);
108 }
109 }