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>
35 %nodefaultctor st_context;
36 %nodefaultdtor st_context;
44 st_context_destroy($self);
48 * State functions (create/bind/destroy state objects)
51 void set_blend( const struct pipe_blend_state *state ) {
52 cso_set_blend($self->cso, state);
55 void set_sampler( unsigned index, const struct pipe_sampler_state *state ) {
56 cso_single_sampler($self->cso, index, state);
57 cso_single_sampler_done($self->cso);
60 void set_rasterizer( const struct pipe_rasterizer_state *state ) {
61 cso_set_rasterizer($self->cso, state);
64 void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) {
65 cso_set_depth_stencil_alpha($self->cso, state);
68 void set_fragment_shader( const struct pipe_shader_state *state ) {
72 cso_set_fragment_shader_handle($self->cso, NULL);
76 fs = $self->pipe->create_fs_state($self->pipe, state);
80 if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
83 cso_delete_fragment_shader($self->cso, $self->fs);
87 void set_vertex_shader( const struct pipe_shader_state *state ) {
91 cso_set_vertex_shader_handle($self->cso, NULL);
95 vs = $self->pipe->create_vs_state($self->pipe, state);
99 if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
102 cso_delete_vertex_shader($self->cso, $self->vs);
107 * Parameter-like state (or properties)
110 void set_blend_color(const struct pipe_blend_color *state ) {
111 cso_set_blend_color($self->cso, state);
114 void set_clip(const struct pipe_clip_state *state ) {
115 $self->pipe->set_clip_state($self->pipe, state);
118 void set_constant_buffer(unsigned shader, unsigned index,
119 struct pipe_buffer *buffer )
121 struct pipe_constant_buffer state;
122 memset(&state, 0, sizeof(state));
123 state.buffer = buffer;
124 $self->pipe->set_constant_buffer($self->pipe, shader, index, &state);
127 void set_framebuffer(const struct pipe_framebuffer_state *state ) {
128 cso_set_framebuffer($self->cso, state);
131 void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
132 $self->pipe->set_polygon_stipple($self->pipe, state);
135 void set_scissor(const struct pipe_scissor_state *state ) {
136 $self->pipe->set_scissor_state($self->pipe, state);
139 void set_viewport(const struct pipe_viewport_state *state) {
140 cso_set_viewport($self->cso, state);
143 void set_sampler_texture(unsigned index,
144 struct pipe_texture *texture) {
146 texture = $self->default_texture;
147 pipe_texture_reference(&$self->sampler_textures[index], texture);
148 $self->pipe->set_sampler_textures($self->pipe,
150 $self->sampler_textures);
153 void set_vertex_buffer(unsigned index,
156 unsigned buffer_offset,
157 struct pipe_buffer *buffer)
160 struct pipe_vertex_buffer state;
162 memset(&state, 0, sizeof(state));
163 state.stride = stride;
164 state.max_index = max_index;
165 state.buffer_offset = buffer_offset;
166 state.buffer = buffer;
168 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
170 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
171 if(self->vertex_buffers[i].buffer)
172 $self->num_vertex_buffers = i + 1;
174 $self->pipe->set_vertex_buffers($self->pipe,
175 $self->num_vertex_buffers,
176 $self->vertex_buffers);
179 void set_vertex_element(unsigned index,
180 const struct pipe_vertex_element *element)
182 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
185 void set_vertex_elements(unsigned num)
187 $self->num_vertex_elements = num;
188 $self->pipe->set_vertex_elements($self->pipe,
189 $self->num_vertex_elements,
190 $self->vertex_elements);
197 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
198 $self->pipe->draw_arrays($self->pipe, mode, start, count);
201 void draw_elements( struct pipe_buffer *indexBuffer,
203 unsigned mode, unsigned start, unsigned count)
205 $self->pipe->draw_elements($self->pipe,
211 void draw_range_elements( struct pipe_buffer *indexBuffer,
212 unsigned indexSize, unsigned minIndex, unsigned maxIndex,
213 unsigned mode, unsigned start, unsigned count)
215 $self->pipe->draw_range_elements($self->pipe,
217 indexSize, minIndex, maxIndex,
221 void draw_vertices(unsigned prim,
223 unsigned num_attribs,
224 const float *vertices)
226 struct pipe_context *pipe = $self->pipe;
227 struct pipe_screen *screen = pipe->screen;
228 struct pipe_buffer *vbuf;
232 size = num_verts * num_attribs * 4 * sizeof(float);
234 vbuf = pipe_buffer_create(screen,
236 PIPE_BUFFER_USAGE_VERTEX,
241 map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
244 memcpy(map, vertices, size);
245 pipe_buffer_unmap(screen, vbuf);
247 util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs);
250 pipe_buffer_reference(&vbuf, NULL);
256 flush(unsigned flags = 0) {
257 struct pipe_fence_handle *fence = NULL;
258 $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
259 /* TODO: allow asynchronous operation */
260 $self->pipe->screen->fence_finish( $self->pipe->screen, fence, 0 );
261 $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
268 void surface_copy(struct pipe_surface *dest,
269 unsigned destx, unsigned desty,
270 struct pipe_surface *src,
271 unsigned srcx, unsigned srcy,
272 unsigned width, unsigned height) {
273 $self->pipe->surface_copy($self->pipe, dest, destx, desty, src, srcx, srcy, width, height);
276 void surface_fill(struct pipe_surface *dst,
277 unsigned x, unsigned y,
278 unsigned width, unsigned height,
280 $self->pipe->surface_fill($self->pipe, dst, x, y, width, height, value);
283 void surface_clear(struct pipe_surface *surface, unsigned value = 0) {
284 $self->pipe->clear($self->pipe, surface, value);