Extra2D/include/assets/asset_loader.h

45 lines
1013 B
C++
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#pragma once
#include <assets/handle.h>
#include <types/ptr/intrusive_ptr.h>
#include <vector>
#include <cstdint>
namespace extra2d {
/**
* @brief 资源加载器接口
*
* 每种资源类型实现一个加载器,插件化设计。
*
* @tparam T 资源类型
*/
template<typename T>
class AssetLoader {
public:
virtual ~AssetLoader() = default;
/**
* @brief 从文件加载资源
* @param path 文件路径
* @return 资源指针,失败返回 nullptr
*/
virtual Ptr<T> load(const std::string& path) = 0;
/**
* @brief 从内存加载资源
* @param data 数据指针
* @param size 数据大小
* @return 资源指针,失败返回 nullptr
*/
virtual Ptr<T> loadFromMemory(const uint8_t* data, size_t size) = 0;
/**
* @brief 获取支持的文件扩展名
* @return 扩展名列表(如 ".png", ".jpg"
*/
virtual std::vector<std::string> getExtensions() const = 0;
};
} // namespace extra2d