summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJonathan Bradley <jcb@pikum.xyz>2025-02-05 19:09:10 -0500
committerJonathan Bradley <jcb@pikum.xyz>2025-02-05 19:09:10 -0500
commita9fb380f9d0b53cde554b265d9c6b66d26183c38 (patch)
tree8ea3648c497d4a3ac8ce2f6dafa2beca324e7249
parent61e179f9580c985cb5ca80ea732fc7572d31c489 (diff)
pke: mtsdf displays, bypass fg/bg not working
-rw-r--r--assets/shaders/glyph.frag9
-rw-r--r--assets/shaders/glyph.vert20
-rw-r--r--editor/editor.cpp23
-rw-r--r--src/font.cpp72
-rw-r--r--src/font.hpp25
-rw-r--r--src/game.cpp7
-rw-r--r--src/window.cpp57
7 files changed, 138 insertions, 75 deletions
diff --git a/assets/shaders/glyph.frag b/assets/shaders/glyph.frag
index ad9a6d1..5387f4e 100644
--- a/assets/shaders/glyph.frag
+++ b/assets/shaders/glyph.frag
@@ -2,9 +2,8 @@
layout(location = 0) in vec4 in_fg_color;
layout(location = 1) in vec4 in_bg_color;
-layout(location = 2) in vec4 in_sprite_region;
-layout(location = 3) in vec2 in_uv;
-layout(location = 4) in float in_width;
+layout(location = 2) in vec2 in_uv;
+layout(location = 3) in float in_width;
layout(location = 0) out vec4 out_color;
@@ -15,10 +14,10 @@ float median(float r, float g, float b) {
}
void main() {
- vec2 atlas_coord = (in_uv - in_sprite_region.xy) / in_sprite_region.zw;
- vec4 msd = texture(mtsdf_sampler, atlas_coord);
+ vec4 msd = texture(mtsdf_sampler, in_uv);
float sd = median(msd.r, msd.g, msd.b);
float screenPxDistance = in_width * (sd - 0.5);
float opacity = clamp(screenPxDistance + 0.5, 0.0, 1.0);
out_color = mix(in_bg_color, in_fg_color, opacity);
+ out_color = msd;
}
diff --git a/assets/shaders/glyph.vert b/assets/shaders/glyph.vert
index f48056d..9907ce1 100644
--- a/assets/shaders/glyph.vert
+++ b/assets/shaders/glyph.vert
@@ -3,18 +3,19 @@
// vertex
layout(location = 0) in vec2 in_position;
layout(location = 1) in vec2 in_uv;
+layout(location = 2) in vec2 in_atlas_size;
// instance
-layout(location = 2) in vec4 in_fg_color;
-layout(location = 3) in vec4 in_bg_color;
-layout(location = 4) in ivec4 in_sprite_region;
-layout(location = 5) in float in_width;
+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 = 0) out vec4 out_fg_color;
layout(location = 1) out vec4 out_bg_color;
-layout(location = 2) out vec4 out_sprite_region;
-layout(location = 3) out vec2 out_uv;
-layout(location = 4) out float out_width;
+layout(location = 2) out vec2 out_uv;
+layout(location = 3) out float out_width;
out gl_PerVertex
{
@@ -23,10 +24,9 @@ out gl_PerVertex
void main()
{
- gl_Position = vec4(in_position, 0.0, 1.0);
+ gl_Position = vec4(in_position / 4.0, 0.0, 1.0);
out_fg_color = in_fg_color;
out_bg_color = in_bg_color;
- out_sprite_region = in_sprite_region;
- out_uv = in_uv;
+ out_uv = mix(in_sprite_region_min, in_sprite_region_max, in_uv) / in_atlas_size;
out_width = in_width;
}
diff --git a/editor/editor.cpp b/editor/editor.cpp
index c0eafcb..4ce15e1 100644
--- a/editor/editor.cpp
+++ b/editor/editor.cpp
@@ -721,6 +721,7 @@ int SortFontGlyphChar(const void *a, const void *b) {
void GenerateMTSDF(const Asset *a) {
assert(PK_HAS_FLAG(a->type, PKE_ASSET_TYPE_FONT));
+ glm::ivec4 bounds;
NULL_CHAR_ARR(path_txtr, 128);
NULL_CHAR_ARR(path_glyphs, 128);
std::error_code e;
@@ -745,7 +746,7 @@ void GenerateMTSDF(const Asset *a) {
// Apply MSDF edge coloring. See edge-coloring.h for other coloring strategies.
const double maxCornerAngle = 3.0;
for (msdf_atlas::GlyphGeometry &glyph : glyphs)
- glyph.edgeColoring(&msdfgen::edgeColoringInkTrap, maxCornerAngle, 0);
+ glyph.edgeColoring(&msdfgen::edgeColoringByDistance, maxCornerAngle, 0);
// TightAtlasPacker class computes the layout of the atlas.
msdf_atlas::TightAtlasPacker packer;
// Set atlas parameters:
@@ -770,9 +771,9 @@ void GenerateMTSDF(const Asset *a) {
// For example, a custom atlas storage class that stores it in VRAM can be used.
> generator(width, height);
// GeneratorAttributes can be modified to change the generator's default settings.
- msdf_atlas::GeneratorAttributes attributes;
- generator.setAttributes(attributes);
- // generator.setThreadCount(4);
+ // msdf_atlas::GeneratorAttributes attributes{};
+ // generator.setAttributes(attributes);
+ generator.setThreadCount(31); // TODO engine should know this
// Generate atlas bitmap
generator.generate(glyphs.data(), glyphs.size());
// The atlas bitmap can now be retrieved via atlasStorage as a BitmapConstRef.
@@ -781,17 +782,23 @@ void GenerateMTSDF(const Asset *a) {
msdf_atlas::saveImage<4>(storage, msdf_atlas::ImageFormat::PNG, path_txtr, msdf_atlas::YDirection::TOP_DOWN);
ah_image = AM_Register(path_txtr, PKE_ASSET_TYPE_UNSET);
- auto f = fopen(path_glyphs, "w+");
- pk_arr arr_glyphs = {};
- arr_glyphs.alignment = 8;
+ pk_arr arr_glyphs{};
+ arr_glyphs.alignment = alignof(FontGlyphChar);
arr_glyphs.stride = sizeof(FontGlyphChar);
pk_arr_resize(&arr_glyphs, glyphs.size());
FontGlyphChar *arr = reinterpret_cast<FontGlyphChar *>(arr_glyphs.data);
for (uint64_t i = 0; i < glyphs.size(); ++i) {
arr[i].unicode = glyphs[i].getCodepoint();
- glyphs[i].getBoxRect(arr[i].bounds.x, arr[i].bounds.y, arr[i].bounds.z, arr[i].bounds.a);
+
+ glyphs[i].getBoxRect(bounds.x, bounds.y, bounds.z, bounds.a);
+ // library counts up from the bottom of the image to the bottom of the glyph
+ bounds.y = height - (bounds.y + bounds.a);
+ arr[i].sprite_region_min = glm::vec2(bounds.x, bounds.y);
+ arr[i].sprite_region_max = glm::vec2(bounds.x, bounds.y) + glm::vec2(bounds.z, bounds.a);
}
qsort(arr_glyphs.data, arr_glyphs.next, arr_glyphs.stride, SortFontGlyphChar);
+
+ auto f = fopen(path_glyphs, "w+");
fwrite(arr_glyphs.data, arr_glyphs.stride, arr_glyphs.next, f);
fclose(f);
ah_glyphs = AM_Register(path_glyphs, PKE_ASSET_TYPE_UNSET);
diff --git a/src/font.cpp b/src/font.cpp
index 6292039..acc80e8 100644
--- a/src/font.cpp
+++ b/src/font.cpp
@@ -27,11 +27,12 @@ struct FontTypeData {
struct FontInstanceBufferItem {
glm::vec4 bg_color;
glm::vec4 fg_color;
- glm::ivec4 bounds;
+ glm::vec2 sprite_region_min;
+ glm::vec2 sprite_region_max;
float width;
};
-const VkDeviceSize instance_buffer_item_size = (sizeof(glm::vec4) * 3) + sizeof(float);
+const VkDeviceSize instance_buffer_item_size = (sizeof(glm::vec4) * 2) + (sizeof(glm::vec2) * 2) + sizeof(float);
// BucketContainer<FontType, TextRenderHandle, 2> bktFont;
@@ -157,7 +158,7 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
pk_arr arr_inst_mem_reqs(arr_vert_mem_reqs);
pk_arr arr_texture_mem_reqs(arr_vert_mem_reqs);
VkDeviceSize index;
- constexpr VkDeviceSize expectedBufferCount = 3;
+ constexpr VkDeviceSize expectedBufferCount = 4;
constexpr VkDeviceSize startingGlyphCount = 4;
assert(fontTextureHandle != AssetHandle_MAX);
assert(glyphsHandle != AssetHandle_MAX);
@@ -193,6 +194,8 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
assert(txtr_bytes != nullptr);
assert(txtr_chan == 4);
uint32_t imageSizeBytes = txtr_x * txtr_y * txtr_chan;
+ ft->atlas_size.x = (float)txtr_x;
+ ft->atlas_size.y = (float)txtr_y;
/*
* vulkan setup
@@ -213,13 +216,19 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
{
for (uint64_t idx = 0; idx < expectedBufferCount; ++idx) {
if (idx == 0) {
+ // vertex
bufferCI.size = sizeof(glm::vec2) * 4;
} else if (idx == 1) {
+ // uv
bufferCI.size = sizeof(glm::vec2) * 4;
} else if (idx == 2) {
+ // atlas size
+ bufferCI.size = sizeof(glm::vec2) * 4;
+ } else if (idx == 3) {
+ // index
bufferCI.size = sizeof(uint16_t) * 6;
}
- if (idx == 2) {
+ if (idx == 3) {
bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_INDEX_BUFFER_BIT;
} else {
bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
@@ -236,7 +245,8 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
bufferCI.size = 0;
bufferCI.size += sizeof(glm::vec4); // fgColor
bufferCI.size += sizeof(glm::vec4); // bgColor
- bufferCI.size += sizeof(glm::vec4); // sprite_region
+ bufferCI.size += sizeof(glm::vec2); // sprite_region_min
+ bufferCI.size += sizeof(glm::vec2); // sprite_region_max
bufferCI.size += sizeof(float); // width
bufferCI.size *= startingGlyphCount;
bufferCI.usage = VK_BUFFER_USAGE_TRANSFER_SRC_BIT | VK_BUFFER_USAGE_TRANSFER_DST_BIT | VK_BUFFER_USAGE_VERTEX_BUFFER_BIT;
@@ -349,6 +359,20 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
runningOffset += sizeUV;
index += 1;
+ // atlas_size
+ uint32_t offsetAtlasSize = runningOffset;
+ uint32_t sizeAtlasSize = sizeof(ft->atlas_size) * 4;
+ ft->bindings.atlasSizeBD.firstBinding = index;
+ ft->bindings.atlasSizeBD.bindingCount = 1;
+ alignmentPadding = sizeAtlasSize % combined_vert_mem_reqs.alignment;
+ alignmentPadding = alignmentPadding == 0 ? 0 : combined_vert_mem_reqs.alignment - alignmentPadding;
+ sizeAtlasSize += alignmentPadding;
+ bufferCI.size = sizeAtlasSize;
+ vkCreateBuffer(vkDevice, &bufferCI, vkAllocator, &ft->bindings.atlasSizeBD.buffer);
+ vkBindBufferMemory(vkDevice, ft->bindings.atlasSizeBD.buffer, ft->deviceMemoryVert, offsetAtlasSize);
+ runningOffset += sizeAtlasSize;
+ index += 1;
+
// 2023-09-27 - JCB
// I don't know where else to put this
ft->bindings.instanceBD.firstBinding = index;
@@ -373,7 +397,6 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
assert(runningOffset == combined_vert_mem_reqs.size);
-
runningOffset = 0;
char *dstPtr = nullptr;
@@ -389,6 +412,15 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
memcpy(dstPtr, srcPtr, sizeUV);
runningOffset += sizeUV;
+ glm::vec2 atlas_size_buffer[4];
+ for (int i = 0; i < 4; ++i) {
+ atlas_size_buffer[i] = ft->atlas_size;
+ }
+ dstPtr = static_cast<char *>(tmpBufferDetails.deviceData) + runningOffset;
+ srcPtr = reinterpret_cast<char *>(atlas_size_buffer);
+ memcpy(dstPtr, srcPtr, sizeAtlasSize);
+ runningOffset += sizeAtlasSize;
+
dstPtr = static_cast<char *>(tmpBufferDetails.deviceData) + runningOffset;
srcPtr = reinterpret_cast<char *>(pkeIntrinsicsPlane.index);
memcpy(dstPtr, srcPtr, sizeIndex);
@@ -416,6 +448,11 @@ FontTypeIndex FontType_RegisterFont(pk_cstr title, AssetHandle fontTextureHandle
vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, ft->bindings.uvBD.buffer, 1, &bufferCopys[index]);
index+=1;
+ bufferCopys[index].srcOffset = offsetAtlasSize;
+ bufferCopys[index].size = sizeAtlasSize;
+ vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, ft->bindings.atlasSizeBD.buffer, 1, &bufferCopys[index]);
+ index+=1;
+
bufferCopys[index].srcOffset = offsetIndex;
bufferCopys[index].size = sizeIndex;
vkCmdCopyBuffer(tmpBufferDetails.cmdBuffer, tmpBufferDetails.buffer, ft->bindings.indexBD.buffer, 1, &bufferCopys[index]);
@@ -693,6 +730,13 @@ void FontType_Unload(FontTypeIndex idx) {
ft->bindings.uvBD.bindingCount = 0;
ft->bindings.uvBD.offsets[0] = 0;
+ if (ft->bindings.atlasSizeBD.buffer != VK_NULL_HANDLE)
+ vkDestroyBuffer(vkDevice, ft->bindings.atlasSizeBD.buffer, vkAllocator);
+ ft->bindings.atlasSizeBD.buffer = VK_NULL_HANDLE;
+ ft->bindings.atlasSizeBD.firstBinding = 0;
+ ft->bindings.atlasSizeBD.bindingCount = 0;
+ ft->bindings.atlasSizeBD.offsets[0] = 0;
+
if (ft->bindings.indexBD.buffer != VK_NULL_HANDLE)
vkDestroyBuffer(vkDevice, ft->bindings.indexBD.buffer, vkAllocator);
ft->bindings.indexBD.buffer = VK_NULL_HANDLE;
@@ -706,7 +750,6 @@ void FontType_Unload(FontTypeIndex idx) {
ft->bindings.instanceBD.firstBinding = 0;
ft->bindings.instanceBD.bindingCount = 0;
ft->bindings.instanceCounter = 0;
- ft->bindings.instanceBufferMaxCount = 0;
ft->bindings.instanceBD.offsets[0] = 0;
if (ft->textureImageView != VK_NULL_HANDLE)
@@ -797,14 +840,15 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
}
buf_item = &instance_buffer_items.Push();
- buf_item->fg_color = glm::vec4(0.4, 0.5, 0.4, 0);
- buf_item->bg_color = glm::vec4(1.0, 1.0, 1.0, 0);
- buf_item->bounds = fgc->bounds;
- buf_item->width = 10;
+ buf_item->fg_color = glm::vec4(0.4, 0.5, 0.4, 1);
+ buf_item->bg_color = glm::vec4(0.0, 0.0, 0.0, 1);
+ buf_item->sprite_region_min = fgc->sprite_region_min;
+ buf_item->sprite_region_max = fgc->sprite_region_max;
+ buf_item->width = 2;
}
}
- VkDeviceSize item_count_orig = ft->bindings.instanceBufferMaxCount;
- VkDeviceSize item_count_new = ft->bindings.instanceBufferMaxCount + count;
+ 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;
@@ -887,7 +931,7 @@ FontRender FontType_AddStringRender(FontTypeIndex idx_ft, pk_cstr cstr) {
ft->deviceMemoryInst = new_memory;
ft->bindings.instanceBD.buffer = newBuffer;
- ft->bindings.instanceBufferMaxCount = item_count_new;
+ ft->bindings.instanceCounter = item_count_new;
}
// create tmp local buffer & copy data to graphics card
diff --git a/src/font.hpp b/src/font.hpp
index 116ac06..fc9c909 100644
--- a/src/font.hpp
+++ b/src/font.hpp
@@ -5,29 +5,15 @@
#include "components.hpp"
#include "pk.h"
-#include <glm/vec4.hpp>
-
-/*
-Vert: (two triangles)
-vec2 vertex
-vec2 uv
-
-Inst:
-vec4 fg_color
-vec4 bg_color
-vec4 sprite_region
-float width
-
-Texture:
-the MTSDF
-*/
+#include <glm/vec2.hpp>
TypeSafeInt_H(FontTypeIndex, uint16_t, 0xFFFF);
TypeSafeInt_H(FontRenderIndex, uint16_t, 0xFFFF);
struct FontGlyphChar {
uint32_t unicode;
- glm::ivec4 bounds;
+ glm::vec2 sprite_region_min;
+ glm::vec2 sprite_region_max;
};
struct FontRender {
uint32_t len;
@@ -47,6 +33,7 @@ struct FontType : public Entity_Base {
VkDescriptorSet *vkDescriptorSets = nullptr;
FontGlyphChar *glyphs;
FontRender *renders = nullptr;
+ glm::vec2 atlas_size;
uint32_t n_glyphs;
FontRenderIndex n_render = FontRenderIndex{0};
FontRenderIndex h_render = FontRenderIndex{0};
@@ -54,11 +41,11 @@ struct FontType : public Entity_Base {
struct FontTypeBindings {
BufferBindingDetails vertexBD;
BufferBindingDetails uvBD;
+ BufferBindingDetails atlasSizeBD;
BufferBindingDetails indexBD;
BufferBindingDetails instanceBD;
- uint32_t indexCount;
+ uint32_t indexCount = 0;
uint32_t instanceCounter = 0;
- uint32_t instanceBufferMaxCount = 0;
} bindings;
};
diff --git a/src/game.cpp b/src/game.cpp
index d65afc6..58e9289 100644
--- a/src/game.cpp
+++ b/src/game.cpp
@@ -608,8 +608,11 @@ void Game_Main(PKEWindowProperties windowProps, const char *executablePath) {
}
}
- // pk_cstr test_text = cstring_to_pk_cstr("this is a test string");
- // FontRender fr = FontType_AddStringRender(FontTypeIndex{0}, test_text);
+ pk_cstr test_text = cstring_to_pk_cstr("$");
+ FontTypeIndex font_type_count;
+ if ((FontType_GetFonts(font_type_count)); font_type_count != FontTypeIndex{0}) {
+ FontType_AddStringRender(FontTypeIndex{0}, test_text);
+ }
GameTimePoint lastTimePoint = pkeSettings.steadyClock.now();
double deltaTillNextRender = pkeSettings.deltaPerFrame;
diff --git a/src/window.cpp b/src/window.cpp
index da4062c..11ce080 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -1,5 +1,3 @@
-#include "pk.h"
-#include <vulkan/vulkan_core.h>
#define GLFW_INCLUDE_NONE
#define GLFW_INCLUDE_VULKAN
@@ -14,6 +12,7 @@
#include "font.hpp"
#include "game-settings.hpp"
#include "math-helpers.hpp"
+#include "pk.h"
#include "plugins.hpp"
#include "static-cube.hpp"
#include "static-missing-texture.hpp"
@@ -1752,19 +1751,25 @@ void CreateGraphicsPipelines() {
index = 0;
long offset = 0;
- const long vertexBindingCount_glyph = 3;
+ const long vertexBindingCount_glyph = 4;
VkVertexInputBindingDescription vertInputBD_glyph[vertexBindingCount_glyph];
- const long vertexAttrDescCount_glyph = 6;
+ const long vertexAttrDescCount_glyph = 8;
VkVertexInputAttributeDescription vertAttrDesc_glyph[vertexAttrDescCount_glyph];
VkPipelineVertexInputStateCreateInfo vkPipelineVertexInputStateCreateInfo_glyph{vkPipelineVertexInputStateCreateInfo_txtr};
{
- // model vertex
+ // vertex - vertex
vertInputBD_glyph[index].binding = index;
vertInputBD_glyph[index].stride = sizeof(glm::vec2);
vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
index += 1;
- // model UV
+ // vertex - UV
+ vertInputBD_glyph[index].binding = index;
+ vertInputBD_glyph[index].stride = sizeof(glm::vec2);
+ vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
+ index += 1;
+
+ // vertex - atlas_size
vertInputBD_glyph[index].binding = index;
vertInputBD_glyph[index].stride = sizeof(glm::vec2);
vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_VERTEX;
@@ -1775,7 +1780,8 @@ void CreateGraphicsPipelines() {
vertInputBD_glyph[index].stride = 0
+ sizeof(glm::vec4)
+ sizeof(glm::vec4)
- + sizeof(glm::ivec4)
+ + sizeof(glm::vec2)
+ + sizeof(glm::vec2)
+ sizeof(float);
vertInputBD_glyph[index].inputRate = VK_VERTEX_INPUT_RATE_INSTANCE;
// index += 1;
@@ -1785,41 +1791,55 @@ void CreateGraphicsPipelines() {
vertAttrDesc_glyph[i].location = i;
}
- // model vertex
+ // vertex - vertex
vertAttrDesc_glyph[index].binding = 0;
vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
vertAttrDesc_glyph[index].offset = 0;
index += 1;
- // model UV
+ // vertex - UV
vertAttrDesc_glyph[index].binding = 1;
vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
vertAttrDesc_glyph[index].offset = 0;
index += 1;
- // instance - in_fg_color
+ // vertex - in_atlas_size
vertAttrDesc_glyph[index].binding = 2;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = offset;
+ offset += sizeof(glm::vec2);
+ index += 1;
+
+ // instance - in_fg_color
+ vertAttrDesc_glyph[index].binding = 3;
vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SFLOAT;
vertAttrDesc_glyph[index].offset = 0;
offset += sizeof(glm::vec4);
index += 1;
// instance - in_bg_color
- vertAttrDesc_glyph[index].binding = 2;
+ 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_sprite_region
- vertAttrDesc_glyph[index].binding = 2;
- vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32B32A32_SINT;
+ // instance - in_sprite_region_min
+ vertAttrDesc_glyph[index].binding = 3;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
vertAttrDesc_glyph[index].offset = offset;
- offset += sizeof(glm::ivec4);
+ offset += sizeof(glm::vec2);
index += 1;
- // instance - in_sprite_region
- vertAttrDesc_glyph[index].binding = 2;
+ // instance - in_sprite_region_max
+ vertAttrDesc_glyph[index].binding = 3;
+ vertAttrDesc_glyph[index].format = VK_FORMAT_R32G32_SFLOAT;
+ vertAttrDesc_glyph[index].offset = offset;
+ offset += sizeof(glm::vec2);
+ index += 1;
+
+ // instance - in_width
+ vertAttrDesc_glyph[index].binding = 3;
vertAttrDesc_glyph[index].format = VK_FORMAT_R32_SFLOAT;
vertAttrDesc_glyph[index].offset = offset;
// offset += sizeof(float);
@@ -2710,6 +2730,8 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
for (FontTypeIndex i = FontTypeIndex{0}; i < count; ++i)
{
FontType *ft = &fts[(FontTypeIndex_T)i];
+ if (ft->bindings.instanceCounter == 0)
+ continue;
vkCmdBindPipeline(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipelines.named.glyph);
vkCmdBindDescriptorSets(commandBuffer, VK_PIPELINE_BIND_POINT_GRAPHICS, pkePipelines.pipe_layouts.named.glyph, 0, 1, &ft->vkDescriptorSets[imageIndex], 0, {});
@@ -2717,6 +2739,7 @@ void RecordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex) {
vkCmdBindVertexBuffers(commandBuffer, ft->bindings.vertexBD.firstBinding, ft->bindings.vertexBD.bindingCount, &ft->bindings.vertexBD.buffer, ft->bindings.vertexBD.offsets);
vkCmdBindVertexBuffers(commandBuffer, ft->bindings.uvBD.firstBinding, ft->bindings.uvBD.bindingCount, &ft->bindings.uvBD.buffer, ft->bindings.uvBD.offsets);
+ vkCmdBindVertexBuffers(commandBuffer, ft->bindings.atlasSizeBD.firstBinding, ft->bindings.atlasSizeBD.bindingCount, &ft->bindings.atlasSizeBD.buffer, ft->bindings.atlasSizeBD.offsets);
vkCmdBindVertexBuffers(commandBuffer, ft->bindings.instanceBD.firstBinding, ft->bindings.instanceBD.bindingCount, &ft->bindings.instanceBD.buffer, ft->bindings.instanceBD.offsets);
vkCmdDrawIndexed(commandBuffer, ft->bindings.indexCount, ft->bindings.instanceCounter, 0, 0, 0);