目录

异步加载

CG Kit提供资源(模型、纹理、shader、glTF等)的异步加载功能,将资源加载和渲染流程隔离。资源的动态异步加载可以消除耗时的资源加载对渲染流程的影响。

  1. 构建资源加载成功及失败后对应的处理函数。
    void OnSuccess(IResource* resource)
    {
        LOGINFO("Async Load %s is Succeed.", resource->GetFilePath().c_str());
        ……// 资源的继续使用,根据用户的逻辑来写
    }
    void MainApplication::OnFailed(const String &filePath)
    {
        LOGERROR("Async Load %s is failed.", filePath.c_str());
    }
  2. 启动资源异步加载。
    1. 通过ResourceLoadInfo构建资源加载信息。
    std::shared_ptr<ResourceLoadInfo> info = std::make_shared<ResourceLoadInfo>();
    info->filePath = path;
    info->OnSuccess = [this](IResource* res) { OnSuccess(res); };
    info->OnFailed = [this](const String& path) { OnFailed(path); };
    1. 调用异步加载Load接口。
    gResourceManager.Load(info);
  1. 调用Get接口获取资源。
    IResource* resource = gResourceManager.Get(filePath);
  2. 调用Delete接口卸载资源。
    gResourceManager.Delete(filePath);