167
206
cso_set_viewport($self->cso, state);
209
void set_fragment_sampler_view(unsigned index,
210
struct pipe_sampler_view *view)
212
pipe_sampler_view_reference(&$self->fragment_sampler_views[index], view);
214
$self->pipe->set_fragment_sampler_views($self->pipe,
216
$self->fragment_sampler_views);
219
void set_vertex_sampler_view(unsigned index,
220
struct pipe_sampler_view *view)
222
pipe_sampler_view_reference(&$self->vertex_sampler_views[index], view);
224
$self->pipe->set_vertex_sampler_views($self->pipe,
225
PIPE_MAX_VERTEX_SAMPLERS,
226
$self->vertex_sampler_views);
170
229
void set_fragment_sampler_texture(unsigned index,
171
struct pipe_texture *texture) {
230
struct pipe_resource *texture) {
231
struct pipe_sampler_view templ;
173
234
texture = $self->default_texture;
174
pipe_texture_reference(&$self->fragment_sampler_textures[index], texture);
175
$self->pipe->set_fragment_sampler_textures($self->pipe,
177
$self->fragment_sampler_textures);
235
pipe_sampler_view_reference(&$self->fragment_sampler_views[index], NULL);
236
u_sampler_view_default_template(&templ,
239
$self->fragment_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
242
$self->pipe->set_fragment_sampler_views($self->pipe,
244
$self->fragment_sampler_views);
180
247
void set_vertex_sampler_texture(unsigned index,
181
struct pipe_texture *texture) {
248
struct pipe_resource *texture) {
249
struct pipe_sampler_view templ;
183
252
texture = $self->default_texture;
184
pipe_texture_reference(&$self->vertex_sampler_textures[index], texture);
185
$self->pipe->set_vertex_sampler_textures($self->pipe,
186
PIPE_MAX_VERTEX_SAMPLERS,
187
$self->vertex_sampler_textures);
253
pipe_sampler_view_reference(&$self->vertex_sampler_views[index], NULL);
254
u_sampler_view_default_template(&templ,
257
$self->vertex_sampler_views[index] = $self->pipe->create_sampler_view($self->pipe,
261
$self->pipe->set_vertex_sampler_views($self->pipe,
262
PIPE_MAX_VERTEX_SAMPLERS,
263
$self->vertex_sampler_views);
190
266
void set_vertex_buffer(unsigned index,
192
268
unsigned max_index,
193
269
unsigned buffer_offset,
194
struct pipe_buffer *buffer)
270
struct pipe_resource *buffer)
197
273
struct pipe_vertex_buffer state;
263
338
struct pipe_context *pipe = $self->pipe;
264
339
struct pipe_screen *screen = pipe->screen;
265
struct pipe_buffer *vbuf;
340
struct pipe_resource *vbuf;
341
struct pipe_transfer *transfer;
342
struct pipe_vertex_element velements[PIPE_MAX_ATTRIBS];
343
struct pipe_vertex_buffer vbuffer;
269
348
size = num_verts * num_attribs * 4 * sizeof(float);
271
350
vbuf = pipe_buffer_create(screen,
273
PIPE_BUFFER_USAGE_VERTEX,
351
PIPE_BIND_VERTEX_BUFFER,
278
map = pipe_buffer_map(screen, vbuf, PIPE_BUFFER_USAGE_CPU_WRITE);
356
map = pipe_buffer_map(pipe, vbuf, PIPE_TRANSFER_WRITE, &transfer);
281
359
memcpy(map, vertices, size);
282
pipe_buffer_unmap(screen, vbuf);
284
util_draw_vertex_buffer(pipe, vbuf, 0, prim, num_verts, num_attribs);
360
pipe_buffer_unmap(pipe, vbuf, transfer);
362
cso_save_vertex_elements($self->cso);
364
/* tell pipe about the vertex attributes */
365
for (i = 0; i < num_attribs; i++) {
366
velements[i].src_offset = i * 4 * sizeof(float);
367
velements[i].instance_divisor = 0;
368
velements[i].vertex_buffer_index = 0;
369
velements[i].src_format = PIPE_FORMAT_R32G32B32A32_FLOAT;
371
cso_set_vertex_elements($self->cso, num_attribs, velements);
373
/* tell pipe about the vertex buffer */
374
memset(&vbuffer, 0, sizeof(vbuffer));
375
vbuffer.buffer = vbuf;
376
vbuffer.stride = num_attribs * 4 * sizeof(float); /* vertex size */
377
vbuffer.buffer_offset = 0;
378
vbuffer.max_index = num_verts - 1;
379
pipe->set_vertex_buffers(pipe, 1, &vbuffer);
382
util_draw_arrays(pipe, prim, 0, num_verts);
384
cso_restore_vertex_elements($self->cso);
287
pipe_buffer_reference(&vbuf, NULL);
387
pipe_resource_reference(&vbuf, NULL);
393
clear(unsigned buffers, const float *rgba, double depth = 0.0f,
394
unsigned stencil = 0)
396
$self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
293
400
flush(unsigned flags = 0) {
294
401
struct pipe_fence_handle *fence = NULL;
295
402
$self->pipe->flush($self->pipe, flags | PIPE_FLUSH_RENDER_CACHE, &fence);
304
411
* Surface functions
307
void surface_copy(struct st_surface *dst,
308
unsigned destx, unsigned desty,
309
struct st_surface *src,
310
unsigned srcx, unsigned srcy,
311
unsigned width, unsigned height)
313
struct pipe_surface *_dst = NULL;
314
struct pipe_surface *_src = NULL;
316
_dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
318
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
320
_src = st_pipe_surface(src, PIPE_BUFFER_USAGE_GPU_READ);
322
SWIG_exception(SWIG_ValueError, "couldn't acquire source surface for reading");
324
$self->pipe->surface_copy($self->pipe, _dst, destx, desty, _src, srcx, srcy, width, height);
327
pipe_surface_reference(&_src, NULL);
328
pipe_surface_reference(&_dst, NULL);
331
void surface_fill(struct st_surface *dst,
332
unsigned x, unsigned y,
333
unsigned width, unsigned height,
336
struct pipe_surface *_dst = NULL;
338
_dst = st_pipe_surface(dst, PIPE_BUFFER_USAGE_GPU_WRITE);
340
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
342
$self->pipe->surface_fill($self->pipe, _dst, x, y, width, height, value);
345
pipe_surface_reference(&_dst, NULL);
348
void clear(unsigned buffers, const float *rgba, double depth = 0.0f,
349
unsigned stencil = 0)
351
$self->pipe->clear($self->pipe, buffers, rgba, depth, stencil);
414
void resource_copy_region(struct pipe_resource *dst,
415
struct pipe_subresource subdst,
416
unsigned dstx, unsigned dsty, unsigned dstz,
417
struct pipe_resource *src,
418
struct pipe_subresource subsrc,
419
unsigned srcx, unsigned srcy, unsigned srcz,
420
unsigned width, unsigned height)
422
$self->pipe->resource_copy_region($self->pipe,
423
dst, subdst, dstx, dsty, dstz,
424
src, subsrc, srcx, srcy, srcz,
429
void clear_render_target(struct st_surface *dst,
431
unsigned x, unsigned y,
432
unsigned width, unsigned height)
434
struct pipe_surface *_dst = NULL;
436
_dst = st_pipe_surface(dst, PIPE_BIND_RENDER_TARGET);
438
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
440
$self->pipe->clear_render_target($self->pipe, _dst, rgba, x, y, width, height);
443
pipe_surface_reference(&_dst, NULL);
446
void clear_depth_stencil(struct st_surface *dst,
447
unsigned clear_flags,
450
unsigned x, unsigned y,
451
unsigned width, unsigned height)
453
struct pipe_surface *_dst = NULL;
455
_dst = st_pipe_surface(dst, PIPE_BIND_DEPTH_STENCIL);
457
SWIG_exception(SWIG_ValueError, "couldn't acquire destination surface for writing");
459
$self->pipe->clear_depth_stencil($self->pipe, _dst, clear_flags, depth, stencil,
460
x, y, width, height);
463
pipe_surface_reference(&_dst, NULL);
466
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
468
surface_read_raw(struct st_surface *surface,
469
unsigned x, unsigned y, unsigned w, unsigned h,
470
char **STRING, int *LENGTH)
472
struct pipe_resource *texture = surface->texture;
473
struct pipe_context *pipe = $self->pipe;
474
struct pipe_transfer *transfer;
477
stride = util_format_get_stride(texture->format, w);
478
*LENGTH = util_format_get_nblocksy(texture->format, h) * stride;
479
*STRING = (char *) malloc(*LENGTH);
483
transfer = pipe_get_transfer(pipe,
491
pipe_get_tile_raw(pipe, transfer, 0, 0, w, h, *STRING, stride);
492
pipe->transfer_destroy(pipe, transfer);
496
%cstring_input_binary(const char *STRING, unsigned LENGTH);
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)
502
struct pipe_resource *texture = surface->texture;
503
struct pipe_context *pipe = $self->pipe;
504
struct pipe_transfer *transfer;
507
stride = util_format_get_stride(texture->format, w);
509
if(LENGTH < util_format_get_nblocksy(texture->format, h) * stride)
510
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
512
transfer = pipe_get_transfer(pipe,
520
SWIG_exception(SWIG_MemoryError, "couldn't initiate transfer");
522
pipe_put_tile_raw(pipe, transfer, 0, 0, w, h, STRING, stride);
523
pipe->transfer_destroy(pipe, transfer);
530
surface_read_rgba(struct st_surface *surface,
531
unsigned x, unsigned y, unsigned w, unsigned h,
534
struct pipe_context *pipe = $self->pipe;
535
struct pipe_transfer *transfer;
536
transfer = pipe_get_transfer(pipe,
544
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
545
pipe->transfer_destroy(pipe, transfer);
550
surface_write_rgba(struct st_surface *surface,
551
unsigned x, unsigned y, unsigned w, unsigned h,
554
struct pipe_context *pipe = $self->pipe;
555
struct pipe_transfer *transfer;
556
transfer = pipe_get_transfer(pipe,
564
pipe_put_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
565
pipe->transfer_destroy(pipe, transfer);
569
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
571
surface_read_rgba8(struct st_surface *surface,
572
unsigned x, unsigned y, unsigned w, unsigned h,
573
char **STRING, int *LENGTH)
575
struct pipe_context *pipe = $self->pipe;
576
struct pipe_transfer *transfer;
578
unsigned char *rgba8;
588
*STRING = (char *) malloc(*LENGTH);
592
rgba = malloc(h*w*4*sizeof(float));
596
rgba8 = (unsigned char *) *STRING;
598
transfer = pipe_get_transfer(pipe,
606
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba);
607
for(j = 0; j < h; ++j) {
608
for(i = 0; i < w; ++i)
609
for(k = 0; k <4; ++k)
610
rgba8[j*w*4 + i*4 + k] = float_to_ubyte(rgba[j*w*4 + i*4 + k]);
612
pipe->transfer_destroy(pipe, transfer);
619
surface_read_z(struct st_surface *surface,
620
unsigned x, unsigned y, unsigned w, unsigned h,
623
struct pipe_context *pipe = $self->pipe;
624
struct pipe_transfer *transfer;
625
transfer = pipe_get_transfer(pipe,
633
pipe_get_tile_z(pipe, transfer, 0, 0, w, h, z);
634
pipe->transfer_destroy(pipe, transfer);
639
surface_write_z(struct st_surface *surface,
640
unsigned x, unsigned y, unsigned w, unsigned h,
643
struct pipe_context *pipe = $self->pipe;
644
struct pipe_transfer *transfer;
645
transfer = pipe_get_transfer(pipe,
653
pipe_put_tile_z(pipe, transfer, 0, 0, w, h, z);
654
pipe->transfer_destroy(pipe, transfer);
659
surface_sample_rgba(struct st_surface *surface,
663
st_sample_surface($self->pipe, surface, rgba, norm != 0);
667
surface_compare_rgba(struct st_surface *surface,
668
unsigned x, unsigned y, unsigned w, unsigned h,
669
const float *rgba, float tol = 0.0)
671
struct pipe_context *pipe = $self->pipe;
672
struct pipe_transfer *transfer;
678
rgba2 = MALLOC(h*w*4*sizeof(float));
682
transfer = pipe_get_transfer(pipe,
694
pipe_get_tile_rgba(pipe, transfer, 0, 0, w, h, rgba2);
695
pipe->transfer_destroy(pipe, transfer);
700
for(i = h*w; i; --i) {
701
unsigned differs = 0;
703
float delta = *p2++ - *p1++;
704
if (delta < -tol || delta > tol)
715
%cstring_input_binary(const char *STRING, unsigned LENGTH);
717
transfer_inline_write(struct pipe_resource *resource,
718
struct pipe_subresource *sr,
720
const struct pipe_box *box,
721
const char *STRING, unsigned LENGTH,
723
unsigned slice_stride)
725
struct pipe_context *pipe = $self->pipe;
727
pipe->transfer_inline_write(pipe, resource, *sr, usage, box, STRING, stride, slice_stride);
730
%cstring_output_allocate_size(char **STRING, int *LENGTH, free(*$1));
731
void buffer_read(struct pipe_resource *buffer,
732
char **STRING, int *LENGTH)
734
struct pipe_context *pipe = $self->pipe;
736
assert(buffer->target == PIPE_BUFFER);
738
*LENGTH = buffer->width0;
739
*STRING = (char *) malloc(buffer->width0);
743
pipe_buffer_read(pipe, buffer, 0, buffer->width0, *STRING);
746
void buffer_write(struct pipe_resource *buffer,
747
const char *STRING, unsigned LENGTH, unsigned offset = 0)
749
struct pipe_context *pipe = $self->pipe;
751
assert(buffer->target == PIPE_BUFFER);
753
if(offset > buffer->width0)
754
SWIG_exception(SWIG_ValueError, "offset must be smaller than buffer size");
756
if(offset + LENGTH > buffer->width0)
757
SWIG_exception(SWIG_ValueError, "data length must fit inside the buffer");
759
pipe_buffer_write(pipe, buffer, offset, LENGTH, STRING);