27std::string extensionOf(
const std::string &path) {
28 const auto pos = path.find_last_of(
'.');
29 if (
pos == std::string::npos)
return {};
30 std::string ext = path.substr(
pos);
31 for (
char &
c : ext)
c = static_cast<char>(std::tolower(static_cast<unsigned char>(
c)));
35bool isImagePath(
const std::string &path) {
36 const std::string ext = extensionOf(path);
37 return ext ==
".png" || ext ==
".jpg" || ext ==
".jpeg" || ext ==
".bmp" || ext ==
".tga" ||
38 ext ==
".gif" || ext ==
".webp" || ext ==
".exr" || ext ==
".hdr";
43 const char *reloadKind()
const override {
return "image"; }
45 bool handlesPath(
const std::string &normPath)
const override {
51 if (!isImagePath(path))
return nullptr;
53 auto *fs = filesystem::Filesystem::create();
54 if (!fs)
return nullptr;
55 std::unique_ptr<filesystem::FileData> fd(fs->read(path));
56 if (!fd || fd->getData() ==
nullptr || fd->getSize() == 0)
57 throw eve::Exception(
"Could not read image file: %s", path.c_str());
59 auto *mod = Image::create();
61 return mod->newImageData(fd.get());
67 static ImageLoader loader;
static std::string pathOfKey(const std::string &key)
The path part of a cache key (everything before the first '?').
Resource is a game object that is managed by the ResourceManager. It can be loaded from a file or gen...