82 lines
2.0 KiB
C
82 lines
2.0 KiB
C
#include "render.h"
|
|
#include "arpa/inet.h"
|
|
#include "ui.h"
|
|
#include "vk_mem_alloc.h"
|
|
#include "vulkan/vk_enum_string_helper.h"
|
|
#include "vulkan/vulkan_core.h"
|
|
|
|
#include "ft2build.h"
|
|
#include FT_FREETYPE_H
|
|
|
|
VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
|
|
VkResult result;
|
|
UIContextStorage ui;
|
|
FT_Library library;
|
|
FontStorage font;
|
|
uint32_t* charmap;
|
|
VkBuffer temp_buffer;
|
|
VmaAllocation temp_memory;
|
|
void* mapped;
|
|
UILayerStorage layer = {};
|
|
|
|
result = create_ui_context(render_context->device, render_context->allocator, render_context->render_pass, &ui);
|
|
if(result != VK_SUCCESS) {
|
|
return result;
|
|
}
|
|
|
|
if(FT_Init_FreeType(&library) != FT_Err_Ok) {
|
|
return VK_ERROR_UNKNOWN;
|
|
}
|
|
|
|
result = load_font(render_context->device, render_context->allocator, ui.font_infos, ui.font_samplers, ui.font_textures, 0, render_context->transfer_pool, render_context->transfer_queue, library, "test.ttf", 16, VK_TRUE, &charmap, &font);
|
|
if(result != VK_SUCCESS) {
|
|
return result;
|
|
}
|
|
|
|
result = create_transfer_buffer(2*sizeof(String) + 100*sizeof(uint32_t), render_context->allocator, &temp_buffer, &temp_memory, (void**)&mapped);
|
|
if(result != VK_SUCCESS) {
|
|
return result;
|
|
}
|
|
|
|
vkQueueWaitIdle(render_context->transfer_queue.handle);
|
|
vmaUnmapMemory(render_context->allocator, temp_memory);
|
|
vmaDestroyBuffer(render_context->allocator, temp_buffer, temp_memory);
|
|
|
|
while(glfwWindowShouldClose(window) == 0) {
|
|
glfwPollEvents();
|
|
|
|
result = draw_frame(render_context, &ui, &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;
|
|
}
|