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, } impl TriangleScene { pub fn new() -> Self { Self { pipeline: None } } } impl Renderable for TriangleScene { fn init(&mut self, device: &Arc, render_pass: &Arc) -> 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(()) } }