pub struct ImageStore { /* private fields */ }Expand description
ImageStore owns uploaded images, mip generation, samplers, and bind groups.
Bind groups are created once per (image, sampling) pair and reused. Dead
images are swept via Weak so the store does not pin host-dropped images.
Implementations§
Source§impl ImageStore
impl ImageStore
Sourcepub fn new(device: &Device, queue: &Queue) -> Self
pub fn new(device: &Device, queue: &Queue) -> Self
new creates an empty image store for device and queue.
Sourcepub fn filtered_image(
&mut self,
image: &Image,
filter: ColorFilter,
) -> (Image, bool)
pub fn filtered_image( &mut self, image: &Image, filter: ColorFilter, ) -> (Image, bool)
filtered_image returns the immutable texture that represents image after filter.
The second return value is true when this call created the texture.
The caller records the producing pass only in that case.
Sourcepub fn end_frame(&mut self)
pub fn end_frame(&mut self)
end_frame drops filtered snapshots unused this frame.
One idle frame releases a filtered snapshot even when the host keeps its source image alive, bounding retention to the visible working set.
Sourcepub fn upload(&mut self, desc: ImageDesc, pixels: &[u8]) -> Image
pub fn upload(&mut self, desc: ImageDesc, pixels: &[u8]) -> Image
upload creates a retained Image from RGBA8 pixels.
Premultiplies when desc.premultiplied is false, writes mip level 0,
and builds the mip chain when desc.mips is true. Panics if
pixels.len() is not width * height * 4.
Sourcepub fn finish_external(
&mut self,
texture: Texture,
size: [u32; 2],
mip_levels: u32,
) -> Image
pub fn finish_external( &mut self, texture: Texture, size: [u32; 2], mip_levels: u32, ) -> Image
finish_external wraps an already-populated texture as a retained Image.
Use this when the host copied pixels itself (for example an
ImageBitmap upload). Builds the mip chain when mip_levels is
greater than 1.
Sourcepub fn regenerate_mips(&mut self, image: &Image)
pub fn regenerate_mips(&mut self, image: &Image)
regenerate_mips rebuilds the mip chain after level 0 was rewritten in place.
Call this after each copy from a per-frame source such as a video frame.
Sourcepub fn create_image_texture(&self, size: [u32; 2], mip_levels: u32) -> Texture
pub fn create_image_texture(&self, size: [u32; 2], mip_levels: u32) -> Texture
create_image_texture allocates an empty image texture of size and mip_levels.
The texture is bindable, copy-destination, and a render attachment so mip levels can be generated by rendering into them.
Sourcepub fn bind_group(
&mut self,
texture_layout: &BindGroupLayout,
image: &Image,
sampling: Sampling,
) -> BindGroup
pub fn bind_group( &mut self, texture_layout: &BindGroupLayout, image: &Image, sampling: Sampling, ) -> BindGroup
bind_group returns the cached (texture, sampler) bind group for a draw.