This commit is contained in:
2019-08-13 17:46:45 +02:00
parent c11ed5c897
commit 1deb7c7e47
2 changed files with 13 additions and 18 deletions

View File

@@ -44,7 +44,7 @@ impl TestGame {
fn update(self: &mut Self, renderer: &mut VulkanRenderer) {
self.input.frame_start();
let new_time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32;
// let new_time = (renderer.game_data.start_time.elapsed().unwrap().as_micros() as f64 / 1000000.0) as f32;
// let frame_time = new_time - renderer.game_data.uniform_buffers.iter().map(|ubo| ubo.time).max_by(|a,b| if a > b {Ordering::Greater} else {Ordering::Less} ).unwrap();
// renderer.game_data.uniform_buffers.iter_mut().for_each(|ubo| ubo.time = new_time);
@@ -63,7 +63,7 @@ impl TestGame {
if self.input.button_just_pressed("test") {
println!("test");
self.cubes = self.test_meshes.iter().map(|(mesh, tex_id)| renderer.add_game_object(GameObject::new(*mesh, *tex_id, renderer))).collect();
self.cubes = self.test_meshes.iter().map(|(mesh, tex_id)| renderer.add_game_object(GameObject::new(*mesh, *tex_id))).collect();
}
self.cam_rotation = self.cam_rotation * Quaternion::from_angle_y(Deg(self.input.get_axis("look_horizontal") * 0.05));

View File

@@ -14,8 +14,7 @@ use vulkano::sync;
use vulkano::format::{Format, ClearValue};
use vulkano::instance::debug::{DebugCallback, MessageTypes};
use vulkano::memory::pool::{PotentialDedicatedAllocation, StdMemoryPoolAlloc};
use vulkano::descriptor::descriptor_set::{PersistentDescriptorSet, FixedSizeDescriptorSetsPool, FixedSizeDescriptorSet};
use vulkano::descriptor::DescriptorSet;
use vulkano::descriptor::descriptor_set::{FixedSizeDescriptorSetsPool, FixedSizeDescriptorSet, PersistentDescriptorSetBuf, PersistentDescriptorSetImg, PersistentDescriptorSetSampler};
use vulkano::sampler::{Sampler, Filter, MipmapMode, SamplerAddressMode};
use vulkano_win::VkSurfaceBuild;
@@ -77,7 +76,7 @@ pub struct GameObject {
pub(crate) type GameObjectHandle = usize;
pub(crate) type MeshHandle = usize;
type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<GraphicsPipelineAbstract + Send + Sync>, ((), vulkano::descriptor::descriptor_set::PersistentDescriptorSetBuf<std::sync::Arc<vulkano::buffer::CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>)>>;
type FixedGraphicsDescriptorSet = Arc<FixedSizeDescriptorSet<Arc<dyn GraphicsPipelineAbstract + Send + Sync>, ((((), PersistentDescriptorSetBuf<Arc<CpuAccessibleBuffer<vs::ty::UniformBufferObject>>>), PersistentDescriptorSetImg<Arc<ImmutableImage<Format>>>), PersistentDescriptorSetSampler)>>;
pub struct GameData {
pub start_time: SystemTime,
@@ -286,8 +285,6 @@ impl VulkanRenderer {
default_tex_future.flush().unwrap();
data.textures.push(default_tex);
// Dynamic viewports allow us to recreate just the viewport when the window is resized
// Otherwise we would have to recreate the whole pipeline.
let mut dynamic_state = DynamicState { line_width: None, viewports: None, scissors: None };
@@ -310,20 +307,18 @@ impl VulkanRenderer {
let descriptor_set_pool = Mutex::new(FixedSizeDescriptorSetsPool::new(pipeline.clone(), 0));
let descriptor_sets = uniform_buffers
.iter()
.map(|uniform_buffer|
.map(|uniform_buffer| {
Arc::new(
descriptor_set_pool
.lock()
.unwrap()
.next()
.add_buffer(uniform_buffer.clone())
.unwrap()
.build()
.unwrap()
)
)
.lock().unwrap().next()
.add_buffer(uniform_buffer.clone()).unwrap()
.add_sampled_image(default_tex.clone(), sampler.clone()).unwrap()
.build().unwrap())
})
.collect();
data.textures.push(default_tex);
// In the loop below we are going to submit commands to the GPU. Submitting a command produces
// an object that implements the `GpuFuture` trait, which holds the resources for as long as
// they are in use by the GPU.
@@ -611,7 +606,7 @@ fn create_pipeline<V: vulkano::pipeline::vertex::Vertex>(device: Arc<Device>, re
}
impl GameObject {
pub fn new(mesh: MeshHandle, texture_index: usize, renderer: &VulkanRenderer) -> GameObject {
pub fn new(mesh: MeshHandle, texture_index: usize) -> GameObject {
GameObject { mesh_index: mesh, texture_index, model_matrix: Matrix4::identity() }
}
}