radiant_rs

Struct Renderer

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

A renderer is used to render Layers or Textures to the Display.

The renderer itself is not thread-safe. Instead, draw or write onto layers (from any one or more threads) and present those layers using the renderer once your threads have concluded drawing.

Implementations§

Source§

impl Renderer

Source

pub fn new(display: &Display) -> Result<Self>

Returns a new renderer instance.

Source

pub fn context(&self) -> RenderContext

Returns a reference to the renderers’ context. The RenderContext implements send+sync and is required by Font, Sprite and Texture to create new instances.

Source

pub fn clear(&self, color: Color) -> &Self

Clears the current target.

Source

pub fn draw_layer(&self, layer: &Layer, component: u32) -> &Self

Draws given layer to the current target. Component refers to the sprite component to draw. All sprites support at least component 0. Sprites that do not support the given component will not be drawn.

Source

pub fn rect<T>(&self, target_rect: T) -> DrawBuilder<'_, DrawBuilderRect>
where ((f32, f32), (f32, f32)): From<T>,

Draws a rectangle to the current target. See DrawBuilder for available options.

§Examples
renderer.rect(((0., 0.), (640., 480.))).blendmode(blendmodes::ALPHA).texture(&tex).draw();
Source

pub fn fill(&self) -> DrawBuilder<'_, DrawBuilderFill>

Fills the current target. See DrawBuilder for available options.

This is a specialization of rect() that simply fills the entire target.

§Examples
renderer.fill().blendmode(blendmodes::ALPHA).texture(&tex).draw();
Source

pub fn render_to<F, T>(&self, target: &T, draw_func: F) -> &Self
where F: FnMut(), T: AsRenderTarget,

Reroutes draws issued within draw_func() to given Texture.

§Examples
// Create a texture to render to.
let surface = Texture::new(&rendercontext, 640, 480);

// Render something to it.
renderer.render_to(&surface, || {
    renderer.rect(((0., 0.), (640., 480.))).texture(&some_texture).draw();
    renderer.draw_layer(&some_layer, 0);
});
Source

pub fn postprocess<P, F>( &self, postprocessor: &P, arg: &<P as Postprocessor>::T, draw_func: F, ) -> &Self
where F: FnMut(), P: Postprocessor,

Reroutes draws issued within draw_func() through the given postprocessor.

The following example uses the Basic postprocessor provided by the library.

§Examples
// Load a shader progam.
let my_program = Program::from_string(&rendercontext, &program_source).unwrap();

// Create the postprocessor with the program.
let my_postprocessor = postprocessors::Basic::new(&rendercontext, my_program);

// ... in your renderloop...
renderer.postprocess(&my_postprocessor, &blendmodes::ALPHA, || {
    renderer.clear(Color::BLACK);
    renderer.draw_layer(&my_layer, 0);
});
Source

pub fn copy_rect_from<R, S, T>( &self, source: &R, source_rect: S, target_rect: T, filter: TextureFilter, )
where R: AsRenderTarget, ((i32, i32), (i32, i32)): From<S> + From<T>,

Copies a rectangle from the source to the current target.

This is a blitting operation that uses integral pixel coordinates (top/left = 0/0). Coordinates must be entirely contained within their respective sources. No blending is performed.

Source

pub fn copy_from<R>(&self, source: &R, filter: TextureFilter)
where R: AsRenderTarget,

Copies the entire source, overwriting the entire current target.

This is a blitting operation, no blending is performed.

Source

pub fn default_program(&self) -> &Program

Returns a reference to the default rendering program.

Trait Implementations§

Source§

impl Clone for Renderer

Source§

fn clone(&self) -> Renderer

Returns a copy 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 Renderer

Source§

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

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for S
where T: Float, Swp: WhitePoint, Dwp: WhitePoint, D: AdaptFrom<S, Swp, Dwp, T>,

Source§

fn adapt_into_using<M>(self, method: M) -> D
where M: TransformMatrix<Swp, Dwp, T>,

Convert the source color to the destination color using the specified method
Source§

fn adapt_into(self) -> D

Convert the source color to the destination color using the bradford method by default
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, dst: *mut T)

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

impl<T> Downcast for T
where T: Any,

Source§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
Source§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
Source§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
Source§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self>

Converts 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 more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
where F: FnOnce(&Self) -> bool,

Converts 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
Source§

impl<T> Pointable for T

Source§

const ALIGN: usize = _

The alignment of pointer.
Source§

type Init = T

The type for initializers.
Source§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
Source§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
Source§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
Source§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
Source§

impl<T> SetParameter for T

Source§

fn set<T>(&mut self, value: T) -> <T as Parameter<Self>>::Result
where T: Parameter<Self>,

Sets value as a parameter of self.
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> Erased for T