Skip to content

Commit e9845da

Browse files
committed
MTSDF for testing, I should make it switchable, we may need to test msdfs again
1 parent 7ffa8cc commit e9845da

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

include/nbl/ext/TextRendering/TextRendering.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class TextRenderer : public nbl::core::IReferenceCounted
3434
{
3535
public:
3636

37-
static constexpr asset::E_FORMAT MSDFTextureFormat = asset::E_FORMAT::EF_R8G8B8_SNORM;
37+
static constexpr asset::E_FORMAT MSDFTextureFormat = asset::E_FORMAT::EF_R8G8B8A8_SNORM;
3838

3939
// Spits out CPUBuffer containing the image data in SNORM format
4040
core::smart_refctd_ptr<ICPUBuffer> generateShapeMSDF(msdfgen::Shape glyph, uint32_t msdfPixelRange, uint32_t2 msdfExtents, float32_t2 scale, float32_t2 translate);

src/nbl/ext/TextRendering/TextRendering.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ core::smart_refctd_ptr<ICPUBuffer> TextRenderer::generateShapeMSDF(msdfgen::Shap
2626
auto shapeBounds = glyph.getBounds();
2727

2828
msdfgen::edgeColoringSimple(glyph, 3.0);
29-
msdfgen::Bitmap<float, 3> msdfMap(glyphW, glyphH);
29+
msdfgen::Bitmap<float, 4> msdfMap(glyphW, glyphH);
3030

31-
msdfgen::generateMSDF(msdfMap, glyph, msdfPixelRange, { scale.x, scale.y }, { translate.x, translate.y });
31+
msdfgen::generateMTSDF(msdfMap, glyph, msdfPixelRange, { scale.x, scale.y }, { translate.x, translate.y });
3232

33-
auto cpuBuf = core::make_smart_refctd_ptr<ICPUBuffer>(glyphW * glyphH * sizeof(int8_t) * 3);
33+
auto cpuBuf = core::make_smart_refctd_ptr<ICPUBuffer>(glyphW * glyphH * sizeof(int8_t) * 4);
3434
int8_t* data = reinterpret_cast<int8_t*>(cpuBuf->getPointer());
3535

3636
auto floatToSNORM8 = [](const float fl) -> int8_t
@@ -43,9 +43,10 @@ core::smart_refctd_ptr<ICPUBuffer> TextRenderer::generateShapeMSDF(msdfgen::Shap
4343
for (int x = 0; x < msdfMap.width(); ++x)
4444
{
4545
auto pixel = msdfMap(x, glyphH - 1 - y);
46-
data[(x + y * glyphW) * 3 + 0] = floatToSNORM8(pixel[0]);
47-
data[(x + y * glyphW) * 3 + 1] = floatToSNORM8(pixel[1]);
48-
data[(x + y * glyphW) * 3 + 2] = floatToSNORM8(pixel[2]);
46+
data[(x + y * glyphW) * 4 + 0] = floatToSNORM8(pixel[0]);
47+
data[(x + y * glyphW) * 4 + 1] = floatToSNORM8(pixel[1]);
48+
data[(x + y * glyphW) * 4 + 2] = floatToSNORM8(pixel[2]);
49+
data[(x + y * glyphW) * 4 + 3] = floatToSNORM8(pixel[3]);
4950
}
5051
}
5152

0 commit comments

Comments
 (0)