Export triangle to external scene
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
Some checks failed
Build legacy Nix package on Ubuntu / build (push) Failing after 1s
This commit is contained in:
parent
4b08b7359d
commit
7b5cae8322
18 changed files with 121 additions and 65 deletions
49
src/scene/triangle.rs
Normal file
49
src/scene/triangle.rs
Normal 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(())
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue