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
|
@ -4,6 +4,7 @@ use super::{
|
|||
};
|
||||
use ash::vk;
|
||||
use std::sync::Arc;
|
||||
use crate::renderer::Renderable;
|
||||
|
||||
pub struct VkRenderContext {
|
||||
instance: Arc<VkInstance>,
|
||||
|
@ -13,7 +14,7 @@ pub struct VkRenderContext {
|
|||
swapchain: Arc<VkSwapchain>,
|
||||
render_pass: Arc<VkRenderPass>,
|
||||
framebuffers: Vec<Arc<VkFramebuffer>>,
|
||||
pipeline: Arc<VkGraphicsPipeline>,
|
||||
|
||||
command_pool: VkCommandPool,
|
||||
command_buffers: Vec<vk::CommandBuffer>,
|
||||
image_available_semaphore: VkSemaphore,
|
||||
|
@ -62,8 +63,6 @@ impl VkRenderContext {
|
|||
.create_framebuffers(&render_pass)
|
||||
.ok_or_else(|| anyhow::anyhow!("Failed to get framebuffers"))?;
|
||||
|
||||
let pipeline = Arc::new(VkGraphicsPipeline::new(&device, &render_pass)?);
|
||||
|
||||
let command_pool = VkCommandPool::new(&device)?;
|
||||
|
||||
// Destroyed with command pool
|
||||
|
@ -82,7 +81,6 @@ impl VkRenderContext {
|
|||
swapchain,
|
||||
render_pass,
|
||||
framebuffers,
|
||||
pipeline,
|
||||
|
||||
command_pool,
|
||||
command_buffers,
|
||||
|
@ -93,7 +91,7 @@ impl VkRenderContext {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn render(&mut self) -> anyhow::Result<()> {
|
||||
pub fn render(&mut self, scene: Option<&Box<dyn Renderable>>) -> anyhow::Result<()> {
|
||||
unsafe { self.device.handle.wait_for_fences(&[self.in_flight_fence.handle], true, u64::MAX)? };
|
||||
unsafe { self.device.handle.reset_fences(&[self.in_flight_fence.handle])? };
|
||||
|
||||
|
@ -133,26 +131,9 @@ impl VkRenderContext {
|
|||
);
|
||||
};
|
||||
|
||||
unsafe {
|
||||
self.device.handle.cmd_bind_pipeline(
|
||||
command_buffer,
|
||||
vk::PipelineBindPoint::GRAPHICS,
|
||||
self.pipeline.pipeline,
|
||||
)
|
||||
};
|
||||
|
||||
let viewport = vk::Viewport::default()
|
||||
.width(self.swapchain.surface_resolution.width as f32)
|
||||
.height(self.swapchain.surface_resolution.height as f32)
|
||||
.max_depth(1.0);
|
||||
|
||||
unsafe { self.device.handle.cmd_set_viewport(command_buffer, 0, &[viewport]) }
|
||||
|
||||
let scissor = self.swapchain.surface_resolution.into();
|
||||
|
||||
unsafe { self.device.handle.cmd_set_scissor(command_buffer, 0, &[scissor]) }
|
||||
|
||||
unsafe { self.device.handle.cmd_draw(command_buffer, 3, 1, 0, 0) };
|
||||
if let Some(scene) = scene {
|
||||
scene.render(&self.device, &self.swapchain, &command_buffer)?;
|
||||
}
|
||||
|
||||
unsafe { self.device.handle.cmd_end_render_pass(command_buffer) };
|
||||
|
||||
|
@ -204,6 +185,10 @@ impl VkRenderContext {
|
|||
unsafe { self.device.handle.device_wait_idle().unwrap() }
|
||||
}
|
||||
|
||||
pub fn init_scene(&self, scene: &mut Box<dyn Renderable>) -> anyhow::Result<()> {
|
||||
scene.init(&self.device, &self.render_pass)
|
||||
}
|
||||
|
||||
fn update_swapchain(&mut self) -> anyhow::Result<()> {
|
||||
match Arc::get_mut(&mut self.swapchain) {
|
||||
Some(swapchain) => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue