diff options
| author | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-10-18 15:54:29 +0200 |
|---|---|---|
| committer | Jean-Philippe Bruyère <jp_bruyere@hotmail.com> | 2026-10-18 15:54:29 +0200 |
| commit | 0d42ced8d6a168b0d5e2330e0f5bb0b197d9c60f (patch) | |
| tree | 075285ac052d8ece8c0a2f21987ba527e59708e9 | |
| parent | 64c0615b03f9dd93e8202c40b74aa60a2318d3be (diff) | |
unnormalized texture coords for fonts, update font descriptor
| -rw-r--r-- | shaders/vkvg_main.frag | 2 | ||||
| -rw-r--r-- | src/shaders.h | 37 | ||||
| -rw-r--r-- | src/vkvg_device_internal.c | 4 | ||||
| -rw-r--r-- | src/vkvg_fonts.c | 38 |
4 files changed, 43 insertions, 38 deletions
diff --git a/shaders/vkvg_main.frag b/shaders/vkvg_main.frag index a083d8d..24a6afb 100644 --- a/shaders/vkvg_main.frag +++ b/shaders/vkvg_main.frag @@ -127,7 +127,7 @@ void main() } if (inFontUV.z >= 0.0) - c *= texture(fontMap, inFontUV).r; + c *= textureLod(fontMap, inFontUV, 0.0).r; #ifdef VKVG_PREMULT_ALPHA c *= inOpacity; diff --git a/src/shaders.h b/src/shaders.h index ccc72f8..ec5f278 100644 --- a/src/shaders.h +++ b/src/shaders.h @@ -1296,26 +1296,27 @@ unsigned char vkvg_main_frag_spv[] = { 0x85, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x84, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x87, 0x01, 0x00, 0x00, 0x8a, 0x01, 0x00, 0x00, 0x89, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x7e, 0x01, 0x00, 0x00, - 0x8b, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x57, 0x00, 0x05, 0x00, + 0x8b, 0x01, 0x00, 0x00, 0x80, 0x01, 0x00, 0x00, 0x58, 0x00, 0x07, 0x00, 0x07, 0x00, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, 0x8a, 0x01, 0x00, 0x00, - 0x8b, 0x01, 0x00, 0x00, 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x8d, 0x01, 0x00, 0x00, 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, - 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, 0x8e, 0x01, 0x00, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, - 0x8f, 0x01, 0x00, 0x00, 0x8e, 0x01, 0x00, 0x00, 0x8d, 0x01, 0x00, 0x00, - 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x00, - 0xf9, 0x00, 0x02, 0x00, 0x85, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, - 0x85, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, - 0x91, 0x01, 0x00, 0x00, 0x90, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x92, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x8e, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x93, 0x01, 0x00, 0x00, - 0x92, 0x01, 0x00, 0x00, 0x91, 0x01, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, - 0x09, 0x00, 0x00, 0x00, 0x93, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, - 0x07, 0x00, 0x00, 0x00, 0x96, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, - 0x3e, 0x00, 0x03, 0x00, 0x95, 0x01, 0x00, 0x00, 0x96, 0x01, 0x00, 0x00, - 0xfd, 0x00, 0x01, 0x00, 0x38, 0x00, 0x01, 0x00 + 0x8b, 0x01, 0x00, 0x00, 0x02, 0x00, 0x00, 0x00, 0x7d, 0x00, 0x00, 0x00, + 0x51, 0x00, 0x05, 0x00, 0x06, 0x00, 0x00, 0x00, 0x8d, 0x01, 0x00, 0x00, + 0x8c, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x8e, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x8e, 0x00, 0x05, 0x00, 0x07, 0x00, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x00, + 0x8e, 0x01, 0x00, 0x00, 0x8d, 0x01, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, + 0x09, 0x00, 0x00, 0x00, 0x8f, 0x01, 0x00, 0x00, 0xf9, 0x00, 0x02, 0x00, + 0x85, 0x01, 0x00, 0x00, 0xf8, 0x00, 0x02, 0x00, 0x85, 0x01, 0x00, 0x00, + 0x3d, 0x00, 0x04, 0x00, 0x06, 0x00, 0x00, 0x00, 0x91, 0x01, 0x00, 0x00, + 0x90, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x92, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x8e, 0x00, 0x05, 0x00, + 0x07, 0x00, 0x00, 0x00, 0x93, 0x01, 0x00, 0x00, 0x92, 0x01, 0x00, 0x00, + 0x91, 0x01, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, 0x09, 0x00, 0x00, 0x00, + 0x93, 0x01, 0x00, 0x00, 0x3d, 0x00, 0x04, 0x00, 0x07, 0x00, 0x00, 0x00, + 0x96, 0x01, 0x00, 0x00, 0x09, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x03, 0x00, + 0x95, 0x01, 0x00, 0x00, 0x96, 0x01, 0x00, 0x00, 0xfd, 0x00, 0x01, 0x00, + 0x38, 0x00, 0x01, 0x00 }; -unsigned int vkvg_main_frag_spv_len = 9560; +unsigned int vkvg_main_frag_spv_len = 9568; unsigned char vkvg_main_vert_spv[] = { 0x03, 0x02, 0x23, 0x07, 0x00, 0x00, 0x01, 0x00, 0x0b, 0x00, 0x0d, 0x00, 0x85, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x11, 0x00, 0x02, 0x00, diff --git a/src/vkvg_device_internal.c b/src/vkvg_device_internal.c index 2f8528c..78fdcea 100644 --- a/src/vkvg_device_internal.c +++ b/src/vkvg_device_internal.c @@ -80,7 +80,9 @@ void _device_createDescriptorSetLayout(VkvgDevice dev) { .addressModeW = VK_SAMPLER_ADDRESS_MODE_CLAMP_TO_EDGE, .magFilter = VK_FILTER_NEAREST, .minFilter = VK_FILTER_NEAREST, - .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST}; + .mipmapMode = VK_SAMPLER_MIPMAP_MODE_NEAREST, + .unnormalizedCoordinates = VK_TRUE + }; vkCreateSampler(dev->vkDev, &samplerInfo, NULL, &dev->smpFont); VkDescriptorBindingFlags bindingFlags[] = { diff --git a/src/vkvg_fonts.c b/src/vkvg_fonts.c index 641a396..f943316 100644 --- a/src/vkvg_fonts.c +++ b/src/vkvg_fonts.c @@ -83,10 +83,21 @@ static inline uint32_t get_face_glyph_count (FontFace face) { return face->stbInfo.numGlyphs; #endif } - +void _fonts_cache_update_font_descriptor_set (VkvgDevice dev) { + VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor(dev->fontCache->texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); + VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, + .dstSet = dev->fontCache->dsFont, + .dstBinding = 0, + .descriptorCount = 1, + .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, + .pImageInfo = &descSrcTex}; + vkUpdateDescriptorSets(dev->vkDev, 1, &writeDescriptorSet, 0, NULL); +} void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { font_cache_t* cache = (font_cache_t*)calloc(1, sizeof(font_cache_t)); + dev->fontCache = cache; + if (dev->threadAware) mtx_init(&cache->mutex, mtx_plain); @@ -175,14 +186,7 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { .pSetLayouts = &dev->dslFont}; VK_CHECK_RESULT(vkAllocateDescriptorSets(dev->vkDev, &descriptorSetAllocateInfo, &cache->dsFont)); - VkDescriptorImageInfo descSrcTex = vkh_image_get_descriptor(cache->texture, VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL); - VkWriteDescriptorSet writeDescriptorSet = {.sType = VK_STRUCTURE_TYPE_WRITE_DESCRIPTOR_SET, - .dstSet = cache->dsFont, - .dstBinding = 0, - .descriptorCount = 1, - .descriptorType = VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER, - .pImageInfo = &descSrcTex}; - vkUpdateDescriptorSets(dev->vkDev, 1, &writeDescriptorSet, 0, NULL); + _fonts_cache_update_font_descriptor_set(dev); const uint32_t buffLength = FONT_PAGE_SIZE * FONT_PAGE_SIZE * cache->texPixelSize; @@ -209,8 +213,6 @@ void _fonts_cache_create(VkvgDevice dev, const char* fontDirs) { "Font cache Descriptor Pool"); vkh_device_set_object_name(vkhd, VK_OBJECT_TYPE_DESCRIPTOR_SET, (uint64_t)cache->dsFont, "Cache DescSet FONT"); #endif - - dev->fontCache = cache; } void _font_buffer_destroy (font_cache_t* cache, FontBuffer fontBuffer) { LOG(VKVG_LOG_FONT, "FontBuffer destroy\n"); @@ -353,6 +355,8 @@ void _increase_font_tex_array(VkvgDevice dev) { cache->texture = newImg; _device_wait_idle(dev); + + _fonts_cache_update_font_descriptor_set(dev); } // flush font stagging buffer to cache texture array // Trigger stagging buffer to be uploaded in font cache. Groupping upload improve performances. @@ -528,7 +532,7 @@ glyph_ref _put_glyph_in_cache(VkvgDevice dev, VkvgFont font, uint32_t gindex) { cr.bmpDiff.y = (int16_t)-c_y1; cr.advance = (vec2){(uint32_t)roundf(font->scale * advance) << 6, 0}; #endif - vec4 uvBounds = {{(float)(penX + font->penX) / (float)FONT_PAGE_SIZE}, + vec4 uvBounds = {{(float)(penX + font->penX)}, {0.f}, {(float)bmpPixelWidth}, {(float)bmpRows}}; @@ -953,8 +957,6 @@ void text_run_render(VkvgText tr, VkvgContext ctx) { if (vkvg_unlikely (f->status)) break; - float uvWidth = cr.bounds.width / (float)FONT_PAGE_SIZE; - float uvHeight = cr.bounds.height / (float)FONT_PAGE_SIZE; vec2 p0 = {pen.x + cr.bmpDiff.x + (tr->glyphs[i].x_offset >> 6), pen.y - cr.bmpDiff.y + (tr->glyphs[i].y_offset >> 6)}; v.pos = p0; @@ -962,7 +964,7 @@ void text_run_render(VkvgText tr, VkvgContext ctx) { VKVG_IBO_INDEX_TYPE firstIdx = (VKVG_IBO_INDEX_TYPE)(ctx->vertCount - ctx->curVertOffset); TexRef l = cr.texRef; - float uvY = (float)l->penY / (float)FONT_PAGE_SIZE; + float uvY = (float)l->penY; v.uv.x = cr.bounds.x; v.uv.y = uvY; // + cr.bounds.y @@ -970,17 +972,17 @@ void text_run_render(VkvgText tr, VkvgContext ctx) { _add_vertex(ctx, v); v.pos.y += cr.bounds.height; - v.uv.y += uvHeight; + v.uv.y += cr.bounds.height; _add_vertex(ctx, v); v.pos.x += cr.bounds.width; v.pos.y = p0.y; - v.uv.x += uvWidth; + v.uv.x += cr.bounds.width; v.uv.y = uvY; // + cr.bounds.y; _add_vertex(ctx, v); v.pos.y += cr.bounds.height; - v.uv.y += uvHeight; + v.uv.y += cr.bounds.height; _add_vertex(ctx, v); _add_tri_indices_for_rect(ctx, firstIdx); |