Atlas minor refactor
This commit is contained in:
parent
bca4de179d
commit
ba762584a7
@ -5,51 +5,42 @@
|
|||||||
#include "Texture.h"
|
#include "Texture.h"
|
||||||
#include "ImageData.h"
|
#include "ImageData.h"
|
||||||
|
|
||||||
using std::vector;
|
Atlas::Atlas(ImageData* image, std::unordered_map<std::string, UVRegion> regions)
|
||||||
using std::string;
|
|
||||||
using std::unique_ptr;
|
|
||||||
using std::shared_ptr;
|
|
||||||
using std::unordered_map;
|
|
||||||
|
|
||||||
Atlas::Atlas(ImageData* image,
|
|
||||||
unordered_map<string, UVRegion> regions)
|
|
||||||
: texture(Texture::from(image)),
|
: texture(Texture::from(image)),
|
||||||
image(image),
|
image(image),
|
||||||
regions(regions) {
|
regions(regions) {
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas::~Atlas() {
|
Atlas::~Atlas() {
|
||||||
delete image;
|
|
||||||
delete texture;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Atlas::has(string name) const {
|
bool Atlas::has(const std::string& name) const {
|
||||||
return regions.find(name) != regions.end();
|
return regions.find(name) != regions.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
const UVRegion& Atlas::get(string name) const {
|
const UVRegion& Atlas::get(const std::string& name) const {
|
||||||
return regions.at(name);
|
return regions.at(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
Texture* Atlas::getTexture() const {
|
Texture* Atlas::getTexture() const {
|
||||||
return texture;
|
return texture.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
ImageData* Atlas::getImage() const {
|
ImageData* Atlas::getImage() const {
|
||||||
return image;
|
return image.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AtlasBuilder::add(string name, ImageData* image) {
|
void AtlasBuilder::add(std::string name, ImageData* image) {
|
||||||
entries.push_back(atlasentry{name, shared_ptr<ImageData>(image)});
|
entries.push_back(atlasentry{name, std::shared_ptr<ImageData>(image)});
|
||||||
names.insert(name);
|
names.insert(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool AtlasBuilder::has(string name) const {
|
bool AtlasBuilder::has(const std::string& name) const {
|
||||||
return names.find(name) != names.end();
|
return names.find(name) != names.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
||||||
unique_ptr<uint[]> sizes (new uint[entries.size() * 2]);
|
auto sizes = std::make_unique<uint[]>(entries.size() * 2);
|
||||||
uint index = 0;
|
uint index = 0;
|
||||||
for (auto& entry : entries) {
|
for (auto& entry : entries) {
|
||||||
auto image = entry.image;
|
auto image = entry.image;
|
||||||
@ -73,9 +64,9 @@ Atlas* AtlasBuilder::build(uint extrusion, uint maxResolution) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
unordered_map<string, UVRegion> regions;
|
auto canvas = std::make_unique<ImageData>(ImageFormat::rgba8888, width, height);
|
||||||
unique_ptr<ImageData> canvas (new ImageData(ImageFormat::rgba8888, width, height));
|
std::unordered_map<std::string, UVRegion> regions;
|
||||||
vector<rectangle> rects = packer.getResult();
|
std::vector<rectangle> rects = packer.getResult();
|
||||||
for (uint i = 0; i < entries.size(); i++) {
|
for (uint i = 0; i < entries.size(); i++) {
|
||||||
const rectangle& rect = rects[i];
|
const rectangle& rect = rects[i];
|
||||||
const atlasentry& entry = entries[rect.idx];
|
const atlasentry& entry = entries[rect.idx];
|
||||||
|
|||||||
@ -13,15 +13,15 @@ class ImageData;
|
|||||||
class Texture;
|
class Texture;
|
||||||
|
|
||||||
class Atlas {
|
class Atlas {
|
||||||
Texture* texture;
|
std::unique_ptr<Texture> texture;
|
||||||
ImageData* image;
|
std::unique_ptr<ImageData> image;
|
||||||
std::unordered_map<std::string, UVRegion> regions;
|
std::unordered_map<std::string, UVRegion> regions;
|
||||||
public:
|
public:
|
||||||
Atlas(ImageData* image, std::unordered_map<std::string, UVRegion> regions);
|
Atlas(ImageData* image, std::unordered_map<std::string, UVRegion> regions);
|
||||||
~Atlas();
|
~Atlas();
|
||||||
|
|
||||||
bool has(std::string name) const;
|
bool has(const std::string& name) const;
|
||||||
const UVRegion& get(std::string name) const;
|
const UVRegion& get(const std::string& name) const;
|
||||||
|
|
||||||
Texture* getTexture() const;
|
Texture* getTexture() const;
|
||||||
ImageData* getImage() const;
|
ImageData* getImage() const;
|
||||||
@ -39,7 +39,7 @@ class AtlasBuilder {
|
|||||||
public:
|
public:
|
||||||
AtlasBuilder() {}
|
AtlasBuilder() {}
|
||||||
void add(std::string name, ImageData* image);
|
void add(std::string name, ImageData* image);
|
||||||
bool has(std::string name) const;
|
bool has(const std::string& name) const;
|
||||||
const std::set<std::string>& getNames() { return names; };
|
const std::set<std::string>& getNames() { return names; };
|
||||||
|
|
||||||
Atlas* build(uint extrusion, uint maxResolution=8192);
|
Atlas* build(uint extrusion, uint maxResolution=8192);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user