pub struct Texture2D { /* private fields */ }Expand description
Texture, data stored in GPU memory
Implementations§
Source§impl Texture2D
impl Texture2D
pub fn weak_clone(&self) -> Texture2D
Sourcepub fn from_file_with_format(
bytes: &[u8],
format: Option<ImageFormat>,
) -> Texture2D
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,
);Sourcepub fn from_image(image: &Image) -> Texture2D
pub fn from_image(image: &Image) -> Texture2D
Creates a Texture2D from an Image.
Sourcepub const fn from_miniquad_texture(texture: TextureId) -> Texture2D
pub const fn from_miniquad_texture(texture: TextureId) -> Texture2D
Creates a Texture2D from a miniquad Texture
Sourcepub fn from_rgba8(width: u16, height: u16, bytes: &[u8]) -> Texture2D
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);pub fn update_from_bytes(&self, width: u32, height: u32, bytes: &[u8])
Sourcepub fn update_part(
&self,
image: &Image,
x_offset: i32,
y_offset: i32,
width: i32,
height: i32,
)
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.
pub fn size(&self) -> Vec2
Sourcepub fn set_filter(&self, filter_mode: FilterMode)
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);Sourcepub fn raw_miniquad_id(&self) -> TextureId
pub fn raw_miniquad_id(&self) -> TextureId
Returns the handle for this texture.
Sourcepub fn grab_screen(&self)
pub fn grab_screen(&self)
Updates this texture from the screen.
Sourcepub fn get_texture_data(&self) -> Image
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 From<Texture2D> for ImageSource
impl From<Texture2D> for ImageSource
impl StructuralPartialEq for Texture2D
Auto Trait Implementations§
impl Freeze for Texture2D
impl RefUnwindSafe for Texture2D
impl Send for Texture2D
impl Sync for Texture2D
impl Unpin for Texture2D
impl UnsafeUnpin for Texture2D
impl UnwindSafe for Texture2D
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more