0

将解码图像上传到像素缓冲区时,有时这些行包含一个步幅。也就是说,出于性能原因(对齐),线条大于图像线条。因此,如果我们要上传名为 的图像slice,如果它没有步幅 ( linesize==width),我们要么完全上传它,要么逐行上传:

    //If the linesize is equal to width then we don't need to respect stride
    if linesize == width as usize {
        pixel_buffer.write(slice);
    } else {
        for line in 0..height {
            let current_line_start = (line * width) as usize;
            let s = &slice[(current_line_start)..(current_line_start + linesize)];
            pixel_buffer.write(s);
        }
    }

但是,pixel_buffer.write(s)如果s.len()pixel_buffer的大小不同,则失败。

阅读https://docs.rs/glium/0.30.0/glium/texture/pixel_buffer/struct.PixelBuffer.html,不清楚如何分段编写。看起来map_write可能会这样做:

pub fn map_write(&mut self) -> WriteMapping<'_, T>

映射内存中的缓冲区仅用于写入。

但是我该怎么写WriteMapping呢?

PS:我认为这不是解决方案,因为我必须等待 GPU 映射出现。我只想尽快将数据发送到像素缓冲区

4

0 回答 0