Files
CDAG/Research/core/OctreeBuilder/CompressedTextureFactory.h

79 lines
2.1 KiB
C++

#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 <regex>
enum CompressionType
{
BASIC, BLOCK, TIGHT, TIGHTBLOCK, PALETTEBLOCK, DAGBASED, MULTIROOTBASED
};
template<typename T>
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<T>* GetCompressedTexture(std::string type)
{
CompressedTexture<T>* texture = NULL;
std::smatch sm;
if (type == "" || type == "t")
{
texture = new TightlyPackedTexture<T>();
}
else if (type == "b") // b for basic texture (no compression)
{
texture = new BasicTexture<T>();
}
else if (type == "p") // p for palette
{
texture = new PaletteBlockTexture<T>();
}
else if (type == "d")
{
texture = new DagBasedTexture<T>();
}
else if (type == "m")
{
return new MultiRootBasedTexture<T>();
}
else if (std::regex_match(type, sm, std::regex("[0-8]+")))
{
unsigned blockSize = (unsigned)std::stoi(sm.str(0));
texture = new BlockCompressedTexture<T>(blockSize);
}
else if (std::regex_match(type, sm, std::regex("t([0-8]+)")))
{
unsigned blockSize = (unsigned)std::stoi(sm.str(1));
texture = new BlockCompressedTexture<T, TightlyPackedTexture<T>>(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]*");
}
};