| 231 | } |
| 232 | |
| 233 | void SceneCache::writeCache(const Scene::SceneData& sceneData, const Key& key) |
| 234 | { |
| 235 | auto cachePath = getCachePath(key); |
| 236 | |
| 237 | logInfo("Writing scene cache to '{}'.", cachePath); |
| 238 | |
| 239 | // Create directories if not existing. |
| 240 | std::filesystem::create_directories(cachePath.parent_path()); |
| 241 | |
| 242 | // Open file. |
| 243 | std::ofstream fs(cachePath.c_str(), std::ios_base::binary); |
| 244 | if (fs.bad()) FALCOR_THROW("Failed to create scene cache file '{}'.", cachePath); |
| 245 | |
| 246 | // Write header (uncompressed). |
| 247 | Header header; |
| 248 | std::memcpy(header.magic, kMagic, sizeof(Header::magic)); |
| 249 | header.version = kVersion; |
| 250 | fs.write(reinterpret_cast<const char*>(&header), sizeof(header)); |
| 251 | |
| 252 | // Write cache (compressed). |
| 253 | lz4_stream::basic_ostream<kBlockSize> zs(fs); |
| 254 | OutputStream stream(zs); |
| 255 | writeSceneData(stream, sceneData); |
| 256 | if (fs.bad()) FALCOR_THROW("Failed to write scene cache file to '{}'.", cachePath); |
| 257 | } |
| 258 | |
| 259 | Scene::SceneData SceneCache::readCache(ref<Device> pDevice, const Key& key) |
| 260 | { |