assets-related refactor

This commit is contained in:
MihailRis
2024-04-10 17:44:17 +03:00
parent 216e38e411
commit befc9cf09c
14 changed files with 242 additions and 202 deletions
+8 -3
View File
@@ -6,7 +6,7 @@
#include "ImageData.h"
Atlas::Atlas(ImageData* image, std::unordered_map<std::string, UVRegion> regions)
: texture(Texture::from(image)),
: texture(nullptr),
image(image),
regions(regions) {
}
@@ -14,6 +14,10 @@ Atlas::Atlas(ImageData* image, std::unordered_map<std::string, UVRegion> regions
Atlas::~Atlas() {
}
void Atlas::prepare() {
texture.reset(Texture::from(image.get()));
}
bool Atlas::has(const std::string& name) const {
return regions.find(name) != regions.end();
}
@@ -80,8 +84,9 @@ Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
}
float unitX = 1.0f / width;
float unitY = 1.0f / height;
regions[entry.name] = UVRegion(unitX * x, unitY * y,
unitX * (x + w), unitY * (y + h));
regions[entry.name] = UVRegion(
unitX * x, unitY * y, unitX * (x + w), unitY * (y + h)
);
}
return new Atlas(canvas.release(), regions);
}