Added window scale adjustments

main
noah metz 2024-10-15 12:11:28 -06:00
parent a8fe640b26
commit 3c059e4333
5 changed files with 12 additions and 6 deletions

@ -124,7 +124,7 @@ typedef struct UIContextStruct {
ComputePipeline ui_compute_text; ComputePipeline ui_compute_text;
} UIContext; } 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); 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);

@ -81,6 +81,7 @@ typedef struct RenderContextStruct {
VkFence* in_flight_fences; VkFence* in_flight_fences;
uint32_t current_frame; uint32_t current_frame;
vec2 window_scale;
} RenderContext; } RenderContext;
GLFWwindow* init_window(); GLFWwindow* init_window();

@ -106,7 +106,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
VmaAllocation colored_rect_memory; VmaAllocation colored_rect_memory;
VmaAllocation text_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) { if(result != VK_SUCCESS) {
return result; return result;
} }

@ -684,7 +684,7 @@ VkResult create_text_descriptor(VkDevice device, VmaAllocator allocator, VkDescr
return VK_SUCCESS; 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[] = { VkDescriptorSetLayoutBinding ui_descriptor_bindings[] = {
{ {
.binding = 0, .binding = 0,
@ -758,7 +758,7 @@ VkResult create_ui_descriptor_set(VkDevice device, VmaAllocator allocator, VkExt
} }
UIUniform ui_uniform; UIUniform ui_uniform;
vec3 screen_offset = {-1.0, -1.0, 0.0}; 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_mat4_identity(ui_uniform.screen);
glm_translate(ui_uniform.screen, screen_offset); glm_translate(ui_uniform.screen, screen_offset);
glm_scale(ui_uniform.screen, screen_scale); 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; 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; 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) { if(result != VK_SUCCESS) {
return result; return result;
} }

@ -1,4 +1,5 @@
#include "render.h" #include "render.h"
#include "GLFW/glfw3.h"
#include "stdio.h" #include "stdio.h"
#include "string.h" #include "string.h"
#include "pipeline.h" #include "pipeline.h"
@ -837,6 +838,10 @@ VkResult init_vulkan(GLFWwindow* window, RenderContext* context) {
return VK_ERROR_VALIDATION_FAILED_EXT; 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); result = create_instance(&context->instance);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;