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
pub fn from_path<T, P>(src: T, path: P) -> Result<Texture, ImageError> where
T: WithDeviceQueuePair,
P: AsRef<Path>,
pub fn from_path<T, P>(src: T, path: P) -> Result<Texture, ImageError> where
T: WithDeviceQueuePair,
P: AsRef<Path>,
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)
.
pub fn load_from_path<P>(
device: &Device,
queue: &Queue,
usage: TextureUsages,
path: P
) -> Result<Texture, ImageError> where
P: AsRef<Path>,
pub fn load_from_path<P>(
device: &Device,
queue: &Queue,
usage: TextureUsages,
path: P
) -> Result<Texture, ImageError> where
P: AsRef<Path>,
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: TextureUsages,
image: &DynamicImage
) -> Texture
pub fn load_from_image(
device: &Device,
queue: &Queue,
usage: TextureUsages,
image: &DynamicImage
) -> Texture
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: TextureUsages,
buffer: &ImageBuffer<P, Container>
) -> Texture where
P: 'static + Pixel,
Container: Deref<Target = [<P as Pixel>::Subpixel]>,
pub fn load_from_image_buffer<P, Container>(
device: &Device,
queue: &Queue,
usage: TextureUsages,
buffer: &ImageBuffer<P, Container>
) -> Texture where
P: 'static + Pixel,
Container: Deref<Target = [<P as Pixel>::Subpixel]>,
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: TextureUsages,
buffers: I
) -> Option<Texture> where
I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
P: 'static + Pixel,
Container: 'a + Deref<Target = [<P as Pixel>::Subpixel]>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
pub fn load_array_from_image_buffers<'a, I, P, Container>(
device: &Device,
queue: &Queue,
usage: TextureUsages,
buffers: I
) -> Option<Texture> where
I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
P: 'static + Pixel,
Container: 'a + Deref<Target = [<P as Pixel>::Subpixel]>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
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: TextureUsages,
image: &DynamicImage
) -> Texture
pub fn encode_load_from_image(
device: &Device,
encoder: &mut CommandEncoder,
usage: TextureUsages,
image: &DynamicImage
) -> Texture
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: TextureUsages,
buffer: &ImageBuffer<P, Container>
) -> Texture where
P: 'static + Pixel,
Container: Deref<Target = [<P as Pixel>::Subpixel]>,
pub fn encode_load_from_image_buffer<P, Container>(
device: &Device,
encoder: &mut CommandEncoder,
usage: TextureUsages,
buffer: &ImageBuffer<P, Container>
) -> Texture where
P: 'static + Pixel,
Container: Deref<Target = [<P as Pixel>::Subpixel]>,
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_3d_from_image_buffers<'a, I, P, Container>(
device: &Device,
encoder: &mut CommandEncoder,
usage: TextureUsages,
buffers: I
) -> Option<Texture> where
I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
P: 'static + Pixel,
Container: 'a + Deref<Target = [<P as Pixel>::Subpixel]>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
pub fn encode_load_3d_from_image_buffers<'a, I, P, Container>(
device: &Device,
encoder: &mut CommandEncoder,
usage: TextureUsages,
buffers: I
) -> Option<Texture> where
I: IntoIterator<Item = &'a ImageBuffer<P, Container>>,
P: 'static + Pixel,
Container: 'a + Deref<Target = [<P as Pixel>::Subpixel]>,
<I as IntoIterator>::IntoIter: ExactSizeIterator,
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
The width and height of the texture.
See the extent
method for producing the full 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 = Texture>
Returns the inner hal Texture using a callback. The hal texture will be None
if the
backend type argument does not match with this wgpu Texture
Safety
- The raw handle obtained from the hal Texture must not be manually destroyed
Creates a view of this texture.
Make an ImageCopyTexture
representing the whole texture.
Trait Implementations
Auto Trait Implementations
impl !RefUnwindSafe for Texture
impl !UnwindSafe for Texture
Blanket Implementations
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: Component + Float,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S where
T: Component + Float,
Swp: WhitePoint,
Dwp: WhitePoint,
D: AdaptFrom<S, Swp, Dwp, T>,
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