#pragma once #include "../../scene/TextureCompressor/CompressedTexture.h" #include "../../scene/TextureCompressor/BlockCompressedTexture.h" #include "../../scene/TextureCompressor/TightlyPackedTexture.h" #include "../../scene/TextureCompressor/PaletteBlockTexture.h" #include "../../scene/TextureCompressor/DagBasedTexture.h" #include "../../scene/TextureCompressor/MultiRootBasedTexture.h" #include enum CompressionType { BASIC, BLOCK, TIGHT, TIGHTBLOCK, PALETTEBLOCK, DAGBASED, MULTIROOTBASED }; template class CompressedTextureFactory { public: static CompressionType GetCompressionType(std::string type) { if (type == "b") return BASIC; if (type == "p") return PALETTEBLOCK; if (type == "d") return DAGBASED; if (type == "m") return MULTIROOTBASED; if (std::regex_match(type, std::regex("[0-9]+"))) return BLOCK; if (std::regex_match(type, std::regex("t([0-9]+)"))) return TIGHTBLOCK; return TIGHT; } static CompressedTexture* GetCompressedTexture(std::string type) { CompressedTexture* texture = NULL; std::smatch sm; if (type == "" || type == "t") { texture = new TightlyPackedTexture(); } else if (type == "b") // b for basic texture (no compression) { texture = new BasicTexture(); } else if (type == "p") // p for palette { texture = new PaletteBlockTexture(); } else if (type == "d") { texture = new DagBasedTexture(); } else if (type == "m") { return new MultiRootBasedTexture(); } else if (std::regex_match(type, sm, std::regex("[0-8]+"))) { unsigned blockSize = (unsigned)std::stoi(sm.str(0)); texture = new BlockCompressedTexture(blockSize); } else if (std::regex_match(type, sm, std::regex("t([0-8]+)"))) { unsigned blockSize = (unsigned)std::stoi(sm.str(1)); texture = new BlockCompressedTexture>(blockSize); } return texture; } // Returns a string that can be used as a regex to match all compressed texture types static std::string GetRegexMatcher() { return std::string("p|b|d|m|[0-9]+|t[0-9]*"); } };