summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--assets/shaders/glyph.vert14
-rw-r--r--src/font.cpp224
-rw-r--r--src/font.hpp18
-rw-r--r--src/game.cpp14
-rw-r--r--src/window.cpp17
5 files changed, 229 insertions, 58 deletions
diff --git a/assets/shaders/glyph.vert b/assets/shaders/glyph.vert
index 9907ce1..a2c7de3 100644
--- a/assets/shaders/glyph.vert
+++ b/assets/shaders/glyph.vert
@@ -6,11 +6,12 @@ layout(location = 1) in vec2 in_uv;
layout(location = 2) in vec2 in_atlas_size;
// instance
-layout(location = 3) in vec4 in_fg_color;
-layout(location = 4) in vec4 in_bg_color;
-layout(location = 5) in vec2 in_sprite_region_min;
-layout(location = 6) in vec2 in_sprite_region_max;
-layout(location = 7) in float in_width;
+layout(location = 3) in mat4 pos_scale;
+layout(location = 7) in vec4 in_fg_color;
+layout(location = 8) in vec4 in_bg_color;
+layout(location = 9) in vec2 in_sprite_region_min;
+layout(location = 10) in vec2 in_sprite_region_max;
+layout(location = 11) in float in_width;
layout(location = 0) out vec4 out_fg_color;
layout(location = 1) out vec4 out_bg_color;
@@ -24,7 +25,8 @@ out gl_PerVertex
void main()
{
- gl_Position = vec4(in_position / 4.0, 0.0, 1.0);
+ vec4 transformed_position = pos_scale * vec4(in_position, 0.0, 1.0);
+ gl_Position = vec4(transformed_position.xy, 0.0, 1.0);
out_fg_color = in_fg_color;
out_bg_color = in_bg_color;
out_uv = mix(in_sprite_region_min, in_sprite_region_max, in_uv) / in_atlas_size;
diff --git a/src/font.cpp b/src/font.cpp
index 1ecb831..203eea3 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -32,21 +32,15 @@ struct FontTypeData {
} ftd;
struct FontInstanceBufferItem {
+ glm::mat4 pos_scale;
glm::vec4 fg_color;
glm::vec4 bg_color;
glm::vec2 sprite_region_min;
glm::vec2 sprite_region_max;
float width;
+ float padding[3];
};
-const VkDeviceSize instance_buffer_item_size = 0
- + sizeof(glm::vec4)
- + sizeof(glm::vec4)
- + sizeof(glm::vec2)
- + sizeof(glm::vec2)
- + sizeof(float)
- + 0;
-
// BucketContainer<FontType, TextRenderHandle, 2> bktFont;
uint32_t utf8_to_unicode(const char* str, uint32_t &out) {
@@ -90,23 +84,148 @@ uint32_t utf8_to_unicode(const char* str, uint32_t &out) {
return i;
}
+void FontType_Inner_CalcTransforms(const FontType *ft, FontRender *fr, FontInstanceBufferItem *ptr_dst) {
+ assert(ft != nullptr);
+ assert(fr != nullptr);
+ assert(ptr_dst != nullptr);
+ FontGlyphChar *fgc;
+ FontInstanceBufferItem *buf_item;
+ uint32_t i;
+ float cursor_head, line_index, line_height;
+ float glyph_ratio, screen_ratio;
+ glm::vec2 glyph_size;
+ glm::mat3 tr_scale_glyph = glm::mat3(1);
+ glm::mat3 tr_scale_screen = glm::mat3(1);
+ glm::mat3 tr_translate = glm::mat3(1);
+
+ cursor_head = 0;
+ line_index = 0;
+ line_height = (1 / ft->spacing.geometry_scale) * ft->spacing.line_height;
+
+ for (i = 0; i < fr->n_glyphs; ++i) {
+
+ fgc = &ft->glyphs[fr->glyph_indices[i]];
+
+ glyph_size.x = fgc->baseline_bounding_box.z - fgc->baseline_bounding_box.x;
+ glyph_size.y = fgc->baseline_bounding_box.w - fgc->baseline_bounding_box.y;
+ glyph_ratio = glyph_size.x / glyph_size.y;
+
+ // this might break if the screen is vertical?
+ // scale the uniform box to the glyph ratio
+ if (glyph_ratio > 0) {
+ tr_scale_glyph[0][0] = glyph_ratio;
+ tr_scale_glyph[1][1] = 1;
+ screen_ratio = glyph_size.x / (float)Extent.width;
+ } else {
+ tr_scale_glyph[0][0] = 1;
+ tr_scale_glyph[1][1] = glyph_ratio;
+ screen_ratio = glyph_size.y / (float)Extent.height;
+ }
+ // shrink the correctly sized box to screen size
+ tr_scale_screen[0][0] = screen_ratio;
+ tr_scale_screen[1][1] = screen_ratio;
+
+ // move to appropriate position + char placement
+ tr_translate[2][0] = ((fr->settings.surface_area_pos.x + cursor_head) - (Extent.width / 2.0)) / (Extent.width / 2.0);
+ tr_translate[2][1] = ((fr->settings.surface_area_pos.y + ((line_index + 1) * line_height)) - (Extent.width / 2.0)) / (Extent.width / 2.0);
+
+ cursor_head += fgc->advance * fr->settings.char_scale * (ft->spacing.em_size / ft->spacing.geometry_scale);
+
+ buf_item = &ptr_dst[i];
+ buf_item->pos_scale = tr_translate * tr_scale_glyph * tr_scale_screen;
+ buf_item->fg_color = glm::vec4(0.4, 0.9, 0.5, 0.8);
+ buf_item->bg_color = glm::vec4(0.0, 0.0, 0.0, 0.0);
+ buf_item->sprite_region_min = fgc->sprite_region_min;
+ buf_item->sprite_region_max = fgc->sprite_region_max;
+ buf_item->width = 1;
+ // buf_item->pos_scale[0][1] *= -1.0;
+ }
+}
+
void FontType_Init() {
ftd.n_ft = FontTypeIndex{5};
ftd.arr_ft = pk_new<FontType>(5);
- // memset(ftd.arr_ft, 0, sizeof(FontType) * 5);
+ for (FontTypeIndex_T i = 0; i < 5; ++i) {
+ FontType *ft = &ftd.arr_ft[i];
+ ft->glyphs = nullptr;
+ ft->renders = nullptr;
+ }
}
void FontType_Teardown() {
FontTypeIndex i;
- FontType *ft;
for (i = FontTypeIndex{0}; i < ftd.h_ft; ++i) {
FontType_Unload(i);
- ft = &ftd.arr_ft[(FontTypeIndex_T)i];
- if (ft->renders != nullptr) pk_delete<FontRender>(ft->renders, (FontTypeIndex_T)ft->n_render);
}
if (ftd.arr_ft != nullptr) pk_delete(ftd.arr_ft, (FontTypeIndex_T)ftd.n_ft);
}
+void FontType_Tick(double delta) {
+ (void)delta;
+ VkResult vkResult;
+ FontInstanceBufferItem *fibis = nullptr;
+ size_t index;
+ FontRender *fr;
+ for (FontTypeIndex_T i = 0; i < (FontTypeIndex_T)ftd.h_ft; ++i) {
+ index = 0;
+ FontType *ft = &ftd.arr_ft[i];
+ if (ft->last_graphics_resize_index == pkeRuntime.graphics.resize_index)
+ continue;
+ if (ft->bindings.instanceCounter == 0)
+ continue;
+ ft->last_graphics_resize_index = pkeRuntime.graphics.resize_index;
+
+ // TODO specific bucket
+ fibis = pk_new<FontInstanceBufferItem>(ft->bindings.instanceCounter);
+ for (FontRenderIndex_T k = 0; k < (FontRenderIndex_T)ft->n_render; ++k) {
+ fr = &ft->renders[k];
+ FontType_Inner_CalcTransforms(ft, fr, &fibis[index]);
+ index += fr->n_glyphs;
+ }
+
+ PKVK_TmpBufferDetails tmpBufferDetails{};
+ PKVK_BeginBuffer(graphicsFamilyIndex, sizeof(FontInstanceBufferItem) * ft->bindings.instanceCounter, tmpBufferDetails);
+ {
+ VkCommandBufferBeginInfo vkCommandBufferBeginInfo;
+ vkCommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
+ vkCommandBufferBeginInfo.pNext = nullptr;
+ // TODO consider single-use?
+ vkCommandBufferBeginInfo.flags = 0;
+ vkCommandBufferBeginInfo.pInheritanceInfo = nullptr;
+ vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ assert(vkResult == VK_SUCCESS);
+
+ memcpy(tmpBufferDetails.deviceData, fibis, sizeof(FontInstanceBufferItem) * ft->bindings.instanceCounter);
+
+ VkBufferCopy vk_buffer_copy{};
+ vk_buffer_copy.srcOffset = 0;
+ vk_buffer_copy.dstOffset = 0;
+ vk_buffer_copy.size = sizeof(FontInstanceBufferItem) * ft->bindings.instanceCounter;
+ vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, ft->bindings.instanceBD.buffer, 1, &vk_buffer_copy);
+
+ vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ assert(vkResult == VK_SUCCESS);
+
+ VkSubmitInfo submitInfo;
+ submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
+ submitInfo.pNext = nullptr;
+ submitInfo.waitSemaphoreCount = 0;
+ submitInfo.pWaitSemaphores = nullptr;
+ submitInfo.pWaitDstStageMask = nullptr;
+ submitInfo.commandBufferCount = 1;
+ submitInfo.pCommandBuffers = &tmpBufferDetails.cmdBuffer;
+ submitInfo.signalSemaphoreCount = 0;
+ submitInfo.pSignalSemaphores = nullptr;
+ vkResult = vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
+ assert(vkResult == VK_SUCCESS);
+ vkResult = vkQueueWaitIdle(tmpBufferDetails.queue);
+ assert(vkResult == VK_SUCCESS);
+ }
+ PKVK_EndBuffer(tmpBufferDetails);
+ pk_delete<FontInstanceBufferItem>(fibis, ft->bindings.instanceCounter);
+ }
+}
+
void FontType_Serialize(std::ofstream &stream, FontType *ft) {
FontTypeSpacing sp{};
memset(&sp, 0, sizeof(sp));
@@ -786,6 +905,17 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
void FontType_Unload(FontTypeIndex idx) {
FontType *ft = &ftd.arr_ft[(FontTypeIndex_T)idx];
+
+ // TODO specific bucket
+ if (ft->renders != nullptr) {
+ for (FontRenderIndex_T i = 0; i < (FontRenderIndex_T)ft->n_render; ++i) {
+ if (ft->renders[i].glyph_indices != nullptr) {
+ pk_delete<uint32_t>(ft->renders[i].glyph_indices, ft->renders[i].n_glyphs);
+ }
+ }
+ pk_delete<FontRender>(ft->renders, (FontTypeIndex_T)ft->n_render);
+ }
+
if (ft->gr.vkDescriptorSets != VK_NULL_HANDLE && ft->gr.vkDescriptorPool != VK_NULL_HANDLE) {
// 2023-09-27 - JCB (copied from entities.cpp)
// We are not setting the pool flag for allowing freeing descriptor sets
@@ -864,13 +994,13 @@ void FontType_Unload(FontTypeIndex idx) {
// This could probably be shortened or deferred by creating a larger-than-needed
// buffer.
// TODO threading
-FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
+FontRender FontType_AddStringRender(FontTypeIndex idx_ft, const pk_str str, FontRenderSettings *settings) {
+ assert(settings != nullptr);
VkResult vkResult;
FontType *ft = &ftd.arr_ft[(FontTypeIndex_T)idx_ft];
FontRender *fr;
FontGlyphChar *fgc;
FontRenderIndex idx_fr = ft->n_render;
- DynArray<FontInstanceBufferItem> instance_buffer_items;
uint32_t i, ii, u, count;
int32_t l, m, r;
@@ -882,27 +1012,26 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
ft->renders = arr;
}
fr = &ft->renders[(FontRenderIndex_T)idx_fr];
- fr->len = cstr.length;
fr->index_ft = idx_ft;
fr->index_fr = idx_fr;
+ fr->settings = *settings;
// insert new characters into tmp buffer
- instance_buffer_items.Reserve(cstr.length);
{
+ DynArray<uint32_t> glyph_indices;
+ glyph_indices.Reserve(str.length);
count = 0;
- FontInstanceBufferItem *buf_item;
- for (i = 0; i < cstr.length;) {
+ for (i = 0; i < str.length;) {
fgc = nullptr;
u = 0;
// determine unicode char
- ii = utf8_to_unicode(&cstr.val[i], u);
+ ii = utf8_to_unicode(&str.val[i], u);
if (ii == 0) {
- fprintf(stderr, "failed to determine unicode for character: '%c'\n", cstr.val[i]);
+ fprintf(stderr, "failed to determine unicode for character: '%c' at byte index: '%i'\n", str.val[i], i);
i += 1;
continue;
}
i += ii;
- count += 1;
// binary search for glyph details
l = 0;
@@ -917,23 +1046,27 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
} while (fgc->unicode != u && l <= r);
if (fgc->unicode != u) {
- fprintf(stderr, "font: '%s' doesn't contain unicode character: '%u'\n", ft->title.val, u);
+ fprintf(stderr, "font: '%s' doesn't contain unicode character '%u': '%lc'\n", ft->title.val, u, (wint_t)u);
continue;
}
+ count += 1;
+ glyph_indices.Push(m);
+ }
- buf_item = &instance_buffer_items.Push();
- buf_item->fg_color = glm::vec4(0.4, 0.9, 0.5, 0.8);
- buf_item->bg_color = glm::vec4(0.0, 0.0, 0.0, 0.0);
- buf_item->sprite_region_min = fgc->sprite_region_min;
- buf_item->sprite_region_max = fgc->sprite_region_max;
- buf_item->width = 24;
+ // TODO specific bucket
+ fr->n_glyphs = count;
+ fr->glyph_indices = pk_new<uint32_t>(count);
+ for (i = 0; i < count; ++i) {
+ fr->glyph_indices[i] = glyph_indices[i];
}
}
+
VkDeviceSize item_count_orig = ft->bindings.instanceCounter;
VkDeviceSize item_count_new = ft->bindings.instanceCounter + count;
// copy existing buffer to new buffer
- VkDeviceSize byteCount = instance_buffer_item_size * item_count_new;
+ // create new buffer
+ VkDeviceSize byteCount = sizeof(FontInstanceBufferItem) * item_count_new;
PKVK_TmpBufferDetails tmpBufferDetails{};
{
VkBuffer newBuffer;
@@ -951,6 +1084,7 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
VkMemoryRequirements vkMemReqs;
vkGetBufferMemoryRequirements(vkDevice, newBuffer, &vkMemReqs);
+ assert(sizeof(FontInstanceBufferItem) % vkMemReqs.alignment == 0);
vkDestroyBuffer(vkDevice, newBuffer, vkAllocator);
newBuffer = VK_NULL_HANDLE;
@@ -972,8 +1106,8 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
vkResult = vkBindBufferMemory(vkDevice, newBuffer, new_memory, 0);
assert(vkResult == VK_SUCCESS);
- PKVK_BeginBuffer(transferFamilyIndex, byteCount, tmpBufferDetails, PKVK_TmpBufferFlags_NONE);
if (ft->bindings.instanceBD.buffer != VK_NULL_HANDLE) {
+ PKVK_BeginBuffer(transferFamilyIndex, byteCount, tmpBufferDetails, PKVK_TmpBufferFlags_NONE);
VkCommandBufferBeginInfo vkCommandBufferBeginInfo;
vkCommandBufferBeginInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO;
@@ -981,15 +1115,17 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
// TODO consider single-use?
vkCommandBufferBeginInfo.flags = 0;
vkCommandBufferBeginInfo.pInheritanceInfo = nullptr;
- vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ assert(vkResult == VK_SUCCESS);
VkBufferCopy vk_buffer_copy{};
vk_buffer_copy.srcOffset = 0;
vk_buffer_copy.dstOffset = 0;
- vk_buffer_copy.size = instance_buffer_item_size * item_count_orig;
+ vk_buffer_copy.size = sizeof(FontInstanceBufferItem) * item_count_orig;
vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, ft->bindings.instanceBD.buffer, newBuffer, 1, &vk_buffer_copy);
- vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ assert(vkResult == VK_SUCCESS);
VkSubmitInfo submitInfo;
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
@@ -1001,11 +1137,13 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
submitInfo.pCommandBuffers = &tmpBufferDetails.cmdBuffer;
submitInfo.signalSemaphoreCount = 0;
submitInfo.pSignalSemaphores = nullptr;
- vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
- vkQueueWaitIdle(tmpBufferDetails.queue);
+ vkResult = vkQueueSubmit(tmpBufferDetails.queue, 1, &submitInfo, nullptr);
+ assert(vkResult == VK_SUCCESS);
+ vkResult = vkQueueWaitIdle(tmpBufferDetails.queue);
+ assert(vkResult == VK_SUCCESS);
+ PKVK_EndBuffer(tmpBufferDetails, PKVK_TmpBufferFlags_NONE);
}
- PKVK_EndBuffer(tmpBufferDetails, PKVK_TmpBufferFlags_NONE);
if (ft->bindings.instanceBD.buffer != VK_NULL_HANDLE)
vkDestroyBuffer(vkDevice, ft->bindings.instanceBD.buffer, vkAllocator);
if (ft->gr.deviceMemoryInst != VK_NULL_HANDLE)
@@ -1017,7 +1155,7 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
}
// create tmp local buffer & copy data to graphics card
- byteCount = instance_buffer_item_size * count;
+ byteCount = sizeof(FontInstanceBufferItem) * count;
PKVK_BeginBuffer(transferFamilyIndex, byteCount, tmpBufferDetails);
{
@@ -1027,17 +1165,19 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
// TODO consider single-use?
vkCommandBufferBeginInfo.flags = 0;
vkCommandBufferBeginInfo.pInheritanceInfo = nullptr;
- vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ vkResult = vkBeginCommandBuffer(tmpBufferDetails.cmdBuffer, &vkCommandBufferBeginInfo);
+ assert(vkResult == VK_SUCCESS);
- memcpy(tmpBufferDetails.deviceData, instance_buffer_items.GetPtr(), instance_buffer_items.Count() * instance_buffer_item_size);
+ FontType_Inner_CalcTransforms(ft, fr, (FontInstanceBufferItem*)tmpBufferDetails.deviceData);
VkBufferCopy vk_buffer_copy{};
vk_buffer_copy.srcOffset = 0;
- vk_buffer_copy.dstOffset = instance_buffer_item_size * item_count_orig;
- vk_buffer_copy.size = instance_buffer_item_size * count;
+ vk_buffer_copy.dstOffset = sizeof(FontInstanceBufferItem) * item_count_orig;
+ vk_buffer_copy.size = sizeof(FontInstanceBufferItem) * count;
vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, ft->bindings.instanceBD.buffer, 1, &vk_buffer_copy);
- vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ vkResult = vkEndCommandBuffer(tmpBufferDetails.cmdBuffer);
+ assert(vkResult == VK_SUCCESS);
VkSubmitInfo submitInfo;
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
diff --git a/src/font.hpp b/src/font.hpp
index 9be881c..5fd0f61 100644
--- a/src/font.hpp
+++ b/src/font.hpp
@@ -26,17 +26,20 @@ struct FontGlyphChar {
glm::vec2 sprite_region_max;
glm::dvec4 baseline_bounding_box;
uint32_t unicode;
- bool is_whitespace;
+ bool is_whitespace; // TODO
};
struct FontRenderSettings {
- float char_scale;
+ float char_scale; // TODO
float line_height_scale;
float char_spacing_scale;
- glm::ivec2 surface_area_size;
- FONT_RENDER_SURFACE_AREA_TYPE_FLAGS surface_area_type_flags;
+ glm::ivec2 surface_area_size; // TODO
+ glm::ivec2 surface_area_pos;
+ FONT_RENDER_SURFACE_AREA_TYPE_FLAGS surface_area_type_flags; // TODO
};
struct FontRender {
- uint32_t len;
+ uint32_t *glyph_indices;
+ uint32_t n_glyphs;
+ uint32_t buffer_start_index;
FontTypeIndex index_ft;
FontRenderIndex index_fr;
FontRenderSettings settings;
@@ -55,6 +58,7 @@ struct FontTypeSpacing {
double underline_thickness;
};
struct FontType : public Entity_Base {
+ uint64_t last_graphics_resize_index;
pk_cstr title;
AssetHandle fontTextureAssetHandle;
AssetHandle glyphDetailsAssetHandle;
@@ -89,13 +93,13 @@ struct FontType : public Entity_Base {
void FontType_Init();
void FontType_Teardown();
-void FontType_Tick();
+void FontType_Tick(double delta);
void FontType_Serialize(std::ofstream &stream, FontType *ft);
void FontType_Deserialize(std::ifstream &stream);
FontType* FontType_GetFonts(FontTypeIndex &count);
FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle, AssetHandle glyphsHandle, FontTypeSpacing *spacing);
void FontType_Unload(FontTypeIndex idx);
-FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr);
+FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_str str, FontRenderSettings *settings);
void FontType_RemoveStringRender(FontRender fr);
#endif /* PKE_FONT_TYPE_HPP */
diff --git a/src/game.cpp b/src/game.cpp
index 58e9289..434dc56 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -568,6 +568,7 @@ void Game_Tick(double delta) {
EntityType_Tick(delta);
ECS_Tick(delta);
PkeInput_Tick(delta);
+ FontType_Tick(delta);
const auto pluginCount = LoadedPkePlugins.Count();
for (long i = 0; i < pluginCount; ++i) {
@@ -608,10 +609,21 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
}
}
+ // pk_cstr test_text = cstring_to_pk_cstr("*0123456789$");
+ // pk_cstr test_text = cstring_to_pk_cstr("$#");
pk_cstr test_text = cstring_to_pk_cstr("$");
FontTypeIndex font_type_count;
+ FontRenderSettings fr_set;
+ fr_set.char_scale = 1.0;
+ fr_set.line_height_scale = 1.0;
+ fr_set.char_spacing_scale = 1.0;
+ fr_set.surface_area_size.x = 1;
+ fr_set.surface_area_size.y = 1;
+ fr_set.surface_area_pos.x = 1920 / 2.0;
+ fr_set.surface_area_pos.y = 1080 / 2.0;
+ fr_set.surface_area_type_flags = FONT_RENDER_SURFACE_AREA_TYPE_FLAGS_NONE;
if ((FontType_GetFonts(font_type_count)); font_type_count != FontTypeIndex{0}) {
- FontType_AddStringRender(FontTypeIndex{0}, test_text);
+ FontType_AddStringRender(FontTypeIndex{0}, pk_cstr_to_pk_str(&test_text), &fr_set);
}
GameTimePoint lastTimePoint = pkeSettings.steadyClock.now();
diff --git a/src/window.cpp b/src/window.cpp
index f356221..55fafff 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -225,6 +225,7 @@ VkCommandBuffer GetCommandBuffer_Transfer() {
return pkvk_shared.command_buffer.transfer;
}
+// TODO fence
void PKVK_BeginBuffer(unsigned int family_index, VkDeviceSize requestedMemorySize, PKVK_TmpBufferDetails &tmpBufferDetails, PKVK_TmpBufferFlags flags) {
if (family_index == graphicsFamilyIndex) {
tmpBufferDetails.queue = pkvk_shared.queue.graphics;
@@ -1753,7 +1754,7 @@ void CreateGraphicsPipelines() {
long offset = 0;
const long vertexBindingCount_glyph = 4;
VkVertexInputBindingDescription vertInputBD_glyph[vertexBindingCount_glyph];
- const long vertexAttrDescCount_glyph = 8;
+ const long vertexAttrDescCount_glyph = 12;
VkVertexInputAttributeDescription vertAttrDesc_glyph[vertexAttrDescCount_glyph];
VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo_glyph{vkPipelineVertexInputStateCreateInfo_txtr};
{
@@ -1778,11 +1779,14 @@ void CreateGraphicsPipelines() {
// instance - total
vertInputBD_glyph[index].binding = index;
vertInputBD_glyph[index].stride = 0
+ + sizeof(glm::mat4)
+ sizeof(glm::vec4)
+ sizeof(glm::vec4)
+ sizeof(glm::vec2)
+ sizeof(glm::vec2)
- + sizeof(float);
+ + sizeof(float)
+ + (sizeof(float) * 3) // padding
+ + 0;
vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
// index += 1;
@@ -1809,6 +1813,15 @@ void CreateGraphicsPipelines() {
vertAttrDesc_glyph[index].offset = 0;
index += 1;
+ // instance - pos_scale
+ for (long i = 0; i < 4; ++i) {
+ vertAttrDesc_glyph[index].binding = 3;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = offset;
+ offset += sizeof(glm::vec4);
+ index += 1;
+ }
+
// instance - in_fg_color
vertAttrDesc_glyph[index].binding = 3;
vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;