it works again!!

This commit is contained in:
2021-10-24 19:27:37 +02:00
parent 2834623ba7
commit c8d4da62b6
9 changed files with 14 additions and 22 deletions

View File

@@ -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;

Binary file not shown.

View File

@@ -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;

Binary file not shown.

View File

@@ -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) => {

View File

@@ -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;

View File

@@ -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<dyn PushConstant> {
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 },
})

View File

@@ -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<GameObject>) -> Arc<PrimaryAutoCommandBuffer> {
// 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 {

View File

@@ -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<RenderPass>;
type GP = Arc<GraphicsPipeline>;
@@ -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();
}
}