aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
Diffstat (limited to 'include')
-rw-r--r--include/utils.hpp28
-rw-r--r--include/vk-renderer.hpp48
-rw-r--r--include/window.hpp6
3 files changed, 51 insertions, 31 deletions
diff --git a/include/utils.hpp b/include/utils.hpp
index 42a5a1a..830b006 100644
--- a/include/utils.hpp
+++ b/include/utils.hpp
@@ -2,13 +2,37 @@
#define __UTILS_HPP_
#include <cstdint>
-
+#include <cstdlib>
#include <vector>
-#include <cstdlib>
+#include "vec3.hpp"
+#include "sphere.hpp"
+#include "camera.hpp"
+
+struct input_data {
+ color sky_color;
+ color ground_color;
+
+ camera cam;
+
+ float random_offset[2000];
+ float random_disk[2000];
+ vec3 random_in_sphere[1000];
+
+ sphere spheres[512];
+
+ uint32_t max_bounce;
+ uint32_t samples_per_pixel;
+
+ // Output image resolution
+ uint32_t width;
+ uint32_t height;
+};
std::vector<uint8_t> get_shader_code(const char* path);
+struct input_data create_inputs(uint32_t width, uint32_t height);
+
#define PI 3.14159265359
inline float deg_to_rad(float deg) {
diff --git a/include/vk-renderer.hpp b/include/vk-renderer.hpp
index 580ca72..a8c5d2b 100644
--- a/include/vk-renderer.hpp
+++ b/include/vk-renderer.hpp
@@ -7,45 +7,27 @@
#include "thirdparty/vk_mem_alloc.h"
#include "window.hpp"
-#include "camera.hpp"
-#include "sphere.hpp"
-struct input_data {
- color sky_color;
- color ground_color;
-
- camera cam;
-
- float random_offset[2000];
- float random_disk[2000];
- vec3 random_in_sphere[1000];
-
- sphere spheres[512];
-
- uint32_t max_bounce;
- uint32_t samples_per_pixel;
-
- // Output image resolution
- uint32_t width;
- uint32_t height;
-};
+class input_data;
class vkrenderer {
public:
vkrenderer(window& wnd, const input_data& inputs);
- void compute(size_t width, size_t height);
+ void compute();
+
+ void recreate_swapchain();
private:
void create_instance();
void create_debugger();
- void create_surface(window& wnd);
+ void create_surface();
void create_device();
- void create_swapchain(window& wnd);
+ void create_swapchain();
void create_pipeline();
@@ -59,11 +41,19 @@ class vkrenderer {
void create_semaphores();
+ void create_input_buffer(const input_data& inputs);
+
+ void destroy_swapchain();
+
void select_physical_device();
void select_compute_queue();
- void update_sets(const input_data& data);
+ 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;
@@ -91,14 +81,16 @@ class vkrenderer {
std::vector<VkSemaphore> acquire_semaphores;
VkSurfaceFormatKHR surface_format;
- VkSurfaceKHR platform_surface;
- VkSwapchainKHR swapchain;
+ VkSurfaceKHR platform_surface = VK_NULL_HANDLE;
+ VkSwapchainKHR swapchain = VK_NULL_HANDLE;
size_t swapchain_images_count = 3;
std::vector<VkImage> swapchain_images;
std::vector<VkImageView> swapchain_images_views;
uint32_t current_image_index;
- struct input_data* mapped_data;
+ struct input_data* mapped_data;
+
+ window& wnd;
};
#endif // !__VK_RENDERER_HPP_
diff --git a/include/window.hpp b/include/window.hpp
index 550463d..3298d36 100644
--- a/include/window.hpp
+++ b/include/window.hpp
@@ -1,9 +1,12 @@
#ifndef __WINDOW_HPP_
#define __WINDOW_HPP_
-#include "defines.hpp"
#include <cstdint>
+#include "defines.hpp"
+
+class vkrenderer;
+
#if defined(LINUX)
#include <xcb/xcb.h>
@@ -35,6 +38,7 @@ class window {
static LRESULT CALLBACK window_procedure(HWND hwnd, UINT umsg, WPARAM wparam, LPARAM lparam);
HWND win_handle;
+ vkrenderer* renderer = nullptr;
uint32_t width;
uint32_t height;