Got text pipeline showing strings

main
noah metz 2024-10-15 16:37:20 -06:00
parent 405cf139ef
commit 934a0a30f3
3 changed files with 13 additions and 9 deletions

@ -71,8 +71,11 @@ void main() {
String string = push.pointers.strings.strings[gID]; String string = push.pointers.strings.strings[gID];
uint buffer_pos = atomicAdd(push.pointers.draw.instance_count, string.len); uint buffer_pos = atomicAdd(push.pointers.draw.instance_count, string.len);
float x = 0;
for(uint i = 0; i < string.len; i++) { for(uint i = 0; i < string.len; i++) {
push.pointers.characters.characters[buffer_pos + i].pos = string.pos; Symbol symbol = font.symbol_list.symbols[push.pointers.codes.codes[buffer_pos + i]];
push.pointers.characters.characters[buffer_pos + i].pos = string.pos + vec3(x, symbol.top/font.height*string.size, 0);
x += symbol.width * string.size / font.height;
push.pointers.characters.characters[buffer_pos + i].size = string.size; push.pointers.characters.characters[buffer_pos + i].size = string.size;
push.pointers.characters.characters[buffer_pos + i].color = string.color; push.pointers.characters.characters[buffer_pos + i].color = string.color;
push.pointers.characters.characters[buffer_pos + i].code = push.pointers.codes.codes[buffer_pos + i]; push.pointers.characters.characters[buffer_pos + i].code = push.pointers.codes.codes[buffer_pos + i];

@ -374,7 +374,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
VkBuffer temp_buffer; VkBuffer temp_buffer;
VmaAllocation temp_memory; VmaAllocation temp_memory;
void* mapped; void* mapped;
result = create_transfer_buffer(sizeof(String) + 2*sizeof(uint32_t), render_context->allocator, &temp_buffer, &temp_memory, (void**)&mapped); result = create_transfer_buffer(sizeof(String) + 100*sizeof(uint32_t), render_context->allocator, &temp_buffer, &temp_memory, (void**)&mapped);
if(result != VK_SUCCESS) { if(result != VK_SUCCESS) {
return result; return result;
} }
@ -387,13 +387,14 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
mapped_string->color[1] = 1.0; mapped_string->color[1] = 1.0;
mapped_string->color[2] = 1.0; mapped_string->color[2] = 1.0;
mapped_string->color[3] = 1.0; mapped_string->color[3] = 1.0;
mapped_string->size = 200.0; mapped_string->size = 50.0;
mapped_string->length = 2; mapped_string->length = 100;
mapped_string->offset = 0; mapped_string->offset = 0;
uint32* mapped_codes = (uint32_t*)(mapped + sizeof(String)); uint32* mapped_codes = (uint32_t*)(mapped + sizeof(String));
mapped_codes[0] = 4; for(uint32_t i = 0; i < 100; i++) {
mapped_codes[1] = 5; mapped_codes[i] = i;
}
VkCommandBuffer command_buffer = command_begin_single(render_context->device, render_context->transfer_pool); VkCommandBuffer command_buffer = command_begin_single(render_context->device, render_context->transfer_pool);
VkBufferCopy copy_string = { VkBufferCopy copy_string = {
@ -402,7 +403,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
}; };
vkCmdCopyBuffer(command_buffer, temp_buffer, text_pointers.strings_buffer, 1, &copy_string); vkCmdCopyBuffer(command_buffer, temp_buffer, text_pointers.strings_buffer, 1, &copy_string);
VkBufferCopy copy_codes = { VkBufferCopy copy_codes = {
.size = 2*sizeof(uint32_t), .size = 100*sizeof(uint32_t),
.srcOffset = sizeof(String), .srcOffset = sizeof(String),
}; };
vkCmdCopyBuffer(command_buffer, temp_buffer, text_pointers.codes_buffer, 1, &copy_codes); vkCmdCopyBuffer(command_buffer, temp_buffer, text_pointers.codes_buffer, 1, &copy_codes);
@ -422,7 +423,7 @@ VkResult render_thread(GLFWwindow* window, RenderContext* render_context) {
.font = test_font_descriptor, .font = test_font_descriptor,
.chars_size = 10*sizeof(Character), .chars_size = 10*sizeof(Character),
.chars = text_pointers.characters_buffer, .chars = text_pointers.characters_buffer,
.string_count = 2, .string_count = 1,
.string_pointers = text_pointers_address, .string_pointers = text_pointers_address,
.string_draw = text_pointers.draw_buffer, .string_draw = text_pointers.draw_buffer,
.string_draw_clear = text_pointers.draw_clear_buffer, .string_draw_clear = text_pointers.draw_clear_buffer,

@ -435,7 +435,7 @@ VkResult create_font_descriptor_pools(VkDevice device, uint32_t max_sets, VkDesc
.binding = 0, .binding = 0,
.descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, .descriptorType = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
.descriptorCount = 1, .descriptorCount = 1,
.stageFlags = VK_SHADER_STAGE_VERTEX_BIT, .stageFlags = VK_SHADER_STAGE_VERTEX_BIT | VK_SHADER_STAGE_COMPUTE_BIT,
}, },
{ {
.binding = 1, .binding = 1,