st/python: remove unused 'buf' parameter in pipe_buffer_unmap
[mesa.git] / src / gallium / state_trackers / python / p_context.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 %nodefaultctor st_context;
36 %nodefaultdtor st_context;
37
38 struct st_context {
39 };
40
41 %extend st_context {
42
43 ~st_context() {
44 st_context_destroy($self);
45 }
46
47 /*
48 * State functions (create/bind/destroy state objects)
49 */
50
51 void set_blend( const struct pipe_blend_state *state ) {
52 cso_set_blend($self->cso, state);
53 }
54
55 void set_fragment_sampler( unsigned index, const struct pipe_sampler_state *state ) {
56 cso_single_sampler($self->cso, index, state);
57 cso_single_sampler_done($self->cso);
58 }
59
60 void set_vertex_sampler( unsigned index, const struct pipe_sampler_state *state ) {
61 cso_single_vertex_sampler($self->cso, index, state);
62 cso_single_vertex_sampler_done($self->cso);
63 }
64
65 void set_rasterizer( const struct pipe_rasterizer_state *state ) {
66 cso_set_rasterizer($self->cso, state);
67 }
68
69 void set_depth_stencil_alpha(const struct pipe_depth_stencil_alpha_state *state) {
70 cso_set_depth_stencil_alpha($self->cso, state);
71 }
72
73 void set_fragment_shader( const struct pipe_shader_state *state ) {
74 void *fs;
75
76 if(!state) {
77 cso_set_fragment_shader_handle($self->cso, NULL);
78 return;
79 }
80
81 fs = $self->pipe->create_fs_state($self->pipe, state);
82 if(!fs)
83 return;
84
85 if(cso_set_fragment_shader_handle($self->cso, fs) != PIPE_OK)
86 return;
87
88 cso_delete_fragment_shader($self->cso, $self->fs);
89 $self->fs = fs;
90 }
91
92 void set_vertex_shader( const struct pipe_shader_state *state ) {
93 void *vs;
94
95 if(!state) {
96 cso_set_vertex_shader_handle($self->cso, NULL);
97 return;
98 }
99
100 vs = $self->pipe->create_vs_state($self->pipe, state);
101 if(!vs)
102 return;
103
104 if(cso_set_vertex_shader_handle($self->cso, vs) != PIPE_OK)
105 return;
106
107 cso_delete_vertex_shader($self->cso, $self->vs);
108 $self->vs = vs;
109 }
110
111 void set_geometry_shader( const struct pipe_shader_state *state ) {
112 void *gs;
113
114 if(!state) {
115 cso_set_geometry_shader_handle($self->cso, NULL);
116 return;
117 }
118
119 gs = $self->pipe->create_gs_state($self->pipe, state);
120 if(!gs)
121 return;
122
123 if(cso_set_geometry_shader_handle($self->cso, gs) != PIPE_OK)
124 return;
125
126 cso_delete_geometry_shader($self->cso, $self->gs);
127 $self->gs = gs;
128 }
129
130 struct pipe_sampler_view *
131 create_sampler_view(struct pipe_resource *texture,
132 enum pipe_format format = PIPE_FORMAT_NONE,
133 unsigned first_level = 0,
134 unsigned last_level = ~0,
135 unsigned first_layer = 0,
136 unsigned last_layer = ~0,
137 unsigned swizzle_r = 0,
138 unsigned swizzle_g = 1,
139 unsigned swizzle_b = 2,
140 unsigned swizzle_a = 3)
141 {
142 struct pipe_context *pipe = $self->pipe;
143 struct pipe_sampler_view templat;
144
145 memset(&templat, 0, sizeof templat);
146 if (format == PIPE_FORMAT_NONE) {
147 templat.format = texture->format;
148 } else {
149 templat.format = format;
150 }
151 templat.u.tex.last_level = MIN2(last_level, texture->last_level);
152 templat.u.tex.first_level = first_level;
153 templat.u.tex.first_layer = first_layer;
154 templat.u.tex.last_layer = last_layer;
155 templat.swizzle_r = swizzle_r;
156 templat.swizzle_g = swizzle_g;
157 templat.swizzle_b = swizzle_b;
158 templat.swizzle_a = swizzle_a;
159
160 return pipe->create_sampler_view(pipe, texture, &templat);
161 }
162
163 void
164 sampler_view_destroy(struct pipe_context *ctx,
165 struct pipe_sampler_view *view)
166 {
167 struct pipe_context *pipe = $self->pipe;
168
169 pipe->sampler_view_destroy(pipe, view);
170 }
171
172 /*
173 * Parameter-like state (or properties)
174 */
175
176 void set_blend_color(const struct pipe_blend_color *state ) {
177 cso_set_blend_color($self->cso, state);
178 }
179
180 void set_stencil_ref(const struct pipe_stencil_ref *state ) {
181 cso_set_stencil_ref($self->cso, state);
182 }
183
184 void set_clip(const struct pipe_clip_state *state ) {
185 $self->pipe->set_clip_state($self->pipe, state);
186 }
187
188 void set_constant_buffer(unsigned shader, unsigned index,
189 struct pipe_resource *buffer )
190 {
191 $self->pipe->set_constant_buffer($self->pipe, shader, index, buffer);
192 }
193
194 void set_framebuffer(const struct pipe_framebuffer_state *state )
195 {
196 memcpy(&$self->framebuffer, state, sizeof *state);
197 cso_set_framebuffer($self->cso, state);
198 }
199
200 void set_polygon_stipple(const struct pipe_poly_stipple *state ) {
201 $self->pipe->set_polygon_stipple($self->pipe, state);
202 }
203
204 void set_scissor(const struct pipe_scissor_state *state ) {
205 $self->pipe->set_scissor_state($self->pipe, state);
206 }
207
208 void set_viewport(const struct pipe_viewport_state *state) {
209 cso_set_viewport($self->cso, state);
210 }
211
212 void set_fragment_sampler_view(unsigned index,
213 struct pipe_sampler_view *view)
214 {
215 pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view);
216
217 $self->pipe->set_fragment_sampler_views($self->pipe,
218 PIPE_MAX_SAMPLERS,
219 $self->fragment_sampler_views);
220 }
221
222 void set_vertex_sampler_view(unsigned index,
223 struct pipe_sampler_view *view)
224 {
225 pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view);
226
227 $self->pipe->set_vertex_sampler_views($self->pipe,
228 PIPE_MAX_VERTEX_SAMPLERS,
229 $self->vertex_sampler_views);
230 }
231
232 void set_fragment_sampler_texture(unsigned index,
233 struct pipe_resource *texture) {
234 struct pipe_sampler_view templ;
235
236 if(!texture)
237 texture = $self->default_texture;
238 pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL);
239 u_sampler_view_default_template(&templ,
240 texture,
241 texture->format);
242 $self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
243 texture,
244 &templ);
245 $self->pipe->set_fragment_sampler_views($self->pipe,
246 PIPE_MAX_SAMPLERS,
247 $self->fragment_sampler_views);
248 }
249
250 void set_vertex_sampler_texture(unsigned index,
251 struct pipe_resource *texture) {
252 struct pipe_sampler_view templ;
253
254 if(!texture)
255 texture = $self->default_texture;
256 pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL);
257 u_sampler_view_default_template(&templ,
258 texture,
259 texture->format);
260 $self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
261 texture,
262 &templ);
263
264 $self->pipe->set_vertex_sampler_views($self->pipe,
265 PIPE_MAX_VERTEX_SAMPLERS,
266 $self->vertex_sampler_views);
267 }
268
269 void set_vertex_buffer(unsigned index,
270 unsigned stride,
271 unsigned max_index,
272 unsigned buffer_offset,
273 struct pipe_resource *buffer)
274 {
275 unsigned i;
276 struct pipe_vertex_buffer state;
277
278 memset(&state, 0, sizeof(state));
279 state.stride = stride;
280 state.max_index = max_index;
281 state.buffer_offset = buffer_offset;
282 state.buffer = buffer;
283
284 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
285
286 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
287 if(self->vertex_buffers[i].buffer)
288 $self->num_vertex_buffers = i + 1;
289
290 $self->pipe->set_vertex_buffers($self->pipe,
291 $self->num_vertex_buffers,
292 $self->vertex_buffers);
293 }
294
295 void set_index_buffer(unsigned index_size,
296 unsigned offset,
297 struct pipe_resource *buffer)
298 {
299 struct pipe_index_buffer ib;
300
301 memset(&ib, 0, sizeof(ib));
302 ib.index_size = index_size;
303 ib.offset = offset;
304 ib.buffer = buffer;
305
306 $self->pipe->set_index_buffer($self->pipe, &ib);
307 }
308
309 void set_vertex_element(unsigned index,
310 const struct pipe_vertex_element *element)
311 {
312 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
313 }
314
315 void set_vertex_elements(unsigned num)
316 {
317 $self->num_vertex_elements = num;
318 cso_set_vertex_elements($self->cso,
319 $self->num_vertex_elements,
320 $self->vertex_elements);
321 }
322
323 /*
324 * Draw functions
325 */
326
327 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
328 util_draw_arrays($self->pipe, mode, start, count);
329 }
330
331 void draw_vbo(const struct pipe_draw_info *info)
332 {
333 $self->pipe->draw_vbo($self->pipe, info);
334 }
335
336 void draw_vertices(unsigned prim,
337 unsigned num_verts,
338 unsigned num_attribs,
339 const float *vertices)
340 {
341 struct pipe_context *pipe = $self->pipe;
342 struct pipe_screen *screen = pipe->screen;
343 struct pipe_resource *vbuf;
344 struct pipe_transfer *transfer;
345 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
346 struct pipe_vertex_buffer vbuffer;
347 float *map;
348 unsigned size;
349 unsigned i;
350
351 size = num_verts * num_attribs * 4 * sizeof(float);
352
353 vbuf = pipe_buffer_create(screen,
354 PIPE_BIND_VERTEX_BUFFER,
355 size);
356 if(!vbuf)
357 goto error1;
358
359 map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
360 if (!map)
361 goto error2;
362 memcpy(map, vertices, size);
363 pipe_buffer_unmap(pipe, transfer);
364
365 cso_save_vertex_elements($self->cso);
366
367 /* tell pipe about the vertex attributes */
368 for (i = 0; i < num_attribs; i++) {
369 velements[i].src_offset = i * 4 * sizeof(float);
370 velements[i].instance_divisor = 0;
371 velements[i].vertex_buffer_index = 0;
372 velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
373 }
374 cso_set_vertex_elements($self->cso, num_attribs, velements);
375
376 /* tell pipe about the vertex buffer */
377 memset(&vbuffer, 0, sizeof(vbuffer));
378 vbuffer.buffer = vbuf;
379 vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */
380 vbuffer.buffer_offset = 0;
381 vbuffer.max_index = num_verts - 1;
382 pipe->set_vertex_buffers(pipe, 1, &vbuffer);
383
384 /* draw */
385 util_draw_arrays(pipe, prim, 0, num_verts);
386
387 cso_restore_vertex_elements($self->cso);
388
389 error2:
390 pipe_resource_reference(&vbuf, NULL);
391 error1:
392 ;
393 }
394
395 void
396 clear(unsigned buffers, const float *rgba, double depth = 0.0f,
397 unsigned stencil = 0)
398 {
399 $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
400 }
401
402 void
403 flush(unsigned flags = 0) {
404 struct pipe_fence_handle *fence = NULL;
405 $self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
406 if(fence) {
407 /* TODO: allow asynchronous operation */
408 $self->pipe->screen->fence_finish( $self->pipe->screen, fence, 0 );
409 $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
410 }
411 }
412
413 /*
414 * Surface functions
415 */
416
417 void resource_copy_region(struct pipe_resource *dst,
418 unsigned dst_level,
419 unsigned dstx, unsigned dsty, unsigned dstz,
420 struct pipe_resource *src,
421 unsigned src_level,
422 const struct pipe_box *src_box)
423 {
424 $self->pipe->resource_copy_region($self->pipe,
425 dst, dst_level, dstx, dsty, dstz,
426 src, src_level, src_box);
427 }
428
429
430 void clear_render_target(struct st_surface *dst,
431 float *rgba,
432 unsigned x, unsigned y,
433 unsigned width, unsigned height)
434 {
435 struct pipe_surface *_dst = NULL;
436
437 _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_RENDER_TARGET);
438 if(!_dst)
439 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
440
441 $self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height);
442
443 fail:
444 pipe_surface_reference(&_dst, NULL);
445 }
446
447 void clear_depth_stencil(struct st_surface *dst,
448 unsigned clear_flags,
449 double depth,
450 unsigned stencil,
451 unsigned x, unsigned y,
452 unsigned width, unsigned height)
453 {
454 struct pipe_surface *_dst = NULL;
455
456 _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_DEPTH_STENCIL);
457 if(!_dst)
458 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
459
460 $self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil,
461 x, y, width, height);
462
463 fail:
464 pipe_surface_reference(&_dst, NULL);
465 }
466
467 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
468 void
469 surface_read_raw(struct st_surface *surface,
470 unsigned x, unsigned y, unsigned w, unsigned h,
471 char **STRING, int *LENGTH)
472 {
473 struct pipe_resource *texture = surface->texture;
474 struct pipe_context *pipe = $self->pipe;
475 struct pipe_transfer *transfer;
476 unsigned stride;
477
478 stride = util_format_get_stride(texture->format, w);
479 *LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
480 *STRING = (char *) malloc(*LENGTH);
481 if(!*STRING)
482 return;
483
484 transfer = pipe_get_transfer(pipe,
485 surface->texture,
486 surface->level,
487 surface->layer,
488 PIPE_TRANSFER_READ,
489 x, y, w, h);
490 if(transfer) {
491 pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
492 pipe->transfer_destroy(pipe, transfer);
493 }
494 }
495
496 %cstring_input_binary(const char *STRING, unsigned LENGTH);
497 void
498 surface_write_raw(struct st_surface *surface,
499 unsigned x, unsigned y, unsigned w, unsigned h,
500 const char *STRING, unsigned LENGTH, unsigned stride = 0)
501 {
502 struct pipe_resource *texture = surface->texture;
503 struct pipe_context *pipe = $self->pipe;
504 struct pipe_transfer *transfer;
505
506 if(stride == 0)
507 stride = util_format_get_stride(texture->format, w);
508
509 if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
510 SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
511
512 transfer = pipe_get_transfer(pipe,
513 surface->texture,
514 surface->level,
515 surface->layer,
516 PIPE_TRANSFER_WRITE,
517 x, y, w, h);
518 if(!transfer)
519 SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
520
521 pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
522 pipe->transfer_destroy(pipe, transfer);
523
524 fail:
525 return;
526 }
527
528 void
529 surface_read_rgba(struct st_surface *surface,
530 unsigned x, unsigned y, unsigned w, unsigned h,
531 float *rgba)
532 {
533 struct pipe_context *pipe = $self->pipe;
534 struct pipe_transfer *transfer;
535 transfer = pipe_get_transfer(pipe,
536 surface->texture,
537 surface->level,
538 surface->layer,
539 PIPE_TRANSFER_READ,
540 x, y, w, h);
541 if(transfer) {
542 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
543 pipe->transfer_destroy(pipe, transfer);
544 }
545 }
546
547 void
548 surface_write_rgba(struct st_surface *surface,
549 unsigned x, unsigned y, unsigned w, unsigned h,
550 const float *rgba)
551 {
552 struct pipe_context *pipe = $self->pipe;
553 struct pipe_transfer *transfer;
554 transfer = pipe_get_transfer(pipe,
555 surface->texture,
556 surface->level,
557 surface->layer,
558 PIPE_TRANSFER_WRITE,
559 x, y, w, h);
560 if(transfer) {
561 pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
562 pipe->transfer_destroy(pipe, transfer);
563 }
564 }
565
566 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
567 void
568 surface_read_rgba8(struct st_surface *surface,
569 unsigned x, unsigned y, unsigned w, unsigned h,
570 char **STRING, int *LENGTH)
571 {
572 struct pipe_context *pipe = $self->pipe;
573 struct pipe_transfer *transfer;
574 float *rgba;
575 unsigned char *rgba8;
576 unsigned i, j, k;
577
578 *LENGTH = 0;
579 *STRING = NULL;
580
581 if (!surface)
582 return;
583
584 *LENGTH = h*w*4;
585 *STRING = (char *) malloc(*LENGTH);
586 if(!*STRING)
587 return;
588
589 rgba = malloc(h*w*4*sizeof(float));
590 if(!rgba)
591 return;
592
593 rgba8 = (unsigned char *) *STRING;
594
595 transfer = pipe_get_transfer(pipe,
596 surface->texture,
597 surface->level,
598 surface->layer,
599 PIPE_TRANSFER_READ,
600 x, y, w, h);
601 if(transfer) {
602 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
603 for(j = 0; j < h; ++j) {
604 for(i = 0; i < w; ++i)
605 for(k = 0; k <4; ++k)
606 rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
607 }
608 pipe->transfer_destroy(pipe, transfer);
609 }
610
611 free(rgba);
612 }
613
614 void
615 surface_read_z(struct st_surface *surface,
616 unsigned x, unsigned y, unsigned w, unsigned h,
617 unsigned *z)
618 {
619 struct pipe_context *pipe = $self->pipe;
620 struct pipe_transfer *transfer;
621 transfer = pipe_get_transfer(pipe,
622 surface->texture,
623 surface->level,
624 surface->layer,
625 PIPE_TRANSFER_READ,
626 x, y, w, h);
627 if(transfer) {
628 pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
629 pipe->transfer_destroy(pipe, transfer);
630 }
631 }
632
633 void
634 surface_write_z(struct st_surface *surface,
635 unsigned x, unsigned y, unsigned w, unsigned h,
636 const unsigned *z)
637 {
638 struct pipe_context *pipe = $self->pipe;
639 struct pipe_transfer *transfer;
640 transfer = pipe_get_transfer(pipe,
641 surface->texture,
642 surface->level,
643 surface->layer,
644 PIPE_TRANSFER_WRITE,
645 x, y, w, h);
646 if(transfer) {
647 pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
648 pipe->transfer_destroy(pipe, transfer);
649 }
650 }
651
652 void
653 surface_sample_rgba(struct st_surface *surface,
654 float *rgba,
655 int norm = 0)
656 {
657 st_sample_surface($self->pipe, surface, rgba, norm != 0);
658 }
659
660 unsigned
661 surface_compare_rgba(struct st_surface *surface,
662 unsigned x, unsigned y, unsigned w, unsigned h,
663 const float *rgba, float tol = 0.0)
664 {
665 struct pipe_context *pipe = $self->pipe;
666 struct pipe_transfer *transfer;
667 float *rgba2;
668 const float *p1;
669 const float *p2;
670 unsigned i, j, n;
671
672 rgba2 = MALLOC(h*w*4*sizeof(float));
673 if(!rgba2)
674 return ~0;
675
676 transfer = pipe_get_transfer(pipe,
677 surface->texture,
678 surface->level,
679 surface->layer,
680 PIPE_TRANSFER_READ,
681 x, y, w, h);
682 if(!transfer) {
683 FREE(rgba2);
684 return ~0;
685 }
686
687 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
688 pipe->transfer_destroy(pipe, transfer);
689
690 p1 = rgba;
691 p2 = rgba2;
692 n = 0;
693 for(i = h*w; i; --i) {
694 unsigned differs = 0;
695 for(j = 4; j; --j) {
696 float delta = *p2++ - *p1++;
697 if (delta < -tol || delta > tol)
698 differs = 1;
699 }
700 n += differs;
701 }
702
703 FREE(rgba2);
704
705 return n;
706 }
707
708 %cstring_input_binary(const char *STRING, unsigned LENGTH);
709 void
710 transfer_inline_write(struct pipe_resource *resource,
711 unsigned level,
712 unsigned usage,
713 const struct pipe_box *box,
714 const char *STRING, unsigned LENGTH,
715 unsigned stride,
716 unsigned layer_stride)
717 {
718 struct pipe_context *pipe = $self->pipe;
719
720 pipe->transfer_inline_write(pipe, resource, level, usage, box, STRING, stride, layer_stride);
721 }
722
723 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
724 void buffer_read(struct pipe_resource *buffer,
725 char **STRING, int *LENGTH)
726 {
727 struct pipe_context *pipe = $self->pipe;
728
729 assert(buffer->target == PIPE_BUFFER);
730
731 *LENGTH = buffer->width0;
732 *STRING = (char *) malloc(buffer->width0);
733 if(!*STRING)
734 return;
735
736 pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING);
737 }
738
739 void buffer_write(struct pipe_resource *buffer,
740 const char *STRING, unsigned LENGTH, unsigned offset = 0)
741 {
742 struct pipe_context *pipe = $self->pipe;
743
744 assert(buffer->target == PIPE_BUFFER);
745
746 if(offset > buffer->width0)
747 SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
748
749 if(offset + LENGTH > buffer->width0)
750 SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
751
752 pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING);
753
754 fail:
755 return;
756 }
757
758 };