#ifndef GPU_H #define GPU_H #define GLFW_INCLUDE_VULKAN #include #define SWAPCHAIN_IMG_BUFFER_SIZE 4 typedef float vec2_t[3]; typedef float vec3_t[3]; typedef float mat4_t[16]; typedef struct { vec2_t position; vec3_t colour; } vertex_t; typedef struct { mat4_t model; mat4_t view; mat4_t proj; } mvp_t; typedef struct { VkInstance inst; VkSurfaceKHR surface; VkPhysicalDevice physical_dev; VkDevice dev; VkQueue queue; VkSwapchainKHR swapchain; VkExtent2D swapchain_extent; uint32_t swapchain_img_count; VkImageView swapchain_img_views[SWAPCHAIN_IMG_BUFFER_SIZE]; VkFramebuffer framebuffers[SWAPCHAIN_IMG_BUFFER_SIZE]; VkShaderModule vert_shader; VkShaderModule frag_shader; VkPipelineLayout pipeline_layout; VkRenderPass render_pass; VkPipeline pipeline; VkCommandPool cmd_pool; VkCommandBuffer cmd_buf; VkFence in_flight; VkSemaphore render_fin; VkSemaphore img_avail; VkBuffer vertex_buf; VkDeviceMemory vertex_buf_mem; VkBuffer index_buf; VkDeviceMemory index_buf_mem; size_t index_count; } gpu_ctx_t; typedef struct { const char *application_name; GLFWwindow *window; const vertex_t *vertex_data; size_t vertex_data_size; const uint16_t *index_data; size_t index_data_size; } gpu_config_t; void gpu_init(gpu_ctx_t *ctx, const gpu_config_t *config); void gpu_cleanup(const gpu_ctx_t *ctx); void gpu_render(const gpu_ctx_t *ctx, const mvp_t *mvp); #endif