Modules and stuff
This commit is contained in:
@@ -1,6 +1,8 @@
|
|||||||
use serde_derive::{Serialize, Deserialize};
|
|
||||||
use toml;
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
|
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use toml;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
#[derive(Debug, Serialize, Deserialize, Clone, Copy)]
|
||||||
pub struct LogConfigInput {
|
pub struct LogConfigInput {
|
||||||
pub mouse_motion: bool,
|
pub mouse_motion: bool,
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use std::{error::Error, io::{BufReader, BufWriter}};
|
use std::{error::Error, io::{BufReader, BufWriter}};
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
|
|
||||||
use serde_derive::{Deserialize, Serialize};
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::{TestGame, gameobject::GameObjectHandle, vulkan::{MeshHandle, VulkanRenderer}};
|
use crate::{vulkan::{MeshHandle, VulkanRenderer, gameobject::GameObjectHandle}};
|
||||||
|
use crate::game::TestGame;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize)]
|
#[derive(Debug, Serialize, Deserialize)]
|
||||||
struct MeshJson {
|
struct MeshJson {
|
||||||
155
src/game/mod.rs
Normal file
155
src/game/mod.rs
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
|
||||||
|
use winit::event::Event;
|
||||||
|
|
||||||
|
use level::{load_level, save_level};
|
||||||
|
use player::Player;
|
||||||
|
|
||||||
|
use crate::config::{LogConfig};
|
||||||
|
use crate::input::InputState;
|
||||||
|
use crate::vulkan::{Game, MeshHandle, VulkanRenderer};
|
||||||
|
use crate::vulkan::gameobject::{GameObject, GameObjectHandle, Updatable};
|
||||||
|
use crate::vulkan::mesh;
|
||||||
|
use crate::vulkan::pipelines::vs::ty::ObjectUniformData;
|
||||||
|
|
||||||
|
pub mod player;
|
||||||
|
mod level;
|
||||||
|
|
||||||
|
pub struct TestGame {
|
||||||
|
pub input: InputState,
|
||||||
|
pub player: Player,
|
||||||
|
pub game_objects: Vec<GameObjectHandle>,
|
||||||
|
pub log_config: LogConfig,
|
||||||
|
pub texture_index_counter: usize,
|
||||||
|
pub last_time: f32,
|
||||||
|
pub components: Vec<Box<dyn Updatable>>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Game for TestGame {
|
||||||
|
fn on_window_event(self: &mut Self, event: &Event<()>) {
|
||||||
|
self.input.on_window_event(event);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn update(self: &mut Self, renderer: &mut VulkanRenderer) -> ObjectUniformData {
|
||||||
|
// Input and timing
|
||||||
|
self.input.frame_start();
|
||||||
|
let time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32;
|
||||||
|
let frame_time = time - self.last_time;
|
||||||
|
|
||||||
|
// Component update
|
||||||
|
let input = &self.input;
|
||||||
|
let components = &mut self.components;
|
||||||
|
components.iter_mut().for_each(|component| {
|
||||||
|
component.update(frame_time, &input, renderer);
|
||||||
|
});
|
||||||
|
|
||||||
|
// User interaction
|
||||||
|
if self.input.button_just_released("quit") {
|
||||||
|
renderer.game_data.shutdown = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.input.button_just_pressed("reload_shaders") {
|
||||||
|
renderer.game_data.recreate_pipeline = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.input.button_just_pressed("quicksave") {
|
||||||
|
save_level("levels/test.lvl", self, renderer).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.input.button_just_pressed("quickload") {
|
||||||
|
self.clear_level(renderer);
|
||||||
|
load_level("levels/test.lvl", self, renderer).unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
|
if self.input.button_down("print_framerate") {
|
||||||
|
println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Custom game object stuff
|
||||||
|
let light_pos = self.player.camera.position * -1.0;
|
||||||
|
self.player.update(frame_time, &self.input, renderer);
|
||||||
|
|
||||||
|
// End frame
|
||||||
|
self.last_time = time;
|
||||||
|
self.input.frame_end();
|
||||||
|
|
||||||
|
ObjectUniformData {
|
||||||
|
view: self.player.camera.view.into(),
|
||||||
|
projection: self.player.camera.proj.into(),
|
||||||
|
time,
|
||||||
|
light_position: light_pos.into(),
|
||||||
|
camera_position: self.player.camera.position.into(),
|
||||||
|
_dummy0: [0; 12],
|
||||||
|
_dummy1: [0; 4],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl TestGame {
|
||||||
|
pub fn new(toml_path: &str, log_config: LogConfig) -> TestGame {
|
||||||
|
TestGame {
|
||||||
|
input: InputState::new(toml_path, log_config),
|
||||||
|
player: Player::new(),
|
||||||
|
game_objects: vec![],
|
||||||
|
log_config,
|
||||||
|
texture_index_counter: 0,
|
||||||
|
last_time: 0.0,
|
||||||
|
components: vec![],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
||||||
|
// let plane_mesh = self.load_gltf(renderer, "models/plane.gltf");
|
||||||
|
// self.add_game_object(renderer, plane_mesh[0].clone());
|
||||||
|
load_level("levels/test.lvl", self, renderer).unwrap();
|
||||||
|
println!("Game loaded!");
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn offset_texture_id(&mut self, local_tex_id: Option<usize>) -> usize {
|
||||||
|
match local_tex_id {
|
||||||
|
Some(local_id) => local_id + self.texture_index_counter,
|
||||||
|
None => 0,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn load_gltf(&mut self, renderer: &mut VulkanRenderer, gltf_path: &str) -> Vec<MeshHandle> {
|
||||||
|
let mut mesh_handles = Vec::new();
|
||||||
|
|
||||||
|
// Load file
|
||||||
|
let (meshes, textures) = mesh::load_mesh(gltf_path, self.log_config.mesh_load_info).unwrap();
|
||||||
|
|
||||||
|
for cpu_mesh in meshes.into_iter() {
|
||||||
|
// Convert file texture id to game texture id
|
||||||
|
let diffuse_id = self.offset_texture_id(cpu_mesh.local_texture_index);
|
||||||
|
let normal_id = self.offset_texture_id(cpu_mesh.local_normal_map_index);
|
||||||
|
|
||||||
|
// Upload mesh
|
||||||
|
let mesh_id = renderer.upload_mesh(cpu_mesh, gltf_path.to_string());
|
||||||
|
let mesh_handle = MeshHandle {
|
||||||
|
index: mesh_id,
|
||||||
|
diffuse_handle: diffuse_id,
|
||||||
|
normal_handle: normal_id,
|
||||||
|
original_path: gltf_path.to_string()
|
||||||
|
};
|
||||||
|
mesh_handles.push(mesh_handle);
|
||||||
|
}
|
||||||
|
|
||||||
|
textures.iter().for_each(|tex| {
|
||||||
|
renderer.upload_texture(tex);
|
||||||
|
self.texture_index_counter += 1;
|
||||||
|
});
|
||||||
|
mesh_handles
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn add_game_object(&mut self, renderer: &mut VulkanRenderer, mesh: MeshHandle) -> GameObjectHandle {
|
||||||
|
let obj = GameObject::new(mesh);
|
||||||
|
let obj_handle = renderer.add_game_object(obj, 0);
|
||||||
|
self.game_objects.push(obj_handle);
|
||||||
|
self.game_objects.last().unwrap().clone()
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn clear_level(&mut self, renderer: &mut VulkanRenderer) {
|
||||||
|
self.game_objects.clear();
|
||||||
|
self.texture_index_counter = 0;
|
||||||
|
renderer.clear_all();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
|
use cgmath::{Deg, InnerSpace, Matrix4, One, Quaternion, Rad, Rotation, Rotation3, SquareMatrix, vec3, Vector3};
|
||||||
|
|
||||||
|
use crate::game::player::PlayerMovementMode::{FirstPerson, Flying};
|
||||||
|
|
||||||
|
use crate::input::InputState;
|
||||||
use crate::MeshHandle;
|
use crate::MeshHandle;
|
||||||
use cgmath::{vec3, One, SquareMatrix, Deg, Rad, Quaternion, Vector3, Matrix4, Rotation, Rotation3, InnerSpace};
|
use crate::vulkan::{
|
||||||
use crate::{
|
gameobject::Updatable,
|
||||||
VulkanRenderer,
|
VulkanRenderer
|
||||||
input::InputState,
|
|
||||||
gameobject::Updatable
|
|
||||||
};
|
};
|
||||||
use crate::player::PlayerMovementMode::{FirstPerson, Flying};
|
|
||||||
|
|
||||||
pub struct Camera {
|
pub struct Camera {
|
||||||
pub fov_y: f32,
|
pub fov_y: f32,
|
||||||
11
src/input.rs
11
src/input.rs
@@ -1,17 +1,14 @@
|
|||||||
#![allow(deprecated)]
|
#![allow(deprecated)]
|
||||||
|
|
||||||
use winit::event::{ScanCode, MouseButton, ElementState, MouseScrollDelta, Event, WindowEvent, DeviceEvent, ModifiersState};
|
|
||||||
|
|
||||||
use std::collections::{HashMap, HashSet};
|
use std::collections::{HashMap, HashSet};
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::iter::FromIterator;
|
use std::iter::FromIterator;
|
||||||
|
|
||||||
use toml;
|
|
||||||
|
|
||||||
use serde_derive::{Serialize, Deserialize};
|
|
||||||
|
|
||||||
use gilrs;
|
use gilrs;
|
||||||
use gilrs::{Gilrs, EventType};
|
use gilrs::{EventType, Gilrs};
|
||||||
|
use serde_derive::{Deserialize, Serialize};
|
||||||
|
use toml;
|
||||||
|
use winit::event::{DeviceEvent, ElementState, Event, ModifiersState, MouseButton, MouseScrollDelta, ScanCode, WindowEvent};
|
||||||
|
|
||||||
use crate::config::LogConfig;
|
use crate::config::LogConfig;
|
||||||
|
|
||||||
|
|||||||
169
src/main.rs
169
src/main.rs
@@ -1,172 +1,19 @@
|
|||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use cgmath::{Matrix4, Vector3, Vector4};
|
|
||||||
use level::{load_level, save_level};
|
use vulkan::gameobject::GameObject;
|
||||||
use winit::event::Event;
|
|
||||||
|
|
||||||
|
|
||||||
use crate::config::{LogConfig, RenderConfig};
|
use crate::config::{LogConfig, RenderConfig};
|
||||||
use crate::gameobject::{GameObject, GameObjectHandle, Updatable};
|
use crate::game::TestGame;
|
||||||
use crate::input::InputState;
|
|
||||||
use crate::player::Player;
|
use crate::vulkan::{LinePoint, MeshHandle, VulkanRenderer};
|
||||||
use crate::vulkan::{Game, LinePoint, MeshHandle, VulkanRenderer};
|
|
||||||
use crate::pipelines::vs::ty::ObjectUniformData;
|
|
||||||
|
|
||||||
mod vulkan;
|
mod vulkan;
|
||||||
mod input;
|
mod input;
|
||||||
mod config;
|
mod config;
|
||||||
mod mesh;
|
mod game;
|
||||||
mod gameobject;
|
|
||||||
mod player;
|
|
||||||
mod pipelines;
|
|
||||||
mod level;
|
|
||||||
|
|
||||||
pub struct TestGame {
|
|
||||||
input: InputState,
|
|
||||||
player: Player,
|
|
||||||
game_objects: Vec<GameObjectHandle>,
|
|
||||||
log_config: LogConfig,
|
|
||||||
texture_index_counter: usize,
|
|
||||||
last_time: f32,
|
|
||||||
components: Vec<Box<dyn Updatable>>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestGame {
|
|
||||||
fn new(toml_path: &str, log_config: LogConfig) -> TestGame {
|
|
||||||
TestGame {
|
|
||||||
input: InputState::new(toml_path, log_config),
|
|
||||||
player: Player::new(),
|
|
||||||
game_objects: vec![],
|
|
||||||
log_config,
|
|
||||||
texture_index_counter: 0,
|
|
||||||
last_time: 0.0,
|
|
||||||
components: vec![],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Game for TestGame {
|
|
||||||
fn on_window_event(self: &mut Self, event: &Event<()>) {
|
|
||||||
self.input.on_window_event(event);
|
|
||||||
}
|
|
||||||
|
|
||||||
fn update(self: &mut Self, renderer: &mut VulkanRenderer) -> ObjectUniformData {
|
|
||||||
// Input and timing
|
|
||||||
self.input.frame_start();
|
|
||||||
let time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32;
|
|
||||||
let frame_time = time - self.last_time;
|
|
||||||
|
|
||||||
// Component update
|
|
||||||
let input = &self.input;
|
|
||||||
let components = &mut self.components;
|
|
||||||
components.iter_mut().for_each(|component| {
|
|
||||||
component.update(frame_time, &input, renderer);
|
|
||||||
});
|
|
||||||
|
|
||||||
// User interaction
|
|
||||||
if self.input.button_just_released("quit") {
|
|
||||||
renderer.game_data.shutdown = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.input.button_just_pressed("reload_shaders") {
|
|
||||||
renderer.game_data.recreate_pipeline = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.input.button_just_pressed("quicksave") {
|
|
||||||
save_level("levels/test.lvl", self, renderer).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.input.button_just_pressed("quickload") {
|
|
||||||
self.clear_level(renderer);
|
|
||||||
load_level("levels/test.lvl", self, renderer).unwrap();
|
|
||||||
}
|
|
||||||
|
|
||||||
if self.input.button_down("print_framerate") {
|
|
||||||
println!("{:.0} ms / {:.0} FPS", frame_time * 1000.0, 1.0 / frame_time);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Custom game object stuff
|
|
||||||
let light_pos = self.player.camera.position * -1.0;
|
|
||||||
self.player.update(frame_time, &self.input, renderer);
|
|
||||||
|
|
||||||
// End frame
|
|
||||||
self.last_time = time;
|
|
||||||
self.input.frame_end();
|
|
||||||
|
|
||||||
ObjectUniformData {
|
|
||||||
view: self.player.camera.view.into(),
|
|
||||||
projection: self.player.camera.proj.into(),
|
|
||||||
time,
|
|
||||||
light_position: light_pos.into(),
|
|
||||||
camera_position: self.player.camera.position.into(),
|
|
||||||
_dummy0: [0; 12],
|
|
||||||
_dummy1: [0; 4],
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn _matrix_vector_mul(matrix: &Matrix4<f32>, vector: &Vector3<f32>) -> Vector3<f32> {
|
|
||||||
let v4 = Vector4::new(vector.x, vector.y, vector.z, 1.0);
|
|
||||||
let out = matrix * v4;
|
|
||||||
Vector3::new(out.x, out.y, out.z)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl TestGame {
|
|
||||||
fn game_start(self: &mut Self, renderer: &mut VulkanRenderer) {
|
|
||||||
// let plane_mesh = self.load_gltf(renderer, "models/plane.gltf");
|
|
||||||
// self.add_game_object(renderer, plane_mesh[0].clone());
|
|
||||||
load_level("levels/test.lvl", self, renderer).unwrap();
|
|
||||||
println!("Game loaded!");
|
|
||||||
}
|
|
||||||
|
|
||||||
fn offset_texture_id(&mut self, local_tex_id: Option<usize>) -> usize {
|
|
||||||
match local_tex_id {
|
|
||||||
Some(local_id) => local_id + self.texture_index_counter,
|
|
||||||
None => 0,
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load_gltf(&mut self, renderer: &mut VulkanRenderer, gltf_path: &str) -> Vec<MeshHandle> {
|
|
||||||
let mut mesh_handles = Vec::new();
|
|
||||||
|
|
||||||
// Load file
|
|
||||||
let (meshes, textures) = mesh::load_mesh(gltf_path, self.log_config.mesh_load_info).unwrap();
|
|
||||||
|
|
||||||
for cpu_mesh in meshes.into_iter() {
|
|
||||||
// Convert file texture id to game texture id
|
|
||||||
let diffuse_id = self.offset_texture_id(cpu_mesh.local_texture_index);
|
|
||||||
let normal_id = self.offset_texture_id(cpu_mesh.local_normal_map_index);
|
|
||||||
|
|
||||||
// Upload mesh
|
|
||||||
let mesh_id = renderer.upload_mesh(cpu_mesh, gltf_path.to_string());
|
|
||||||
let mesh_handle = MeshHandle {
|
|
||||||
index: mesh_id,
|
|
||||||
diffuse_handle: diffuse_id,
|
|
||||||
normal_handle: normal_id,
|
|
||||||
original_path: gltf_path.to_string()
|
|
||||||
};
|
|
||||||
mesh_handles.push(mesh_handle);
|
|
||||||
}
|
|
||||||
|
|
||||||
textures.iter().for_each(|tex| {
|
|
||||||
renderer.upload_texture(tex);
|
|
||||||
self.texture_index_counter += 1;
|
|
||||||
});
|
|
||||||
mesh_handles
|
|
||||||
}
|
|
||||||
|
|
||||||
fn add_game_object(&mut self, renderer: &mut VulkanRenderer, mesh: MeshHandle) -> GameObjectHandle {
|
|
||||||
let obj = GameObject::new(mesh);
|
|
||||||
let obj_handle = renderer.add_game_object(obj, 0);
|
|
||||||
self.game_objects.push(obj_handle);
|
|
||||||
self.game_objects.last().unwrap().clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn clear_level(&mut self, renderer: &mut VulkanRenderer) {
|
|
||||||
self.game_objects.clear();
|
|
||||||
self.texture_index_counter = 0;
|
|
||||||
renderer.clear_all();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
let log_config = LogConfig::from_file("config/log.toml");
|
let log_config = LogConfig::from_file("config/log.toml");
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use crate::vulkan::{RendererDescriptorSets, TextureHandle};
|
|
||||||
use cgmath::{Matrix4, Vector3, Quaternion, Euler, Deg};
|
use cgmath::{Deg, Euler, Matrix4, Quaternion, Vector3};
|
||||||
use crate::vulkan::{MeshHandle, VulkanRenderer};
|
|
||||||
use crate::input::InputState;
|
use crate::input::InputState;
|
||||||
|
use crate::vulkan::{RendererDescriptorSets, TextureHandle};
|
||||||
|
use crate::vulkan::{MeshHandle, VulkanRenderer};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct GameObject {
|
pub struct GameObject {
|
||||||
@@ -3,7 +3,7 @@ use std::time::SystemTime;
|
|||||||
use gltf::Error;
|
use gltf::Error;
|
||||||
use gltf::mesh::util::{ReadJoints, ReadNormals, ReadPositions, ReadTangents, ReadTexCoords, ReadWeights};
|
use gltf::mesh::util::{ReadJoints, ReadNormals, ReadPositions, ReadTangents, ReadTexCoords, ReadWeights};
|
||||||
|
|
||||||
use crate::mesh::LoadError::{GltfError, MeshDataMissing, NoIndices};
|
use crate::vulkan::mesh::LoadError::{GltfError, MeshDataMissing, NoIndices};
|
||||||
use crate::vulkan::Vertex;
|
use crate::vulkan::Vertex;
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@@ -1,18 +1,16 @@
|
|||||||
use crate::pipelines::{Drawcall, LineShader};
|
|
||||||
use crate::pipelines::DefaultShader;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::SystemTime;
|
use std::time::SystemTime;
|
||||||
|
|
||||||
use cgmath::{Matrix4, SquareMatrix};
|
use cgmath::{Matrix4, SquareMatrix};
|
||||||
use image::{ImageBuffer, Rgb, Rgba};
|
use image::{ImageBuffer, Rgb, Rgba};
|
||||||
use image::buffer::ConvertBuffer;
|
use image::buffer::ConvertBuffer;
|
||||||
use vulkano::{command_buffer::CommandBuffer, buffer::{BufferUsage, CpuAccessibleBuffer}, image::{ImageLayout, MipmapsCount}};
|
use vulkano::{buffer::{BufferUsage, CpuAccessibleBuffer}, command_buffer::CommandBuffer, image::{ImageLayout, MipmapsCount}};
|
||||||
use vulkano::command_buffer::{AutoCommandBuffer, AutoCommandBufferBuilder, DynamicState};
|
use vulkano::command_buffer::{AutoCommandBuffer, AutoCommandBufferBuilder, DynamicState};
|
||||||
use vulkano::descriptor::DescriptorSet;
|
use vulkano::descriptor::DescriptorSet;
|
||||||
use vulkano::device::{Device, DeviceExtensions, Queue};
|
use vulkano::device::{Device, DeviceExtensions, Queue};
|
||||||
use vulkano::format::{ClearValue, Format};
|
use vulkano::format::{ClearValue, Format};
|
||||||
use vulkano::framebuffer::{Framebuffer, FramebufferAbstract, RenderPassAbstract};
|
use vulkano::framebuffer::{Framebuffer, FramebufferAbstract, RenderPassAbstract};
|
||||||
use vulkano::image::{AttachmentImage, Dimensions, ImageUsage, ImmutableImage, SwapchainImage, ImageViewAccess};
|
use vulkano::image::{AttachmentImage, Dimensions, ImageUsage, ImageViewAccess, ImmutableImage, SwapchainImage};
|
||||||
use vulkano::instance::{ApplicationInfo, Instance, InstanceExtensions, PhysicalDevice, Version};
|
use vulkano::instance::{ApplicationInfo, Instance, InstanceExtensions, PhysicalDevice, Version};
|
||||||
use vulkano::instance::debug::{DebugCallback, MessageSeverity, MessageType};
|
use vulkano::instance::debug::{DebugCallback, MessageSeverity, MessageType};
|
||||||
use vulkano::pipeline::viewport::Viewport;
|
use vulkano::pipeline::viewport::Viewport;
|
||||||
@@ -26,13 +24,19 @@ use winit::event::{Event, WindowEvent};
|
|||||||
use winit::event_loop::{ControlFlow, EventLoop};
|
use winit::event_loop::{ControlFlow, EventLoop};
|
||||||
use winit::window::{Window, WindowBuilder};
|
use winit::window::{Window, WindowBuilder};
|
||||||
|
|
||||||
use crate::pipelines::{line_vs::ty::LinePushConstants};
|
use mesh::CPUMesh;
|
||||||
use crate::pipelines::vs::ty::PushConstants;
|
use pipelines::{Drawcall, LineShader};
|
||||||
|
use pipelines::{line_vs::ty::LinePushConstants};
|
||||||
|
use pipelines::DefaultShader;
|
||||||
|
use pipelines::vs;
|
||||||
|
use pipelines::vs::ty::PushConstants;
|
||||||
|
|
||||||
use crate::pipelines::vs;
|
|
||||||
use crate::{gameobject::{GameObject, GameObjectHandle}};
|
|
||||||
use crate::mesh::CPUMesh;
|
|
||||||
use crate::config::RenderConfig;
|
use crate::config::RenderConfig;
|
||||||
|
use crate::vulkan::{gameobject::{GameObject, GameObjectHandle}};
|
||||||
|
|
||||||
|
pub mod pipelines;
|
||||||
|
pub mod gameobject;
|
||||||
|
pub mod mesh;
|
||||||
|
|
||||||
const VALIDATION_LAYERS: &[&str] = &[
|
const VALIDATION_LAYERS: &[&str] = &[
|
||||||
"VK_LAYER_KHRONOS_validation"
|
"VK_LAYER_KHRONOS_validation"
|
||||||
@@ -1,15 +1,17 @@
|
|||||||
use vulkano::command_buffer::DynamicState;
|
|
||||||
use crate::vulkan::GameData;
|
|
||||||
use crate::vulkan::{LinePoint, Vertex};
|
|
||||||
use crate::GameObject;
|
|
||||||
use vulkano::{command_buffer::AutoCommandBufferBuilder, descriptor::descriptor_set::PersistentDescriptorSet};
|
|
||||||
use crate::VulkanRenderer;
|
|
||||||
use vulkano::pipeline::{GraphicsPipeline};
|
|
||||||
use vulkano::framebuffer::Subpass;
|
|
||||||
use vulkano::pipeline::GraphicsPipelineAbstract;
|
|
||||||
use vulkano::framebuffer::RenderPassAbstract;
|
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use vulkano::{command_buffer::AutoCommandBufferBuilder, descriptor::descriptor_set::PersistentDescriptorSet};
|
||||||
|
use vulkano::command_buffer::DynamicState;
|
||||||
use vulkano::device::Device;
|
use vulkano::device::Device;
|
||||||
|
use vulkano::framebuffer::RenderPassAbstract;
|
||||||
|
use vulkano::framebuffer::Subpass;
|
||||||
|
use vulkano::pipeline::GraphicsPipeline;
|
||||||
|
use vulkano::pipeline::GraphicsPipelineAbstract;
|
||||||
|
|
||||||
|
use crate::GameObject;
|
||||||
|
use crate::vulkan::{LinePoint, Vertex};
|
||||||
|
use crate::vulkan::GameData;
|
||||||
|
use crate::VulkanRenderer;
|
||||||
|
|
||||||
type RP = Arc<dyn RenderPassAbstract + Send + Sync>;
|
type RP = Arc<dyn RenderPassAbstract + Send + Sync>;
|
||||||
type GP = Arc<dyn GraphicsPipelineAbstract + Send + Sync>;
|
type GP = Arc<dyn GraphicsPipelineAbstract + Send + Sync>;
|
||||||
@@ -68,8 +70,21 @@ impl DefaultShader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Drawcall for DefaultShader {
|
impl Drawcall for DefaultShader {
|
||||||
fn recreate_pipeline(self: &mut Self, device: Arc<Device>, render_pass: RP) {
|
fn draw(self: &Self, builder: &mut AutoCommandBufferBuilder, fb_index: usize, game_data: &GameData, dynamic_state: &DynamicState) {
|
||||||
self.pipeline = Self::create_pipeline(device, render_pass);
|
for i in 0..game_data.game_objects.len() {
|
||||||
|
let game_object = &game_data.game_objects[i];
|
||||||
|
let mesh = &game_data.meshes[game_object.mesh_index];
|
||||||
|
let mut push_constants = game_data.push_constants.clone();
|
||||||
|
push_constants.model = game_object.get_model_matrix().into();
|
||||||
|
|
||||||
|
builder.draw_indexed(
|
||||||
|
self.pipeline.clone(),
|
||||||
|
dynamic_state,
|
||||||
|
vec![mesh.vertex_buffer.clone()],
|
||||||
|
mesh.index_buffer.clone(),
|
||||||
|
game_object.descriptor_sets[fb_index].clone(),
|
||||||
|
push_constants).unwrap();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_descriptor_set(self: &Self, game_object: &mut GameObject, renderer: &VulkanRenderer) {
|
fn create_descriptor_set(self: &Self, game_object: &mut GameObject, renderer: &VulkanRenderer) {
|
||||||
@@ -91,21 +106,8 @@ impl Drawcall for DefaultShader {
|
|||||||
}).collect();
|
}).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn draw(self: &Self, builder: &mut AutoCommandBufferBuilder, fb_index: usize, game_data: &GameData, dynamic_state: &DynamicState) {
|
fn recreate_pipeline(self: &mut Self, device: Arc<Device>, render_pass: RP) {
|
||||||
for i in 0..game_data.game_objects.len() {
|
self.pipeline = Self::create_pipeline(device, render_pass);
|
||||||
let game_object = &game_data.game_objects[i];
|
|
||||||
let mesh = &game_data.meshes[game_object.mesh_index];
|
|
||||||
let mut push_constants = game_data.push_constants.clone();
|
|
||||||
push_constants.model = game_object.get_model_matrix().into();
|
|
||||||
|
|
||||||
builder.draw_indexed(
|
|
||||||
self.pipeline.clone(),
|
|
||||||
dynamic_state,
|
|
||||||
vec![mesh.vertex_buffer.clone()],
|
|
||||||
mesh.index_buffer.clone(),
|
|
||||||
game_object.descriptor_sets[fb_index].clone(),
|
|
||||||
push_constants).unwrap();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_pipeline(self: &Self) -> &GP {
|
fn get_pipeline(self: &Self) -> &GP {
|
||||||
Reference in New Issue
Block a user