render: add depth buffer
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m13s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 8m13s
This commit is contained in:
parent
77c717f90b
commit
650b61e3ae
4 changed files with 61 additions and 21 deletions
|
@ -9,6 +9,12 @@ use egui_winit_vulkano::{Gui, egui};
|
|||
use glam::EulerRot;
|
||||
use glam::Quat;
|
||||
use glam::Vec3;
|
||||
use vulkano::format::Format;
|
||||
use vulkano::image::Image;
|
||||
use vulkano::image::ImageCreateInfo;
|
||||
use vulkano::image::ImageLayout;
|
||||
use vulkano::image::ImageUsage;
|
||||
use vulkano::memory::allocator::AllocationCreateInfo;
|
||||
use vulkano::{
|
||||
command_buffer::{
|
||||
AutoCommandBufferBuilder, CommandBufferUsage, PrimaryCommandBufferAbstract,
|
||||
|
@ -28,6 +34,7 @@ pub struct MainSceneState {
|
|||
camera: Camera3D,
|
||||
texture: Texture,
|
||||
speed: f32,
|
||||
depth_image_view: Arc<ImageView>,
|
||||
}
|
||||
|
||||
#[derive(Default)]
|
||||
|
@ -41,10 +48,27 @@ impl Scene for MainScene {
|
|||
}
|
||||
|
||||
fn load(&mut self, scene_context: &SceneContext) -> Result<(), Box<dyn Error>> {
|
||||
let depth_image = Image::new(
|
||||
scene_context.memory_allocator.clone(),
|
||||
ImageCreateInfo {
|
||||
format: Format::D16_UNORM,
|
||||
extent: [
|
||||
scene_context.window_size[0] as u32,
|
||||
scene_context.window_size[1] as u32,
|
||||
1,
|
||||
],
|
||||
usage: ImageUsage::DEPTH_STENCIL_ATTACHMENT,
|
||||
..Default::default()
|
||||
},
|
||||
AllocationCreateInfo::default(),
|
||||
)?;
|
||||
let depth_image_view = ImageView::new_default(depth_image)?;
|
||||
|
||||
let square = Square::new(
|
||||
&scene_context.device,
|
||||
&scene_context.memory_allocator,
|
||||
scene_context.swapchain_format,
|
||||
Format::D16_UNORM,
|
||||
)?;
|
||||
|
||||
let num_instances = 100;
|
||||
|
@ -98,6 +122,7 @@ impl Scene for MainScene {
|
|||
camera,
|
||||
texture,
|
||||
speed: 50.0,
|
||||
depth_image_view,
|
||||
});
|
||||
|
||||
Ok(())
|
||||
|
@ -146,6 +171,12 @@ impl Scene for MainScene {
|
|||
clear_value: Some([0.0, 0.0, 0.0, 1.0].into()),
|
||||
..RenderingAttachmentInfo::image_view(image_view.clone())
|
||||
})],
|
||||
depth_attachment: Some(RenderingAttachmentInfo {
|
||||
load_op: AttachmentLoadOp::Clear,
|
||||
store_op: AttachmentStoreOp::DontCare,
|
||||
clear_value: Some([1.0].into()),
|
||||
..RenderingAttachmentInfo::image_view(state.depth_image_view.clone())
|
||||
}),
|
||||
..Default::default()
|
||||
})?
|
||||
.set_viewport(0, [viewport].into_iter().collect())?;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue