WIP "Drawing: Framebuffers"
TODO: "Drawing: Command buffers" https://vulkan-tutorial.com/Drawing_a_triangle/Drawing/Command_buffers
This commit is contained in:
parent
fa9c52ac10
commit
9651b338f3
1 changed files with 40 additions and 0 deletions
40
src/main.rs
40
src/main.rs
|
@ -174,6 +174,7 @@ struct VulkanApp {
|
||||||
render_pass: ffi::VkRenderPass,
|
render_pass: ffi::VkRenderPass,
|
||||||
pipeline_layout: ffi::VkPipelineLayout,
|
pipeline_layout: ffi::VkPipelineLayout,
|
||||||
graphics_pipeline: ffi::VkPipeline,
|
graphics_pipeline: ffi::VkPipeline,
|
||||||
|
swap_chain_framebuffers: Vec<ffi::VkFramebuffer>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl VulkanApp {
|
impl VulkanApp {
|
||||||
|
@ -195,6 +196,7 @@ impl VulkanApp {
|
||||||
render_pass: std::ptr::null_mut(),
|
render_pass: std::ptr::null_mut(),
|
||||||
pipeline_layout: std::ptr::null_mut(),
|
pipeline_layout: std::ptr::null_mut(),
|
||||||
graphics_pipeline: std::ptr::null_mut(),
|
graphics_pipeline: std::ptr::null_mut(),
|
||||||
|
swap_chain_framebuffers: Vec::new(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -233,6 +235,7 @@ impl VulkanApp {
|
||||||
self.create_render_pass().unwrap();
|
self.create_render_pass().unwrap();
|
||||||
self.create_graphics_pipeline()
|
self.create_graphics_pipeline()
|
||||||
.expect("Should be able to set up graphics pipeline");
|
.expect("Should be able to set up graphics pipeline");
|
||||||
|
self.create_framebuffers().unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
fn create_instance(&mut self) -> Result<(), String> {
|
fn create_instance(&mut self) -> Result<(), String> {
|
||||||
|
@ -1200,10 +1203,47 @@ impl VulkanApp {
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn create_framebuffers(&mut self) -> Result<(), String> {
|
||||||
|
self.swap_chain_framebuffers
|
||||||
|
.resize(self.swap_chain_image_views.len(), std::ptr::null_mut());
|
||||||
|
|
||||||
|
for (idx, image_view) in self.swap_chain_image_views.iter().enumerate() {
|
||||||
|
let mut framebuffer_info: ffi::VkFramebufferCreateInfo = unsafe { std::mem::zeroed() };
|
||||||
|
framebuffer_info.sType = ffi::VkStructureType_VK_STRUCTURE_TYPE_FRAMEBUFFER_CREATE_INFO;
|
||||||
|
framebuffer_info.renderPass = self.render_pass;
|
||||||
|
framebuffer_info.attachmentCount = 1;
|
||||||
|
framebuffer_info.pAttachments = image_view as *const ffi::VkImageView;
|
||||||
|
framebuffer_info.width = self.swap_chain_extent.width;
|
||||||
|
framebuffer_info.height = self.swap_chain_extent.height;
|
||||||
|
framebuffer_info.layers = 1;
|
||||||
|
|
||||||
|
let result = unsafe {
|
||||||
|
ffi::vkCreateFramebuffer(
|
||||||
|
self.device,
|
||||||
|
std::ptr::addr_of!(framebuffer_info),
|
||||||
|
std::ptr::null(),
|
||||||
|
std::ptr::addr_of_mut!(self.swap_chain_framebuffers[idx]),
|
||||||
|
)
|
||||||
|
};
|
||||||
|
|
||||||
|
if result != ffi::VkResult_VK_SUCCESS {
|
||||||
|
return Err(String::from("Failed to create framebuffer!"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Drop for VulkanApp {
|
impl Drop for VulkanApp {
|
||||||
fn drop(&mut self) {
|
fn drop(&mut self) {
|
||||||
|
for framebuffer in &self.swap_chain_framebuffers {
|
||||||
|
unsafe {
|
||||||
|
ffi::vkDestroyFramebuffer(self.device, *framebuffer, std::ptr::null());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if !self.graphics_pipeline.is_null() {
|
if !self.graphics_pipeline.is_null() {
|
||||||
unsafe {
|
unsafe {
|
||||||
ffi::vkDestroyPipeline(self.device, self.graphics_pipeline, std::ptr::null());
|
ffi::vkDestroyPipeline(self.device, self.graphics_pipeline, std::ptr::null());
|
||||||
|
|
Loading…
Reference in a new issue