[][src]Struct nannou::wgpu::Texture

pub struct Texture { /* fields omitted */ }

A convenient wrapper around a handle to a texture on the GPU along with its descriptor.

A texture can be thought of as an image that resides in GPU memory (as opposed to CPU memory).

This type is a thin wrapper around the wgpu crate's Texture type, but provides access to useful information like size, format, usage, etc.

Implementations

impl Texture[src]

pub fn into_ui_image(self) -> Image[src]

Convert the texture into an image compatible with the UI's image map.

Panics if the texture's Arc<TextureHandle> has been cloned and more than one unique reference to the inner data still exists.

impl Texture[src]

pub fn from_path<'a, T, P>(src: T, path: P) -> ImageResult<Self> where
    T: WithDeviceQueuePair,
    P: AsRef<Path>, 
[src]

Load an image from the given path and upload it as a texture.

The device and queue src can be either the App, a Window, a wgpu::DeviceQueuePair or a tuple (&wgpu::Device, &mut wgpu::Queue). Access to a Device is necessary in order to create the texture and buffer GPU resources, and access to a Queue is necessary for submitting the commands responsible for copying the buffer contents to the texture. Note that a texture may only be used with the device with which it was created. This is worth keeping in mind if you have more than one window and they do not share the same device.

By default, the texture will have the COPY_SRC, COPY_DST, SAMPLED and OUTPUT_ATTACHMENT usages enabled. If you wish to specify the usage yourself, see the load_from_path constructor.

If the &App is passed as the src, the window returned via app.main_window() will be used as the source of the device and queue.

pub fn from_image<'a, T>(src: T, image: &DynamicImage) -> Self where
    T: WithDeviceQueuePair, 
[src]

Load a texture from the given image.

The device and queue src can be either the App, a Window, a wgpu::DeviceQueuePair or a tuple (&wgpu::Device, &mut wgpu::Queue). Access to a Device is necessary in order to create the texture and buffer GPU resources, and access to a Queue is necessary for submitting the commands responsible for copying the buffer contents to the texture. Note that a texture may only be used with the device with which it was created. This is worth keeping in mind if you have more than one window and they do not share the same device.

By default, the texture will have the COPY_SRC, COPY_DST, SAMPLED and OUTPUT_ATTACHMENT usages enabled. If you wish to specify the usage yourself, see the load_from_path constructor.

If the &App is passed as the src, the window returned via app.main_window() will be used as the source of the device and queue.

The DeviceQueuePairSource can be either the App, a Window, a DeviceQueuePair or a tuple (&Device, &Queue).

pub fn load_from_path<P>(
    device: &Device,
    queue: &Queue,
    usage: TextureUsage,
    path: P
) -> ImageResult<Self> where
    P: AsRef<Path>, 
[src]

Read an image file from the given path and load it directly into a texture.

This is short-hand for calling image::open and then Texture::load_from_image.

pub fn load_from_image(
    device: &Device,
    queue: &Queue,
    usage: TextureUsage,
    image: &DynamicImage
) -> Self
[src]

Load a texture directly from a dynamic image.

If the image is already in a format supported by wgpu, no conversions are performed and the image is loaded directly as-is with a texture format that matches the original image color type.

If the image is of an unsupported format, it will be converted to the closest supported format before being uploaded.

pub fn load_from_image_buffer<P, Container>(
    device: &Device,
    queue: &Queue,
    usage: TextureUsage,
    buffer: &ImageBuffer<P, Container>
) -> Self where
    P: 'static + Pixel,
    Container: Deref<Target = [P::Subpixel]>, 
[src]

Load a texture directly from an image buffer using the given device queue.

No format or size conversions are performed - the given buffer is loaded directly into GPU memory.

Pixel type compatibility is ensured via the Pixel trait.

pub fn load_array_from_image_buffers<'a, I, P, Container>(
    device: &Device,
    queue: &Queue,
    usage: TextureUsage,
    buffers: I
) -> Option<Self> where
    I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
    I::IntoIter: ExactSizeIterator,
    P: 'static + Pixel,
    Container: 'a + Deref<Target = [P::Subpixel]>, 
