Allow reusage of ImageData pixels buffer after uploading to a texture
- Dominant language
- Rust
- Stars
- 30.6k
- Forks
- 2.1k
- Avg merge
- 1d 12h
- Merged PRs (30d)
- 67
Description
**Is your feature request related to a problem? Please describe.**
For periodical updates to the texture (for ex. playing gifs/video/etc) we can just call `TextureHandle::set` function. This function expects `ImageData` which holds ownership to the raw buffer and than stores it for future upload to the texture. `ImageData` is then transformed into `ImageDelta` and consumed before painting to update textures:
```rust
for (id, image_delta) in textures_delta.set {
self.painter.set_texture(id, &image_delta);
}
```
At this point `ImageDelta` with its owned buffer is just dropped. Problem here is that this buffer cannot be reclaimed for reusage and for each update we need to allocate a new buffer which is not desirable.
**Describe the solution you'd like**
It would be great if we can have some kind of a callback that gives us back pixels buffer, for example:
```rust
pub struct ColorImage {
/// width, height.
pub size: [usize; 2],
/// The pixels, row by row, from top to bottom.
pub pixels: Vec,
// Pixels reclamation callback
pub reclaim_pixels: Option)>>,
}
impl Drop for ColorImage {
fn drop(&mut self) {
if let Some(reclaim_pixels) = self.reclaim_pixels.take() {
reclaim_pixels(std::mem::take(&mut self.pixels));
}
}
}
```
**Describe alternatives you've considered**
I haven't found any alternatives to reuse buffer yet.
Contributor guide
Assessment
This issue has not been assessed yet.