diff --git a/assets/bitmaps/ui_elements.txt b/assets/bitmaps/ui_elements.txt new file mode 100644 index 0000000..9edcebc --- /dev/null +++ b/assets/bitmaps/ui_elements.txt @@ -0,0 +1,2 @@ +symtex_glyphs ../fonts/symtex.png +sdl_logo sdl.png \ No newline at end of file diff --git a/private/sdl_gpu_test/SModule b/private/sdl_gpu_test/SModule index e20374b..6e5abfc 100644 --- a/private/sdl_gpu_test/SModule +++ b/private/sdl_gpu_test/SModule @@ -49,15 +49,9 @@ for shader_file in shader_files: spv = env.SpirV(source = shader_file, target=f'{shader_file}.spv') env.Default(spv) -ui_textures = Split(""" - #assets/fonts/symtex.png - #assets/bitmaps/cube.png - #assets/bitmaps/sdl.png -""") - pack = env.PackTextures( target = '#assets/bitmaps/ui.png', - source = ui_textures + source = ['#assets/bitmaps/ui_elements.txt'] ) env.Default(pack) diff --git a/private/sdl_gpu_test/gui/ui_renderer.cpp b/private/sdl_gpu_test/gui/ui_renderer.cpp index 1a4ec93..7f80513 100644 --- a/private/sdl_gpu_test/gui/ui_renderer.cpp +++ b/private/sdl_gpu_test/gui/ui_renderer.cpp @@ -99,7 +99,7 @@ void UIRenderer::init(Application& application) .textureHeight = textureArgs.height }); - auto itEntry = mTextureAtlas.entries.find("assets/fonts/symtex.png"); + auto itEntry = mTextureAtlas.entries.find("symtex_glyphs"); if (itEntry == mTextureAtlas.entries.end()) { throw std::runtime_error("Texture atlas is missing entry for the font."); diff --git a/private/texture_packer/main.cpp b/private/texture_packer/main.cpp index 360b486..bc4ddc2 100644 --- a/private/texture_packer/main.cpp +++ b/private/texture_packer/main.cpp @@ -40,7 +40,14 @@ int main(int argc, char* argv[]) sdl_gpu_test::Packer packer; for (const std::string& inputFile : inputFiles) { - packer.addImage(inputFile); + if (inputFile.ends_with(".txt")) + { + packer.addImageList(inputFile); + } + else + { + packer.addImage(inputFile, inputFile); + } } packer.pack(outputFile); } diff --git a/private/texture_packer/packer.cpp b/private/texture_packer/packer.cpp index 8a3947a..00aa32f 100644 --- a/private/texture_packer/packer.cpp +++ b/private/texture_packer/packer.cpp @@ -14,12 +14,13 @@ #define STBIW_ASSERT(x) MIJIN_ASSERT(x, #x) #define STB_IMAGE_WRITE_IMPLEMENTATION #include +#include #undef STB_IMAGE_WRITE_IMPLEMENTATION #undef STBIW_ASSERT namespace sdl_gpu_test { -void Packer::addImage(const fs::path& path) +void Packer::addImage(std::string name, const fs::path& path) { int width = 0; int height = 0; @@ -37,13 +38,35 @@ void Packer::addImage(const fs::path& path) } mImages.push_back({ - .name = path.generic_string(), + .name = std::move(name), .data = std::unique_ptr(reinterpret_cast(pixels)), .width = static_cast(width), .height = static_cast(height) }); } +void Packer::addImageList(const fs::path& path) +{ + mijin::FileStream stream; + mijin::throwOnError(stream.open(path.generic_string(), mijin::FileOpenMode::READ)); + while (!stream.isAtEnd()) + { + std::string line; + mijin::throwOnError(stream.readLine(line)); + if (line.empty()) + { + continue; + } + const auto [name, file] = mijin::splitFixed<2>(line, " "); + if (file.empty()) + { + throw std::runtime_error("Invalid image list format, missing file name."); + } + addImage(std::string(name), path.parent_path() / file); + } +} + + void Packer::pack(const fs::path& outputPath) { static constexpr bool allowFlip = false; // TODO: this could work? diff --git a/private/texture_packer/packer.hpp b/private/texture_packer/packer.hpp index 629f5ce..3059e8e 100644 --- a/private/texture_packer/packer.hpp +++ b/private/texture_packer/packer.hpp @@ -39,7 +39,8 @@ private: std::vector mImages; public: - void addImage(const fs::path& path); + void addImage(std::string name, const fs::path& path); + void addImageList(const fs::path& path); void pack(const fs::path& outputPath); }; } // namespace sdl_gpu_test