This commit is contained in:
parent
1d333b633b
commit
b361965033
6 changed files with 25 additions and 70 deletions
7
src/core/render/material.rs
Normal file
7
src/core/render/material.rs
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
|
use bevy_ecs::component::Component;
|
||||||
|
use vulkano::pipeline::GraphicsPipeline;
|
||||||
|
|
||||||
|
#[derive(Component)]
|
||||||
|
pub struct Material(pub Arc<GraphicsPipeline>);
|
|
@ -1,10 +0,0 @@
|
||||||
pub mod triangle;
|
|
||||||
|
|
||||||
use vulkano::command_buffer::CommandBuffer;
|
|
||||||
|
|
||||||
use crate::vulkan::vulkan_context::VulkanContext;
|
|
||||||
|
|
||||||
pub trait Material {
|
|
||||||
fn load(&self, vulkan_context: &VulkanContext);
|
|
||||||
fn bind(&self, command_buffer: &mut CommandBuffer);
|
|
||||||
}
|
|
|
@ -1,34 +0,0 @@
|
||||||
use glam::Vec4;
|
|
||||||
use vulkano::command_buffer::CommandBuffer;
|
|
||||||
|
|
||||||
use super::Material;
|
|
||||||
|
|
||||||
pub mod shaders {
|
|
||||||
pub mod vs {
|
|
||||||
vulkano_shaders::shader! {
|
|
||||||
ty: "vertex",
|
|
||||||
path: r"res/shaders/vertex.vert",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub mod fs {
|
|
||||||
vulkano_shaders::shader! {
|
|
||||||
ty: "fragment",
|
|
||||||
path: r"res/shaders/vertex.frag",
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub struct TriangleMaterial {
|
|
||||||
pub colors: [Vec4; 3],
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Material for TriangleMaterial {
|
|
||||||
fn bind(&self, command_buffer: &mut CommandBuffer) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
|
|
||||||
fn load(&self, vulkan_context: &crate::vulkan::vulkan_context::VulkanContext) {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,10 +1,10 @@
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
use vulkano::Validated;
|
||||||
use vulkano::buffer::{
|
use vulkano::buffer::{
|
||||||
AllocateBufferError, Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer,
|
AllocateBufferError, Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer,
|
||||||
};
|
};
|
||||||
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator};
|
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator};
|
||||||
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
||||||
use vulkano::Validated;
|
|
||||||
|
|
||||||
#[derive(BufferContents, Vertex)]
|
#[derive(BufferContents, Vertex)]
|
||||||
#[repr(C)]
|
#[repr(C)]
|
||||||
|
|
|
@ -3,9 +3,10 @@ use glam::{Mat3, Mat4, Vec3};
|
||||||
use std::error::Error;
|
use std::error::Error;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use vulkano::buffer::Subbuffer;
|
use vulkano::buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer};
|
||||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer};
|
use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer};
|
||||||
use vulkano::descriptor_set::{DescriptorSet, WriteDescriptorSet};
|
use vulkano::descriptor_set::{DescriptorSet, WriteDescriptorSet};
|
||||||
|
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter};
|
||||||
use vulkano::pipeline::{GraphicsPipeline, Pipeline, PipelineBindPoint};
|
use vulkano::pipeline::{GraphicsPipeline, Pipeline, PipelineBindPoint};
|
||||||
|
|
||||||
use crate::core::render::vertex::Vertex2D;
|
use crate::core::render::vertex::Vertex2D;
|
||||||
|
@ -156,12 +157,19 @@ impl Scene {
|
||||||
projection: proj.to_cols_array_2d(),
|
projection: proj.to_cols_array_2d(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let buffer = vulkan_context
|
Buffer::from_data(
|
||||||
.uniform_buffer_allocator
|
vulkan_context.memory_allocator.clone(),
|
||||||
.allocate_sized()
|
BufferCreateInfo {
|
||||||
.unwrap();
|
usage: BufferUsage::UNIFORM_BUFFER,
|
||||||
*buffer.write().unwrap() = uniform_data;
|
..Default::default()
|
||||||
|
},
|
||||||
buffer
|
AllocationCreateInfo {
|
||||||
|
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
||||||
|
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
||||||
|
..Default::default()
|
||||||
|
},
|
||||||
|
uniform_data,
|
||||||
|
)
|
||||||
|
.unwrap()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,10 +2,6 @@ use std::{any::Any, sync::Arc};
|
||||||
|
|
||||||
use vulkano::{
|
use vulkano::{
|
||||||
Version, VulkanLibrary,
|
Version, VulkanLibrary,
|
||||||
buffer::{
|
|
||||||
BufferUsage,
|
|
||||||
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
|
|
||||||
},
|
|
||||||
command_buffer::{
|
command_buffer::{
|
||||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer,
|
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer,
|
||||||
allocator::StandardCommandBufferAllocator,
|
allocator::StandardCommandBufferAllocator,
|
||||||
|
@ -17,7 +13,7 @@ use vulkano::{
|
||||||
physical::{PhysicalDevice, PhysicalDeviceType},
|
physical::{PhysicalDevice, PhysicalDeviceType},
|
||||||
},
|
},
|
||||||
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions},
|
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions},
|
||||||
memory::allocator::{MemoryTypeFilter, StandardMemoryAllocator},
|
memory::allocator::StandardMemoryAllocator,
|
||||||
swapchain::Surface,
|
swapchain::Surface,
|
||||||
};
|
};
|
||||||
use winit::{
|
use winit::{
|
||||||
|
@ -32,7 +28,6 @@ pub struct VulkanContext {
|
||||||
|
|
||||||
pub memory_allocator: Arc<StandardMemoryAllocator>,
|
pub memory_allocator: Arc<StandardMemoryAllocator>,
|
||||||
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||||
pub uniform_buffer_allocator: Arc<SubbufferAllocator>,
|
|
||||||
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -54,16 +49,6 @@ impl From<&EventLoop<()>> for VulkanContext {
|
||||||
Default::default(),
|
Default::default(),
|
||||||
));
|
));
|
||||||
|
|
||||||
let uniform_buffer_allocator = Arc::new(SubbufferAllocator::new(
|
|
||||||
memory_allocator.clone(),
|
|
||||||
SubbufferAllocatorCreateInfo {
|
|
||||||
buffer_usage: BufferUsage::UNIFORM_BUFFER,
|
|
||||||
memory_type_filter: MemoryTypeFilter::PREFER_DEVICE
|
|
||||||
| MemoryTypeFilter::HOST_SEQUENTIAL_WRITE,
|
|
||||||
..Default::default()
|
|
||||||
},
|
|
||||||
));
|
|
||||||
|
|
||||||
let descriptor_set_allocator = Arc::new(StandardDescriptorSetAllocator::new(
|
let descriptor_set_allocator = Arc::new(StandardDescriptorSetAllocator::new(
|
||||||
device.clone(),
|
device.clone(),
|
||||||
Default::default(),
|
Default::default(),
|
||||||
|
@ -75,7 +60,6 @@ impl From<&EventLoop<()>> for VulkanContext {
|
||||||
graphics_queue,
|
graphics_queue,
|
||||||
memory_allocator,
|
memory_allocator,
|
||||||
command_buffer_allocator,
|
command_buffer_allocator,
|
||||||
uniform_buffer_allocator,
|
|
||||||
descriptor_set_allocator,
|
descriptor_set_allocator,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue