diff --git a/src/Features/DynamicCubemaps.cpp b/src/Features/DynamicCubemaps.cpp index fd723146c..55c7fee7e 100644 --- a/src/Features/DynamicCubemaps.cpp +++ b/src/Features/DynamicCubemaps.cpp @@ -86,15 +86,30 @@ void DynamicCubemaps::DrawSettings() } ID3D11Texture2D* tempTexture; - DX::ThrowIfFailed(device->CreateTexture2D(&texDesc, subresourceData, &tempTexture)); - DirectX::ScratchImage image; - DX::ThrowIfFailed(CaptureTexture(device, context, tempTexture, image)); - std::string filename = std::format("Data\\Textures\\DynamicCubemaps\\{:.2f}{:.2f}{:.2f}R{:.2f}.dds", settings.CubemapColor.x, settings.CubemapColor.y, settings.CubemapColor.z, settings.CubemapColor.w); + try { + DX::ThrowIfFailed(device->CreateTexture2D(&texDesc, subresourceData, &tempTexture)); + DX::ThrowIfFailed(CaptureTexture(device, context, tempTexture, image)); + + if (std::filesystem::create_directories(defaultDynamicCubeMapSavePath)) { + logger::info("Missing DynamicCubeMap Creator directory created: {}", defaultDynamicCubeMapSavePath); + } + + std::filesystem::path DynamicCubeMapSavePath = defaultDynamicCubeMapSavePath; + std::filesystem::path filename(std::format("R{:03d}G{:03d}B{:03d}A{:03d}.dds", colorPixel.r, colorPixel.g, colorPixel.b, colorPixel.a)); + DynamicCubeMapSavePath /= filename; - std::wstring wfilename = std::wstring(filename.begin(), filename.end()); - DX::ThrowIfFailed(SaveToDDSFile(image.GetImages(), image.GetImageCount(), image.GetMetadata(), DirectX::DDS_FLAGS::DDS_FLAGS_NONE, wfilename.c_str())); + if (std::filesystem::exists(DynamicCubeMapSavePath)) { + logger::info("DynamicCubeMap Creator file for {} already exists, skipping.", filename.string()); + } else { + DX::ThrowIfFailed(SaveToDDSFile(image.GetImages(), image.GetImageCount(), image.GetMetadata(), DirectX::DDS_FLAGS::DDS_FLAGS_NONE, DynamicCubeMapSavePath.c_str())); + logger::info("DynamicCubeMap Creator file for {} written", filename.string()); + } + + } catch (const std::exception& e) { + logger::error("Failed in DynamicCubeMap Creator file: {} {}", defaultDynamicCubeMapSavePath, e.what()); + } image.Release(); tempTexture->Release(); diff --git a/src/Features/DynamicCubemaps.h b/src/Features/DynamicCubemaps.h index fed763080..a18819096 100644 --- a/src/Features/DynamicCubemaps.h +++ b/src/Features/DynamicCubemaps.h @@ -19,6 +19,8 @@ struct DynamicCubemaps : Feature return &singleton; } + const std::string defaultDynamicCubeMapSavePath = "Data\\textures\\DynamicCubemaps"; + // Specular irradiance ID3D11SamplerState* computeSampler = nullptr;