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

pub struct Texture { /* fields omitted */ }
Expand description

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

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.

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 RENDER_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.

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 RENDER_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).

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.

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.

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.

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.

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.

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.

Encode the necessary commands to load a 3d texture 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.

NOTE: The returned texture will be 3d; you must create

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.

The inner descriptor from which this Texture was constructed.

Consume the Texture and produce the inner Arc.

A reference to the inner TextureHandle.

The width and height of the texture.

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

The width, height and depth of the texture.

Mip count of texture. For a texture with no extra mips, this must be 1.

Sample count of texture. If this is not 1, texture must have BindingType::SampledTexture::multisampled set to true.

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

The format of the underlying texture data.

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

The size of the texture data in bytes.

The component type associated with the texture’s format.

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.

A unique identifier associated with this texture.

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

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.

A TextureViewDimension for a full view of the entire texture.

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

The view info, describing a full view of the texture.

The view descriptor, describing a full view of the texture.

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().

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.

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: 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>

Creates a view of this texture.

Destroy the associated native resources as soon as possible.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

The resulting type after dereferencing.

Dereferences the value.

Performs the conversion.

Auto Trait Implementations

Blanket Implementations

Convert the source color to the destination color using the specified method Read more

Convert the source color to the destination color using the bradford method by default Read more

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Convert into T with values clamped to the color defined bounds Read more

Convert into T. The resulting color might be invalid in its color space Read more

Convert into T, returning ok if the color is inside of its defined range, otherwise an OutOfBounds error is returned which contains the unclamped color. Read more

Performs the conversion.

Performs the conversion.

The alignment of pointer.

The type for initializers.

Initializes a with the given initializer. Read more

Dereferences the given pointer. Read more

Mutably dereferences the given pointer. Read more

Drops the object pointed to by the given pointer. Read more

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.