28std::string extensionOf(
const std::string &
path) {
29 const auto pos =
path.find_last_of(
'.');
30 if (
pos == std::string::npos)
return {};
31 std::string ext =
path.substr(
pos);
32 for (
char &
c : ext)
c = static_cast<char>(
std::tolower(static_cast<unsigned char>(
c)));
36bool isImagePath(
const std::string &
path) {
37 const std::string ext = extensionOf(
path);
38 return ext ==
".png" || ext ==
".jpg" || ext ==
".jpeg" || ext ==
".bmp" || ext ==
".tga" ||
39 ext ==
".gif" || ext ==
".webp" || ext ==
".exr" || ext ==
".hdr";
44 const char *reloadKind()
const override {
return "image"; }
46 bool handlesPath(
const std::string &normPath)
const override {
60 if (!isImagePath(
path))
return nullptr;
62 auto *fs = filesystem::Filesystem::create();
63 if (!fs)
return nullptr;
64 std::unique_ptr<filesystem::FileData> fd;
66 static std::mutex vfsReadMu;
67 std::lock_guard<std::mutex> vfsLock(vfsReadMu);
68 fd.reset(fs->read(
path));
70 if (!fd || fd->getData() ==
nullptr || fd->getSize() == 0)
73 auto *mod = Image::create();
75 return mod->newImageData(fd.get());
81 static ImageLoader loader;
EVENGINE_API_FOUNDATION public API.
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...
Move-only operation result carrying either a value or Status.
static Result success(T value)
Construct a successful result owning value.
EVENGINE_API_FOUNDATION public API.