/*virtual*/ HdTextureResourceSharedPtr HdSt_UnitTestDelegate::GetTextureResource(SdfPath const& textureId) { GlfTextureHandleRefPtr texture = GlfTextureRegistry::GetInstance().GetTextureHandle(_textures[textureId].texture); // Simple way to detect if the glf texture is ptex or not bool isPtex = false; #ifdef PXR_PTEX_SUPPORT_ENABLED GlfPtexTextureRefPtr pTex = TfDynamic_cast<GlfPtexTextureRefPtr>(_textures[textureId].texture); if (pTex) { isPtex = true; } #endif return HdTextureResourceSharedPtr( new HdStSimpleTextureResource(texture, isPtex)); }
/*virtual*/ HdTextureResourceSharedPtr HdSceneDelegate::GetTextureResource(SdfPath const& textureId) { return HdTextureResourceSharedPtr(); }
HdTextureResourceSharedPtr UsdImagingGL_GetTextureResource(UsdPrim const& usdPrim, SdfPath const& usdPath, UsdTimeCode time) { if (!TF_VERIFY(usdPrim)) return HdTextureResourceSharedPtr(); if (!TF_VERIFY(usdPath != SdfPath())) return HdTextureResourceSharedPtr(); UsdAttribute attr = _GetTextureResourceAttr(usdPrim, usdPath); SdfAssetPath asset; if (!TF_VERIFY(attr) || !TF_VERIFY(attr.Get(&asset, time))) { return HdTextureResourceSharedPtr(); } HdTextureType textureType = HdTextureType::Uv; TfToken filePath = TfToken(asset.GetResolvedPath()); // If the path can't be resolved, it's either an UDIM texture // or the texture doesn't exists and we can to exit early. if (filePath.IsEmpty()) { filePath = TfToken(asset.GetAssetPath()); if (GlfIsSupportedUdimTexture(filePath)) { textureType = HdTextureType::Udim; } else { TF_DEBUG(USDIMAGING_TEXTURES).Msg( "File does not exist, returning nullptr"); TF_WARN("Unable to find Texture '%s' with path '%s'.", filePath.GetText(), usdPath.GetText()); return {}; } } else { if (GlfIsSupportedPtexTexture(filePath)) { textureType = HdTextureType::Ptex; } } GlfImage::ImageOriginLocation origin = UsdImagingGL_ComputeTextureOrigin(usdPrim); HdWrap wrapS = _GetWrapS(usdPrim, textureType); HdWrap wrapT = _GetWrapT(usdPrim, textureType); HdMinFilter minFilter = _GetMinFilter(usdPrim); HdMagFilter magFilter = _GetMagFilter(usdPrim); float memoryLimit = _GetMemoryLimit(usdPrim); TF_DEBUG(USDIMAGING_TEXTURES).Msg( "Loading texture: id(%s), type(%s)\n", usdPath.GetText(), textureType == HdTextureType::Uv ? "Uv" : textureType == HdTextureType::Ptex ? "Ptex" : "Udim"); HdTextureResourceSharedPtr texResource; TfStopwatch timer; timer.Start(); // Udim's can't be loaded through like other textures, because // we can't select the right factory based on the file type. // We also need to pass the layer context to the factory, // so each file gets resolved properly. GlfTextureHandleRefPtr texture; if (textureType == HdTextureType::Udim) { UdimTextureFactory factory(_FindLayerHandle(attr, time)); texture = GlfTextureRegistry::GetInstance().GetTextureHandle( filePath, origin, &factory); } else { texture = GlfTextureRegistry::GetInstance().GetTextureHandle( filePath, origin); } texResource = HdTextureResourceSharedPtr( new HdStSimpleTextureResource(texture, textureType, wrapS, wrapT, minFilter, magFilter, memoryLimit)); timer.Stop(); TF_DEBUG(USDIMAGING_TEXTURES).Msg(" Load time: %.3f s\n", timer.GetSeconds()); return texResource; }