| 261 | } |
| 262 | |
| 263 | ref<Texture> Texture::createMippedFromFiles( |
| 264 | ref<Device> pDevice, |
| 265 | fstd::span<const std::filesystem::path> paths, |
| 266 | bool loadAsSrgb, |
| 267 | ResourceBindFlags bindFlags, |
| 268 | Bitmap::ImportFlags importFlags |
| 269 | ) |
| 270 | { |
| 271 | std::vector<Bitmap::UniqueConstPtr> mips; |
| 272 | mips.reserve(paths.size()); |
| 273 | size_t combinedSize = 0; |
| 274 | std::filesystem::path fullPathMip0; |
| 275 | |
| 276 | for (const auto& path : paths) |
| 277 | { |
| 278 | Bitmap::UniqueConstPtr pBitmap; |
| 279 | if (hasExtension(path, "dds")) |
| 280 | { |
| 281 | pBitmap = ImageIO::loadBitmapFromDDS(path); |
| 282 | } |
| 283 | else |
| 284 | { |
| 285 | pBitmap = Bitmap::createFromFile(path, kTopDown, importFlags); |
| 286 | } |
| 287 | if (!pBitmap) |
| 288 | { |
| 289 | logWarning("Error loading mip {}. Loading failed for image file '{}'.", mips.size(), path); |
| 290 | break; |
| 291 | } |
| 292 | |
| 293 | if (!mips.empty()) |
| 294 | { |
| 295 | if (mips.back()->getFormat() != pBitmap->getFormat()) |
| 296 | { |
| 297 | logWarning("Error loading mip {} from file {}. Texture format of all mip levels must match.", mips.size(), path); |
| 298 | break; |
| 299 | } |
| 300 | if (std::max(mips.back()->getWidth() / 2, 1u) != pBitmap->getWidth() || |
| 301 | std::max(mips.back()->getHeight() / 2, 1u) != pBitmap->getHeight()) |
| 302 | { |
| 303 | logWarning( |
| 304 | "Error loading mip {} from file {}. Image resolution must decrease by half. ({}, {}) != ({}, {})/2", |
| 305 | mips.size(), |
| 306 | path, |
| 307 | pBitmap->getWidth(), |
| 308 | pBitmap->getHeight(), |
| 309 | mips.back()->getWidth(), |
| 310 | mips.back()->getHeight() |
| 311 | ); |
| 312 | break; |
| 313 | } |
| 314 | } |
| 315 | else |
| 316 | { |
| 317 | fullPathMip0 = path; |
| 318 | } |
| 319 | combinedSize += pBitmap->getSize(); |
| 320 | mips.emplace_back(std::move(pBitmap)); |
nothing calls this directly
no test coverage detected