Struct Renderer

Source
pub struct Renderer {
    pub gl: GL,
    pub program: Shader,
    pub camera: Camera,
    pub components: BTreeMap<&'static str, Box<dyn Component>>,
    /* private fields */
}
Expand description

The Renderer is responsible for drawing on the screen. It handles the Camera and Shaders.

Fields§

§gl: GL§program: Shader

The Shader used by the Renderer.

§camera: Camera

The Camera used by the Renderer.

§components: BTreeMap<&'static str, Box<dyn Component>>

Components that can be added to the Renderer.

Implementations§

Source§

impl Renderer

Source

pub fn new_with_camera(camera: Camera) -> Self

Create a new Renderer with a given Camera.

Source

pub fn new_with_camera_and_program(camera: Camera, program: Shader) -> Self

Create a new Renderer with a given Camera and Shader.

Source

pub fn set_camera(&mut self, camera: Camera)

Set the Camera that the Renderer will use.

Source

pub fn set_shader(&mut self, program: Shader)

Set the Shader that the Renderer will use.

Source

pub fn resize(&mut self, width: f32, height: f32)

Handle screen resizes.

Source

pub fn init_shader(&mut self)

Initialise the uniforms for the current Shader.

Source

pub fn add_texture(&mut self, key: &'static str, texture: Texture)

Add a Texture to the Renderer.

The renderer stores Textures that can be retreived later, via a string slice.

Source

pub fn use_texture(&self, key: &str)

Use the requested Texture.

Sets the currently bound Texture to the one that matches the key. If no such texture is found, a default MAGENTA one is found.

Source

pub fn get_texture(&mut self, key: &str) -> Rc<Texture>

Get the requested Texture, or MAGENTA if none is found.

Source

pub fn begin_draw(&mut self)

Clear the batch queue and start a new batch.

Source

pub fn add_quad(&mut self, quad: &Quad)

Add a Quad to the batching queue.

Source

pub fn begin_layer(&mut self)

Begin a new layer.

A new mesh is added to the batches and subsequent calls are made on this layer.

Source

pub fn delete_layer(&mut self) -> Option<Mesh>

Remove the last layer.

Source

pub fn draw_layer(&self)

Draw the current layer.

Source

pub fn end_draw(&mut self)

Draw all batched geometry.

Source

pub fn clear(&mut self, color: [f32; 4])

Clear the screen with a given Color.

Source

pub fn add_component( &mut self, name: &'static str, component: Box<dyn Component>, )

Add a Component to the Renderer.

Source

pub fn init_components(&mut self)

(Re)Initialize the Components of the Renderer.

Source

pub fn update_components(&mut self, delta_time: f32)

Update the Components of the Renderer.

Source

pub fn get_component<T: 'static + Component>( &self, key: &'static str, ) -> Result<&T, String>

Get a Components using a key, and ty to cast it to a given type.

Source

pub fn get_mut_component<T: 'static + Component>( &mut self, key: &'static str, ) -> Result<&mut T, String>

Get a mutable Components using a key, and ty to cast it to a given type.

Source

pub fn draw_components(&mut self)

Draw the Components of the Renderer.

Trait Implementations§

Source§

impl Debug for Renderer

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for Renderer

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

Blanket Implementations§

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

Source§

type Output = T

Should always be Self
Source§

impl<SS, SP> SupersetOf<SS> for SP
where SS: SubsetOf<SP>,

Source§

fn to_subset(&self) -> Option<SS>

The inverse inclusion map: attempts to construct self from the equivalent element of its superset. Read more
Source§

fn is_in_subset(&self) -> bool

Checks if self is actually part of its subset T (and can be converted to it).
Source§

fn to_subset_unchecked(&self) -> SS

Use with care! Same as self.to_subset but without any property checks. Always succeeds.
Source§

fn from_subset(element: &SS) -> SP

The inclusion map: converts self to the equivalent element of its superset.
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.