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

Method readMaterial

Source/Falcor/Scene/SceneCache.cpp:752–802  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

750 }
751
752 ref<Material> SceneCache::readMaterial(InputStream& stream, MaterialTextureLoader& materialTextureLoader, ref<Device> pDevice)
753 {
754 // Create derived material class of the right type.
755 ref<Material> pMaterial;
756 {
757 uint32_t type;
758 stream.read(type);
759 switch ((MaterialType)type)
760 {
761 case MaterialType::Standard:
762 pMaterial = StandardMaterial::create(pDevice, "");
763 break;
764 case MaterialType::Hair:
765 pMaterial = HairMaterial::create(pDevice, "");
766 break;
767 case MaterialType::Cloth:
768 pMaterial = ClothMaterial::create(pDevice, "");
769 break;
770 default:
771 FALCOR_THROW("Unsupported material type");
772 }
773 }
774 FALCOR_ASSERT(pMaterial);
775
776 // Read common fields.
777 stream.read(pMaterial->mName);
778 stream.read(pMaterial->mHeader);
779 stream.read(pMaterial->mUpdates);
780 pMaterial->mTextureTransform = readTransform(stream);
781
782 auto readTextureSlot = [&](Material::TextureSlot slot)
783 {
784 auto hasTexture = stream.read<bool>();
785 if (hasTexture)
786 {
787 auto path = stream.read<std::filesystem::path>();
788 materialTextureLoader.loadTexture(pMaterial, slot, path);
789 }
790 };
791
792 for (uint32_t slot = 0; slot < (uint32_t)Material::TextureSlot::Count; ++slot)
793 {
794 readTextureSlot(Material::TextureSlot(slot));
795 }
796
797 // Read data in derived class.
798 if (auto pBasicMaterial = pMaterial->toBasicMaterial()) readBasicMaterial(stream, materialTextureLoader, pBasicMaterial, pDevice);
799 else FALCOR_THROW("Unsupported material type");
800
801 return pMaterial;
802 }
803
804 void SceneCache::readBasicMaterial(InputStream& stream, MaterialTextureLoader& materialTextureLoader, const ref<BasicMaterial>& pMaterial, ref<Device> pDevice)
805 {

Callers

nothing calls this directly

Calls 5

TextureSlotEnum · 0.85
toBasicMaterialMethod · 0.80
createFunction · 0.50
readMethod · 0.45
loadTextureMethod · 0.45

Tested by

no test coverage detected