GlfImageSharedPtr GlfImageRegistry::_ConstructImage(std::string const & filename) { static GlfImageSharedPtr NULL_IMAGE; // Lookup the plug-in type name based on the filename. TfToken fileExtension(ArGetResolver().GetExtension(filename)); TfType const & pluginType = _typeMap->Find(fileExtension); if (!pluginType) { // Unknown prim type. TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg( "[PluginLoad] Unknown image type '%s'\n", fileExtension.GetText()); return NULL_IMAGE; } PlugRegistry& plugReg = PlugRegistry::GetInstance(); PlugPluginPtr plugin = plugReg.GetPluginForType(pluginType); if (!plugin || !plugin->Load()) { TF_CODING_ERROR("[PluginLoad] PlugPlugin could not be loaded for " "TfType '%s'\n", pluginType.GetTypeName().c_str()); return NULL_IMAGE; } GlfImageFactoryBase* factory = pluginType.GetFactory<GlfImageFactoryBase>(); if (!factory) { TF_CODING_ERROR("[PluginLoad] Cannot manufacture type '%s' " "for image type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); return NULL_IMAGE; } GlfImageSharedPtr instance = factory->New(); if (!instance) { TF_CODING_ERROR("[PluginLoad] Cannot construct instance of type '%s' " "for image type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); return NULL_IMAGE; } TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg( "[PluginLoad] Loaded plugin '%s' for image type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); return instance; }
GlfTextureFactoryBase* GlfTextureRegistry::_GetTextureFactory(const TfToken &filename) { // Lookup the plug-in type name based on the file extension. TfToken fileExtension(TfStringGetSuffix(filename)); TfType pluginType = _typeMap->Find(fileExtension); if (!pluginType) { // Unknown type. Try the wildcard. pluginType = _typeMap->Find(TfToken("*")); if (!pluginType) { TF_DEBUG(GLF_DEBUG_TEXTURE_PLUGINS).Msg( "[PluginLoad] Unknown texture type '%s'\n", fileExtension.GetText()); return nullptr; } } PlugRegistry& plugReg = PlugRegistry::GetInstance(); PlugPluginPtr plugin = plugReg.GetPluginForType(pluginType); if (!plugin || !plugin->Load()) { TF_CODING_ERROR("[PluginLoad] PlugPlugin could not be loaded for " "TfType '%s'\n", pluginType.GetTypeName().c_str()); return nullptr; } TF_DEBUG(GLF_DEBUG_TEXTURE_IMAGE_PLUGINS).Msg( "[PluginLoad] Loaded plugin '%s' for texture type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); if (GlfTextureFactoryBase* factory = pluginType.GetFactory<GlfTextureFactoryBase>()) { return factory; } TF_CODING_ERROR("[PluginLoad] Cannot manufacture type '%s' " "for texture type '%s'\n", pluginType.GetTypeName().c_str(), fileExtension.GetText()); return nullptr; }