Made width/height a variable

main
noah metz 2024-10-21 15:54:35 -06:00
parent b19240899a
commit 79e3f99d4f
4 changed files with 39 additions and 42 deletions

@ -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;

@ -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);

@ -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;
}

@ -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,
};