From 79e3f99d4f1c7b09c234ee45cc341ecea924d9dc Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 21 Oct 2024 15:54:35 -0600 Subject: [PATCH] Made width/height a variable --- client/include/gpu.h | 2 ++ client/src/draw.c | 16 ++++++++++++ client/src/gpu.c | 4 ++- client/src/main.c | 59 ++++++++++++++------------------------------ 4 files changed, 39 insertions(+), 42 deletions(-) diff --git a/client/include/gpu.h b/client/include/gpu.h index a81e3c9..b974206 100644 --- a/client/include/gpu.h +++ b/client/include/gpu.h @@ -47,6 +47,8 @@ VkResult command_transition_image_layout(VkDevice device, VkCommandPool transfer } extern const uint32_t MAX_FRAMES_IN_FLIGHT; +extern const uint32_t WINDOW_WIDTH; +extern const uint32_t WINDOW_HEIGHT; typedef struct SwapchainDetailsStruct { VkSurfaceCapabilitiesKHR capabilities; diff --git a/client/src/draw.c b/client/src/draw.c index 1da6445..0151d0d 100644 --- a/client/src/draw.c +++ b/client/src/draw.c @@ -1,6 +1,13 @@ #include "draw.h" #include "gpu.h" +/* + * Must be updated if any of the following changes + * - ui_context->max_containers <- uint32 + * - ui_context->containers[*].layer_count <- uint32 + * - ui_context->containers[*].layers[*].address <- device address + * Basically, needs to be re-run whenever the number of layers/containers changes + */ void record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_context) { VkDeviceAddress push[2] = {ui_context->address, 0}; @@ -54,6 +61,13 @@ void record_ui_compute(VkCommandBuffer command_buffer, UIContextStorage* ui_cont } } +/* + * Must be updated if any of the following changes + * - ui_context->max_containers <- uint32 + * - ui_context->containers[*].layer_count <- uint32 + * - ui_context->containers[*].layers[*].address <- device address + * Basically, needs to be re-run whenever the number of layers/containers changes + */ void record_ui_draw(VkCommandBuffer command_buffer, UIContextStorage* ui_context) { VkDeviceAddress push[2] = {ui_context->address, 0}; @@ -113,7 +127,9 @@ VkResult record_draw_commands( record_ui_compute(command_buffer, ui_context); vkCmdBeginRenderPass(command_buffer, &render_pass_begin, VK_SUBPASS_CONTENTS_INLINE); + // Render World vkCmdNextSubpass(command_buffer, VK_SUBPASS_CONTENTS_INLINE); + // Render UI record_ui_draw(command_buffer, ui_context); vkCmdEndRenderPass(command_buffer); diff --git a/client/src/gpu.c b/client/src/gpu.c index 4bc7bed..0d72ada 100644 --- a/client/src/gpu.c +++ b/client/src/gpu.c @@ -6,6 +6,8 @@ #include "vulkan/vulkan_core.h" const uint32_t MAX_FRAMES_IN_FLIGHT = 2; +const uint32_t WINDOW_WIDTH = 800; +const uint32_t WINDOW_HEIGHT = 500; const char * validation_layers[] = { "VK_LAYER_KHRONOS_validation", @@ -56,7 +58,7 @@ GLFWwindow* init_window() { glfwWindowHint(GLFW_CLIENT_API, GLFW_NO_API); glfwWindowHint(GLFW_RESIZABLE, GLFW_FALSE); - GLFWwindow* window = glfwCreateWindow(800, 500, "roleplay", 0, 0); + GLFWwindow* window = glfwCreateWindow(WINDOW_WIDTH, WINDOW_HEIGHT, "roleplay", 0, 0); return window; } diff --git a/client/src/main.c b/client/src/main.c index 92eb71f..0adb2e3 100644 --- a/client/src/main.c +++ b/client/src/main.c @@ -16,7 +16,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) { UIContextStorage ui; uint32_t font_index; - uint32_t texture_index; + uint32_t background_index; VkResult result; @@ -32,57 +32,34 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render) { } VK_RESULT(load_font("test.ttf", 16, VK_TRUE, library, render, &ui, &font_index)); + VK_RESULT(load_texture("background.png", render, &ui, &background_index)); - VK_RESULT(load_texture("test.png", render, &ui, &texture_index)); - - UIDrawable image = { - .pos = {0.0, 0.0}, - .size = {100.0, 200.0}, - .color = {1.0, 1.0, 1.0, 1.0}, - .type = 2, - .code = 0, - .id = 0x01, - }; - - UIDrawable rect = { - .pos = {100.0, 0.0}, - .size = {100.0, 200.0}, - .color = {1.0, 0.0, 0.0, 1.0}, - .type = 0, - .id = 0x02, - }; - - UIString string = { - .pos = {0.0, 100.0}, - .color = {1.0, 1.0, 1.0, 1.0}, - .size = 32.0, - .length = strlen("Hello, World!"), - .offset = 0, - .id = 0x03, - }; - - UILayerInput layers[] = { + UIDrawable rects[] = { { - .num_drawables = 1, - .drawables = &image, + .pos = {0.0, 0.0}, + .size = {WINDOW_WIDTH, WINDOW_HEIGHT}, + .color = {1.0, 1.0, 1.0, 1.0}, + .type = 2, + .code = background_index, }, { - .num_strings = 1, - .strings = &string, - .num_codes = strlen("Hello, World!"), - .codes = malloc(strlen("Hello, World!")*sizeof(uint32_t)), - .num_drawables = 1, - .drawables = &rect, - .font = font_index, + .pos = {150.0, 100.0}, + .size = {500.0, 300.0}, + .color = {1.0, 1.0, 1.0, 1.0}, }, }; - map_string("Hello, World!", layers[1].codes, 0, ui.fonts[0].charmap, ui.fonts[0].num_symbols); + UILayerInput layers[] = { + { + .num_drawables = sizeof(rects)/sizeof(UIDrawable), + .drawables = rects, + }, + }; UIContainerInput container_info = { .id = 0xDEADBEEF, .pos = {0.0, 0.0}, - .size = {200.0, 200.0}, + .size = {WINDOW_WIDTH, WINDOW_HEIGHT}, .layer_count = sizeof(layers)/sizeof(UILayerInput), .layers = layers, };