python: Use transfer object to read from a surface.
This commit is contained in:
@@ -524,20 +524,33 @@ st_sample_pixel_block(enum pipe_format format,
|
|||||||
void
|
void
|
||||||
st_sample_surface(struct pipe_surface *surface, float *rgba)
|
st_sample_surface(struct pipe_surface *surface, float *rgba)
|
||||||
{
|
{
|
||||||
const struct pipe_format_block *block = &surface->block;
|
struct pipe_screen *screen = surface->texture->screen;
|
||||||
unsigned rgba_stride = surface->width*4;
|
uint rgba_stride = surface->width * 4;
|
||||||
|
struct pipe_transfer *transfer;
|
||||||
void *raw;
|
void *raw;
|
||||||
unsigned x, y;
|
|
||||||
|
|
||||||
raw = pipe_surface_map(surface, PIPE_BUFFER_USAGE_CPU_READ);
|
transfer = screen->get_tex_transfer(screen,
|
||||||
if(!raw)
|
surface->texture,
|
||||||
|
surface->face,
|
||||||
|
surface->level,
|
||||||
|
surface->zslice,
|
||||||
|
PIPE_TRANSFER_READ,
|
||||||
|
0, 0,
|
||||||
|
surface->width,
|
||||||
|
surface->height);
|
||||||
|
if (!transfer)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
for (y = 0; y < surface->nblocksy; ++y) {
|
raw = screen->transfer_map(screen, transfer);
|
||||||
for(x = 0; x < surface->nblocksx; ++x) {
|
if (raw) {
|
||||||
|
const struct pipe_format_block *block = &transfer->block;
|
||||||
|
uint x, y;
|
||||||
|
|
||||||
|
for (y = 0; y < transfer->nblocksy; ++y) {
|
||||||
|
for (x = 0; x < transfer->nblocksx; ++x) {
|
||||||
st_sample_pixel_block(surface->format,
|
st_sample_pixel_block(surface->format,
|
||||||
block,
|
block,
|
||||||
(uint8_t*)raw + y*surface->stride + x*block->size,
|
(uint8_t *) raw + y * transfer->stride + x * block->size,
|
||||||
rgba + y * block->height * rgba_stride + x * block->width * 4,
|
rgba + y * block->height * rgba_stride + x * block->width * 4,
|
||||||
rgba_stride,
|
rgba_stride,
|
||||||
MIN2(block->width, surface->width - x*block->width),
|
MIN2(block->width, surface->width - x*block->width),
|
||||||
@@ -545,5 +558,8 @@ st_sample_surface(struct pipe_surface *surface, float *rgba)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pipe_surface_unmap(surface);
|
screen->transfer_unmap(screen, transfer);
|
||||||
|
}
|
||||||
|
|
||||||
|
screen->tex_transfer_destroy(transfer);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user