Struct blue_engine::Renderer

source ·
pub struct Renderer {
Show 14 fields pub surface: Option<Surface<'static>>, pub instance: Instance, pub adapter: Adapter, pub device: Device, pub queue: Queue, pub config: SurfaceConfiguration, pub size: PhysicalSize<u32>, pub texture_bind_group_layout: BindGroupLayout, pub default_uniform_bind_group_layout: BindGroupLayout, pub depth_buffer: (Texture, TextureView, Sampler), pub default_data: Option<(Textures, Shaders, UniformBuffers)>, pub camera: Option<UniformBuffers>, pub clear_color: Color, pub scissor_rect: Option<(u32, u32, u32, u32)>,
}
Expand description

Main renderer class. this will contain all methods and data related to the renderer

Fields§

§surface: Option<Surface<'static>>

A wgpu::Surface represents a platform-specific surface (e.g. a window) onto which rendered images may be presented.

§instance: Instance

Context for all of the gpu objects

§adapter: Adapter

Handle to a physical graphics and/or compute device.

§device: Device

Open connection to a graphics and/or compute device.

§queue: Queue

Handle to a command queue on a device.

§config: SurfaceConfiguration

Describes a wgpu::Surface

§size: PhysicalSize<u32>

The size of the window

§texture_bind_group_layout: BindGroupLayout

The texture bind group layout

§default_uniform_bind_group_layout: BindGroupLayout

The uniform bind group layout

§depth_buffer: (Texture, TextureView, Sampler)

The depth buffer, used to render object depth

§default_data: Option<(Textures, Shaders, UniformBuffers)>

The default data used within the renderer

§camera: Option<UniformBuffers>

The camera used in the engine

§clear_color: Color

Background clear color

§scissor_rect: Option<(u32, u32, u32, u32)>

Scissor cut section of the screen to render to (x, y, width, height)

Implementations§

source§

impl Renderer

source

pub fn build_pipeline( &mut self, shader: Shaders, vertex_buffer: VertexBuffers, texture: Textures, uniform: Option<UniformBuffers> ) -> Result<Pipeline>

Creates a new render pipeline. Could be thought of as like materials in game engines.

source

pub fn build_shader( &mut self, name: impl StringBuffer, shader_source: String, uniform_layout: Option<&BindGroupLayout>, settings: ShaderSettings ) -> Result<Shaders>

Creates a shader group, the input must be spir-v compiled vertex and fragment shader

source

pub fn build_texture( &mut self, name: impl StringBuffer, texture_data: TextureData, texture_mode: TextureMode ) -> Result<Textures>

Creates a new texture data

