engine/render: move Vertex out of vulkan
parent
e90ebae6f6
commit
88cb4cff6e
|
@ -24,9 +24,24 @@ use vulkano::sync::GpuFuture;
|
||||||
|
|
||||||
use crate::vulkan::data;
|
use crate::vulkan::data;
|
||||||
|
|
||||||
|
#[derive(Default, Copy, Clone, Debug)]
|
||||||
|
pub struct Vertex {
|
||||||
|
pub pos: [f32; 3],
|
||||||
|
pub normal: [f32; 3],
|
||||||
|
pub tex: [f32; 2],
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Vertex {
|
||||||
|
pub fn new(pos: [f32; 3], normal: [f32; 3], tex: [f32; 2]) -> Self {
|
||||||
|
Self {
|
||||||
|
pos, normal, tex,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct Mesh {
|
pub struct Mesh {
|
||||||
vertices: Arc<Vec<data::Vertex>>,
|
vertices: Arc<Vec<Vertex>>,
|
||||||
indices: Arc<Vec<u16>>,
|
indices: Arc<Vec<u16>>,
|
||||||
// vulkan buffers cache
|
// vulkan buffers cache
|
||||||
vulkan: Mutex<Option<data::VertexData>>,
|
vulkan: Mutex<Option<data::VertexData>>,
|
||||||
|
@ -34,7 +49,7 @@ pub struct Mesh {
|
||||||
|
|
||||||
impl Mesh {
|
impl Mesh {
|
||||||
pub fn new(
|
pub fn new(
|
||||||
vertices: Arc<Vec<data::Vertex>>,
|
vertices: Arc<Vec<Vertex>>,
|
||||||
indices: Arc<Vec<u16>>,
|
indices: Arc<Vec<u16>>,
|
||||||
) -> Self {
|
) -> Self {
|
||||||
Self {
|
Self {
|
||||||
|
@ -47,7 +62,7 @@ impl Mesh {
|
||||||
&self,
|
&self,
|
||||||
graphics_queue: Arc<vd::Queue>,
|
graphics_queue: Arc<vd::Queue>,
|
||||||
) -> (
|
) -> (
|
||||||
Arc<vb::ImmutableBuffer<[data::Vertex]>>,
|
Arc<vb::ImmutableBuffer<[Vertex]>>,
|
||||||
Arc<vb::ImmutableBuffer<[u16]>>,
|
Arc<vb::ImmutableBuffer<[u16]>>,
|
||||||
) {
|
) {
|
||||||
let mut cache = self.vulkan.lock().unwrap();
|
let mut cache = self.vulkan.lock().unwrap();
|
||||||
|
|
|
@ -16,26 +16,7 @@
|
||||||
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use vulkano::buffer as vb;
|
use crate::mesh::Vertex;
|
||||||
use vulkano::image as vm;
|
|
||||||
use vulkano::format::Format;
|
|
||||||
|
|
||||||
use cgmath as cgm;
|
|
||||||
|
|
||||||
#[derive(Default, Copy, Clone, Debug)]
|
|
||||||
pub struct Vertex {
|
|
||||||
pos: [f32; 3],
|
|
||||||
normal: [f32; 3],
|
|
||||||
tex: [f32; 2],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Vertex {
|
|
||||||
pub fn new(pos: [f32; 3], normal: [f32; 3], tex: [f32; 2]) -> Self {
|
|
||||||
Self {
|
|
||||||
pos, normal, tex,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
vulkano::impl_vertex!(Vertex, pos, normal, tex);
|
vulkano::impl_vertex!(Vertex, pos, normal, tex);
|
||||||
|
|
||||||
#[derive(Default, Copy, Clone)]
|
#[derive(Default, Copy, Clone)]
|
||||||
|
@ -44,7 +25,7 @@ pub struct Instance {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Instance {
|
impl Instance {
|
||||||
pub fn new(model: &cgm::Matrix4<f32>) -> Self {
|
pub fn new(model: &cgmath::Matrix4<f32>) -> Self {
|
||||||
let slice: &[f32; 16] = model.as_ref();
|
let slice: &[f32; 16] = model.as_ref();
|
||||||
Self {
|
Self {
|
||||||
model: slice.clone(),
|
model: slice.clone(),
|
||||||
|
@ -61,26 +42,26 @@ pub struct OmniLight {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct PushConstantObject {
|
pub struct PushConstantObject {
|
||||||
pub view: cgm::Matrix4<f32>,
|
pub view: cgmath::Matrix4<f32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug)]
|
#[derive(Copy, Clone, Debug)]
|
||||||
pub struct FragmentUniformBufferObject {
|
pub struct FragmentUniformBufferObject {
|
||||||
pub camera_pos: cgm::Vector4<f32>,
|
pub camera_pos: cgmath::Vector4<f32>,
|
||||||
pub omni_lights: [OmniLight; 4],
|
pub omni_lights: [OmniLight; 4],
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug)]
|
#[derive(Clone, Debug)]
|
||||||
pub struct Textures {
|
pub struct Textures {
|
||||||
// diffuse: RGB
|
// diffuse: RGB
|
||||||
pub diffuse: Arc<vm::ImmutableImage<Format>>,
|
pub diffuse: Arc<vulkano::image::ImmutableImage<vulkano::format::Format>>,
|
||||||
// roughness: R
|
// roughness: R
|
||||||
pub roughness: Arc<vm::ImmutableImage<Format>>,
|
pub roughness: Arc<vulkano::image::ImmutableImage<vulkano::format::Format>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct VertexData {
|
pub struct VertexData {
|
||||||
pub vbuffer: Arc<vb::ImmutableBuffer<[Vertex]>>,
|
pub vbuffer: Arc<vulkano::buffer::ImmutableBuffer<[Vertex]>>,
|
||||||
pub ibuffer: Arc<vb::ImmutableBuffer<[u16]>>,
|
pub ibuffer: Arc<vulkano::buffer::ImmutableBuffer<[u16]>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl std::fmt::Debug for VertexData {
|
impl std::fmt::Debug for VertexData {
|
||||||
|
|
|
@ -30,6 +30,7 @@ use vulkano::pipeline::shader as vps;
|
||||||
use vulkano::pipeline::vertex as vpv;
|
use vulkano::pipeline::vertex as vpv;
|
||||||
use vulkano::sampler as vs;
|
use vulkano::sampler as vs;
|
||||||
|
|
||||||
|
use crate::mesh::Vertex;
|
||||||
use crate::vulkan::data;
|
use crate::vulkan::data;
|
||||||
use crate::vulkan::shaders;
|
use crate::vulkan::shaders;
|
||||||
use crate::vulkan::pipeline;
|
use crate::vulkan::pipeline;
|
||||||
|
@ -180,7 +181,7 @@ impl Forward {
|
||||||
// against most existing software and practices. This might bite us in the ass at some
|
// against most existing software and practices. This might bite us in the ass at some
|
||||||
// point in the future.
|
// point in the future.
|
||||||
let pipeline = Arc::new(vp::GraphicsPipeline::start()
|
let pipeline = Arc::new(vp::GraphicsPipeline::start()
|
||||||
.vertex_input(vpv::OneVertexOneInstanceDefinition::<data::Vertex, data::Instance>::new())
|
.vertex_input(vpv::OneVertexOneInstanceDefinition::<Vertex, data::Instance>::new())
|
||||||
.vertex_shader(vertex_shader.entry_point(), ())
|
.vertex_shader(vertex_shader.entry_point(), ())
|
||||||
.triangle_list()
|
.triangle_list()
|
||||||
.primitive_restart(false)
|
.primitive_restart(false)
|
||||||
|
|
56
hsvr/main.rs
56
hsvr/main.rs
|
@ -5,8 +5,6 @@ use ecs_macros::Access;
|
||||||
use engine::{
|
use engine::{
|
||||||
globals, input, physics, render, scripting, util,
|
globals, input, physics, render, scripting, util,
|
||||||
};
|
};
|
||||||
use engine::render::material;
|
|
||||||
use engine::render::vulkan::data;
|
|
||||||
|
|
||||||
struct Main {
|
struct Main {
|
||||||
light1: ecs::EntityID,
|
light1: ecs::EntityID,
|
||||||
|
@ -21,35 +19,35 @@ impl Main {
|
||||||
let mut rm = render::resource::Manager::new();
|
let mut rm = render::resource::Manager::new();
|
||||||
let mesh = {
|
let mesh = {
|
||||||
let vertices = Arc::new(vec![
|
let vertices = Arc::new(vec![
|
||||||
data::Vertex::new([-0.5, -0.5, 0.5], [ 0.0, 0.0, 1.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, 0.5], [ 0.0, 0.0, 1.0], [1.0, 0.0]),
|
||||||
data::Vertex::new([ 0.5, -0.5, 0.5], [ 0.0, 0.0, 1.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, 0.5], [ 0.0, 0.0, 1.0], [0.0, 0.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, 0.5], [ 0.0, 0.0, 1.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, 0.5], [ 0.0, 0.0, 1.0], [0.0, 1.0]),
|
||||||
data::Vertex::new([-0.5, 0.5, 0.5], [ 0.0, 0.0, 1.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, 0.5], [ 0.0, 0.0, 1.0], [1.0, 1.0]),
|
||||||
|
|
||||||
data::Vertex::new([ 0.5, -0.5, -0.5], [ 1.0, 0.0, 0.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, -0.5], [ 1.0, 0.0, 0.0], [0.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, -0.5], [ 1.0, 0.0, 0.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, -0.5], [ 1.0, 0.0, 0.0], [1.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, 0.5], [ 1.0, 0.0, 0.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, 0.5], [ 1.0, 0.0, 0.0], [1.0, 0.0]),
|
||||||
data::Vertex::new([ 0.5, -0.5, 0.5], [ 1.0, 0.0, 0.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, 0.5], [ 1.0, 0.0, 0.0], [0.0, 0.0]),
|
||||||
|
|
||||||
data::Vertex::new([-0.5, -0.5, -0.5], [-1.0, 0.0, 0.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, -0.5], [-1.0, 0.0, 0.0], [1.0, 1.0]),
|
||||||
data::Vertex::new([-0.5, 0.5, -0.5], [-1.0, 0.0, 0.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, -0.5], [-1.0, 0.0, 0.0], [0.0, 1.0]),
|
||||||
data::Vertex::new([-0.5, 0.5, 0.5], [-1.0, 0.0, 0.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, 0.5], [-1.0, 0.0, 0.0], [0.0, 0.0]),
|
||||||
data::Vertex::new([-0.5, -0.5, 0.5], [-1.0, 0.0, 0.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, 0.5], [-1.0, 0.0, 0.0], [1.0, 0.0]),
|
||||||
|
|
||||||
data::Vertex::new([-0.5, -0.5, -0.5], [ 0.0, -1.0, 0.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, -0.5], [ 0.0, -1.0, 0.0], [0.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, -0.5, -0.5], [ 0.0, -1.0, 0.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, -0.5], [ 0.0, -1.0, 0.0], [1.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, -0.5, 0.5], [ 0.0, -1.0, 0.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, 0.5], [ 0.0, -1.0, 0.0], [1.0, 0.0]),
|
||||||
data::Vertex::new([-0.5, -0.5, 0.5], [ 0.0, -1.0, 0.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, 0.5], [ 0.0, -1.0, 0.0], [0.0, 0.0]),
|
||||||
|
|
||||||
data::Vertex::new([-0.5, 0.5, -0.5], [ 0.0, 1.0, 0.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, -0.5], [ 0.0, 1.0, 0.0], [1.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, -0.5], [ 0.0, 1.0, 0.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, -0.5], [ 0.0, 1.0, 0.0], [0.0, 1.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, 0.5], [ 0.0, 1.0, 0.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, 0.5], [ 0.0, 1.0, 0.0], [0.0, 0.0]),
|
||||||
data::Vertex::new([-0.5, 0.5, 0.5], [ 0.0, 1.0, 0.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, 0.5], [ 0.0, 1.0, 0.0], [1.0, 0.0]),
|
||||||
|
|
||||||
data::Vertex::new([-0.5, -0.5, -0.5], [ 0.0, 0.0, -1.0], [0.0, 0.0]),
|
render::mesh::Vertex::new([-0.5, -0.5, -0.5], [ 0.0, 0.0, -1.0], [0.0, 0.0]),
|
||||||
data::Vertex::new([ 0.5, -0.5, -0.5], [ 0.0, 0.0, -1.0], [1.0, 0.0]),
|
render::mesh::Vertex::new([ 0.5, -0.5, -0.5], [ 0.0, 0.0, -1.0], [1.0, 0.0]),
|
||||||
data::Vertex::new([ 0.5, 0.5, -0.5], [ 0.0, 0.0, -1.0], [1.0, 1.0]),
|
render::mesh::Vertex::new([ 0.5, 0.5, -0.5], [ 0.0, 0.0, -1.0], [1.0, 1.0]),
|
||||||
data::Vertex::new([-0.5, 0.5, -0.5], [ 0.0, 0.0, -1.0], [0.0, 1.0]),
|
render::mesh::Vertex::new([-0.5, 0.5, -0.5], [ 0.0, 0.0, -1.0], [0.0, 1.0]),
|
||||||
]);
|
]);
|
||||||
let indices = Arc::new(vec![
|
let indices = Arc::new(vec![
|
||||||
0, 1, 2, 2, 3, 0,
|
0, 1, 2, 2, 3, 0,
|
||||||
|
@ -66,9 +64,9 @@ impl Main {
|
||||||
rm.add(render::Mesh::new(vertices, indices), Some("cube"))
|
rm.add(render::Mesh::new(vertices, indices), Some("cube"))
|
||||||
};
|
};
|
||||||
|
|
||||||
let material = rm.add(material::PBRMaterialBuilder {
|
let material = rm.add(render::material::PBRMaterialBuilder {
|
||||||
diffuse: material::Texture::from_image(String::from("//assets/test-128px.png")),
|
diffuse: render::material::Texture::from_image(String::from("//assets/test-128px.png")),
|
||||||
roughness: material::Texture::from_image(String::from("//assets/test-128px-roughness.png")),
|
roughness: render::material::Texture::from_image(String::from("//assets/test-128px-roughness.png")),
|
||||||
}.build(), Some("test-128px"));
|
}.build(), Some("test-128px"));
|
||||||
|
|
||||||
let light = rm.add(render::Light::omni_test(), Some("omni"));
|
let light = rm.add(render::Light::omni_test(), Some("omni"));
|
||||||
|
|
Loading…
Reference in New Issue