From e3c514f1c279c9955cac6b1fa9d0ede6ecbc310d Mon Sep 17 00:00:00 2001 From: gramanas Date: Tue, 4 Jun 2024 15:50:06 +0300 Subject: vks work and clang-format --- src/state.h | 76 +++++++++++++++++++++++++++---------------------------------- 1 file changed, 34 insertions(+), 42 deletions(-) (limited to 'src/state.h') diff --git a/src/state.h b/src/state.h index 95f636b..28f49e6 100644 --- a/src/state.h +++ b/src/state.h @@ -3,8 +3,10 @@ #include #include -#define CGLM_FORCE_DEPTH_ZERO_TO_ONE +#define VKSETUP_IMPLEMENTATION +#include "vksetup.h" +#define CGLM_FORCE_DEPTH_ZERO_TO_ONE #include "../lib/cglm/include/cglm/cglm.h" #pragma once @@ -38,11 +40,13 @@ typedef struct { VkSemaphore render_finished_semaphore; VkFence in_flight_fence; - VkBuffer vk_uniform_buffer; - VkDeviceMemory vk_uniform_buffer_memory; - void * vk_uniform_buffer_mapped; + vks_buffer uniform_buffer; + void * uniform_buffer_mapped; VkDescriptorSet vk_descriptor_set; + + VkDescriptorSet vk_compute_descriptor_set; + vks_buffer shader_storage_buffer; } frame_data; typedef struct { @@ -62,6 +66,13 @@ typedef struct { V2 texCoord; } Vertex; +typedef struct { + vec2 position; + vec2 velocity; + vec4 color; +} Particle; + + typedef struct state { camera3d camera; @@ -75,62 +86,44 @@ typedef struct state { int mouse_pressed; int middle_click; - UniformBufferObject ubo; - float x; int zoom; - SDL_Window *sdl_window; + UniformBufferObject ubo; + int sdl_window_resized; - VkInstance vk_instance; VkDebugUtilsMessengerEXT vk_debug_messenger; PFN_vkCreateDebugUtilsMessengerEXT pfnCreateDebugUtilsMessengerEXT; PFN_vkDestroyDebugUtilsMessengerEXT pfnDestroyDebugUtilsMessengerEXT; - VkPhysicalDevice vk_physical_device; - VkDevice vk_device; + vks_context vk; + VkQueue vk_graphics_queue; - VkSurfaceKHR vk_surface; VkQueue vk_present_queue; - VkSwapchainKHR vk_swap_chain; - - uint32_t vk_swap_chain_image_count; - VkImage vk_swap_chain_images[5]; - VkImageView vk_swap_chain_image_views[5]; // 5 for some reason - - VkFormat vk_swap_chain_image_format; - VkExtent2D vk_swap_chain_extent; - VkDescriptorSetLayout vk_descriptor_set_layout; - VkPipelineLayout vk_pipeline_layout; - VkPipeline vk_graphics_pipeline; + + vks_pipeline graphics_pipeline; VkCommandPool vk_command_pool; frame_data frames[MAX_FRAMES_IN_FLIGHT]; - VkBuffer vk_vertex_buffer; - VkDeviceMemory vk_vertex_buffer_memory; - - VkBuffer vk_index_buffer; - VkDeviceMemory vk_index_buffer_memory; + vks_buffer vertex_buffer; + vks_buffer index_buffer; VkDescriptorPool vk_descriptor_pool; shaderc_compilation_result_t prev_vert_result; shaderc_compilation_result_t prev_frag_result; + shaderc_compilation_result_t prev_comp_result; uint32_t vk_mip_levels; - VkImage vk_texture_image; - VkDeviceMemory vk_texture_image_memory; - VkImageView vk_texture_image_view; + vks_image texture_image; VkSampler vk_texture_sampler; - VkImage vk_depth_image; - VkDeviceMemory vk_depth_image_memory; - VkImageView vk_depth_image_view; + vks_image depth_image; VkPolygonMode polygon_mode; @@ -138,22 +131,21 @@ typedef struct state { size_t vertices_count; uint32_t * indices; size_t indices_count; - VkBuffer vertexBuffer; - VkDeviceMemory vertexBufferMemory; char model_path[1000]; VkSampleCountFlagBits msaa_samples; - VkImage vk_color_image; - VkDeviceMemory vk_color_image_memory; - VkImageView vk_color_image_view; + vks_image color_image; + + VkDescriptorSetLayout vk_compute_descriptor_set_layout; + VkPipelineLayout vk_compute_pipeline_layout; + VkPipeline vk_compute_pipeline; } state_t; static void init_state(state_t *s) { - strcpy(s->model_path, "assets/monkey.obj"); s->camera.pos[0] = 2.0f; s->camera.pos[1] = 2.0f; @@ -195,10 +187,10 @@ init_state(state_t *s) glm_mat4_identity(s->ubo.model); - s->sdl_window = NULL; + s->vk.window = NULL; - s->vk_swap_chain_image_count = 0; - s->vk_physical_device = VK_NULL_HANDLE; + s->vk.swapchain.image_count = 0; + s->vk.physical_device = VK_NULL_HANDLE; s->prev_vert_result = NULL; s->prev_frag_result = NULL; -- cgit v1.2.3