Struct TextureCreator
pub struct TextureCreator<T> { /* private fields */ }
dep_sdl3
only.Expand description
Creates Textures that cannot outlive the creator
The TextureCreator
does not hold a lifetime to its Canvas by design choice.
If a Canvas
is dropped before its TextureCreator
, it is still safe to use.
It is, however, useless.
Any Texture
created here can only be drawn onto the original Canvas
. A Texture
used in a
Canvas
must come from a TextureCreator
coming from that same Canvas
. Using a Texture
to
render to a Canvas
not being the parent of the Texture
’s TextureCreator
is undefined
behavior.
Implementations§
§impl<T> TextureCreator<T>
Texture-creating methods for the renderer
impl<T> TextureCreator<T>
Texture-creating methods for the renderer
pub fn raw(&self) -> *mut SDL_Renderer
pub fn default_pixel_format(&self) -> PixelFormat
pub fn create_texture<F>(
&self,
format: F,
access: TextureAccess,
width: u32,
height: u32,
) -> Result<Texture<'_>, TextureValueError> ⓘ
pub fn create_texture<F>( &self, format: F, access: TextureAccess, width: u32, height: u32, ) -> Result<Texture<'_>, TextureValueError> ⓘ
Creates a texture for a rendering context.
If format is None
, the format will be the one the parent Window or Surface uses.
If format is Some(pixel_format)
, the default will be overridden, and the texture will be
created with the specified format if possible. If the PixelFormat is not supported, this
will return an error.
You should prefer the default format if possible to have performance gains and to avoid
unsupported Pixel Formats that can cause errors. However, be careful with the default
PixelFormat
if you want to create transparent textures.
pub fn create_texture_static<F>(
&self,
format: F,
width: u32,
height: u32,
) -> Result<Texture<'_>, TextureValueError> ⓘ
pub fn create_texture_static<F>( &self, format: F, width: u32, height: u32, ) -> Result<Texture<'_>, TextureValueError> ⓘ
Shorthand for create_texture(format, TextureAccess::Static, width, height)
pub fn create_texture_streaming<F>(
&self,
format: F,
width: u32,
height: u32,
) -> Result<Texture<'_>, TextureValueError> ⓘ
pub fn create_texture_streaming<F>( &self, format: F, width: u32, height: u32, ) -> Result<Texture<'_>, TextureValueError> ⓘ
Shorthand for create_texture(format, TextureAccess::Streaming, width, height)
pub fn create_texture_target<F>(
&self,
format: F,
width: u32,
height: u32,
) -> Result<Texture<'_>, TextureValueError> ⓘ
pub fn create_texture_target<F>( &self, format: F, width: u32, height: u32, ) -> Result<Texture<'_>, TextureValueError> ⓘ
Shorthand for create_texture(format, TextureAccess::Target, width, height)
pub fn create_texture_from_surface<S>(
&self,
surface: S,
) -> Result<Texture<'_>, TextureValueError> ⓘwhere
S: AsRef<SurfaceRef>,
pub fn create_texture_from_surface<S>(
&self,
surface: S,
) -> Result<Texture<'_>, TextureValueError> ⓘwhere
S: AsRef<SurfaceRef>,
Creates a texture from an existing surface.
§Remarks
The access hint for the created texture is TextureAccess::Static
.
use sdl3::pixels::PixelFormat;
use sdl3::surface::Surface;
use sdl3::render::{Canvas, Texture};
use sdl3::video::Window;
// We init systems.
let sdl_context = sdl3::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("sdl3 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();
let texture_creator = canvas.texture_creator();
let surface = Surface::new(512, 512, PixelFormat::RGB24).unwrap();
let texture = texture_creator.create_texture_from_surface(surface).unwrap();
pub const unsafe fn raw_create_texture(
&self,
raw: *mut SDL_Texture,
) -> Texture<'_>
pub const unsafe fn raw_create_texture( &self, raw: *mut SDL_Texture, ) -> Texture<'_>
Create a texture from its raw SDL_Texture
.
Auto Trait Implementations§
impl<T> Freeze for TextureCreator<T>
impl<T> RefUnwindSafe for TextureCreator<T>where
T: RefUnwindSafe,
impl<T> !Send for TextureCreator<T>
impl<T> !Sync for TextureCreator<T>
impl<T> Unpin for TextureCreator<T>
impl<T> UnwindSafe for TextureCreator<T>where
T: RefUnwindSafe,
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