|
|
|
@ -273,6 +273,41 @@ VkResult create_ui_pipeline(
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_container(
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
float width,
|
|
|
|
|
float height,
|
|
|
|
|
VkDevice device,
|
|
|
|
|
VmaAllocator allocator,
|
|
|
|
|
VkCommandPool transfer_pool,
|
|
|
|
|
Queue transfer_queue,
|
|
|
|
|
UIContainerStorage* memory) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, 0, sizeof(UIContainer), &memory->container, &memory->container_memory));
|
|
|
|
|
|
|
|
|
|
VkBuffer transfer;
|
|
|
|
|
VmaAllocation transfer_memory;
|
|
|
|
|
void* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, sizeof(UIContainer), &transfer, &transfer_memory, &mapped));
|
|
|
|
|
|
|
|
|
|
memory->data.pos[0] = x;
|
|
|
|
|
memory->data.pos[1] = y;
|
|
|
|
|
memory->data.size[0] = width;
|
|
|
|
|
memory->data.size[1] = height;
|
|
|
|
|
memcpy(mapped, &memory->data, sizeof(UIContainer));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, memory->container, 0, 0, sizeof(UIContainer));
|
|
|
|
|
VK_RESULT(command_end_single(device, command_buffer, transfer_pool, transfer_queue));
|
|
|
|
|
destroy_transfer_buffer(allocator, transfer, transfer_memory);
|
|
|
|
|
|
|
|
|
|
memory->address = buffer_address(device, memory->container);
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult create_layer(
|
|
|
|
|
uint32_t max_strings,
|
|
|
|
|
uint32_t max_codes,
|
|
|
|
@ -282,39 +317,40 @@ VkResult create_layer(
|
|
|
|
|
VmaAllocator allocator,
|
|
|
|
|
VkCommandPool transfer_pool,
|
|
|
|
|
Queue transfer_queue,
|
|
|
|
|
UIContainerStorage* container,
|
|
|
|
|
UILayerStorage* memory) {
|
|
|
|
|
VkResult result;
|
|
|
|
|
|
|
|
|
|
memory->max_strings = max_strings;
|
|
|
|
|
memory->max_codes = max_codes;
|
|
|
|
|
memory->max_drawables = max_drawables;
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, VK_BUFFER_USAGE_INDIRECT_BUFFER_BIT | VK_BUFFER_USAGE_TRANSFER_SRC_BIT, sizeof(UILayer), &memory->layer, &memory->layer_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, 0, sizeof(UIString)*max_strings, &memory->strings, &memory->strings_memory))
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, 0, sizeof(UIDrawable)*max_drawables, &memory->drawables, &memory->drawables_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, 0, sizeof(UIDrawable)*(max_drawables + max_codes), &memory->drawables, &memory->drawables_memory));
|
|
|
|
|
VK_RESULT(create_storage_buffer(allocator, 0, sizeof(uint32_t)*max_codes, &memory->codes, &memory->codes_memory));
|
|
|
|
|
|
|
|
|
|
VkBuffer transfer;
|
|
|
|
|
VmaAllocation transfer_memory;
|
|
|
|
|
UILayer* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, sizeof(UILayer), &transfer, &transfer_memory, (void**)&mapped));
|
|
|
|
|
void* mapped;
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, sizeof(UILayer), &transfer, &transfer_memory, &mapped));
|
|
|
|
|
|
|
|
|
|
mapped->strings = buffer_address(device, memory->strings);
|
|
|
|
|
mapped->codes = buffer_address(device, memory->codes);
|
|
|
|
|
memory->data.strings = buffer_address(device, memory->strings);
|
|
|
|
|
memory->data.codes = buffer_address(device, memory->codes);
|
|
|
|
|
|
|
|
|
|
mapped->drawables = buffer_address(device, memory->drawables);
|
|
|
|
|
memory->data.drawables = buffer_address(device, memory->drawables);
|
|
|
|
|
|
|
|
|
|
mapped->draw.first_vertex = 0;
|
|
|
|
|
mapped->draw.vertex_count = 6;
|
|
|
|
|
mapped->draw.first_instance = 0;
|
|
|
|
|
mapped->draw.instance_count = 0;
|
|
|
|
|
memory->data.draw.first_vertex = 0;
|
|
|
|
|
memory->data.draw.vertex_count = 6;
|
|
|
|
|
memory->data.draw.first_instance = 0;
|
|
|
|
|
memory->data.draw.instance_count = 0;
|
|
|
|
|
|
|
|
|
|
mapped->dispatch_strings.x = 0;
|
|
|
|
|
mapped->dispatch_strings.y = 1;
|
|
|
|
|
mapped->dispatch_strings.z = 1;
|
|
|
|
|
memory->data.dispatch_strings.x = 0;
|
|
|
|
|
memory->data.dispatch_strings.y = 1;
|
|
|
|
|
memory->data.dispatch_strings.z = 1;
|
|
|
|
|
|
|
|
|
|
mapped->font_index = font_index;
|
|
|
|
|
mapped->drawable_count = 0;
|
|
|
|
|
memory->data.font_index = font_index;
|
|
|
|
|
memory->data.max_drawables = max_drawables;
|
|
|
|
|
memory->data.max_strings = max_strings;
|
|
|
|
|
memory->data.num_drawables = 0;
|
|
|
|
|
memory->data.container = container->address;
|
|
|
|
|
memcpy(mapped, &memory->data, sizeof(UILayer));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, memory->layer, 0, 0, sizeof(UILayer));
|
|
|
|
@ -717,14 +753,12 @@ VkResult create_ui_context(
|
|
|
|
|
|
|
|
|
|
VK_RESULT(create_transfer_buffer(allocator, sizeof(UIContext), &transfer, &transfer_memory, (void**)&mapped));
|
|
|
|
|
|
|
|
|
|
mapped->font_infos = buffer_address(device, memory->font_infos);
|
|
|
|
|
vec3 screen_offset = {-1.0, -1.0, 0.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(mapped->screen);
|
|
|
|
|
glm_translate(mapped->screen, screen_offset);
|
|
|
|
|
glm_scale(mapped->screen, screen_scale);
|
|
|
|
|
memory->data.font_infos = buffer_address(device, memory->font_infos);
|
|
|
|
|
memory->data.screen[0] = swapchain_extent.width;
|
|
|
|
|
memory->data.screen[1] = swapchain_extent.height;
|
|
|
|
|
memory->data.scale[0] = window_scale[0];
|
|
|
|
|
memory->data.scale[1] = window_scale[1];
|
|
|
|
|
memcpy(mapped, &memory->data, sizeof(UIContext));
|
|
|
|
|
|
|
|
|
|
VkCommandBuffer command_buffer = command_begin_single(device, transfer_pool);
|
|
|
|
|
command_copy_buffer(command_buffer, transfer, memory->context, 0, 0, sizeof(UIContext));
|
|
|
|
@ -738,3 +772,72 @@ VkResult create_ui_context(
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_ui_rect(
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
float width,
|
|
|
|
|
float height,
|
|
|
|
|
float r,
|
|
|
|
|
float g,
|
|
|
|
|
float b,
|
|
|
|
|
float a,
|
|
|
|
|
UIDrawable* drawable) {
|
|
|
|
|
drawable->pos[0] = x;
|
|
|
|
|
drawable->pos[1] = y;
|
|
|
|
|
drawable->size[0] = width;
|
|
|
|
|
drawable->size[1] = height;
|
|
|
|
|
drawable->color[0] = r;
|
|
|
|
|
drawable->color[1] = g;
|
|
|
|
|
drawable->color[2] = b;
|
|
|
|
|
drawable->color[3] = a;
|
|
|
|
|
drawable->type = 0;
|
|
|
|
|
drawable->code = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void set_ui_string(
|
|
|
|
|
float x,
|
|
|
|
|
float y,
|
|
|
|
|
float size,
|
|
|
|
|
float r,
|
|
|
|
|
float g,
|
|
|
|
|
float b,
|
|
|
|
|
float a,
|
|
|
|
|
uint32_t length,
|
|
|
|
|
uint32_t offset,
|
|
|
|
|
UIString* string) {
|
|
|
|
|
string->pos[0] = x;
|
|
|
|
|
string->pos[1] = y;
|
|
|
|
|
string->size = size;
|
|
|
|
|
string->color[0] = r;
|
|
|
|
|
string->color[1] = g;
|
|
|
|
|
string->color[2] = b;
|
|
|
|
|
string->color[3] = a;
|
|
|
|
|
string->length = length;
|
|
|
|
|
string->offset = offset;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
VkResult set_ui_codes(
|
|
|
|
|
const char * text,
|
|
|
|
|
uint32_t* buffer,
|
|
|
|
|
uint32_t offset,
|
|
|
|
|
uint32_t* charmap,
|
|
|
|
|
uint32_t charmap_size) {
|
|
|
|
|
size_t i = 0;
|
|
|
|
|
while(text[i] != '\0') {
|
|
|
|
|
uint32_t mapped = 0xFFFFFFFF;
|
|
|
|
|
for(uint32_t j = 0; j < charmap_size; j++) {
|
|
|
|
|
if(charmap[j] == (uint32_t)text[i]) {
|
|
|
|
|
mapped = j;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
if(mapped == 0xFFFFFFFF) {
|
|
|
|
|
return VK_ERROR_UNKNOWN;
|
|
|
|
|
}
|
|
|
|
|
buffer[i] = mapped;
|
|
|
|
|
i += 1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return VK_SUCCESS;
|
|
|
|
|
}
|
|
|
|
|