Saves image data to a DDS file using the specified compression mode. Optionally generates mips.
| 332 | |
| 333 | // Saves image data to a DDS file using the specified compression mode. Optionally generates mips. |
| 334 | void exportDDS(const std::filesystem::path& path, ExportData& image, ImageIO::CompressionMode mode, bool generateMips) |
| 335 | { |
| 336 | nvtt::CompressionOptions compressionOptions; |
| 337 | nvtt::Format format = convertModeToNvttFormat(mode); |
| 338 | compressionOptions.setFormat(format); |
| 339 | if (format == nvtt::Format::Format_RGBA && !isCompressedFormat(image.format)) |
| 340 | { |
| 341 | if (getFormatType(image.format) == FormatType::Float) |
| 342 | { |
| 343 | compressionOptions.setPixelType(nvtt::PixelType::PixelType_Float); |
| 344 | if (image.format == ResourceFormat::R32Float) |
| 345 | { |
| 346 | compressionOptions.setPixelFormat(32, 0, 0, 0); |
| 347 | } |
| 348 | else |
| 349 | { |
| 350 | uint32_t bits = getNumChannelBits(image.format, 0); |
| 351 | compressionOptions.setPixelFormat(bits, bits, bits, bits); |
| 352 | } |
| 353 | } |
| 354 | } |
| 355 | else if (format == nvtt::Format::Format_BC6S) |
| 356 | { |
| 357 | compressionOptions.setPixelType(nvtt::PixelType::PixelType_Float); |
| 358 | } |
| 359 | |
| 360 | nvtt::OutputOptions outputOptions; |
| 361 | std::string pathStr = path.string(); |
| 362 | outputOptions.setFileName(pathStr.c_str()); |
| 363 | if (format == nvtt::Format::Format_BC6S || format == nvtt::Format::Format_BC7) |
| 364 | { |
| 365 | outputOptions.setContainer(nvtt::Container::Container_DDS10); |
| 366 | } |
| 367 | outputOptions.setSrgbFlag(isSrgbFormat(image.format)); |
| 368 | |
| 369 | nvtt::Context context; |
| 370 | if (!context.outputHeader( |
| 371 | image.type, |
| 372 | image.width, |
| 373 | image.height, |
| 374 | image.depth, |
| 375 | image.mipLevels, |
| 376 | image.images[0].isNormalMap(), |
| 377 | compressionOptions, |
| 378 | outputOptions |
| 379 | )) |
| 380 | { |
| 381 | FALCOR_THROW("Failed to output file header."); |
| 382 | } |
| 383 | |
| 384 | for (uint32_t f = 0; f < image.faceCount; ++f) |
| 385 | { |
| 386 | size_t faceIndex = f * image.mipLevels; |
| 387 | nvtt::Surface tmp = image.images[faceIndex]; |
| 388 | if (!context.compress(tmp, f, 0, compressionOptions, outputOptions)) |
| 389 | { |
| 390 | FALCOR_THROW("Failed to compress file."); |
| 391 | } |
no test coverage detected