[][src]Struct web_glitz::image::Image2DSource

pub struct Image2DSource<D, T> { /* fields omitted */ }

Encapsulates data that may be uploaded to a 2D texture (sub-)image.

Example

use web_glitz::image::{Image2DSource, MipmapLevels};
use web_glitz::image::format::RGB8;
use web_glitz::image::texture_2d::Texture2DDescriptor;

let texture = context.try_create_texture_2d(&Texture2DDescriptor {
    format: RGB8,
    width: 256,
    height: 256,
    levels: MipmapLevels::Complete
}).unwrap();

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

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

Note that the pixel data type ([u8; 3] in the example) must implement [ClientFormat] for the texture's [InternalFormat] (in this case that means ClientFormat<RGB8> must be implemented for [u8; 3], which it is).

Implementations

impl<D, T> Image2DSource<D, T> where
    D: Borrow<[T]>, 
[src]

pub fn from_pixels(
    pixels: D,
    width: u32,
    height: u32
) -> Result<Self, FromPixelsError>
[src]

Creates a new Image2DSource from the pixels for an image with the given width and the given height.

Returns FromPixelsError::NotEnoughPixels if the pixels does not contain enough data for at least width * height pixels.

Example

use web_glitz::image::Image2DSource;

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

impl Image2DSource<Vec<[u8; 4]>, [u8; 4]>[src]

pub fn from_image_element(image_element: &HtmlImageElement) -> Self[src]

Creates a new Image2DSource for the image_element.

The width will be equal to the HtmlImageElement::natural_width of the image element and the height will be equal the HtmlImageElement::natural_height of the image element.

Panics

Panics if the image element is not yet "complete" (see HtmlImageElement::complete).

Auto Trait Implementations

impl<D, T> RefUnwindSafe for Image2DSource<D, T> where
    D: RefUnwindSafe,
    T: RefUnwindSafe

impl<D, T> Send for Image2DSource<D, T> where
    D: Send,
    T: Send

impl<D, T> Sync for Image2DSource<D, T> where
    D: Sync,
    T: Sync

impl<D, T> Unpin for Image2DSource<D, T> where
    D: Unpin,
    T: Unpin

impl<D, T> UnwindSafe for Image2DSource<D, T> where
    D: UnwindSafe,
    T: UnwindSafe

Blanket Implementations

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> From<T> for T[src]

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

impl<D, T> IntoBuffer<T> for D where
    D: Borrow<T> + 'static,
    T: Copy + 'static, 
[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.