Skip to main content

Texture2D

Struct Texture2D 

Source
pub struct Texture2D { /* private fields */ }
Expand description

Texture, data stored in GPU memory

Implementations§

Source§

impl Texture2D

Source

pub fn weak_clone(&self) -> Texture2D

Source

pub fn empty() -> Texture2D

Creates an empty Texture2D.

§Example
let texture = Texture2D::empty();
Source

pub fn from_file_with_format( bytes: &[u8], format: Option<ImageFormat>, ) -> Texture2D

Creates a Texture2D from a slice of bytes that contains an encoded image.

If format is None, it will make an educated guess on the ImageFormat.

§Example
let texture = Texture2D::from_file_with_format(
    include_bytes!("../examples/rust.png"),
    None,
    );
Source

pub fn from_image(image: &Image) -> Texture2D

Creates a Texture2D from an Image.

Source

pub const fn from_miniquad_texture(texture: TextureId) -> Texture2D

Creates a Texture2D from a miniquad Texture

Source

pub fn from_rgba8(width: u16, height: u16, bytes: &[u8]) -> Texture2D

Creates a Texture2D from a slice of bytes in an R,G,B,A sequence, with the given width and height.

§Example
// Create a 2x2 texture from a byte slice with 4 rgba pixels
let bytes: Vec<u8> = vec![255, 0, 0, 192, 0, 255, 0, 192, 0, 0, 255, 192, 255, 255, 255, 192];
let texture = Texture2D::from_rgba8(2, 2, &bytes);
Source

pub fn update(&self, image: &Image)

Uploads Image data to this texture.

Source

pub fn update_from_bytes(&self, width: u32, height: u32, bytes: &[u8])

Source

pub fn update_part( &self, image: &Image, x_offset: i32, y_offset: i32, width: i32, height: i32, )

Uploads Image data to part of this texture.

Source

pub fn width(&self) -> f32

Returns the width of this texture.

Source

pub fn height(&self) -> f32

Returns the height of this texture.

Source

pub fn size(&self) -> Vec2

Source

pub fn set_filter(&self, filter_mode: FilterMode)

Sets the FilterMode of this texture.

Use Nearest if you need integer-ratio scaling for pixel art, for example.

§Example
let texture = Texture2D::empty();
texture.set_filter(FilterMode::Linear);
Source

pub fn raw_miniquad_id(&self) -> TextureId

Returns the handle for this texture.

Source

pub fn grab_screen(&self)

Updates this texture from the screen.

Source

pub fn get_texture_data(&self) -> Image

Returns an Image from the pixel data in this texture.

This operation can be expensive.

Trait Implementations§

Source§

impl Clone for Texture2D

Source§

fn clone(&self) -> Texture2D

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Texture2D

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error>

Formats the value using the given formatter. Read more
Source§

impl From<Texture2D> for ImageSource

Source§

fn from(tex: Texture2D) -> Self

Converts to this type from the input type.
Source§

impl PartialEq for Texture2D

Source§

fn eq(&self, other: &Texture2D) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl StructuralPartialEq for Texture2D

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

fn clone_into(&self, target: &mut T)

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

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

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

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more