diff options
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 38 |
1 files changed, 22 insertions, 16 deletions
diff --git a/src/main.rs b/src/main.rs index 3267d0b..8a42147 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,11 +6,11 @@ use crate::graphics_permanent::{ use crate::graphics_window_dressing::{ WindowDressing, N_SIMULTANEOUS_FRAMES }; -use crate::linear_algebra::{ Vec3, Vec4, Mat4, Transformation }; +use crate::linear_algebra::{ Vec3, Mat4, Transformation }; use crate::shader_data::UniformBlock; use std::cell::RefCell; -use std::f32::consts::{ FRAC_PI_4, TAU }; +use std::f32::consts::FRAC_PI_4; use std::ptr::copy_nonoverlapping; use std::time::Instant; use vulkanalia::Device; @@ -23,6 +23,7 @@ use winit::window::WindowId; mod error; mod graphics_permanent; +mod graphics_scene; mod graphics_window_dressing; mod linear_algebra; mod model_loader; @@ -138,16 +139,28 @@ impl Surreality { concurrency.image_fences[image_index] = *frame_fence; - render_uniforms(device, + let time = self.simulation_start.elapsed().as_secs_f32(); + + let command_buffer = window_dressing.command_buffers[image_index]; + let framebuffer = window_dressing.framebuffers[image_index]; + let descriptor_set = window_dressing.descriptor_sets[image_index]; + + crate::graphics_scene::generate_scene_commands( + &command_buffer, time, device, &window_dressing.swapchain.extent, + &framebuffer, &window_dressing.render_pass, + &window_dressing.pipeline_layout, &window_dressing.pipeline, + &window_dressing.vertex_buffer, &window_dressing.index_buffer, + window_dressing.index_count, &descriptor_set)?; + + render_uniforms(time, device, &window_dressing.uniform_buffer_memory[image_index], - &window_dressing.swapchain.extent, - self.simulation_start)?; + &window_dressing.swapchain.extent)?; let first_semaphores = [*image_available_semaphore]; let second_semaphores = [*rendering_finished_semaphore]; let wait_stages = [vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT]; - let command_buffers = [window_dressing.command_buffers[image_index]]; + let command_buffers = [command_buffer]; let submit_info = vk::SubmitInfo::builder() .wait_semaphores(&first_semaphores) .wait_dst_stage_mask(&wait_stages) @@ -282,23 +295,16 @@ fn main() -> std::process::ExitCode { #[allow(unsafe_code)] -fn render_uniforms(device: &Device, device_memory: &vk::DeviceMemory, - extent: &vk::Extent2D, simulation_start: Instant) +fn render_uniforms(time: f32, device: &Device, + device_memory: &vk::DeviceMemory, extent: &vk::Extent2D) -> Result<()> { - let time = simulation_start.elapsed().as_secs_f32(); - - let scale = Vec3::new(1.0, 1.0, 1.0); - let model = Transformation { - rotation: Vec4::rotation_quaternion(&Vec3::new(0.0, 1.0, 0.0), time % TAU), - translation: Vec3::new(0.0, 0.0, 0.0), - }; let view = Transformation::look_at(&Vec3::new(0.0, -3.0, -10.0), &Vec3::new(0.0, -1.0, 0.0), &Vec3::new(0.0, -1.0, 0.0)); let aspect_ratio = extent.width as f32 / extent.height as f32; let projection = Mat4::perspective(FRAC_PI_4, aspect_ratio, 0.1, 100.0); - let block = UniformBlock::<f32> { scale, model, view, projection }; + let block = UniformBlock::<f32> { view, projection }; let size = size_of::<UniformBlock<f32>>() as u64; let host_memory = unsafe { |