Examples found in repository?
examples/utils/resource_sharing.rs (lines 17-21)
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
fn main() {
    // Start the engine
    let mut engine = Engine::new().expect("window not initialized");

    // build a texture as an example of resource to be shared
    let texture = engine
        .renderer
        .build_texture(
            "background",
            TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
            blue_engine::TextureMode::Clamp,
        )
        .unwrap();

    // build your main object with the texture
    square(
        "main",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    )
    .expect("Error during creation of main square");

    // add the texture to the main object as normally would
    engine
        .objects
        .get_mut("main")
        .unwrap()
        .set_texture(texture)
        .expect("Error during inserting texture to the main square");
    // set position to make it visible
    engine
        .objects
        .get_mut("main")
        .expect("Error during setting the position of the main square")
        .set_position(-1.5f32, 0f32, 0f32);

    // create another object where you want to get resources shared with
    square(
        "alt",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    )
    .expect("Error during creation of alt square");

    // here you can use `reference_texture` to reference the texture from the main object
    engine
        .objects
        .get_mut("alt")
        .expect("Error during copying texture of the main square")
        .reference_texture("main");
    // setting position again to make it visible
    engine
        .objects
        .get_mut("alt")
        .expect("Error during setting the position of the alt square")
        .set_position(1.5f32, 0f32, 0f32);

    engine
        .update_loop(move |_, _, _, _, _, _| {})
        .expect("Error during update loop");
}
More examples
Hide additional examples
examples/dev/dev.rs (lines 24-28)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
fn main() {
    let mut engine = Engine::new_config(blue_engine::WindowDescriptor {
        power_preference: blue_engine::PowerPreference::LowPower,
        present_mode: blue_engine::wgpu::PresentMode::Immediate,
        ..Default::default()
    })
    .expect("win");

    //let test_instance = Instance::default();
    //println!("{:?}", test_instance.to_raw());

    let texture = engine
        .renderer
        .build_texture(
            "background",
            TextureData::Path("resources/BlueLogoDiscord.png".to_string()),
            blue_engine::TextureMode::Clamp,
        )
        .unwrap();
    let texture2 = engine
        .renderer
        .build_texture(
            "background",
            TextureData::Path("resources/player.png".to_string()),
            blue_engine::TextureMode::Clamp,
        )
        .unwrap();

    let texture3 = engine
        .renderer
        .build_texture(
            "background",
            TextureData::Path("resources/image.png".to_string()),
            blue_engine::TextureMode::Clamp,
        )
        .unwrap();

    square(
        "main",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    );

    engine.objects.get_mut("main").unwrap().set_texture(texture);
    engine
        .objects
        .get_mut("main")
        .unwrap()
        .set_position(-1f32, 0f32, 0f32);

    square(
        "alt",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    );
    engine.objects.get_mut("alt").unwrap().set_texture(texture2);
    engine
        .objects
        .get_mut("alt")
        .unwrap()
        .set_position(0.2f32, 0f32, 0.001f32);

    square(
        "alt2",
        ObjectSettings::default(),
        &mut engine.renderer,
        &mut engine.objects,
    );
    engine
        .objects
        .get_mut("alt2")
        .unwrap()
        .set_texture(texture3);
    engine
        .objects
        .get_mut("alt2")
        .unwrap()
        .set_position(-0.2f32, 0f32, 0.001f32);

    let speed = -0.05;

    let mut last_time = std::time::Instant::now();
    let mut frames = 0;
    engine
        .update_loop(move |renderer, _window, objects, input, camera, plugins| {
            // calculate FPS
            let current_time = std::time::Instant::now();
            frames += 1;
            if current_time - last_time >= std::time::Duration::from_secs(1) {
                println!("{}ms/frame", 1000f32 / frames as f32);
                frames = 0;
                last_time = current_time;
            }

            let sprite = objects.get_mut("alt").unwrap();

            if input.key_held(blue_engine::KeyCode::ArrowUp) {
                sprite.set_position(
                    sprite.position.x,
                    sprite.position.y - speed,
                    sprite.position.z,
                );
                //lm.ambient_color.data = [1f32, 1f32, 1f32, 1f32];
            }
            if input.key_held(blue_engine::KeyCode::ArrowDown) {
                sprite.set_position(
                    sprite.position.x,
                    sprite.position.y + speed,
                    sprite.position.z,
                );
                //lm.ambient_color.data = [0.1f32, 0.1f32, 0.1f32, 1f32];
            }

            if input.key_held(blue_engine::KeyCode::ArrowLeft) {
                sprite.set_position(
                    sprite.position.x + speed,
                    sprite.position.y,
                    sprite.position.z,
                );
            }
            if input.key_held(blue_engine::KeyCode::ArrowRight) {
                sprite.set_position(
                    sprite.position.x - speed,
                    sprite.position.y,
                    sprite.position.z,
                );
            }

            if input.key_held(blue_engine::KeyCode::KeyE) {
                sprite.set_position(
                    sprite.position.x,
                    sprite.position.y,
                    sprite.position.z + speed,
                );
            }
            if input.key_held(blue_engine::KeyCode::KeyQ) {
                sprite.set_position(
                    sprite.position.x,
                    sprite.position.y,
                    sprite.position.z - speed,
                );
            }
        })
        .expect("Error during update loop");
}
source

pub fn build_uniform_buffer_part<T: Zeroable + Pod>( &self, name: impl StringBuffer, value: T ) -> Buffer

Creates a new uniform buffer part

This function doesn’t build the entire uniform buffers list, but rather only one of them

source

pub fn build_uniform_buffer( &mut self, uniforms: &Vec<Buffer> ) -> Result<(UniformBuffers, BindGroupLayout)>

Creates a new uniform buffer group, according to a list of types

source

pub fn build_vertex_buffer( &mut self, vertices: &Vec<Vertex>, indices: &Vec<u16> ) -> Result<VertexBuffers>

