From 3c059e433377bb5ca431849ed6c33b700f3bb704 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Tue, 15 Oct 2024 12:11:28 -0600 Subject: [PATCH] Added window scale adjustments --- client/include/pipeline.h | 2 +- client/include/render.h | 1 + client/src/main.c | 2 +- client/src/pipeline.c | 8 ++++---- client/src/render.c | 5 +++++ 5 files changed, 12 insertions(+), 6 deletions(-) diff --git a/client/include/pipeline.h b/client/include/pipeline.h index da99e13..2bf8b69 100644 --- a/client/include/pipeline.h +++ b/client/include/pipeline.h @@ -124,7 +124,7 @@ typedef struct UIContextStruct { ComputePipeline ui_compute_text; } UIContext; -VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context); +VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, vec2 window_scale, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context); VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescriptorSetLayout layout, VkDescriptorPool pool, FontData* font, SymbolInfo* symbols, uint32_t* atlas, VkCommandPool transfer_pool, Queue transfer_queue, FontDescriptor* descriptor); diff --git a/client/include/render.h b/client/include/render.h index d3cf54e..7d76591 100644 --- a/client/include/render.h +++ b/client/include/render.h @@ -81,6 +81,7 @@ typedef struct RenderContextStruct { VkFence* in_flight_fences; uint32_t current_frame; + vec2 window_scale; } RenderContext; GLFWwindow* init_window(); diff --git a/client/src/main.c b/client/src/main.c index 155148c..5014bd7 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -106,7 +106,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) { VmaAllocation colored_rect_memory; VmaAllocation text_memory; - result = init_pipelines(render_context->device, render_context->allocator, render_context->swapchain_extent, render_context->render_pass, render_context->transfer_queue, render_context->transfer_pool, &ui_context); + result = init_pipelines(render_context->device, render_context->allocator, render_context->swapchain_extent, render_context->window_scale, render_context->render_pass, render_context->transfer_queue, render_context->transfer_pool, &ui_context); if(result != VK_SUCCESS) { return result; } diff --git a/client/src/pipeline.c b/client/src/pipeline.c index 2d1603d..c3e2ad0 100644 --- a/client/src/pipeline.c +++ b/client/src/pipeline.c @@ -684,7 +684,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr return VK_SUCCESS; } -VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkDescriptorSetLayout* ui_descriptor_layout, VkDescriptorPool* ui_descriptor_pool, VkDescriptorSet* ui_descriptor_set, VmaAllocation* ui_descriptor_memory, VkBuffer* ui_descriptor_buffer) { +VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, vec2 window_scale, VkDescriptorSetLayout* ui_descriptor_layout, VkDescriptorPool* ui_descriptor_pool, VkDescriptorSet* ui_descriptor_set, VmaAllocation* ui_descriptor_memory, VkBuffer* ui_descriptor_buffer) { VkDescriptorSetLayoutBinding ui_descriptor_bindings[] = { { .binding = 0, @@ -758,7 +758,7 @@ VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExt } UIUniform ui_uniform; vec3 screen_offset = {-1.0, -1.0, 0.0}; - vec3 screen_scale = {1.0/(float)swapchain_extent.width, 1.0/(float)swapchain_extent.height, 1.0}; + vec3 screen_scale = {1.0/(float)swapchain_extent.width*window_scale[0], 1.0/(float)swapchain_extent.height*window_scale[1], 1.0}; glm_mat4_identity(ui_uniform.screen); glm_translate(ui_uniform.screen, screen_offset); glm_scale(ui_uniform.screen, screen_scale); @@ -891,10 +891,10 @@ VkResult create_ui_rect_buffer(VkDevice device, Queue transfer_queue, VkCommandP return VK_SUCCESS; } -VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context) { +VkResult init_pipelines(VkDevice device, VmaAllocator allocator, VkExtent2D swapchain_extent, vec2 window_scale, VkRenderPass render_pass, Queue transfer_queue, VkCommandPool transfer_pool, UIContext* context) { VkResult result; - result = create_ui_descriptor_set(device, allocator, swapchain_extent, &context->ui_descriptor_layout, &context->ui_descriptor_pool, &context->ui_descriptor_set, &context->ui_descriptor_memory, &context->ui_descriptor_buffer); + result = create_ui_descriptor_set(device, allocator, swapchain_extent, window_scale, &context->ui_descriptor_layout, &context->ui_descriptor_pool, &context->ui_descriptor_set, &context->ui_descriptor_memory, &context->ui_descriptor_buffer); if(result != VK_SUCCESS) { return result; } diff --git a/client/src/render.c b/client/src/render.c index 1fef78d..b5ed095 100644 --- a/client/src/render.c +++ b/client/src/render.c @@ -1,4 +1,5 @@ #include "render.h" +#include "GLFW/glfw3.h" #include "stdio.h" #include "string.h" #include "pipeline.h" @@ -837,6 +838,10 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) { return VK_ERROR_VALIDATION_FAILED_EXT; } + int monitor_count; + GLFWmonitor** monitors = glfwGetMonitors(&monitor_count); + glfwGetMonitorContentScale(monitors[0], &context->window_scale[0], &context->window_scale[1]); + result = create_instance(&context->instance); if(result != VK_SUCCESS) { return result;