MCPcopy Create free account
hub / github.com/NVIDIAGameWorks/Falcor / createFromFile

Method createFromFile

Source/Falcor/Core/API/Texture.cpp:364–432  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

362}
363
364ref<Texture> Texture::createFromFile(
365 ref<Device> pDevice,
366 const std::filesystem::path& path,
367 bool generateMipLevels,
368 bool loadAsSrgb,
369 ResourceBindFlags bindFlags,
370 Bitmap::ImportFlags importFlags
371)
372{
373 if (!std::filesystem::exists(path))
374 {
375 logWarning("Error when loading image file. File '{}' does not exist.", path);
376 return nullptr;
377 }
378
379 ref<Texture> pTex;
380 if (hasExtension(path, "dds"))
381 {
382 try
383 {
384 pTex = ImageIO::loadTextureFromDDS(pDevice, path, loadAsSrgb);
385 }
386 catch (const std::exception& e)
387 {
388 logWarning("Error loading '{}': {}", path, e.what());
389 }
390 }
391 else
392 {
393 Bitmap::UniqueConstPtr pBitmap = Bitmap::createFromFile(path, kTopDown, importFlags);
394 if (pBitmap)
395 {
396 ResourceFormat texFormat = pBitmap->getFormat();
397 if (loadAsSrgb)
398 {
399 texFormat = linearToSrgbFormat(texFormat);
400 }
401
402 pTex = pDevice->createTexture2D(
403 pBitmap->getWidth(),
404 pBitmap->getHeight(),
405 texFormat,
406 1,
407 generateMipLevels ? Texture::kMaxPossible : 1,
408 pBitmap->getData(),
409 bindFlags
410 );
411 }
412 }
413
414 if (pTex != nullptr)
415 {
416 pTex->setSourcePath(path);
417 pTex->mImportFlags = importFlags;
418
419 // Log debug info.
420 std::string str = fmt::format(
421 "Loaded texture: size={}x{} mips={} format={} path={}",

Callers

nothing calls this directly

Calls 11

hasExtensionFunction · 0.85
linearToSrgbFormatFunction · 0.85
logDebugFunction · 0.85
whatMethod · 0.80
getFormatMethod · 0.80
createTexture2DMethod · 0.80
getWidthMethod · 0.80
getHeightMethod · 0.80
to_stringFunction · 0.70
logWarningFunction · 0.50
getDataMethod · 0.45

Tested by

no test coverage detected