#include "render.h" #include "pipeline.h" #include "vk_mem_alloc.h" #include "vulkan/vk_enum_string_helper.h" ColoredRect colored_rect(float width, float height, float r, float g, float b, float a, float x, float y, float z) { ColoredRect rect = { .size = {width, height}, .pos = {x, y, z}, .color = {r, g, b, a}, }; return rect; } VkResult render_thread(GLFWwindow* window, RenderContext* render_context) { VkBuffer colored_rect_buffer; VmaAllocation colored_rect_memory; VkBufferCreateInfo colored_rect_buffer_info = { .sType = VK_STRUCTURE_TYPE_BUFFER_CREATE_INFO, .usage = VK_BUFFER_USAGE_VERTEX_BUFFER_BIT, .size = 3*sizeof(ColoredRect), .sharingMode = VK_SHARING_MODE_EXCLUSIVE, }; VmaAllocationCreateInfo colored_rect_memory_info = { .usage = VMA_MEMORY_USAGE_CPU_TO_GPU, }; VkResult result = vmaCreateBuffer(render_context->allocator, &colored_rect_buffer_info, &colored_rect_memory_info, &colored_rect_buffer, &colored_rect_memory, NULL); if(result != VK_SUCCESS) { return result; } ColoredRect* colored_rects; result = vmaMapMemory(render_context->allocator, colored_rect_memory, (void**)&colored_rects); if(result != VK_SUCCESS) { return result; } colored_rects[0] = colored_rect(100.0, 100.0, 1.0, 0.0, 0.0, 1.0, 0.0, 0.0, 0.5); colored_rects[1] = colored_rect(100.0, 100.0, 0.0, 1.0, 0.0, 1.0, 0.0, 100.0, 0.5); colored_rects[2] = colored_rect(100.0, 100.0, 0.0, 0.0, 1.0, 1.0, 100.0, 0.0, 0.5); vmaUnmapMemory(render_context->allocator, colored_rect_memory); UILayer test_layer = { .colored_rects = colored_rect_buffer, .colored_rect_count = 3, }; while(glfwWindowShouldClose(window) == 0) { glfwPollEvents(); result = draw_frame(render_context, &test_layer, 1); if(result != VK_SUCCESS) { fprintf(stderr, "draw_frame error: %s\n", string_VkResult(result)); return result; } } return 0; } int logic_thread() { return 0; } int network_thread() { return 0; } int main() { GLFWwindow* window = init_window(); if(window == NULL) { return 1; } RenderContext render_context = {}; if(init_vulkan(window, &render_context) != VK_SUCCESS) { return 2; } if(render_thread(window, &render_context) != VK_SUCCESS) { return 3; } return 0; }