Added reading texture map input from file so we can give custom names to the entries.
This commit is contained in:
parent
cf4d4cb8a6
commit
c469772afa
2
assets/bitmaps/ui_elements.txt
Normal file
2
assets/bitmaps/ui_elements.txt
Normal file
@ -0,0 +1,2 @@
|
||||
symtex_glyphs ../fonts/symtex.png
|
||||
sdl_logo sdl.png
|
@ -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)
|
||||
|
||||
|
@ -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.");
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -14,12 +14,13 @@
|
||||
#define STBIW_ASSERT(x) MIJIN_ASSERT(x, #x)
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include <stb_image_write.h>
|
||||
#include <mijin/util/string.hpp>
|
||||
#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<Pixel[], FreeDeleter>(reinterpret_cast<Pixel*>(pixels)),
|
||||
.width = static_cast<unsigned>(width),
|
||||
.height = static_cast<unsigned>(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?
|
||||
|
@ -39,7 +39,8 @@ private:
|
||||
|
||||
std::vector<ImageData> 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
|
||||
|
Loading…
x
Reference in New Issue
Block a user