[src]

Load a texture array directly from a sequence of image buffers.

No format or size conversions are performed - the given buffer is loaded directly into GPU memory.

Pixel type compatibility is ensured via the Pixel trait.

Returns None if there are no images in the given sequence.

pub fn encode_load_from_image(
    device: &Device,
    encoder: &mut CommandEncoder,
    usage: TextureUsage,
    image: &DynamicImage
) -> Self
[src]

Encode the necessary commands to load a texture directly from a dynamic image.

If the image is already in a format supported by wgpu, no conversions are performed and the image is loaded directly as-is with a texture format that matches the original image color type.

If the image is of an unsupported format, it will be converted to the closest supported format before being uploaded.

NOTE: The returned texture will remain empty until the given encoder has its command buffer submitted to the given device's queue.

pub fn encode_load_from_image_buffer<P, Container>(
    device: &Device,
    encoder: &mut CommandEncoder,
    usage: TextureUsage,
    buffer: &ImageBuffer<P, Container>
) -> Self where
    P: 'static + Pixel,
    Container: Deref<Target = [P::Subpixel]>, 
[src]

Encode the necessary commands to load a texture from the given image buffer.

NOTE: The returned texture will remain empty until the given encoder has its command buffer submitted to the given device's queue.

No format or size conversions are performed - the given buffer is loaded directly into GPU memory.

Pixel type compatibility is ensured via the Pixel trait.

pub fn encode_load_array_from_image_buffers<'a, I, P, Container>(
    device: &Device,
    encoder: &mut CommandEncoder,
    usage: TextureUsage,
    buffers: I
) -> Option<Self> where
    I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
    I::IntoIter: ExactSizeIterator,
    P: 'static + Pixel,
    Container: 'a + Deref<Target = [P::Subpixel]>, 
[src]

Encode the necessary commands to load a texture array directly from a sequence of image buffers.

NOTE: The returned texture will remain empty until the given encoder has its command buffer submitted to the given device's queue.

No format or size conversions are performed - the given buffer is loaded directly into GPU memory.

Pixel type compatibility is ensured via the Pixel trait.

Returns None if there are no images in the given sequence.

pub fn to_image(
    &self,
    device: &Device,
    encoder: &mut CommandEncoder
) -> Option<BufferImage>
[src]

Write the contents of the texture into a new image buffer.

Commands will be added to the given encoder to copy the entire contents of the texture into the buffer.

Returns a buffer from which the image can be read asynchronously via read.

Returns None if there is no directly compatible image::ColorType for the texture's format.

NOTE: read should not be called on the returned buffer until the encoded commands have been submitted to the device queue.

impl Texture[src]

pub fn descriptor(&self) -> &TextureDescriptor<'static>[src]

The inner descriptor from which this Texture was constructed.

pub fn descriptor_cloned(&self) -> TextureDescriptor<'static>[src]

The inner descriptor from which this Texture was constructed.

TODO: This method should be removed upon updating to wgpu 0.5 as the new version will include an implementation of Clone for TextureDescriptor.

pub fn into_inner(self) -> Arc<TextureHandle>[src]

Consume the Texture and produce the inner Arc.

pub fn inner(&self) -> &Arc<TextureHandle>[src]

A reference to the inner TextureHandle.

pub fn size(&self) -> [u32; 2][src]

The width and height of the texture.

See the extent method for producing the full width, height and depth of the texture.

pub fn extent(&self) -> Extent3d[src]

The width, height and depth of the texture.

pub fn array_layer_count(&self) -> u32[src]

pub fn mip_level_count(&self) -> u32[src]

pub fn sample_count(&self) -> u32[src]

pub fn dimension(&self) -> TextureDimension[src]

Describes whether the texture is of 1, 2 or 3 dimensions.

pub fn format(&self) -> TextureFormat[src]

The format of the underlying texture data.

pub fn usage(&self) -> TextureUsage[src]

The set of usage bits describing the ways in which the Texture may be used.

pub fn size_bytes(&self) -> usize[src]

The size of the texture data in bytes.

