-
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implementing character string (Text) rendering (WIP) * added text_shader.glsl * Added space (' ') whitespace support. * Added new font * Deleted MeshLib * Added MeshLib * Deleted MeshLib * Updated MeshLib, SafeMemory and BufferLib submodules * Updated safe memory submodule
- Loading branch information
Showing
16 changed files
with
322 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule MeshLib
updated
15 files
+1 −1 | dependencies/BufferLib | |
+1 −1 | dependencies/DiskManager | |
+1 −1 | dependencies/HPML | |
+1 −1 | dependencies/SafeMemory | |
+10 −3 | include/meshlib/assert.h | |
+7 −3 | include/meshlib/debug.h | |
+7 −2 | include/meshlib/defines.h | |
+9 −0 | include/meshlib/obj/parse_error.h | |
+10 −0 | include/meshlib/obj/readers/ascii.h | |
+11 −0 | include/meshlib/obj/readers/binary.h | |
+7 −0 | include/meshlib/parsers/binary.h | |
+16 −1 | include/meshlib/parsers/string.h | |
+8 −0 | include/meshlib/stl/parse_error.h | |
+9 −0 | include/meshlib/stl/readers/ascii.h | |
+9 −0 | include/meshlib/stl/readers/binary.h |
Submodule SafeMemory
updated
7 files
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Submodule BufferLib
updated
13 files
+13 −0 | binding-cpp/BufferLibcpp.gv | |
+90 −0 | binding-cpp/include/buffer.hpp | |
+1 −0 | binding-cpp/lib/testbed.a | |
+197 −0 | binding-cpp/makefile | |
+20 −0 | binding-cpp/source/buffer.cpp | |
+60 −0 | binding-cpp/source/main.cpp | |
+1 −1 | dependencies/CallTrace | |
+17 −3 | include/buffer.h | |
+11 −1 | include/buffer_test.h | |
+0 −6 | include/example.h | |
+0 −4 | source/example.c | |
+ − | source/example.o | |
+0 −1 | source/main.c |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,133 @@ | ||
|
||
|
||
#include <renderer/text_mesh.h> | ||
#include <renderer/assert.h> | ||
#include <renderer/mesh.h> | ||
#include <renderer/internal/vulkan/vulkan_mesh.h> | ||
#include <renderer/mesh3d.h> | ||
#include <renderer/font.h> | ||
#include <memory_allocator/memory_allocator.h> | ||
#include <renderer/assert.h> | ||
#include <ctype.h> | ||
|
||
static void build_meshes(BUFFER* meshes, font_t* font); | ||
|
||
text_mesh_t* text_mesh_create(font_t* font) | ||
{ | ||
assert(font != NULL); | ||
text_mesh_t* text_mesh = heap_new(text_mesh_t); | ||
memset(text_mesh, 0, sizeof(text_mesh_t)); | ||
text_mesh->handle = mesh3d_new(); | ||
text_mesh->font = font; | ||
return text_mesh; | ||
text_mesh_t* text = heap_new(text_mesh_t); | ||
memset(text, 0, sizeof(text_mesh_t)); | ||
text->meshes = buf_create(sizeof(mesh3d_t*), 0, 0); | ||
text->render_meshes = buf_create(sizeof(mesh_t*), 0, 0); | ||
text->instance_counts = buf_create(sizeof(u32), 0, 0); | ||
text->font = font; | ||
build_meshes(&text->meshes, font); | ||
return text; | ||
} | ||
|
||
void text_mesh_destroy(text_mesh_t* text, renderer_t* renderer) | ||
{ | ||
assert(text != NULL); | ||
mesh_destroy(text->render_handle, renderer); | ||
mesh3d_destroy(text->handle); | ||
for(u32 i = 0; i < text->meshes.element_count; i++) | ||
mesh3d_destroy(*(mesh3d_t**)buf_get_ptr_at(&text->meshes, i)); | ||
for(u32 i = 0; i < text->render_meshes.element_count; i++) | ||
mesh_destroy(*(mesh_t**)buf_get_ptr_at(&text->render_meshes, i), renderer); | ||
} | ||
|
||
void text_mesh_release_resources(text_mesh_t* text) | ||
{ | ||
assert(text != NULL); | ||
mesh_release_resources(text->render_handle); | ||
for(u32 i = 0; i < text->render_meshes.element_count; i++) | ||
mesh_release_resources(*(mesh_t**)buf_get_ptr_at(&text->render_meshes, i)); | ||
buf_free(&text->render_meshes); | ||
buf_free(&text->meshes); | ||
heap_free(text); | ||
} | ||
|
||
|
||
void text_mesh_draw(text_mesh_t* text, renderer_t* renderer) | ||
{ | ||
assert(text != NULL); | ||
mesh_draw_indexed(text->render_handle, renderer); | ||
for(u32 i = 0; i < text->render_meshes.element_count; i++) | ||
mesh_draw_indexed_instanced(*(mesh_t**)buf_get_ptr_at(&text->render_meshes, i), renderer, *(u32*)buf_get_ptr_at(&text->instance_counts, i)); | ||
} | ||
|
||
|
||
void text_mesh_set_string(text_mesh_t* text, const char* string) | ||
void text_mesh_set_string(text_mesh_t* text, renderer_t* renderer, const char* string) | ||
{ | ||
assert(text != NULL); | ||
|
||
//maximum number of characters in the character set | ||
u8 unique_char_count = 126 - 33 + 1; | ||
|
||
//create a count_mask, | ||
u32 count_mask[unique_char_count]; | ||
memset(count_mask, 0UL, sizeof(u32) * unique_char_count); | ||
|
||
//create instance buffers for each possible character in the character set | ||
BUFFER instance_buffers[unique_char_count]; | ||
for(u8 i = 0; i < unique_char_count; i++) | ||
instance_buffers[i] = buf_create(sizeof(vec3_t(float)), 0, 0); | ||
|
||
float horizontal_pen = 0; | ||
while(*string != 0) | ||
{ | ||
char ch = *string; | ||
assert((ch >= 32) && (ch <= 126)); | ||
font_glyph_info_t info; | ||
font_get_glyph_info(text->font, ch, &info); | ||
|
||
vec3_t(float) v = { 0, 0, horizontal_pen }; | ||
horizontal_pen += info.advance_width; | ||
|
||
if(ch != 32) | ||
{ | ||
BUFFER* buffer = &instance_buffers[ch - 33]; | ||
count_mask[ch - 33]++; | ||
buf_push(buffer, &v); | ||
} | ||
string++; | ||
} | ||
|
||
for(u8 i = 0; i < unique_char_count; i++) | ||
{ | ||
if(count_mask[i] == 0UL) continue; | ||
mesh_t* mesh = mesh_create(renderer, *(mesh3d_t**)buf_get_ptr_at(&text->meshes, i)); | ||
vulkan_vertex_buffer_create_info_t create_info = | ||
{ | ||
.data = instance_buffers[i].bytes, | ||
.stride = sizeof(vec3_t(float)), | ||
.count = instance_buffers[i].element_count | ||
}; | ||
vulkan_mesh_create_and_add_vertex_buffer(mesh, renderer, &create_info); | ||
buf_free(&instance_buffers[i]); | ||
buf_push(&text->render_meshes, &mesh); | ||
} | ||
|
||
for(u8 i = 0; i < unique_char_count; i++) | ||
if(count_mask[i] != 0UL) | ||
buf_push(&text->instance_counts, &count_mask[i]); | ||
} | ||
|
||
void text_mesh_set_size(text_mesh_t* text, const u32 size) | ||
{ | ||
assert(text != NULL); | ||
|
||
} | ||
|
||
|
||
static void build_meshes(BUFFER* meshes, font_t* font) | ||
{ | ||
/*NOTE: 32 is space, not printable character*/ | ||
u16 A = 33; | ||
buf_clear(meshes, NULL); | ||
while(A <= 126) | ||
{ | ||
font_glyph_info_t info; | ||
font_get_glyph_info(font, A, &info); | ||
mesh3d_t* mesh = mesh3d_new(); | ||
font_get_glyph_mesh(font, A, FONT_GLYPH_MESH_QUALITY_LOW, mesh); | ||
buf_push(meshes, &mesh); | ||
A++; | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.