Atlas.build: max resolution limit argument
This commit is contained in:
@@ -42,7 +42,7 @@ void AtlasBuilder::add(string name, ImageData* image) {
|
|||||||
entries.push_back(atlasentry{name, shared_ptr<ImageData>(image)});
|
entries.push_back(atlasentry{name, shared_ptr<ImageData>(image)});
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas* AtlasBuilder::build(uint extrusion) {
|
Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
||||||
unique_ptr<uint[]> sizes (new uint[entries.size() * 2]);
|
unique_ptr<uint[]> sizes (new uint[entries.size() * 2]);
|
||||||
for (uint i = 0; i < entries.size(); i++) {
|
for (uint i = 0; i < entries.size(); i++) {
|
||||||
auto& entry = entries[i];
|
auto& entry = entries[i];
|
||||||
@@ -53,14 +53,18 @@ Atlas* AtlasBuilder::build(uint extrusion) {
|
|||||||
LMPacker packer(sizes.get(), entries.size()*2);
|
LMPacker packer(sizes.get(), entries.size()*2);
|
||||||
sizes.reset(nullptr);
|
sizes.reset(nullptr);
|
||||||
|
|
||||||
int width = 32;
|
uint width = 32;
|
||||||
int height = 32;
|
uint height = 32;
|
||||||
while (!packer.buildCompact(width, height, extrusion)) {
|
while (!packer.buildCompact(width, height, extrusion)) {
|
||||||
if (width > height) {
|
if (width > height) {
|
||||||
height *= 2;
|
height *= 2;
|
||||||
} else {
|
} else {
|
||||||
width *= 2;
|
width *= 2;
|
||||||
}
|
}
|
||||||
|
if (width > maxResolution || height > maxResolution) {
|
||||||
|
throw std::runtime_error("max atlas resolution "+
|
||||||
|
std::to_string(maxResolution)+" exceeded");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unordered_map<string, UVRegion> regions;
|
unordered_map<string, UVRegion> regions;
|
||||||
|
|||||||
@@ -38,7 +38,7 @@ public:
|
|||||||
AtlasBuilder() {}
|
AtlasBuilder() {}
|
||||||
void add(std::string name, ImageData* image);
|
void add(std::string name, ImageData* image);
|
||||||
|
|
||||||
Atlas* build(uint extrusion);
|
Atlas* build(uint extrusion, uint maxResolution=8192);
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // GRAPHICS_ATLAS_H_
|
#endif // GRAPHICS_ATLAS_H_
|
||||||
Reference in New Issue
Block a user