pub fn component_type(&self) -> TextureComponentType[src]

The component type associated with the texture's format.

pub fn from_handle_and_descriptor(
    handle: Arc<TextureHandle>,
    descriptor: TextureDescriptor<'static>
) -> Self
[src]

Create a Texture from the inner wgpu texture handle and the descriptor used to create it.

This constructor should only be used in the case that you already have a texture handle and a descriptor but need a Texture. The preferred construction approach is to use the TextureBuilder.

The descriptor must be the same used to create the texture.

pub fn id(&self) -> TextureId[src]

A unique identifier associated with this texture.

This is useful for distinguishing between two Textures or for producing a hashable representation.

pub fn view(&self) -> ViewBuilder<'_>[src]

Begin building a TextureView for this Texture.

By default, the produced TextureViewBuilder will build a texture view for the descriptor returned via default_view_descriptor.

pub fn view_dimension(&self) -> TextureViewDimension[src]

A TextureViewDimension for a full view of the entire texture.

NOTE: This will never produce the Cube or CubeArray variants. You may have to construct your own wgpu::TextureViewDimension via the view method if these are desired.

pub fn default_view_descriptor(&self) -> TextureViewDescriptor[src]

The view descriptor describing a full view of the texture.

pub fn default_copy_view(&self) -> TextureCopyView<'_>[src]

Creates a TextureCopyView ready for copying to or from the entire texture.

pub fn default_buffer_copy_view<'a>(
    &self,
    buffer: &'a Buffer
) -> BufferCopyView<'a>
[src]

Creates a BufferCopyView ready for copying to or from the given buffer where the given buffer is assumed to have the same size as the entirety of this texture.

pub fn upload_data(
    &self,
    device: &Device,
    encoder: &mut CommandEncoder,
    data: &[u8]
)
[src]

Encode a command for uploading the given data to the texture.

The length of the data must be equal to the length returned by texture.size_bytes().

pub fn to_buffer(
    &self,
    device: &Device,
    encoder: &mut CommandEncoder
) -> (Buffer, BufferAddress)
[src]

Write the contents of the texture into a new buffer.

Commands will be added to the given encoder to copy the entire contents of the texture into the buffer.

The buffer is returned alongside its size in bytes.

If the texture has a sample count greater than one, it will first be resolved to a non-multisampled texture before being copied to the buffer. copy_texture_to_buffer command has been performed by the GPU.

NOTE: map_read_async should not be called on the returned buffer until the encoded commands have been submitted to the device queue.

pub fn to_buffer_bytes(
    &self,
    device: &Device,
    encoder: &mut CommandEncoder
) -> BufferBytes
[src]

Encode the necessary commands to read the contents of the texture into memory.

The entire contents of the texture will be made available as a single slice of bytes.

This method uses to_buffer internally, exposing a simplified API for reading the produced buffer as a slice of bytes.

If the texture has a sample count greater than one, it will first be resolved to a non-multisampled texture before being copied to the buffer.

NOTE: read should not be called on the returned buffer until the encoded commands have been submitted to the device queue.

Methods from Deref<Target = TextureHandle>

pub fn create_view(&self, desc: &TextureViewDescriptor) -> TextureView[src]

Creates a view of this texture.

pub fn create_default_view(&self) -> TextureView[src]

Creates a default view of this whole texture.

Trait Implementations

impl Clone for Texture[src]

impl Debug for Texture[src]

impl Deref for Texture[src]

type Target = TextureHandle

The resulting type after dereferencing.

impl Into<Arc<Texture>> for Texture[src]

impl ToTextureView for Texture[src]

Auto Trait Implementations

impl !RefUnwindSafe for Texture

impl Send for Texture

impl Sync for Texture

impl Unpin for Texture

impl !UnwindSafe for Texture

Blanket Implementations

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
    D: AdaptFrom<S, Swp, Dwp, T>,
    Dwp: WhitePoint,
    Swp: WhitePoint,
    T: Component + Float
[src]

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T, U> ConvertInto<U> for T where
    U: ConvertFrom<T>, 
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> SetParameter for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,