diff --git a/shaders/text.frag b/shaders/text.frag index fbc98ab..1170b49 100644 --- a/shaders/text.frag +++ b/shaders/text.frag @@ -1,10 +1,6 @@ #version 450 #extension GL_ARB_separate_shader_objects : enable -layout(push_constant) uniform PushConstants { - mat4 model; -} push; - layout(binding = 0, set = 0) uniform ObjectUniformData { mat4 view; mat4 projection; diff --git a/shaders/text.frag.spv b/shaders/text.frag.spv index d4aa6e8..40904a0 100644 Binary files a/shaders/text.frag.spv and b/shaders/text.frag.spv differ diff --git a/shaders/text.vert b/shaders/text.vert index 99a9784..1792918 100644 --- a/shaders/text.vert +++ b/shaders/text.vert @@ -1,10 +1,6 @@ #version 450 #extension GL_ARB_separate_shader_objects : enable -layout(push_constant) uniform PushConstants { - mat4 model; -} push; - layout(binding = 0, set = 0) uniform ObjectUniformData { mat4 view; mat4 projection; diff --git a/shaders/text.vert.spv b/shaders/text.vert.spv index d27da4f..4a5fc54 100644 Binary files a/shaders/text.vert.spv and b/shaders/text.vert.spv differ diff --git a/src/input.rs b/src/input.rs index 4172e8d..1ac8761 100644 --- a/src/input.rs +++ b/src/input.rs @@ -293,6 +293,7 @@ impl InputState { } } + #[allow(dead_code)] pub fn button_down(self: &Self, button_code: &str) -> bool { match self.virtual_buttons.get(button_code) { Some(virtual_button) => { diff --git a/src/vulkan/framebuffers.rs b/src/vulkan/framebuffers.rs index f76e237..cb6d9b1 100644 --- a/src/vulkan/framebuffers.rs +++ b/src/vulkan/framebuffers.rs @@ -4,7 +4,6 @@ use vulkano::device::Device; use vulkano::format::Format; use vulkano::image::view::ImageView; use vulkano::image::{AttachmentImage, ImageUsage, SampleCount, SwapchainImage}; -use vulkano::pipeline::viewport::Viewport; use vulkano::render_pass::{Framebuffer, FramebufferAbstract, RenderPass}; use winit::window::Window; use vulkano::swapchain::Swapchain; diff --git a/src/vulkan/gameobject.rs b/src/vulkan/gameobject.rs index 3cb5298..3d75653 100644 --- a/src/vulkan/gameobject.rs +++ b/src/vulkan/gameobject.rs @@ -8,11 +8,7 @@ use crate::input::InputState; use crate::vulkan::TextureHandle; use crate::vulkan::{MeshHandle, VulkanRenderer}; -use super::pipelines::{vs, vs_text}; - -pub trait PushConstant {} -impl PushConstant for vs::ty::PushConstants {} -impl PushConstant for vs_text::ty::PushConstants {} +use super::pipelines::vs; #[derive(Clone)] pub struct GameObject { @@ -28,6 +24,10 @@ pub struct GameObject { pub visible: bool, } +pub enum PushConstantType { + MeshPC(vs::ty::PushConstants), +} + impl GameObject { pub fn new(mesh: MeshHandle) -> GameObject { GameObject { mesh_index: mesh.index, textures: mesh.textures, position: Vector3::new(0.0, 0.0, 0.0), @@ -65,8 +65,8 @@ impl GameObject { self.rotation = self.rotation * Quaternion::from(Euler::new(Deg(x), Deg(y), Deg(z))); } - pub fn get_push_constants(&self) -> Box { - Box::new(vs::ty::PushConstants { + pub fn get_push_constants(&self) -> PushConstantType { + PushConstantType::MeshPC(vs::ty::PushConstants { model: self.get_model_matrix().into(), is_selected: if self.is_selected { 1 } else { 0 }, }) diff --git a/src/vulkan/mod.rs b/src/vulkan/mod.rs index 8ad6bb4..be7b3a7 100644 --- a/src/vulkan/mod.rs +++ b/src/vulkan/mod.rs @@ -322,7 +322,7 @@ impl VulkanRenderer { fn create_command_buffer(self: &mut Self, fb_index: usize, uniform_buffer_data: vs::ty::ObjectUniformData, game_objects: &Vec) -> Arc { // General setup let mut builder = AutoCommandBufferBuilder::primary(self.device.clone(), self.queue.family(), CommandBufferUsage::OneTimeSubmit).unwrap(); - // builder.update_buffer(self.uniform_buffers[fb_index].clone(), uniform_buffer_data).unwrap(); + builder.update_buffer(self.uniform_buffers[fb_index].clone(), Arc::new(uniform_buffer_data)).unwrap(); if self.render_config.msaa_samples > 0 { builder.begin_render_pass(self.framebuffers[fb_index].clone(), SubpassContents::Inline, vec![ClearValue::None, ClearValue::Float([0.0, 0.0, 0.0, 1.0]), ClearValue::Depth(1.0)]).unwrap(); } else { diff --git a/src/vulkan/pipelines.rs b/src/vulkan/pipelines.rs index faf02d5..5b83b22 100644 --- a/src/vulkan/pipelines.rs +++ b/src/vulkan/pipelines.rs @@ -9,7 +9,7 @@ use crate::vulkan::Vertex; use crate::vulkan::GameData; use crate::VulkanRenderer; -use super::TextureHandle; +use super::{TextureHandle, gameobject::PushConstantType}; type RP = Arc; type GP = Arc; @@ -142,15 +142,16 @@ impl Drawcall for DefaultShader { for i in 0..game_objects.len() { let game_object = &game_objects[i]; let mesh = &game_data.meshes[game_object.mesh_index]; - let push_constants = game_object.get_push_constants(); - builder + if let PushConstantType::MeshPC(mesh_push) = game_object.get_push_constants() { + builder .bind_pipeline_graphics(self.pipeline.clone()) .bind_descriptor_sets(PipelineBindPoint::Graphics, self.pipeline.layout().clone(), 0, game_object.descriptor_sets[fb_index].clone()) .bind_vertex_buffers(0, mesh.vertex_buffer.clone()) .bind_index_buffer(mesh.index_buffer.clone()) - .push_constants(self.pipeline.layout().clone(), 0, push_constants) + .push_constants(self.pipeline.layout().clone(), 0, mesh_push) .draw_indexed(mesh.index_buffer.len() as u32, 1, 0, 0, 0).unwrap(); + } } } @@ -341,7 +342,6 @@ impl Drawcall for TextShader { .bind_descriptor_sets(PipelineBindPoint::Graphics, self.pipeline.layout().clone(), 0, game_object.descriptor_sets[fb_index].clone()) .bind_vertex_buffers(0, mesh.vertex_buffer.clone()) .bind_index_buffer(mesh.index_buffer.clone()) - .push_constants(self.pipeline.layout().clone(), 0, game_object.get_push_constants()) .draw_indexed(mesh.index_buffer.len() as u32, 1, 0, 0, 0).unwrap(); } }