From 1314f696a7861f3b1509c7f5c27d6b06bc22d5f1 Mon Sep 17 00:00:00 2001 From: ladevieq Date: Tue, 26 Jan 2021 23:12:49 +0100 Subject: Split vkinstance/vkdevice of renderer into context class --- include/vk-context.hpp | 40 ++++++++++++++++++++++++++++++++++++++++ include/vk-renderer.hpp | 43 ++++++------------------------------------- 2 files changed, 46 insertions(+), 37 deletions(-) create mode 100644 include/vk-context.hpp (limited to 'include') diff --git a/include/vk-context.hpp b/include/vk-context.hpp new file mode 100644 index 0000000..405cd83 --- /dev/null +++ b/include/vk-context.hpp @@ -0,0 +1,40 @@ +#ifndef __VK_CONTEXT_HPP_ +#define __VK_CONTEXT_HPP_ + +#include "vulkan-loader.hpp" +#include "thirdparty/vk_mem_alloc.h" + +class vkcontext { + public: + vkcontext(); + + ~vkcontext(); + + VkInstance instance; + + VkPhysicalDevice physical_device; + VkDevice device; + + VmaAllocator allocator; + + uint32_t queue_index; + VkQueue queue; + + private: + void create_instance(); + + void create_debugger(); + + void create_device(); + + void create_memory_allocator(); + + void select_physical_device(); + + void select_queue(); + + + VkDebugUtilsMessengerEXT debugMessenger; +}; + +#endif // !__VK_CONTEXT_HPP_ diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp index 5f70718..c13f029 100644 --- a/include/vk-renderer.hpp +++ b/include/vk-renderer.hpp @@ -3,12 +3,11 @@ #include +#include "vk-context.hpp" #include "vulkan-loader.hpp" -#include "thirdparty/vk_mem_alloc.h" - -#include "window.hpp" class input_data; +class window; class vkrenderer { public: @@ -16,27 +15,19 @@ class vkrenderer { ~vkrenderer(); - void compute(); + void compute(uint32_t width, uint32_t height); void recreate_swapchain(); struct input_data* mapped_data; private: - void create_instance(); - - void create_debugger(); - - void create_surface(); - - void create_device(); + void create_surface(window& wnd); void create_swapchain(); void create_pipeline(); - void create_memory_allocator(); - void create_command_buffers(); void create_descriptor_sets(); @@ -47,14 +38,8 @@ class vkrenderer { void create_input_buffer(const input_data& inputs); - void destroy_instance(); - - void destroy_debugger(); - void destroy_surface(); - void destroy_device(); - void destroy_swapchain(); void destroy_swapchain_images(); @@ -63,8 +48,6 @@ class vkrenderer { void destroy_command_buffers(); - void destroy_allocator(); - void destroy_descriptor_sets(); void destroy_fences(); @@ -73,28 +56,16 @@ class vkrenderer { void destroy_input_buffer(); - void select_physical_device(); - - void select_compute_queue(); - void update_descriptors_buffer(); void update_descriptors_image(); void handle_swapchain_result(VkResult function_result); - uint32_t compute_queue_index; - uint64_t frame_index = 0; - - VkInstance instance; - - VkDebugUtilsMessengerEXT debugMessenger; + vkcontext context; - VkPhysicalDevice physical_device; - VkDevice device; - VkQueue compute_queue; + uint64_t frame_index = 0; - VmaAllocator allocator; VmaAllocation allocation; VkBuffer compute_shader_buffer; @@ -120,8 +91,6 @@ class vkrenderer { std::vector swapchain_images; std::vector swapchain_images_views; uint32_t current_image_index; - - window& wnd; }; #endif // !__VK_RENDERER_HPP_ -- cgit v1.3