| 257 | } |
| 258 | |
| 259 | Scene::SceneData SceneCache::readCache(ref<Device> pDevice, const Key& key) |
| 260 | { |
| 261 | auto cachePath = getCachePath(key); |
| 262 | |
| 263 | logInfo("Loading scene cache from '{}'.", cachePath); |
| 264 | |
| 265 | // Open file. |
| 266 | std::ifstream fs(cachePath.c_str(), std::ios_base::binary); |
| 267 | if (fs.bad()) FALCOR_THROW("Failed to open scene cache file '{}'.", cachePath); |
| 268 | |
| 269 | // Read header (uncompressed). |
| 270 | Header header; |
| 271 | fs.read(reinterpret_cast<char*>(&header), sizeof(header)); |
| 272 | if (!header.isValid()) FALCOR_THROW("Invalid header in scene cache file '{}'.", cachePath); |
| 273 | |
| 274 | // Read cache (compressed). |
| 275 | lz4_stream::basic_istream<kBlockSize, kBlockSize> zs(fs); |
| 276 | InputStream stream(zs); |
| 277 | auto sceneData = readSceneData(stream, pDevice); |
| 278 | if (fs.bad()) FALCOR_THROW("Failed to read scene cache file from '{}'.", cachePath); |
| 279 | return sceneData; |
| 280 | } |
| 281 | |
| 282 | std::filesystem::path SceneCache::getCachePath(const Key& key) |
| 283 | { |