Creates a new vertex buffer and indices

source

pub fn build_instance(&self, instance_data: Vec<InstanceRaw>) -> Buffer

Creates a new instance buffer for the object

source§

impl Renderer

source

pub fn build_object( &mut self, name: impl StringBuffer, vertices: Vec<Vertex>, indices: Vec<u16>, settings: ObjectSettings ) -> Result<Object>

Creates a new object

Is used to define a new object and add it to the storage. This offers full customizability and a framework for in-engine shapes to be developed.

§Arguments
  • name - The name of the object.
  • vertices - A list of vertices for the object to draw with
  • indices - A list of indices that references the vertices, defining draw order
  • settings - The settings of the object

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 Send for Renderer

source§

impl Sync for Renderer

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> Any for T
where T: Any,

source§

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

source§

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

source§

fn type_name(&self) -> &'static str

source§

impl<T> AnySync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

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

source§

fn downcast(&self) -> &T

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> DowncastSync for T
where T: Any + Send + Sync,

source§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

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

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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<D> OwoColorize for D

source§

fn fg<C>(&self) -> FgColorDisplay<'_, C, Self>
where C: Color,

Set the foreground color generically Read more
source§

fn bg<C>(&self) -> BgColorDisplay<'_, C, Self>
where C: Color,

Set the background color generically. Read more
source§

fn black<'a>(&'a self) -> FgColorDisplay<'a, Black, Self>

Change the foreground color to black
source§

fn on_black<'a>(&'a self) -> BgColorDisplay<'a, Black, Self>

Change the background color to black
source§

fn red<'a>(&'a self) -> FgColorDisplay<'a, Red, Self>

Change the foreground color to red
source§

fn on_red<'a>(&'a self) -> BgColorDisplay<'a, Red, Self>

Change the background color to red
source§

fn green<'a>(&'a self) -> FgColorDisplay<'a, Green, Self>

Change the foreground color to green
source§

fn on_green<'a>(&'a self) -> BgColorDisplay<'a, Green, Self>

Change the background color to green
source§

fn yellow<'a>(&'a self) -> FgColorDisplay<'a, Yellow, Self>

Change the foreground color to yellow
source§

fn on_yellow<'a>(&'a self) -> BgColorDisplay<'a, Yellow, Self>

Change the background color to yellow
source§

fn blue<'a>(&'a self) -> FgColorDisplay<'a, Blue, Self>

Change the foreground color to blue
source§

fn on_blue<'a>(&'a self) -> BgColorDisplay<'a, Blue, Self>

Change the background color to blue
source§

fn magenta<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to magenta
source§

fn on_magenta<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to magenta
source§

fn purple<'a>(&'a self) -> FgColorDisplay<'a, Magenta, Self>

Change the foreground color to purple
source§

fn on_purple<'a>(&'a self) -> BgColorDisplay<'a, Magenta, Self>

Change the background color to purple
source§

fn cyan<'a>(&'a self) -> FgColorDisplay<'a, Cyan, Self>

Change the foreground color to cyan
source§

fn on_cyan<'a>(&'a self) -> BgColorDisplay<'a, Cyan, Self>

Change the background color to cyan
source§

fn white<'a>(&'a self) -> FgColorDisplay<'a, White, Self>

Change the foreground color to white
source§

fn on_white<'a>(&'a self) -> BgColorDisplay<'a, White, Self>

Change the background color to white
source§

fn default_color<'a>(&'a self) -> FgColorDisplay<'a, Default, Self>

Change the foreground color to the terminal default
source§

fn on_default_color<'a>(&'a self) -> BgColorDisplay<'a, Default, Self>

Change the background color to the terminal default
source§

fn bright_black<'a>(&'a self) -> FgColorDisplay<'a, BrightBlack, Self>

Change the foreground color to bright black
source§

fn on_bright_black<'a>(&'a self) -> BgColorDisplay<'a, BrightBlack, Self>

Change the background color to bright black
source§

fn bright_red<'a>(&'a self) -> FgColorDisplay<'a, BrightRed, Self>

Change the foreground color to bright red
source§

fn on_bright_red<'a>(&'a self) -> BgColorDisplay<'a, BrightRed, Self>

Change the background color to bright red
source§

fn bright_green<'a>(&'a self) -> FgColorDisplay<'a, BrightGreen, Self>

Change the foreground color to bright green
source§

fn on_bright_green<'a>(&'a self) -> BgColorDisplay<'a, BrightGreen, Self>

Change the background color to bright green
source§

fn bright_yellow<'a>(&'a self) -> FgColorDisplay<'a, BrightYellow, Self>

Change the foreground color to bright yellow
source§

fn on_bright_yellow<'a>(&'a self) -> BgColorDisplay<'a, BrightYellow, Self>

Change the background color to bright yellow
source§

fn bright_blue<'a>(&'a self) -> FgColorDisplay<'a, BrightBlue, Self>

Change the foreground color to bright blue
source§

fn on_bright_blue<'a>(&'a self) -> BgColorDisplay<'a, BrightBlue, Self>

Change the background color to bright blue
source§

fn bright_magenta<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright magenta
source§

fn on_bright_magenta<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright magenta
source§

fn bright_purple<'a>(&'a self) -> FgColorDisplay<'a, BrightMagenta, Self>

Change the foreground color to bright purple
source§

fn on_bright_purple<'a>(&'a self) -> BgColorDisplay<'a, BrightMagenta, Self>

Change the background color to bright purple
source§

fn bright_cyan<'a>(&'a self) -> FgColorDisplay<'a, BrightCyan, Self>

Change the foreground color to bright cyan
source§

fn on_bright_cyan<'a>(&'a self) -> BgColorDisplay<'a, BrightCyan, Self>

Change the background color to bright cyan
source§

fn bright_white<'a>(&'a self) -> FgColorDisplay<'a, BrightWhite, Self>

Change the foreground color to bright white
source§

fn on_bright_white<'a>(&'a self) -> BgColorDisplay<'a, BrightWhite, Self>

Change the background color to bright white
source§

fn bold<'a>(&'a self) -> BoldDisplay<'a, Self>

Make the text bold
source§

fn dimmed<'a>(&'a self) -> DimDisplay<'a, Self>

Make the text dim
source§

fn italic<'a>(&'a self) -> ItalicDisplay<'a, Self>

Make the text italicized
source§

fn underline<'a>(&'a self) -> UnderlineDisplay<'a, Self>

Make the text italicized
Make the text blink
Make the text blink (but fast!)
source§

fn reversed<'a>(&'a self) -> ReversedDisplay<'a, Self>

Swap the foreground and background colors
source§

fn hidden<'a>(&'a self) -> HiddenDisplay<'a, Self>

Hide the text
source§

fn strikethrough<'a>(&'a self) -> StrikeThroughDisplay<'a, Self>

Cross out the text
source§

fn color<Color>(&self, color: Color) -> FgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the foreground color at runtime. Only use if you do not know which color will be used at compile-time. If the color is constant, use either OwoColorize::fg or a color-specific method, such as OwoColorize::green, Read more
source§

fn on_color<Color>(&self, color: Color) -> BgDynColorDisplay<'_, Color, Self>
where Color: DynColor,

Set the background color at runtime. Only use if you do not know what color to use at compile-time. If the color is constant, use either OwoColorize::bg or a color-specific method, such as OwoColorize::on_yellow, Read more
source§

fn fg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> FgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the foreground color to a specific RGB value.
source§

fn bg_rgb<const R: u8, const G: u8, const B: u8>( &self ) -> BgColorDisplay<'_, CustomColor<R, G, B>, Self>

Set the background color to a specific RGB value.
source§

fn truecolor(&self, r: u8, g: u8, b: u8) -> FgDynColorDisplay<'_, Rgb, Self>

Sets the foreground color to an RGB value.
source§

fn on_truecolor(&self, r: u8, g: u8, b: u8) -> BgDynColorDisplay<'_, Rgb, Self>

Sets the background color to an RGB value.
source§

fn style(&self, style: Style) -> Styled<&Self>

Apply a runtime-determined style
source§

impl<T> Pointable for T

source§

const ALIGN: usize = _

The alignment of pointer.
§

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

§

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>,

§

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>,

§

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

source§

fn upcast(&self) -> Option<&T>

source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

impl<T> WasmNotSend for T
where T: Send,

source§

impl<T> WasmNotSendSync for T

source§

impl<T> WasmNotSync for T
where T: Sync,