2024-10-09 10:54:19 -06:00
|
|
|
#ifndef RENDER_H
|
|
|
|
#define RENDER_H
|
|
|
|
|
|
|
|
#define VK_USE_PLATFORM_MACOS_MVK
|
|
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
|
|
|
|
#include "vk_mem_alloc.h"
|
|
|
|
|
|
|
|
#define GLFW_INCLUDE_VULKAN
|
|
|
|
#include <GLFW/glfw3.h>
|
2024-10-14 21:29:35 -06:00
|
|
|
|
|
|
|
#ifdef __APPLE__
|
2024-10-09 10:54:19 -06:00
|
|
|
#define GLFW_EXPOSE_NATIVE_COCOA
|
2024-10-14 21:29:35 -06:00
|
|
|
#endif
|
|
|
|
|
2024-10-09 10:54:19 -06:00
|
|
|
#include <GLFW/glfw3native.h>
|
|
|
|
|
|
|
|
#define GLM_FORCE_RADIANS
|
|
|
|
#define GLM_FORCE_DEPTH_ZERO_TO_ONE
|
|
|
|
#include <cglm/types.h>
|
|
|
|
#include <cglm/mat4.h>
|
|
|
|
#include <cglm/vec3.h>
|
|
|
|
#include <cglm/affine.h>
|
|
|
|
#include <cglm/quat.h>
|
|
|
|
#include <cglm/cam.h>
|
|
|
|
|
2024-10-17 15:56:35 -06:00
|
|
|
#include "ui.h"
|
2024-10-09 20:00:56 -06:00
|
|
|
#include "command.h"
|
2024-10-09 14:31:30 -06:00
|
|
|
|
2024-10-09 20:00:56 -06:00
|
|
|
extern const uint32_t MAX_FRAMES_IN_FLIGHT;
|
2024-10-09 10:54:19 -06:00
|
|
|
|
|
|
|
typedef struct SwapchainDetailsStruct {
|
|
|
|
VkSurfaceCapabilitiesKHR capabilities;
|
|
|
|
|
|
|
|
VkSurfaceFormatKHR* formats;
|
|
|
|
uint32_t formats_count;
|
|
|
|
|
|
|
|
VkPresentModeKHR* present_modes;
|
|
|
|
uint32_t present_modes_count;
|
|
|
|
} SwapchainDetails;
|
|
|
|
|
|
|
|
typedef struct RenderContextStruct {
|
|
|
|
VkInstance instance;
|
|
|
|
VkDebugUtilsMessengerEXT debug_messenger;
|
|
|
|
VkPhysicalDevice physical_device;
|
|
|
|
VkPhysicalDeviceMemoryProperties memories;
|
|
|
|
VkSurfaceKHR surface;
|
|
|
|
Queue graphics_queue;
|
|
|
|
Queue present_queue;
|
|
|
|
Queue transfer_queue;
|
|
|
|
VkDevice device;
|
|
|
|
VmaAllocator allocator;
|
|
|
|
|
|
|
|
SwapchainDetails swapchain_details;
|
|
|
|
VkSurfaceFormatKHR swapchain_format;
|
|
|
|
VkPresentModeKHR swapchain_present_mode;
|
|
|
|
VkExtent2D swapchain_extent;
|
|
|
|
VkSwapchainKHR swapchain;
|
|
|
|
|
|
|
|
uint32_t swapchain_image_count;
|
|
|
|
VkImage* swapchain_images;
|
|
|
|
VkImageView* swapchain_image_views;
|
|
|
|
VkFramebuffer* swapchain_framebuffers;
|
|
|
|
|
|
|
|
VkFormat depth_format;
|
|
|
|
VkImageView depth_image_view;
|
|
|
|
VkImage depth_image;
|
|
|
|
VmaAllocation depth_image_memory;
|
|
|
|
|
|
|
|
VkCommandPool extra_graphics_pool;
|
|
|
|
VkCommandPool graphics_pool;
|
|
|
|
VkCommandPool transfer_pool;
|
|
|
|
|
2024-10-15 00:06:46 -06:00
|
|
|
VkRenderPass render_pass;
|
2024-10-09 10:54:19 -06:00
|
|
|
|
|
|
|
VkCommandBuffer* swapchain_command_buffers;
|
|
|
|
|
|
|
|
VkSemaphore* image_available_semaphores;
|
|
|
|
VkSemaphore* render_finished_semaphores;
|
|
|
|
|
|
|
|
VkFence* in_flight_fences;
|
|
|
|
|
2024-10-09 14:31:30 -06:00
|
|
|
uint32_t current_frame;
|
2024-10-15 12:11:28 -06:00
|
|
|
vec2 window_scale;
|
2024-10-09 10:54:19 -06:00
|
|
|
} RenderContext;
|
|
|
|
|
|
|
|
GLFWwindow* init_window();
|
2024-10-17 11:06:09 -06:00
|
|
|
|
|
|
|
VkResult init_vulkan(
|
|
|
|
GLFWwindow* window,
|
|
|
|
RenderContext* context);
|
|
|
|
|
|
|
|
VkResult draw_frame(
|
|
|
|
RenderContext* context,
|
|
|
|
UIContext* ui_context,
|
|
|
|
UILayer* ui_layers,
|
|
|
|
uint32_t ui_layer_count);
|
|
|
|
|
|
|
|
VkResult create_transfer_buffer(
|
|
|
|
VkDeviceSize size,
|
|
|
|
VmaAllocator allocator,
|
|
|
|
VkBuffer* buffer,
|
|
|
|
VmaAllocation* memory,
|
|
|
|
void** mapped);
|
2024-10-09 10:54:19 -06:00
|
|
|
|
|
|
|
#endif
|