Struct bottomless_pit::material::Material
source · pub struct Material { /* private fields */ }Expand description
A material represents a unique combination of a Texture and RenderPipeline, while also containing all nessicary buffers
Implementations§
source§impl Material
impl Material
sourcepub fn change_texture(&mut self, texture: ResourceId<Texture>)
pub fn change_texture(&mut self, texture: ResourceId<Texture>)
sourcepub fn add_rectangle(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_rectangle( &mut self, position: Vec2<f32>, size: Vec2<f32>, colour: Colour, render: &RenderInformation<'_, '_> )
Will queue a Rectangle to be draw.
Examples found in repository?
39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.current.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 400.0, y: 400.0 },
Colour::WHITE,
&render_handle,
);
self.current.draw(&mut render_handle);
}More examples
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.material.add_triangle_with_coloured_verticies(
[
Vec2 { x: 200.0, y: 0.0 },
Vec2 { x: 400.0, y: 400.0 },
Vec2 { x: 0.0, y: 400.0 },
],
[Colour::RED, Colour::GREEN, Colour::BLUE],
&render_handle,
);
self.material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.material.draw(&mut render_handle);
}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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.mouse_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.circle_material.add_rectangle(
Vec2 { x: 100.0, y: 100.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.defualt_material.add_rectangle(
Vec2 { x: 0.0, y: 200.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.mouse_material.draw(&mut render_handle);
self.circle_material.draw(&mut render_handle);
self.defualt_material.draw(&mut render_handle);
}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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
let defualt_size = Vec2 { x: 50.0, y: 50.0 };
self.regular_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
defualt_size,
Colour::RED,
&render_handle,
);
self.regular_material.add_rectangle(
self.pos,
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.texture_material.add_rectangle(
Vec2 { x: 0.0, y: 50.0 },
defualt_size,
Colour::WHITE,
&render_handle,
);
self.texture_material.add_rectangle_with_uv(
Vec2 { x: 0.0, y: 100.0 },
defualt_size,
Vec2 { x: 311.0, y: 311.0 },
Vec2 { x: 311.0, y: 311.0 },
Colour::WHITE,
&render_handle,
);
self.regular_material.add_rectangle_with_rotation(
Vec2 { x: 0.0, y: 150.0 },
defualt_size,
Colour::GREEN,
45.0,
&render_handle,
);
let points = [
Vec2 { x: 0.0, y: 300.0 },
Vec2 { x: 80.0, y: 290.0 },
Vec2 { x: 100.0, y: 400.0 },
Vec2 { x: 60.0, y: 400.0 },
];
let uvs = [
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 1.0, y: 0.0 },
Vec2 { x: 1.0, y: 1.0 },
Vec2 { x: 0.0, y: 1.0 },
];
self.regular_material
.add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
self.texture_material.draw(&mut render_handle);
self.regular_material.draw(&mut render_handle);
}sourcepub fn add_screenspace_rectangle(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_screenspace_rectangle( &mut self, position: Vec2<f32>, size: Vec2<f32>, colour: Colour, render: &RenderInformation<'_, '_> )
Queues a rectangle using WGSL cordinate space. (0, 0) is the center of the screen and (-1, 1) is the top left corner
sourcepub fn add_rectangle_with_uv(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
uv_position: Vec2<f32>,
uv_size: Vec2<f32>,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_rectangle_with_uv( &mut self, position: Vec2<f32>, size: Vec2<f32>, uv_position: Vec2<f32>, uv_size: Vec2<f32>, colour: Colour, render: &RenderInformation<'_, '_> )
Queues a rectagnle with UV coordniates. The position and size of the UV cordniates are the same as the pixels in the actaul image.
Examples found in repository?
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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
let defualt_size = Vec2 { x: 50.0, y: 50.0 };
self.regular_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
defualt_size,
Colour::RED,
&render_handle,
);
self.regular_material.add_rectangle(
self.pos,
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.texture_material.add_rectangle(
Vec2 { x: 0.0, y: 50.0 },
defualt_size,
Colour::WHITE,
&render_handle,
);
self.texture_material.add_rectangle_with_uv(
Vec2 { x: 0.0, y: 100.0 },
defualt_size,
Vec2 { x: 311.0, y: 311.0 },
Vec2 { x: 311.0, y: 311.0 },
Colour::WHITE,
&render_handle,
);
self.regular_material.add_rectangle_with_rotation(
Vec2 { x: 0.0, y: 150.0 },
defualt_size,
Colour::GREEN,
45.0,
&render_handle,
);
let points = [
Vec2 { x: 0.0, y: 300.0 },
Vec2 { x: 80.0, y: 290.0 },
Vec2 { x: 100.0, y: 400.0 },
Vec2 { x: 60.0, y: 400.0 },
];
let uvs = [
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 1.0, y: 0.0 },
Vec2 { x: 1.0, y: 1.0 },
Vec2 { x: 0.0, y: 1.0 },
];
self.regular_material
.add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
self.texture_material.draw(&mut render_handle);
self.regular_material.draw(&mut render_handle);
}sourcepub fn add_rectangle_with_rotation(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
colour: Colour,
rotation: f32,
render: &RenderInformation<'_, '_>
)
pub fn add_rectangle_with_rotation( &mut self, position: Vec2<f32>, size: Vec2<f32>, colour: Colour, rotation: f32, render: &RenderInformation<'_, '_> )
Queues a rectangle that will be rotated around its centerpoint. Rotation is in degrees
Examples found in repository?
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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
let defualt_size = Vec2 { x: 50.0, y: 50.0 };
self.regular_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
defualt_size,
Colour::RED,
&render_handle,
);
self.regular_material.add_rectangle(
self.pos,
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.texture_material.add_rectangle(
Vec2 { x: 0.0, y: 50.0 },
defualt_size,
Colour::WHITE,
&render_handle,
);
self.texture_material.add_rectangle_with_uv(
Vec2 { x: 0.0, y: 100.0 },
defualt_size,
Vec2 { x: 311.0, y: 311.0 },
Vec2 { x: 311.0, y: 311.0 },
Colour::WHITE,
&render_handle,
);
self.regular_material.add_rectangle_with_rotation(
Vec2 { x: 0.0, y: 150.0 },
defualt_size,
Colour::GREEN,
45.0,
&render_handle,
);
let points = [
Vec2 { x: 0.0, y: 300.0 },
Vec2 { x: 80.0, y: 290.0 },
Vec2 { x: 100.0, y: 400.0 },
Vec2 { x: 60.0, y: 400.0 },
];
let uvs = [
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 1.0, y: 0.0 },
Vec2 { x: 1.0, y: 1.0 },
Vec2 { x: 0.0, y: 1.0 },
];
self.regular_material
.add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
self.texture_material.draw(&mut render_handle);
self.regular_material.draw(&mut render_handle);
}sourcepub fn add_rectangle_ex(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
colour: Colour,
rotation: f32,
uv_position: Vec2<f32>,
uv_size: Vec2<f32>,
render: &RenderInformation<'_, '_>
)
pub fn add_rectangle_ex( &mut self, position: Vec2<f32>, size: Vec2<f32>, colour: Colour, rotation: f32, uv_position: Vec2<f32>, uv_size: Vec2<f32>, render: &RenderInformation<'_, '_> )
Queues a rectangle with both UV, and Rotation,
sourcepub fn add_screenspace_rectangle_ex(
&mut self,
position: Vec2<f32>,
size: Vec2<f32>,
colour: Colour,
rotation: f32,
uv_position: Vec2<f32>,
uv_size: Vec2<f32>,
render: &RenderInformation<'_, '_>
)
pub fn add_screenspace_rectangle_ex( &mut self, position: Vec2<f32>, size: Vec2<f32>, colour: Colour, rotation: f32, uv_position: Vec2<f32>, uv_size: Vec2<f32>, render: &RenderInformation<'_, '_> )
Queues a rectangle with both UV, and Rotation, but will draw the rectangle in WGSL screenspace
sourcepub fn add_custom(
&mut self,
points: [Vec2<f32>; 4],
uv_points: [Vec2<f32>; 4],
rotation: f32,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_custom( &mut self, points: [Vec2<f32>; 4], uv_points: [Vec2<f32>; 4], rotation: f32, colour: Colour, render: &RenderInformation<'_, '_> )
Queues a 4 pointed polygon with complete control over uv coordinates and rotation. The points need to be in top left, right bottom right and bottom left order as it will not render porperly otherwise.
Examples found in repository?
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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
let defualt_size = Vec2 { x: 50.0, y: 50.0 };
self.regular_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
defualt_size,
Colour::RED,
&render_handle,
);
self.regular_material.add_rectangle(
self.pos,
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.texture_material.add_rectangle(
Vec2 { x: 0.0, y: 50.0 },
defualt_size,
Colour::WHITE,
&render_handle,
);
self.texture_material.add_rectangle_with_uv(
Vec2 { x: 0.0, y: 100.0 },
defualt_size,
Vec2 { x: 311.0, y: 311.0 },
Vec2 { x: 311.0, y: 311.0 },
Colour::WHITE,
&render_handle,
);
self.regular_material.add_rectangle_with_rotation(
Vec2 { x: 0.0, y: 150.0 },
defualt_size,
Colour::GREEN,
45.0,
&render_handle,
);
let points = [
Vec2 { x: 0.0, y: 300.0 },
Vec2 { x: 80.0, y: 290.0 },
Vec2 { x: 100.0, y: 400.0 },
Vec2 { x: 60.0, y: 400.0 },
];
let uvs = [
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 1.0, y: 0.0 },
Vec2 { x: 1.0, y: 1.0 },
Vec2 { x: 0.0, y: 1.0 },
];
self.regular_material
.add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
self.texture_material.draw(&mut render_handle);
self.regular_material.draw(&mut render_handle);
}sourcepub fn add_triangle(
&mut self,
p1: Vec2<f32>,
p2: Vec2<f32>,
p3: Vec2<f32>,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_triangle( &mut self, p1: Vec2<f32>, p2: Vec2<f32>, p3: Vec2<f32>, colour: Colour, render: &RenderInformation<'_, '_> )
Queues a traingle, the points must be provided in clockwise order
sourcepub fn add_triangle_with_coloured_verticies(
&mut self,
points: [Vec2<f32>; 3],
colours: [Colour; 3],
render: &RenderInformation<'_, '_>
)
pub fn add_triangle_with_coloured_verticies( &mut self, points: [Vec2<f32>; 3], colours: [Colour; 3], render: &RenderInformation<'_, '_> )
Queues a triangle where each vertex is given its own colour. Points must be given in clockwise order
Examples found in repository?
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.material.add_triangle_with_coloured_verticies(
[
Vec2 { x: 200.0, y: 0.0 },
Vec2 { x: 400.0, y: 400.0 },
Vec2 { x: 0.0, y: 400.0 },
],
[Colour::RED, Colour::GREEN, Colour::BLUE],
&render_handle,
);
self.material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.material.draw(&mut render_handle);
}sourcepub fn add_regular_n_gon(
&mut self,
number_of_sides: usize,
radius: f32,
center: Vec2<f32>,
colour: Colour,
render: &RenderInformation<'_, '_>
)
pub fn add_regular_n_gon( &mut self, number_of_sides: usize, radius: f32, center: Vec2<f32>, colour: Colour, render: &RenderInformation<'_, '_> )
Queues a polygon with the specified number of sides at a position with size and colour. This will not play nicely with texture as all the UV coords will be at [0, 0].
Examples found in repository?
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.regular_material.add_regular_n_gon(
120,
200.0,
Vec2 { x: 250.0, y: 250.0 },
Colour::BLUE,
&render_handle,
);
self.regular_material.draw(&mut render_handle);
}sourcepub fn update_uniform_data<T: ShaderType + WriteInto>(
&mut self,
data: &T,
engine: &Engine
)
pub fn update_uniform_data<T: ShaderType + WriteInto>( &mut self, data: &T, engine: &Engine )
Updates the uniform buffer to contain the same type but new data. You can write in a diffrent type from before but this could cause undefinded behavoir
Examples found in repository?
More examples
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
fn update(&mut self, engine_handle: &mut Engine) {
let dt = engine_handle.get_frame_delta_time();
self.theta = (self.theta + dt) % (2.0 * PI);
let size = engine_handle.get_window_size();
let mouse_pos = engine_handle.get_mouse_position();
let new_data = MousePos {
x: mouse_pos.x / size.x as f32,
y: mouse_pos.y / size.y as f32,
_junk: 0.0,
_padding2: 0.0,
};
self.data = new_data;
self.mouse_material
.update_uniform_data(&self.data, &engine_handle);
self.circle_material
.update_uniform_data(&self.theta, &engine_handle);
}sourcepub fn get_vertex_number(&self) -> u64
pub fn get_vertex_number(&self) -> u64
Returns the number of verticies in the buffer
sourcepub fn get_index_number(&self) -> u64
pub fn get_index_number(&self) -> u64
Returns the number if indincies in the buffer
pub fn get_texture_size(&self) -> Vec2<f32>
sourcepub fn draw<'pass, 'others>(
&'others mut self,
information: &mut RenderInformation<'pass, 'others>
)where
'others: 'pass,
pub fn draw<'pass, 'others>(
&'others mut self,
information: &mut RenderInformation<'pass, 'others>
)where
'others: 'pass,
Draws all queued shapes to the screen.
Examples found in repository?
39 40 41 42 43 44 45 46 47 48 49 50 51 52
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.current.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 400.0, y: 400.0 },
Colour::WHITE,
&render_handle,
);
self.current.draw(&mut render_handle);
}More examples
59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.regular_material.add_regular_n_gon(
120,
200.0,
Vec2 { x: 250.0, y: 250.0 },
Colour::BLUE,
&render_handle,
);
self.regular_material.draw(&mut render_handle);
}27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.material.add_triangle_with_coloured_verticies(
[
Vec2 { x: 200.0, y: 0.0 },
Vec2 { x: 400.0, y: 400.0 },
Vec2 { x: 0.0, y: 400.0 },
],
[Colour::RED, Colour::GREEN, Colour::BLUE],
&render_handle,
);
self.material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.material.draw(&mut render_handle);
}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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
self.mouse_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.circle_material.add_rectangle(
Vec2 { x: 100.0, y: 100.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.defualt_material.add_rectangle(
Vec2 { x: 0.0, y: 200.0 },
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.mouse_material.draw(&mut render_handle);
self.circle_material.draw(&mut render_handle);
self.defualt_material.draw(&mut render_handle);
}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
fn render<'pass, 'others>(
&'others mut self,
mut render_handle: RenderInformation<'pass, 'others>,
) where
'others: 'pass,
{
let defualt_size = Vec2 { x: 50.0, y: 50.0 };
self.regular_material.add_rectangle(
Vec2 { x: 0.0, y: 0.0 },
defualt_size,
Colour::RED,
&render_handle,
);
self.regular_material.add_rectangle(
self.pos,
Vec2 { x: 100.0, y: 100.0 },
Colour::RED,
&render_handle,
);
self.texture_material.add_rectangle(
Vec2 { x: 0.0, y: 50.0 },
defualt_size,
Colour::WHITE,
&render_handle,
);
self.texture_material.add_rectangle_with_uv(
Vec2 { x: 0.0, y: 100.0 },
defualt_size,
Vec2 { x: 311.0, y: 311.0 },
Vec2 { x: 311.0, y: 311.0 },
Colour::WHITE,
&render_handle,
);
self.regular_material.add_rectangle_with_rotation(
Vec2 { x: 0.0, y: 150.0 },
defualt_size,
Colour::GREEN,
45.0,
&render_handle,
);
let points = [
Vec2 { x: 0.0, y: 300.0 },
Vec2 { x: 80.0, y: 290.0 },
Vec2 { x: 100.0, y: 400.0 },
Vec2 { x: 60.0, y: 400.0 },
];
let uvs = [
Vec2 { x: 0.0, y: 0.0 },
Vec2 { x: 1.0, y: 0.0 },
Vec2 { x: 1.0, y: 1.0 },
Vec2 { x: 0.0, y: 1.0 },
];
self.regular_material
.add_custom(points, uvs, 0.0, Colour::RED, &render_handle);
self.texture_material.draw(&mut render_handle);
self.regular_material.draw(&mut render_handle);
}