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 vulkano::Validated;
|
||||
use vulkano::buffer::{
|
||||
AllocateBufferError, Buffer, BufferContents, BufferCreateInfo, BufferUsage, Subbuffer,
|
||||
};
|
||||
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter, StandardMemoryAllocator};
|
||||
use vulkano::pipeline::graphics::vertex_input::Vertex;
|
||||
use vulkano::Validated;
|
||||
|
||||
#[derive(BufferContents, Vertex)]
|
||||
#[repr(C)]
|
||||
|
|
|
@ -3,9 +3,10 @@ use glam::{Mat3, Mat4, Vec3};
|
|||
use std::error::Error;
|
||||
use std::sync::Arc;
|
||||
use std::time::Instant;
|
||||
use vulkano::buffer::Subbuffer;
|
||||
use vulkano::buffer::{Buffer, BufferCreateInfo, BufferUsage, Subbuffer};
|
||||
use vulkano::command_buffer::{AutoCommandBufferBuilder, PrimaryAutoCommandBuffer};
|
||||
use vulkano::descriptor_set::{DescriptorSet, WriteDescriptorSet};
|
||||
use vulkano::memory::allocator::{AllocationCreateInfo, MemoryTypeFilter};
|
||||
use vulkano::pipeline::{GraphicsPipeline, Pipeline, PipelineBindPoint};
|
||||
|
||||
use crate::core::render::vertex::Vertex2D;
|
||||
|
@ -156,12 +157,19 @@ impl Scene {
|
|||
projection: proj.to_cols_array_2d(),
|
||||
};
|
||||
|
||||
let buffer = vulkan_context
|
||||
.uniform_buffer_allocator
|
||||
.allocate_sized()
|
||||
.unwrap();
|
||||
*buffer.write().unwrap() = uniform_data;
|
||||
|
||||
buffer
|
||||
Buffer::from_data(
|
||||
vulkan_context.memory_allocator.clone(),
|
||||
BufferCreateInfo {
|
||||
usage: BufferUsage::UNIFORM_BUFFER,
|
||||
..Default::default()
|
||||
},
|
||||
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::{
|
||||
Version, VulkanLibrary,
|
||||
buffer::{
|
||||
BufferUsage,
|
||||
allocator::{SubbufferAllocator, SubbufferAllocatorCreateInfo},
|
||||
},
|
||||
command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryAutoCommandBuffer,
|
||||
allocator::StandardCommandBufferAllocator,
|
||||
|
@ -17,7 +13,7 @@ use vulkano::{
|
|||
physical::{PhysicalDevice, PhysicalDeviceType},
|
||||
},
|
||||
instance::{Instance, InstanceCreateFlags, InstanceCreateInfo, InstanceExtensions},
|
||||
memory::allocator::{MemoryTypeFilter, StandardMemoryAllocator},
|
||||
memory::allocator::StandardMemoryAllocator,
|
||||
swapchain::Surface,
|
||||
};
|
||||
use winit::{
|
||||
|
@ -32,7 +28,6 @@ pub struct VulkanContext {
|
|||
|
||||
pub memory_allocator: Arc<StandardMemoryAllocator>,
|
||||
pub command_buffer_allocator: Arc<StandardCommandBufferAllocator>,
|
||||
pub uniform_buffer_allocator: Arc<SubbufferAllocator>,
|
||||
pub descriptor_set_allocator: Arc<StandardDescriptorSetAllocator>,
|
||||
}
|
||||
|
||||
|
@ -54,16 +49,6 @@ impl From<&EventLoop<()>> for VulkanContext {
|
|||
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(
|
||||
device.clone(),
|
||||
Default::default(),
|
||||
|
@ -75,7 +60,6 @@ impl From<&EventLoop<()>> for VulkanContext {
|
|||
graphics_queue,
|
||||
memory_allocator,
|
||||
command_buffer_allocator,
|
||||
uniform_buffer_allocator,
|
||||
descriptor_set_allocator,
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue