Skip to content

Commit

Permalink
Add framebuffer_format()
Browse files Browse the repository at this point in the history
  • Loading branch information
RobDangerous committed Feb 9, 2025
1 parent c4d8115 commit 577eaff
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 0 deletions.
15 changes: 15 additions & 0 deletions Backends/Graphics5/Vulkan/Sources/kope/vulkan/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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 = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
4 changes: 4 additions & 0 deletions Sources/kope/graphics5/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
2 changes: 2 additions & 0 deletions Sources/kope/graphics5/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 577eaff

Please sign in to comment.