swrast: simplify assertion to silence warning
[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 buffer_offset,
272 struct pipe_resource *buffer)
273 {
274 unsigned i;
275 struct pipe_vertex_buffer state;
276
277 memset(&state, 0, sizeof(state));
278 state.stride = stride;
279 state.buffer_offset = buffer_offset;
280 state.buffer = buffer;
281
282 memcpy(&$self->vertex_buffers[index], &state, sizeof(state));
283
284 for(i = 0; i < PIPE_MAX_ATTRIBS; ++i)
285 if(self->vertex_buffers[i].buffer)
286 $self->num_vertex_buffers = i + 1;
287
288 $self->pipe->set_vertex_buffers($self->pipe,
289 $self->num_vertex_buffers,
290 $self->vertex_buffers);
291 }
292
293 void set_index_buffer(unsigned index_size,
294 unsigned offset,
295 struct pipe_resource *buffer)
296 {
297 struct pipe_index_buffer ib;
298
299 memset(&ib, 0, sizeof(ib));
300 ib.index_size = index_size;
301 ib.offset = offset;
302 ib.buffer = buffer;
303
304 $self->pipe->set_index_buffer($self->pipe, &ib);
305 }
306
307 void set_vertex_element(unsigned index,
308 const struct pipe_vertex_element *element)
309 {
310 memcpy(&$self->vertex_elements[index], element, sizeof(*element));
311 }
312
313 void set_vertex_elements(unsigned num)
314 {
315 $self->num_vertex_elements = num;
316 cso_set_vertex_elements($self->cso,
317 $self->num_vertex_elements,
318 $self->vertex_elements);
319 }
320
321 /*
322 * Draw functions
323 */
324
325 void draw_arrays(unsigned mode, unsigned start, unsigned count) {
326 util_draw_arrays($self->pipe, mode, start, count);
327 }
328
329 void draw_vbo(const struct pipe_draw_info *info)
330 {
331 $self->pipe->draw_vbo($self->pipe, info);
332 }
333
334 void draw_vertices(unsigned prim,
335 unsigned num_verts,
336 unsigned num_attribs,
337 const float *vertices)
338 {
339 struct pipe_context *pipe = $self->pipe;
340 struct pipe_screen *screen = pipe->screen;
341 struct pipe_resource *vbuf;
342 struct pipe_transfer *transfer;
343 struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
344 struct pipe_vertex_buffer vbuffer;
345 float *map;
346 unsigned size;
347 unsigned i;
348
349 size = num_verts * num_attribs * 4 * sizeof(float);
350
351 vbuf = pipe_buffer_create(screen,
352 PIPE_BIND_VERTEX_BUFFER,
353 PIPE_USAGE_STATIC,
354 size);
355 if(!vbuf)
356 goto error1;
357
358 map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
359 if (!map)
360 goto error2;
361 memcpy(map, vertices, size);
362 pipe_buffer_unmap(pipe, transfer);
363
364 cso_save_vertex_elements($self->cso);
365
366 /* tell pipe about the vertex attributes */
367 for (i = 0; i < num_attribs; i++) {
368 velements[i].src_offset = i * 4 * sizeof(float);
369 velements[i].instance_divisor = 0;
370 velements[i].vertex_buffer_index = 0;
371 velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
372 }
373 cso_set_vertex_elements($self->cso, num_attribs, velements);
374
375 /* tell pipe about the vertex buffer */
376 memset(&vbuffer, 0, sizeof(vbuffer));
377 vbuffer.buffer = vbuf;
378 vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */
379 vbuffer.buffer_offset = 0;
380 pipe->set_vertex_buffers(pipe, 1, &vbuffer);
381
382 /* draw */
383 util_draw_arrays(pipe, prim, 0, num_verts);
384
385 cso_restore_vertex_elements($self->cso);
386
387 error2:
388 pipe_resource_reference(&vbuf, NULL);
389 error1:
390 ;
391 }
392
393 void
394 clear(unsigned buffers, const float *rgba, double depth = 0.0f,
395 unsigned stencil = 0)
396 {
397 $self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
398 }
399
400 void
401 flush(unsigned flags = 0) {
402 struct pipe_fence_handle *fence = NULL;
403 $self->pipe->flush($self->pipe, &fence);
404 if(fence) {
405 /* TODO: allow asynchronous operation */
406 $self->pipe->screen->fence_finish( $self->pipe->screen, fence, PIPE_TIMEOUT_INFINITE );
407 $self->pipe->screen->fence_reference( $self->pipe->screen, &fence, NULL );
408 }
409 }
410
411 /*
412 * Surface functions
413 */
414
415 void resource_copy_region(struct pipe_resource *dst,
416 unsigned dst_level,
417 unsigned dstx, unsigned dsty, unsigned dstz,
418 struct pipe_resource *src,
419 unsigned src_level,
420 const struct pipe_box *src_box)
421 {
422 $self->pipe->resource_copy_region($self->pipe,
423 dst, dst_level, dstx, dsty, dstz,
424 src, src_level, src_box);
425 }
426
427
428 void clear_render_target(struct st_surface *dst,
429 float *rgba,
430 unsigned x, unsigned y,
431 unsigned width, unsigned height)
432 {
433 struct pipe_surface *_dst = NULL;
434
435 _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_RENDER_TARGET);
436 if(!_dst)
437 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
438
439 $self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height);
440
441 fail:
442 pipe_surface_reference(&_dst, NULL);
443 }
444
445 void clear_depth_stencil(struct st_surface *dst,
446 unsigned clear_flags,
447 double depth,
448 unsigned stencil,
449 unsigned x, unsigned y,
450 unsigned width, unsigned height)
451 {
452 struct pipe_surface *_dst = NULL;
453
454 _dst = st_pipe_surface($self->pipe, dst, PIPE_BIND_DEPTH_STENCIL);
455 if(!_dst)
456 SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
457
458 $self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil,
459 x, y, width, height);
460
461 fail:
462 pipe_surface_reference(&_dst, NULL);
463 }
464
465 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
466 void
467 surface_read_raw(struct st_surface *surface,
468 unsigned x, unsigned y, unsigned w, unsigned h,
469 char **STRING, int *LENGTH)
470 {
471 struct pipe_resource *texture = surface->texture;
472 struct pipe_context *pipe = $self->pipe;
473 struct pipe_transfer *transfer;
474 unsigned stride;
475
476 stride = util_format_get_stride(texture->format, w);
477 *LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
478 *STRING = (char *) malloc(*LENGTH);
479 if(!*STRING)
480 return;
481
482 transfer = pipe_get_transfer(pipe,
483 surface->texture,
484 surface->level,
485 surface->layer,
486 PIPE_TRANSFER_READ,
487 x, y, w, h);
488 if(transfer) {
489 pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
490 pipe->transfer_destroy(pipe, transfer);
491 }
492 }
493
494 %cstring_input_binary(const char *STRING, unsigned LENGTH);
495 void
496 surface_write_raw(struct st_surface *surface,
497 unsigned x, unsigned y, unsigned w, unsigned h,
498 const char *STRING, unsigned LENGTH, unsigned stride = 0)
499 {
500 struct pipe_resource *texture = surface->texture;
501 struct pipe_context *pipe = $self->pipe;
502 struct pipe_transfer *transfer;
503
504 if(stride == 0)
505 stride = util_format_get_stride(texture->format, w);
506
507 if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
508 SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
509
510 transfer = pipe_get_transfer(pipe,
511 surface->texture,
512 surface->level,
513 surface->layer,
514 PIPE_TRANSFER_WRITE,
515 x, y, w, h);
516 if(!transfer)
517 SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
518
519 pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
520 pipe->transfer_destroy(pipe, transfer);
521
522 fail:
523 return;
524 }
525
526 void
527 surface_read_rgba(struct st_surface *surface,
528 unsigned x, unsigned y, unsigned w, unsigned h,
529 float *rgba)
530 {
531 struct pipe_context *pipe = $self->pipe;
532 struct pipe_transfer *transfer;
533 transfer = pipe_get_transfer(pipe,
534 surface->texture,
535 surface->level,
536 surface->layer,
537 PIPE_TRANSFER_READ,
538 x, y, w, h);
539 if(transfer) {
540 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
541 pipe->transfer_destroy(pipe, transfer);
542 }
543 }
544
545 void
546 surface_write_rgba(struct st_surface *surface,
547 unsigned x, unsigned y, unsigned w, unsigned h,
548 const float *rgba)
549 {
550 struct pipe_context *pipe = $self->pipe;
551 struct pipe_transfer *transfer;
552 transfer = pipe_get_transfer(pipe,
553 surface->texture,
554 surface->level,
555 surface->layer,
556 PIPE_TRANSFER_WRITE,
557 x, y, w, h);
558 if(transfer) {
559 pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
560 pipe->transfer_destroy(pipe, transfer);
561 }
562 }
563
564 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
565 void
566 surface_read_rgba8(struct st_surface *surface,
567 unsigned x, unsigned y, unsigned w, unsigned h,
568 char **STRING, int *LENGTH)
569 {
570 struct pipe_context *pipe = $self->pipe;
571 struct pipe_transfer *transfer;
572 float *rgba;
573 unsigned char *rgba8;
574 unsigned i, j, k;
575
576 *LENGTH = 0;
577 *STRING = NULL;
578
579 if (!surface)
580 return;
581
582 *LENGTH = h*w*4;
583 *STRING = (char *) malloc(*LENGTH);
584 if(!*STRING)
585 return;
586
587 rgba = malloc(h*w*4*sizeof(float));
588 if(!rgba)
589 return;
590
591 rgba8 = (unsigned char *) *STRING;
592
593 transfer = pipe_get_transfer(pipe,
594 surface->texture,
595 surface->level,
596 surface->layer,
597 PIPE_TRANSFER_READ,
598 x, y, w, h);
599 if(transfer) {
600 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
601 for(j = 0; j < h; ++j) {
602 for(i = 0; i < w; ++i)
603 for(k = 0; k <4; ++k)
604 rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
605 }
606 pipe->transfer_destroy(pipe, transfer);
607 }
608
609 free(rgba);
610 }
611
612 void
613 surface_read_z(struct st_surface *surface,
614 unsigned x, unsigned y, unsigned w, unsigned h,
615 unsigned *z)
616 {
617 struct pipe_context *pipe = $self->pipe;
618 struct pipe_transfer *transfer;
619 transfer = pipe_get_transfer(pipe,
620 surface->texture,
621 surface->level,
622 surface->layer,
623 PIPE_TRANSFER_READ,
624 x, y, w, h);
625 if(transfer) {
626 pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
627 pipe->transfer_destroy(pipe, transfer);
628 }
629 }
630
631 void
632 surface_write_z(struct st_surface *surface,
633 unsigned x, unsigned y, unsigned w, unsigned h,
634 const unsigned *z)
635 {
636 struct pipe_context *pipe = $self->pipe;
637 struct pipe_transfer *transfer;
638 transfer = pipe_get_transfer(pipe,
639 surface->texture,
640 surface->level,
641 surface->layer,
642 PIPE_TRANSFER_WRITE,
643 x, y, w, h);
644 if(transfer) {
645 pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
646 pipe->transfer_destroy(pipe, transfer);
647 }
648 }
649
650 void
651 surface_sample_rgba(struct st_surface *surface,
652 float *rgba,
653 int norm = 0)
654 {
655 st_sample_surface($self->pipe, surface, rgba, norm != 0);
656 }
657
658 unsigned
659 surface_compare_rgba(struct st_surface *surface,
660 unsigned x, unsigned y, unsigned w, unsigned h,
661 const float *rgba, float tol = 0.0)
662 {
663 struct pipe_context *pipe = $self->pipe;
664 struct pipe_transfer *transfer;
665 float *rgba2;
666 const float *p1;
667 const float *p2;
668 unsigned i, j, n;
669
670 rgba2 = MALLOC(h*w*4*sizeof(float));
671 if(!rgba2)
672 return ~0;
673
674 transfer = pipe_get_transfer(pipe,
675 surface->texture,
676 surface->level,
677 surface->layer,
678 PIPE_TRANSFER_READ,
679 x, y, w, h);
680 if(!transfer) {
681 FREE(rgba2);
682 return ~0;
683 }
684
685 pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
686 pipe->transfer_destroy(pipe, transfer);
687
688 p1 = rgba;
689 p2 = rgba2;
690 n = 0;
691 for(i = h*w; i; --i) {
692 unsigned differs = 0;
693 for(j = 4; j; --j) {
694 float delta = *p2++ - *p1++;
695 if (delta < -tol || delta > tol)
696 differs = 1;
697 }
698 n += differs;
699 }
700
701 FREE(rgba2);
702
703 return n;
704 }
705
706 %cstring_input_binary(const char *STRING, unsigned LENGTH);
707 void
708 transfer_inline_write(struct pipe_resource *resource,
709 unsigned level,
710 unsigned usage,
711 const struct pipe_box *box,
712 const char *STRING, unsigned LENGTH,
713 unsigned stride,
714 unsigned layer_stride)
715 {
716 struct pipe_context *pipe = $self->pipe;
717
718 pipe->transfer_inline_write(pipe, resource, level, usage, box, STRING, stride, layer_stride);
719 }
720
721 %cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
722 void buffer_read(struct pipe_resource *buffer,
723 char **STRING, int *LENGTH)
724 {
725 struct pipe_context *pipe = $self->pipe;
726
727 assert(buffer->target == PIPE_BUFFER);
728
729 *LENGTH = buffer->width0;
730 *STRING = (char *) malloc(buffer->width0);
731 if(!*STRING)
732 return;
733
734 pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING);
735 }
736
737 void buffer_write(struct pipe_resource *buffer,
738 const char *STRING, unsigned LENGTH, unsigned offset = 0)
739 {
740 struct pipe_context *pipe = $self->pipe;
741
742 assert(buffer->target == PIPE_BUFFER);
743
744 if(offset > buffer->width0)
745 SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
746
747 if(offset + LENGTH > buffer->width0)
748 SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
749
750 pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING);
751
752 fail:
753 return;
754 }
755
756 };