From 66872ae378ff61733a467a9980ea30bea316ee69 Mon Sep 17 00:00:00 2001 From: TurtleP Date: Wed, 29 May 2024 13:38:05 -0400 Subject: [PATCH] fonts work, but not using color properly --- .github/workflows/Nintendo 3DS.yml | 14 ++--- .github/workflows/Nintendo Switch.yml | 18 +++---- .github/workflows/Nintendo Wii U.yml | 18 +++---- include/modules/font/Rasterizer.hpp | 9 ++++ include/modules/graphics/Graphics.tcc | 4 +- platform/ctr/include/modules/font/Font.hpp | 2 + .../source/modules/font/BCFNTRasterizer.cpp | 5 +- .../ctr/source/modules/graphics/Texture.cpp | 2 - source/modules/font/wrap_Font.cpp | 53 ++++++++++++++++++- source/modules/graphics/Font.cpp | 4 +- 10 files changed, 87 insertions(+), 42 deletions(-) diff --git a/.github/workflows/Nintendo 3DS.yml b/.github/workflows/Nintendo 3DS.yml index 880f5e5f..a7b8b0c5 100644 --- a/.github/workflows/Nintendo 3DS.yml +++ b/.github/workflows/Nintendo 3DS.yml @@ -14,11 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-cmake -S . -B build - - name: Build - run: make -C build + run: catnip -T 3DS - id: commit uses: prompt/actions-commit-hash@v3 @@ -27,8 +24,8 @@ jobs: with: name: Nintendo 3DS-${{ steps.commit.outputs.short }} path: | - build/*.elf - build/*.3dsx + build/**.elf + build/**.3dsx N3DS-Debug: runs-on: ubuntu-latest @@ -41,11 +38,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/3ds/bin/arm-none-eabi-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build - - name: Build - run: make -C build + run: catnip -T 3DS debug - id: commit uses: prompt/actions-commit-hash@v3 diff --git a/.github/workflows/Nintendo Switch.yml b/.github/workflows/Nintendo Switch.yml index 153ca84b..71a73c69 100644 --- a/.github/workflows/Nintendo Switch.yml +++ b/.github/workflows/Nintendo Switch.yml @@ -14,11 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -S . -B build - - name: Build - run: make -C build + run: catnip -T Switch - id: commit uses: prompt/actions-commit-hash@v3 @@ -27,8 +24,8 @@ jobs: with: name: Nintendo Switch-${{ steps.commit.outputs.short }} path: | - build/*.elf - build/*.nro + build/**.elf + build/**.nro Switch-Debug: runs-on: ubuntu-latest @@ -41,11 +38,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/switch/bin/aarch64-none-elf-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build - - name: Build - run: make -C build + run: catnip -T Switch debug - id: commit uses: prompt/actions-commit-hash@v3 @@ -54,5 +48,5 @@ jobs: with: name: Nintendo Switch (Debug)-${{ steps.commit.outputs.short }} path: | - build/*.elf - build/*.nro + build/**.elf + build/**.nro diff --git a/.github/workflows/Nintendo Wii U.yml b/.github/workflows/Nintendo Wii U.yml index d6741b52..4cc87ff5 100644 --- a/.github/workflows/Nintendo Wii U.yml +++ b/.github/workflows/Nintendo Wii U.yml @@ -14,11 +14,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -S . -B build - - name: Build - run: make -C build + run: catnipt -T WiiU - id: commit uses: prompt/actions-commit-hash@v3 @@ -27,8 +24,8 @@ jobs: with: name: Nintendo Wii U-${{ steps.commit.outputs.short }} path: | - build/*.elf - build/*.wuhb + build/**.elf + build/**.wuhb WiiU-Debug: runs-on: ubuntu-latest @@ -41,11 +38,8 @@ jobs: - name: Checkout uses: actions/checkout@v4 - - name: Configure - run: /opt/devkitpro/portlibs/wiiu/bin/powerpc-eabi-cmake -DCMAKE_BUILD_TYPE=Debug -S . -B build - - name: Build - run: make -C build + run: catnip -T WiiU debug - id: commit uses: prompt/actions-commit-hash@v3 @@ -54,5 +48,5 @@ jobs: with: name: Nintendo Wii U (Debug)-${{ steps.commit.outputs.short }} path: | - build/*.elf - build/*.wuhb + build/**.elf + build/**.wuhb diff --git a/include/modules/font/Rasterizer.hpp b/include/modules/font/Rasterizer.hpp index 772f9cda..2e8d7a60 100644 --- a/include/modules/font/Rasterizer.hpp +++ b/include/modules/font/Rasterizer.hpp @@ -102,6 +102,15 @@ namespace love return dpiScale; } + // clang-format off + STRINGMAP_DECLARE(Hintings, Hinting, + { "normal", HINTING_NORMAL }, + { "light", HINTING_LIGHT }, + { "mono", HINTING_MONO }, + { "none", HINTING_NONE } + ); + // clang-format on + protected: FontMetrics metrics; float dpiScale; diff --git a/include/modules/graphics/Graphics.tcc b/include/modules/graphics/Graphics.tcc index 0d81b579..81d1440a 100644 --- a/include/modules/graphics/Graphics.tcc +++ b/include/modules/graphics/Graphics.tcc @@ -325,8 +325,8 @@ namespace love DisplayState() {} - Color color = Color::WHITE; - Color backgroundColor = Color::BLACK; + Color color = Color(1.0f, 1.0f, 1.0f, 1.0f); + Color backgroundColor = Color(0.0f, 0.0f, 0.0f, 1.0f); BlendState blend = computeBlendState(BLEND_ALPHA, BLENDALPHA_MULTIPLY); diff --git a/platform/ctr/include/modules/font/Font.hpp b/platform/ctr/include/modules/font/Font.hpp index ff7fed21..3003e1dc 100644 --- a/platform/ctr/include/modules/font/Font.hpp +++ b/platform/ctr/include/modules/font/Font.hpp @@ -18,6 +18,8 @@ namespace love Rasterizer* newTrueTypeRasterizer(Data* data, int size, const Rasterizer::Settings& settings) const override; + using FontModuleBase::newTrueTypeRasterizer; + private: static constexpr auto FONT_ARCHIVE_TITLE = 0x0004009B00014002ULL; diff --git a/platform/ctr/source/modules/font/BCFNTRasterizer.cpp b/platform/ctr/source/modules/font/BCFNTRasterizer.cpp index 87cdd36e..0d8acccc 100644 --- a/platform/ctr/source/modules/font/BCFNTRasterizer.cpp +++ b/platform/ctr/source/modules/font/BCFNTRasterizer.cpp @@ -82,7 +82,9 @@ namespace love if (this->size == 0) throw love::Exception("Invalid font size: {:d}", this->size); - fontFixPointers((CFNT_s*)data->getData()); + /* if we already have this data loaded, fixing this (again) is a bad timeā„¢ */ + if ((uintptr_t)fontGetInfo((CFNT_s*)data->getData())->tglp < (uintptr_t)data->getData()) + fontFixPointers((CFNT_s*)data->getData()); auto* fontInfo = fontGetInfo((CFNT_s*)data->getData()); auto* sheetInfo = fontInfo->tglp; @@ -94,6 +96,7 @@ namespace love this->metrics.descent = scaleMetric((fontInfo->height - fontInfo->ascent), this->scale); this->metrics.height = scaleMetric(sheetInfo->cellHeight, this->scale); + /* todo: more accuracy? */ for (auto map = fontInfo->cmap; map != nullptr; map = map->next) this->glyphCount += (map->codeEnd - map->codeBegin) + 1; diff --git a/platform/ctr/source/modules/graphics/Texture.cpp b/platform/ctr/source/modules/graphics/Texture.cpp index 23198900..0394013f 100644 --- a/platform/ctr/source/modules/graphics/Texture.cpp +++ b/platform/ctr/source/modules/graphics/Texture.cpp @@ -272,8 +272,6 @@ namespace love const auto mipWidth = this->getPixelWidth(level); const auto mipHeight = this->getPixelHeight(level); - std::printf("Data Size: %zu/Texture Size: %zu\n", size, this->texture->size); - // copy it directly if the size is the whole thing if (rect == Rect(0, 0, mipWidth, mipHeight)) std::memcpy(textureData, data, size); diff --git a/source/modules/font/wrap_Font.cpp b/source/modules/font/wrap_Font.cpp index 25387cbb..78a20322 100644 --- a/source/modules/font/wrap_Font.cpp +++ b/source/modules/font/wrap_Font.cpp @@ -36,9 +36,60 @@ int Wrap_FontModule::newRasterizer(lua_State* L) return newBMFontRasterizer(L); } +static Rasterizer::Settings luax_checktruetypesettings(lua_State* L, int index) +{ + Rasterizer::Settings settings {}; + + if (lua_type(L, index)) + { + const char* hinting = lua_isnoneornil(L, index) ? nullptr : luaL_checkstring(L, index); + if (hinting && !Rasterizer::getConstant(hinting, settings.hinting)) + luax_enumerror(L, "Font hinting mode", Rasterizer::Hintings, hinting); + + if (!lua_isnoneornil(L, index + 1)) + settings.dpiScale.set((float)luaL_checknumber(L, index + 1)); + } + else + { + luaL_checktype(L, index, LUA_TTABLE); + + lua_getfield(L, index, "hinting"); + if (!lua_isnoneornil(L, -1)) + { + const char* hinting = luaL_checkstring(L, -1); + if (!Rasterizer::getConstant(hinting, settings.hinting)) + luax_enumerror(L, "Font hinting mode", Rasterizer::Hintings, hinting); + } + lua_pop(L, 1); + + lua_getfield(L, index, "dpiscale"); + if (!lua_isnoneornil(L, -1)) + settings.dpiScale.set((float)luaL_checknumber(L, -1)); + lua_pop(L, 1); + } + + return settings; +} + int Wrap_FontModule::newTrueTypeRasterizer(lua_State* L) { - return 0; + Rasterizer* rasterizer = nullptr; + + if (lua_type(L, 1) == LUA_TNUMBER || lua_isnone(L, 1)) + { + int size = luaL_optinteger(L, 1, 13); + Rasterizer::Settings settings {}; + + if (!lua_isnoneornil(L, 2)) + settings = luax_checktruetypesettings(L, 2); + + luax_catchexcept(L, [&] { rasterizer = instance()->newTrueTypeRasterizer(size, settings); }); + } + + luax_pushtype(L, rasterizer); + rasterizer->release(); + + return 1; } int Wrap_FontModule::newBMFontRasterizer(lua_State* L) diff --git a/source/modules/graphics/Font.cpp b/source/modules/graphics/Font.cpp index 996c0afc..fba4fec1 100644 --- a/source/modules/graphics/Font.cpp +++ b/source/modules/graphics/Font.cpp @@ -120,7 +120,7 @@ namespace love const auto& rasterizer = shaper->getRasterizers()[glyphindex.rasterizerIndex]; dpiScale = rasterizer->getDPIScale(); - return rasterizer->getGlyphData(glyphindex.index); + return rasterizer->getGlyphDataForIndex(glyphindex.index); } const FontBase::Glyph& FontBase::findGlyph(TextShaper::GlyphIndex glyphindex) @@ -295,7 +295,7 @@ namespace love auto data = graphics->requestBatchedDraw(command); GlyphVertex* vertexdata = (GlyphVertex*)data.stream; - memcpy(vertexdata, &vertices[cmd.startVertex], sizeof(GlyphVertex) * cmd.vertexCount); + std::copy_n(vertexdata, cmd.vertexCount, &vertices[cmd.startVertex]); m.transformXY(vertexdata, &vertices[cmd.startVertex], cmd.vertexCount); } }