summaryrefslogtreecommitdiff
path: root/include/vulkan_swapchain.h
diff options
context:
space:
mode:
authorChuyan Zhang <chuyan@ucsb.edu>2024-10-10 18:51:05 -0700
committerChuyan Zhang <chuyan@ucsb.edu>2024-10-10 18:51:05 -0700
commit6271f5ce797bf12be64c710b66b1b9e93a239829 (patch)
tree44cc6a5ab5a20f7e55829f18b68a9f1191dac81d /include/vulkan_swapchain.h
parentba27f3c22e79b91a2573b7efd00c5a3bbdb96dbc (diff)
downloadiris-6271f5ce797bf12be64c710b66b1b9e93a239829.tar.gz
iris-6271f5ce797bf12be64c710b66b1b9e93a239829.zip
move to new resource abstractionHEADmain
Diffstat (limited to 'include/vulkan_swapchain.h')
-rw-r--r--include/vulkan_swapchain.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/include/vulkan_swapchain.h b/include/vulkan_swapchain.h
new file mode 100644
index 0000000..8d4604e
--- /dev/null
+++ b/include/vulkan_swapchain.h
@@ -0,0 +1,47 @@
+#pragma once
+#include "imgui_impl_glfw.h"
+#include "vulkan_helper.h"
+#include "vulkan/vulkan_core.h"
+#include <cstdint>
+#include <sys/types.h>
+#include <vector>
+#include <string>
+
+std::vector<std::string> get_glfw_instance_extensions();
+
+namespace iris {
+
+struct Swapchain {
+ Device device;
+
+ VkSurfaceKHR surface = VK_NULL_HANDLE;
+ VkSwapchainKHR swapchain = VK_NULL_HANDLE;
+ VkRenderPass render_pass = VK_NULL_HANDLE;
+ VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
+ GLFWwindow *window = nullptr;
+ uint32_t width = -1;
+ uint32_t height = -1;
+ bool needs_recreate = false;
+
+ static constexpr uint32_t SWAPCHAIN_IMAGE_COUNT = 3;
+ VkImage swapchain_images[SWAPCHAIN_IMAGE_COUNT];
+ VkImageView swapchain_image_views[SWAPCHAIN_IMAGE_COUNT];
+ VkFramebuffer framebuffers[SWAPCHAIN_IMAGE_COUNT];
+ VkSemaphore image_available_semaphores[SWAPCHAIN_IMAGE_COUNT];
+ VkSemaphore render_finished_semaphores[SWAPCHAIN_IMAGE_COUNT];
+ CommandBuffer cmd_buf;
+
+ Texture2D upload_texture;
+
+ ImGuiContext *imgui_context = nullptr;
+ uint32_t semaphore_index = 0;
+ uint32_t frame_index = 0;
+
+ void resize(uint32_t new_width, uint32_t new_height);
+ void start_frame();
+ void display(Texture2D &texture);
+ void release();
+ Swapchain(GLFWwindow *window, iris::Device device, uint32_t width, uint32_t height);
+};
+
+} // namespace iris \ No newline at end of file