[−][src]Struct tetra::graphics::Texture
A texture, held in GPU memory.
The following file formats are supported:
- PNG
- JPEG
- GIF
- BMP
- TIFF
- TGA
- WEBP
- ICO
- PNM
Performance
Creating a Texture
is a relatively expensive operation. If you can, store them in your State
struct rather than recreating them each frame.
Cloning a Texture
is a very cheap operation, as the underlying data is shared between the
original instance and the clone via reference-counting.
This does mean, however, that updating a Texture
(for example, changing its filter mode) will also
update any other clones of that Texture
.
Implementations
impl Texture
[src]
pub fn new<P>(ctx: &mut Context, path: P) -> Result<Texture> where
P: AsRef<Path>,
[src]
P: AsRef<Path>,
Creates a new texture from the given file.
The format will be determined based on the file extension.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::FailedToLoadAsset
will be returned if the file could not be loaded.TetraError::InvalidTexture
will be returned if the texture data was invalid.
pub fn from_file_data(ctx: &mut Context, data: &[u8]) -> Result<Texture>
[src]
Creates a new texture from a slice of data, encoded in one of Tetra's supported file formats (except for TGA).
This is useful in combination with include_bytes
, as it allows you to include
your textures directly in the binary.
The format will be determined based on the 'magic bytes' at the beginning of the
data. This should be reasonably reliable, but a from_data_with_format
function
might have to be added later. Note that TGA files do not have recognizable magic
bytes, so this function will not recognize them.
Errors
TetraError::PlatformError
will be returned if the underlying graphics API encounters an error.TetraError::InvalidTexture
will be returned if the texture data was invalid.
pub fn from_rgba(
ctx: &mut Context,
width: i32,
height: i32,
data: &[u8]
) -> Result<Texture>
[src]
ctx: &mut Context,
width: i32,
height: i32,
data: &[u8]
) -> Result<Texture>
Creates a new texture from a slice of RGBA pixel data.
This is useful if you wish to create a texture at runtime.
Note that this method requires you to provide enough data to fill the texture. If you provide too much data, it will be truncated.
Errors
TetraError::NotEnoughData
will be returned if not enough data is provided to fill the texture. This is to prevent the graphics API from trying to read uninitialized memory.
pub fn width(&self) -> i32
[src]
Returns the width of the texture.
pub fn height(&self) -> i32
[src]
Returns the height of the texture.
pub fn size(&self) -> (i32, i32)
[src]
Returns the size of the canvas.
pub fn filter_mode(&self) -> FilterMode
[src]
Returns the filter mode being used by the texture.
pub fn set_filter_mode(&mut self, ctx: &mut Context, filter_mode: FilterMode)
[src]
Sets the filter mode that should be used by the texture.
Trait Implementations
impl Clone for Texture
[src]
impl Debug for Texture
[src]
impl Drawable for Texture
[src]
fn draw<P>(&self, ctx: &mut Context, params: P) where
P: Into<DrawParams>,
[src]
P: Into<DrawParams>,
impl PartialEq<Texture> for Texture
[src]
impl StructuralPartialEq for Texture
[src]
Auto Trait Implementations
impl !RefUnwindSafe for Texture
impl !Send for Texture
impl !Sync for Texture
impl Unpin for Texture
impl !UnwindSafe for Texture
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> SetParameter for T
fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result where
T: Parameter<Self>,
T: Parameter<Self>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,