[][src]Struct web_glitz::image::texture_2d_array::Level

pub struct Level<'a, F> { /* fields omitted */ }

A reference to a mipmap level of a Texture2DArray.

A reference to the base level of a Texture2DArray can be obtained through Texture2DArray::base_level. References to other levels of a Texture2DArray can be obtained via Levels.

Methods

impl<'a, F> Level<'a, F> where
    F: TextureFormat
[src]

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

Returns the integer that identifies this level.

For example, if this Level is the texture's base level, returns 0; if it is the second level, returns 1; etc.

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

Returns the width of this level.

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

Returns the height of this level.

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

Returns the depth of the layered image.

Note that the depth is the same for all levels of a Texture2DArray.

pub fn layers(&self) -> LevelLayers<F>[src]

Returns a reference to the layers of this Level.

Examples

// Returns a reference to layer 2 of the texture's base level if the texture has a 2 or more
// layers, or None otherwise:
let layer_2 = texture.base_level().layers().get(2);

// We can also iterate over references to all layers that exist for the texture's base
// level:
for layer in texture.base_level().layers().iter() {
    // ...
}

pub fn sub_image(&self, region: Region3D) -> LevelSubImage<F>[src]

Returns a reference to the sub-region of this Level's layered image described by region.

Example

This may for example be used to upload data to only a sub-region of a layered image, rather than the complete image:

use web_glitz::image::{LayeredImageSource, MipmapLevels, Region3D};
use web_glitz::image::format::RGB8;
use web_glitz::image::texture_2d_array::Texture2DArrayDescriptor;

let texture = context.create_texture_2d_array(&Texture2DArrayDescriptor {
    format: RGB8,
    width: 256,
    height: 256,
    depth: 16,
    levels: MipmapLevels::Complete
}).unwrap();

let base_level = texture.base_level();
let sub_image = base_level.sub_image(Region3D::Area((0, 0, 0), 128, 128, 8));

let pixels: Vec<[u8; 3]> = vec![[0, 0, 255]; 128 * 128 * 8];
let data = LayeredImageSource::from_pixels(pixels, 128, 128, 8).unwrap();

context.submit(sub_image.upload_command(data));

The lower left quadrants of the first 8 layers of texture's base level now contain blue pixels.

pub fn upload_command<D, T>(
    &self,
    data: LayeredImageSource<D, T>
) -> LevelUploadCommand<D, T, F> where
    T: ClientFormat<F>, 
[src]

Returns a command which, when executed, replaces the image data in this Level's image with the image data provided in data.

The image data must be stored in a ClientFormat that is suitable for the texture's TextureFormat.

If the dimensions of the image provided in data are not sufficient to cover the Level's image entirely, starting from the origin, then only the region of overlap is updated (note that the origin of a layered image is the lower left corner on the first layer). For example, given a Level with a width of 256 pixels, a height of 256 pixels and a depth of 16 layers, and data with a width of 128 pixels, a height of 128 pixels and a depth of 8 layers, then only the lower left quadrants of the first 8 layers of the Level are updated. If the dimensions of the image provided in data would, when starting from the origin, cover more than the Level's image (the width, height and/or depth of data is/are greater than the width, height and/or depth of the Level's image), then any pixels that would fall outside of the Level are ignored. For example, given a Level with a width of 256 pixels, a height of 256 pixels and a depth of 16 layers, and data with a width of 256 pixels, height of 512 pixels and a depth of 20 layers, then only the lower halves of the first 16 layers in data are used to update the Level; the upper halves of the first 16 layers in data are ignored, and the last 4 layers in data are ignored entirely.

Example

use web_glitz::image::{LayeredImageSource, MipmapLevels};
use web_glitz::image::format::RGB8;
use web_glitz::image::texture_2d_array::Texture2DArrayDescriptor;

let texture = context.create_texture_2d_array(&Texture2DArrayDescriptor {
    format: RGB8,
    width: 256,
    height: 256,
    depth: 16,
    levels: MipmapLevels::Complete
}).unwrap();

let pixels: Vec<[u8; 3]> = vec![[255, 0, 0]; 256 * 256 * 16];
let data = LayeredImageSource::from_pixels(pixels, 256, 256, 16).unwrap();

context.submit(texture.base_level().upload_command(data));

Auto Trait Implementations

impl<'a, F> !Send for Level<'a, F>

impl<'a, F> Unpin for Level<'a, F>

impl<'a, F> !Sync for Level<'a, F>

impl<'a, F> !UnwindSafe for Level<'a, F>

impl<'a, F> !RefUnwindSafe for Level<'a, F>

Blanket Implementations

impl<D, T> IntoBuffer<T> for D where
    D: Borrow<T> + 'static,
    T: Copy + 'static, 
[src]

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

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

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<T> BorrowMut<T> for T where
    T: ?Sized
[src]

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

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