vulkano_test/src/scene/triangle.rs
Florian RICHER a1961cff05
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 4m25s
Begin implement Vertex
2024-12-06 17:06:17 +01:00

49 lines
No EOL
1.5 KiB
Rust

use crate::renderer::vulkan::{VkDevice, VkGraphicsPipeline, VkRenderPass, VkSwapchain};
use crate::renderer::Renderable;
use ash::vk;
use ash::vk::CommandBuffer;
use std::sync::Arc;
pub struct TriangleScene {
pipeline: Option<VkGraphicsPipeline>,
}
impl TriangleScene {
pub fn new() -> Self {
Self { pipeline: None }
}
}
impl Renderable for TriangleScene {
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(())
}
}