You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When uploading a decoded image to a pixel buffer, sometimes the lines contain a stride. That is, the lines are bigger than the image lines, for performance reasons (alignment). So if we want to upload the image called slice, we either upload it entirely if it has no stride (linesize==width) or we upload line by line:
//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);
}
}
However, pixel_buffer.write(s) fails if s.len() is not the same as pixel_buffer's size.
PS: I think this is not the solution because I'd have to wait for the GPU map to occur. I just want to send data to the pixel buffer as fast as possible
The text was updated successfully, but these errors were encountered:
Uploads to the GPU are quite expensive, so with the first option it would be better to copy the image data to a Vec and then upload it to the GPU.
The second option should work and is probably better depending on your application, however I think we should extend the WriteMapping to be able to copy slices into the mapped buffer.
You could also try as_slice_mut(), and then call slice() on that. However, it seems as that API is deficient, since calling slice() consume the first mutable slice, while it should probably only take a mut reference.
When uploading a decoded image to a pixel buffer, sometimes the lines contain a stride. That is, the lines are bigger than the image lines, for performance reasons (alignment). So if we want to upload the image called
slice
, we either upload it entirely if it has no stride (linesize==width
) or we upload line by line:However,
pixel_buffer.write(s)
fails ifs.len()
is not the same aspixel_buffer
's size.Reading https://docs.rs/glium/0.30.0/glium/texture/pixel_buffer/struct.PixelBuffer.html, it's not clear how to write by pieces. It looks like
map_write
might do it:But how do I write to
WriteMapping
?PS: I think this is not the solution because I'd have to wait for the GPU map to occur. I just want to send data to the pixel buffer as fast as possible
The text was updated successfully, but these errors were encountered: