From 577eaffe318c852df74a71f0fed7ed751ba0f50b Mon Sep 17 00:00:00 2001 From: Robert Konrad Date: Sun, 9 Feb 2025 20:13:54 +0100 Subject: [PATCH] Add framebuffer_format() --- .../Graphics5/Vulkan/Sources/kope/vulkan/device.c | 15 +++++++++++++++ .../Vulkan/Sources/kope/vulkan/device_functions.h | 2 ++ Sources/kope/graphics5/device.c | 4 ++++ Sources/kope/graphics5/device.h | 2 ++ 4 files changed, 23 insertions(+) diff --git a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c index b3c834a95..24ab61d0f 100644 --- a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c +++ b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c @@ -19,6 +19,7 @@ static VkInstance instance; static VkPhysicalDevice gpu; static VkSwapchainKHR swapchain; static kope_g5_texture framebuffers[4]; +static VkFormat framebuffer_format; static uint32_t framebuffer_count = 0; static uint32_t framebuffer_index = 0; @@ -332,6 +333,7 @@ static void create_swapchain(kope_g5_device *device, uint32_t graphics_queue_fam assert(result == VK_SUCCESS && surface_supported); VkSurfaceFormatKHR format = find_surface_format(surface); + framebuffer_format = format.format; VkSurfaceCapabilitiesKHR surface_capabilities = {0}; result = vulkan_GetPhysicalDeviceSurfaceCapabilitiesKHR(gpu, surface, &surface_capabilities); @@ -780,6 +782,19 @@ kope_g5_texture *kope_vulkan_device_get_framebuffer(kope_g5_device *device) { return &framebuffers[framebuffer_index]; } +kope_g5_texture_format kope_vulkan_device_framebuffer_format(kope_g5_device *device) { + switch (framebuffer_format) { + case VK_FORMAT_R8G8B8A8_UNORM: + return KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; + case VK_FORMAT_B8G8R8A8_UNORM: + return KOPE_G5_TEXTURE_FORMAT_BGRA8_UNORM; + default: + assert(false); + } + + return KOPE_G5_TEXTURE_FORMAT_RGBA8_UNORM; +} + void kope_vulkan_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list) { if (list->vulkan.presenting) { VkImageMemoryBarrier barrier = { diff --git a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device_functions.h b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device_functions.h index 1b25268b0..ba41a30cc 100644 --- a/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device_functions.h +++ b/Backends/Graphics5/Vulkan/Sources/kope/vulkan/device_functions.h @@ -30,6 +30,8 @@ void kope_vulkan_device_create_sampler(kope_g5_device *device, const kope_g5_sam kope_g5_texture *kope_vulkan_device_get_framebuffer(kope_g5_device *device); +kope_g5_texture_format kope_vulkan_device_framebuffer_format(kope_g5_device *device); + void kope_vulkan_device_execute_command_list(kope_g5_device *device, kope_g5_command_list *list); void kope_vulkan_device_wait_until_idle(kope_g5_device *device); diff --git a/Sources/kope/graphics5/device.c b/Sources/kope/graphics5/device.c index 747c81dda..0e0abbbba 100644 --- a/Sources/kope/graphics5/device.c +++ b/Sources/kope/graphics5/device.c @@ -52,6 +52,10 @@ kope_g5_texture *kope_g5_device_get_framebuffer(kope_g5_device *device) { return KOPE_G5_CALL1(device_get_framebuffer, device); } +kope_g5_texture_format kope_g5_device_framebuffer_format(kope_g5_device *device) { + return KOPE_G5_CALL1(device_framebuffer_format, device); +} + void kope_g5_device_create_query_set(kope_g5_device *device, const kope_g5_query_set_parameters *parameters, kope_g5_query_set *query_set) { KOPE_G5_CALL3(device_create_query_set, device, parameters, query_set); } diff --git a/Sources/kope/graphics5/device.h b/Sources/kope/graphics5/device.h index d93aefcf4..6a4f0ba17 100644 --- a/Sources/kope/graphics5/device.h +++ b/Sources/kope/graphics5/device.h @@ -91,6 +91,8 @@ KOPE_FUNC void kope_g5_device_create_texture(kope_g5_device *device, const kope_ KOPE_FUNC kope_g5_texture *kope_g5_device_get_framebuffer(kope_g5_device *device); +KOPE_FUNC kope_g5_texture_format kope_g5_device_framebuffer_format(kope_g5_device *device); + typedef enum kope_g5_address_mode { KOPE_G5_ADDRESS_MODE_CLAMP_TO_EDGE, KOPE_G5_ADDRESS_MODE_REPEAT, KOPE_G5_ADDRESS_MODE_MIRROR_REPEAT } kope_g5_address_mode; typedef enum kope_g5_filter_mode { KOPE_G5_FILTER_MODE_NEAREST, KOPE_G5_FILTER_MODE_LINEAR } kope_g5_filter_mode;