rendering is back, now to render the entities

This commit is contained in:
2021-02-02 01:15:37 -08:00
parent df13db5270
commit 60a950abe2
2 changed files with 72 additions and 45 deletions

View File

@@ -14,7 +14,7 @@ use winit::{
use crate::render::Renderer;
use bytemuck::__core::ops::Range;
use cgmath::Point3;
use cgmath::{Point3, Matrix4};
use std::rc::Rc;
use wgpu::Buffer;
use winit::platform::unix::x11::ffi::Time;
@@ -96,12 +96,23 @@ pub enum ShaderStage {
pub struct Position {
x: f32,
y: f32,
z: f32,
mx: Matrix4<f32>,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Color {
r: f32,
g: f32,
b: f32,
a: f32,
}
#[derive(Clone, Copy, Debug, PartialEq)]
pub struct Velocity {
dx: f32,
dy: f32,
rs: f32,
}
#[derive(Clone, Default, PartialEq, Eq, Hash, Copy, Debug)]
@@ -121,6 +132,7 @@ struct DirectionalLight {
struct Mesh {
index_buffer: Arc<Buffer>,
vertex_buffer: Arc<Buffer>,
uniform_buf: Arc<Buffer>,
}
fn main() {
@@ -203,7 +215,7 @@ fn main() {
// Load up the renderer (and the resources)
let mut renderer = render::Renderer::init(window);
let (plane_vertex_buffer, plane_index_buffer) = renderer.load_mesh_to_buffer("./resources/untitled.obj");
let (plane_vertex_buffer, plane_index_buffer, plane_uniform_buffer) = renderer.load_mesh_to_buffer("./resources/untitled.obj");
// This could be used for relationships between entities...???
let light_entity: Entity = world.push((
@@ -225,21 +237,29 @@ fn main() {
));
let mesh_entity: Entity = world.push((
cgmath::Point3 {
Position {
x: -5.0,
y: 7.0,
z: 10.0,
mx: OPENGL_TO_WGPU_MATRIX
},
Mesh {
index_buffer: plane_index_buffer,
vertex_buffer: plane_vertex_buffer,
}
uniform_buf: plane_uniform_buffer,
},
Color {
r: 1.0,
g: 0.5,
b: 0.5,
a: 1.0,
},
));
let entities: &[Entity] = world.extend(vec![
(Position { x: 0.0, y: 0.0 }, Velocity { dx: 0.0, dy: 0.0 }),
(Position { x: 1.0, y: 1.0 }, Velocity { dx: 0.0, dy: 0.0 }),
(Position { x: 2.0, y: 2.0 }, Velocity { dx: 0.0, dy: 0.0 }),
(Position { x: 0.0, y: 0.0, z: 0.0, mx: OPENGL_TO_WGPU_MATRIX }, Velocity { dx: 0.0, dy: 0.0, rs: 0.0 }),
(Position { x: 1.0, y: 1.0, z: 0.0, mx: OPENGL_TO_WGPU_MATRIX }, Velocity { dx: 0.0, dy: 0.0, rs: 0.0 }),
(Position { x: 2.0, y: 2.0, z: 0.0, mx: OPENGL_TO_WGPU_MATRIX }, Velocity { dx: 0.0, dy: 0.0, rs: 0.0 }),
]);
// Init, this wants the references to the buffers...
@@ -275,8 +295,8 @@ fn main() {
{
// ask for a redraw every 20 millis
if last_update_inst.elapsed() > Duration::from_millis(20) {
render_schedule.execute(&mut world, &mut resources);
//window.request_redraw();
resources.get_mut::<Renderer>().unwrap().window.request_redraw();
last_update_inst = Instant::now();
}
@@ -319,13 +339,13 @@ fn main() {
},
event::Event::RedrawRequested(_) => {
render_schedule.execute(&mut world, &mut resources);
//resources.get_mut::<Renderer>().unwrap().render();
}
_ => {}
}
});
//framework::run::<Example>("shadow");
}