Export triangle to external scene
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s

This commit is contained in:
Florian RICHER 2024-11-27 22:16:26 +01:00
parent 4b08b7359d
commit 7b5cae8322
Signed by: florian.richer
GPG key ID: C73D37CBED7BFC77
18 changed files with 121 additions and 65 deletions

49
src/scene/triangle.rs Normal file
View file

@ -0,0 +1,49 @@
use std::sync::Arc;
use ash::vk;
use crate::renderer::vulkan::{VkDevice, VkGraphicsPipeline, VkRenderPass, VkSwapchain};
use crate::renderer::Renderable;
use ash::vk::CommandBuffer;
pub struct Triangle {
pipeline: Option<VkGraphicsPipeline>,
}
impl Triangle {
pub fn new() -> Self {
Self { pipeline: None }
}
}
impl Renderable for Triangle {
fn init(&mut self, device: &Arc<VkDevice>, render_pass: &Arc<VkRenderPass>) -> anyhow::Result<()> {
let pipeline = VkGraphicsPipeline::new(&device, &render_pass)?;
self.pipeline = Some(pipeline);
Ok(())
}
fn render(&self, device: &VkDevice, swapchain: &VkSwapchain, command_buffer: &CommandBuffer) -> anyhow::Result<()> {
unsafe {
device.handle.cmd_bind_pipeline(
*command_buffer,
vk::PipelineBindPoint::GRAPHICS,
self.pipeline.as_ref().unwrap().pipeline,
)
};
let viewport = vk::Viewport::default()
.width(swapchain.surface_resolution.width as f32)
.height(swapchain.surface_resolution.height as f32)
.max_depth(1.0);
unsafe { device.handle.cmd_set_viewport(*command_buffer, 0, &[viewport]) }
let scissor = swapchain.surface_resolution.into();
unsafe { device.handle.cmd_set_scissor(*command_buffer, 0, &[scissor]) }
unsafe { device.handle.cmd_draw(*command_buffer, 3, 1, 0, 0) };
Ok(())
}
}