Added reading texture map input from file so we can give custom names to the entries.
This commit is contained in:
@@ -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?
|
||||
|
||||
Reference in New Issue
Block a user