Struct Texture
pub struct Texture<'r> { /* private fields */ }
dep_sdl2
only.Expand description
A texture for a rendering context.
Every Texture is owned by a TextureCreator
. Internally, a texture is destroyed via its Drop
implementation. A texture can only be used by the Canvas
it was originally created from, it
is undefined behavior otherwise.
Implementations§
§impl<'r> Texture<'r>
impl<'r> Texture<'r>
pub fn query(&self) -> TextureQuery
pub fn query(&self) -> TextureQuery
Queries the attributes of the texture.
pub fn set_color_mod(&mut self, red: u8, green: u8, blue: u8)
pub fn set_color_mod(&mut self, red: u8, green: u8, blue: u8)
Sets an additional color value multiplied into render copy operations.
pub fn color_mod(&self) -> (u8, u8, u8) ⓘ
pub fn color_mod(&self) -> (u8, u8, u8) ⓘ
Gets the additional color value multiplied into render copy operations.
pub fn set_alpha_mod(&mut self, alpha: u8)
pub fn set_alpha_mod(&mut self, alpha: u8)
Sets an additional alpha value multiplied into render copy operations.
pub fn alpha_mod(&self) -> u8
pub fn alpha_mod(&self) -> u8
Gets the additional alpha value multiplied into render copy operations.
pub fn set_blend_mode(&mut self, blend: BlendMode)
pub fn set_blend_mode(&mut self, blend: BlendMode)
Sets the blend mode used for drawing operations (Fill and Line).
pub fn blend_mode(&self) -> BlendMode
pub fn blend_mode(&self) -> BlendMode
Gets the blend mode used for texture copy operations.
pub fn update<R>(
&mut self,
rect: R,
pixel_data: &[u8],
pitch: usize,
) -> Result<(), UpdateTextureError> ⓘ
pub fn update<R>( &mut self, rect: R, pixel_data: &[u8], pitch: usize, ) -> Result<(), UpdateTextureError> ⓘ
Updates the given texture rectangle with new pixel data.
pitch
is the number of bytes in a row of pixel data, including padding
between lines
- If
rect
isNone
, the entire texture is updated.
pub fn update_yuv<R>(
&mut self,
rect: R,
y_plane: &[u8],
y_pitch: usize,
u_plane: &[u8],
u_pitch: usize,
v_plane: &[u8],
v_pitch: usize,
) -> Result<(), UpdateTextureYUVError> ⓘ
pub fn update_yuv<R>( &mut self, rect: R, y_plane: &[u8], y_pitch: usize, u_plane: &[u8], u_pitch: usize, v_plane: &[u8], v_pitch: usize, ) -> Result<(), UpdateTextureYUVError> ⓘ
Updates a rectangle within a planar YV12 or IYUV texture with new pixel data.
pub fn with_lock<F, R, R2>(&mut self, rect: R2, func: F) -> Result<R, String> ⓘ
pub fn with_lock<F, R, R2>(&mut self, rect: R2, func: F) -> Result<R, String> ⓘ
Locks the texture for write-only pixel access. The texture must have been created with streaming access.
F
is a function that is passed the write-only texture buffer,
and the pitch of the texture (size of a row in bytes).
§Remarks
As an optimization, the pixels made available for editing don’t necessarily contain the old texture data. This is a write-only operation, and if you need to keep a copy of the texture data you should do that at the application level.
pub unsafe fn gl_bind_texture(&mut self) -> (f32, f32) ⓘ
pub unsafe fn gl_bind_texture(&mut self) -> (f32, f32) ⓘ
Binds an OpenGL/ES/ES2 texture to the current context for use with when rendering OpenGL primitives directly.
pub unsafe fn gl_unbind_texture(&mut self)
pub unsafe fn gl_unbind_texture(&mut self)
Unbinds an OpenGL/ES/ES2 texture from the current context.
pub fn gl_with_bind<R, F>(&mut self, f: F) -> R
pub fn gl_with_bind<R, F>(&mut self, f: F) -> R
Binds and unbinds an OpenGL/ES/ES2 texture from the current context.
pub const fn raw(&self) -> *mut SDL_Texture
pub fn from_surface<'a, T>(
surface: &Surface<'_>,
texture_creator: &'a TextureCreator<T>,
) -> Result<Texture<'a>, TextureValueError> ⓘ
pub fn from_surface<'a, T>( surface: &Surface<'_>, texture_creator: &'a TextureCreator<T>, ) -> Result<Texture<'a>, TextureValueError> ⓘ
A convenience function for TextureCreator::create_texture_from_surface
.
use sdl2::pixels::PixelFormatEnum;
use sdl2::surface::Surface;
use sdl2::render::{Canvas, Texture};
use sdl2::video::Window;
// We init systems.
let sdl_context = sdl2::init().expect("failed to init SDL");
let video_subsystem = sdl_context.video().expect("failed to get video context");
// We create a window.
let window = video_subsystem.window("sdl2 demo", 800, 600)
.build()
.expect("failed to build window");
// We get the canvas from which we can get the `TextureCreator`.
let mut canvas: Canvas<Window> = window.into_canvas()
.build()
.expect("failed to build window's canvas");
let texture_creator = canvas.texture_creator();
let surface = Surface::new(512, 512, PixelFormatEnum::RGB24).unwrap();
let texture = Texture::from_surface(&surface, &texture_creator).unwrap();
Trait Implementations§
Auto Trait Implementations§
impl<'r> Freeze for Texture<'r>
impl<'r> RefUnwindSafe for Texture<'r>
impl<'r> !Send for Texture<'r>
impl<'r> !Sync for Texture<'r>
impl<'r> Unpin for Texture<'r>
impl<'r> UnwindSafe for Texture<'r>
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
Source§impl<T> ByteSized for T
impl<T> ByteSized for T
Source§const BYTE_ALIGN: usize = _
const BYTE_ALIGN: usize = _
Source§fn byte_align(&self) -> usize
fn byte_align(&self) -> usize
Source§fn ptr_size_ratio(&self) -> [usize; 2]
fn ptr_size_ratio(&self) -> [usize; 2]
Source§impl<T, R> Chain<R> for Twhere
T: ?Sized,
impl<T, R> Chain<R> for Twhere
T: ?Sized,
Source§impl<T> ExtAny for T
impl<T> ExtAny for T
Source§fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
fn type_hash_with<H: Hasher>(&self, hasher: H) -> u64
TypeId
of Self
using a custom hasher.Source§fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
fn as_any_mut(&mut self) -> &mut dyn Anywhere
Self: Sized,
Source§impl<T> ExtMem for Twhere
T: ?Sized,
impl<T> ExtMem for Twhere
T: ?Sized,
Source§const NEEDS_DROP: bool = _
const NEEDS_DROP: bool = _
Source§fn mem_align_of<T>() -> usize
fn mem_align_of<T>() -> usize
Source§fn mem_align_of_val(&self) -> usize
fn mem_align_of_val(&self) -> usize
Source§fn mem_size_of<T>() -> usize
fn mem_size_of<T>() -> usize
Source§fn mem_size_of_val(&self) -> usize
fn mem_size_of_val(&self) -> usize
Source§fn mem_needs_drop(&self) -> bool
fn mem_needs_drop(&self) -> bool
true
if dropping values of this type matters. Read moreSource§fn mem_forget(self)where
Self: Sized,
fn mem_forget(self)where
Self: Sized,
self
without running its destructor. Read moreSource§fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
fn mem_replace(&mut self, other: Self) -> Selfwhere
Self: Sized,
Source§unsafe fn mem_zeroed<T>() -> T
unsafe fn mem_zeroed<T>() -> T
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe fn mem_transmute_copy<Src, Dst>(src: &Src) -> Dst
unsafe_layout
only.T
represented by the all-zero byte-pattern. Read moreSource§fn mem_as_bytes(&self) -> &[u8] ⓘ
fn mem_as_bytes(&self) -> &[u8] ⓘ
unsafe_slice
only.§impl<S> FromSample<S> for S
impl<S> FromSample<S> for S
fn from_sample_(s: S) -> S
Source§impl<T> Hook for T
impl<T> Hook for T
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read more