From f67019f2628d0833fbb1852edf5ef5de4488f821 Mon Sep 17 00:00:00 2001 From: Sean Lilley Date: Thu, 31 Aug 2023 20:07:45 -0400 Subject: [PATCH] Temp --- .vscode/launch.linux.json | 5 + exts/cesium.omniverse/mdl/cesium.mdl | 30 +++++ .../include/cesium/omniverse/FabricGeometry.h | 1 + .../include/cesium/omniverse/FabricMaterial.h | 16 ++- .../cesium/omniverse/FabricResourceManager.h | 2 + .../include/cesium/omniverse/FabricTexture.h | 4 +- src/core/include/cesium/omniverse/Tokens.h | 6 + src/core/src/FabricGeometry.cpp | 20 +++ src/core/src/FabricMaterial.cpp | 126 +++++++++++++++++- src/core/src/FabricMaterialPool.cpp | 3 +- src/core/src/FabricPrepareRenderResources.cpp | 8 +- src/core/src/FabricResourceManager.cpp | 16 ++- src/core/src/FabricTexture.cpp | 9 +- src/core/src/FabricTexturePool.cpp | 2 +- 14 files changed, 229 insertions(+), 19 deletions(-) diff --git a/.vscode/launch.linux.json b/.vscode/launch.linux.json index 743799ccc..4431fa4b9 100644 --- a/.vscode/launch.linux.json +++ b/.vscode/launch.linux.json @@ -22,6 +22,11 @@ "exceptionList": "libcesium.omniverse.plugin.so;libcesium.omniverse.cpp.tests.plugin.so" }, "setupCommands": [ + { + "description": "Enable pretty-printing for gdb", + "text": "python import sys;sys.path.insert(0, '/usr/share/gcc/python');from libstdcxx.v6.printers import register_libstdcxx_printers;register_libstdcxx_printers(None)", + "ignoreFailures": false + }, { "text": "-enable-pretty-printing", "ignoreFailures": true diff --git a/exts/cesium.omniverse/mdl/cesium.mdl b/exts/cesium.omniverse/mdl/cesium.mdl index e3bdbe16a..c8ac0f84f 100644 --- a/exts/cesium.omniverse/mdl/cesium.mdl +++ b/exts/cesium.omniverse/mdl/cesium.mdl @@ -14,3 +14,33 @@ module [[ // For internal use only. See note in FabricMaterial.cpp export gltf_texture_lookup_value cesium_texture_lookup(*) [[ anno::hidden() ]] = gltf_texture_lookup(); export material cesium_material(*) [[ anno::hidden() ]] = gltf_material(); + +export gltf_texture_lookup_value cesium_texture_array_lookup( + uniform texture_2d texture_0, + uniform texture_2d texture_1, + uniform texture_2d texture_2 +) +{ + gltf_texture_lookup_value tex_ret; + tex_ret.valid = true; + + // uniform texture_2d[3] textures; + // textures[0] = texture_0; + // textures[1] = texture_1; + // textures[2] = texture_2; + + // int texture_index = ::scene::data_lookup_int("textureIndex"); + // texture_index = texture_index % 3; + + // for (int i = 0; i < 3; i++) { + // if (i == texture_index) { + // tex_ret.value = tex::lookup_float4( + // tex: textures[i], + // coord: float2(0.0, 0.0), + // wrap_u: ::tex::wrap_clamp, + // wrap_v: ::tex::wrap_clamp); + // } + // } + + return tex_ret; +} diff --git a/src/core/include/cesium/omniverse/FabricGeometry.h b/src/core/include/cesium/omniverse/FabricGeometry.h index 10f977f6d..781cede10 100644 --- a/src/core/include/cesium/omniverse/FabricGeometry.h +++ b/src/core/include/cesium/omniverse/FabricGeometry.h @@ -39,6 +39,7 @@ class FabricGeometry { [[nodiscard]] const FabricGeometryDefinition& getGeometryDefinition() const; void setMaterial(const omni::fabric::Path& materialPath); + void setTextureIndex(uint64_t textureIndex); private: void initialize(); diff --git a/src/core/include/cesium/omniverse/FabricMaterial.h b/src/core/include/cesium/omniverse/FabricMaterial.h index dc5bc7535..9510d330f 100644 --- a/src/core/include/cesium/omniverse/FabricMaterial.h +++ b/src/core/include/cesium/omniverse/FabricMaterial.h @@ -20,7 +20,9 @@ class FabricMaterial { const omni::fabric::Path& path, const FabricMaterialDefinition& materialDefinition, const pxr::TfToken& defaultTextureAssetPathToken, - long stageId); + long stageId, + bool usesTextureArray, + uint64_t textureArrayLength); ~FabricMaterial(); void setMaterial(int64_t tilesetId, const MaterialInfo& materialInfo); @@ -34,6 +36,8 @@ class FabricMaterial { [[nodiscard]] const omni::fabric::Path& getPath() const; [[nodiscard]] const FabricMaterialDefinition& getMaterialDefinition() const; + bool usesTextureArray() const; + private: void initialize(); @@ -43,6 +47,10 @@ class FabricMaterial { const omni::fabric::Path& texturePath, const omni::fabric::Path& shaderPath, const omni::fabric::Token& shaderInput); + void createTextureArray( + const omni::fabric::Path& texturePath, + const omni::fabric::Path& shaderPath, + const omni::fabric::Token& shaderInput); void reset(); void setShaderValues(const omni::fabric::Path& shaderPath, const MaterialInfo& materialInfo); @@ -50,6 +58,9 @@ class FabricMaterial { const omni::fabric::Path& texturePath, const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo); + void setTextureArrayValues( + const omni::fabric::Path& texturePath, + const std::vector& textureAssetPathTokens); void setTilesetId(int64_t tilesetId); bool stageDestroyed(); @@ -60,6 +71,9 @@ class FabricMaterial { omni::fabric::Path _shaderPath; omni::fabric::Path _baseColorTexturePath; + + bool _usesTextureArray; + uint64_t _textureArrayLength; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/FabricResourceManager.h b/src/core/include/cesium/omniverse/FabricResourceManager.h index dc5db3bb3..0ff846f4d 100644 --- a/src/core/include/cesium/omniverse/FabricResourceManager.h +++ b/src/core/include/cesium/omniverse/FabricResourceManager.h @@ -132,6 +132,8 @@ class FabricResourceManager { bool _debugRandomColors{false}; + bool _usesTextureArray{true}; + std::atomic _geometryId{0}; std::atomic _materialId{0}; std::atomic _textureId{0}; diff --git a/src/core/include/cesium/omniverse/FabricTexture.h b/src/core/include/cesium/omniverse/FabricTexture.h index 48378b4b0..58393b217 100644 --- a/src/core/include/cesium/omniverse/FabricTexture.h +++ b/src/core/include/cesium/omniverse/FabricTexture.h @@ -17,7 +17,7 @@ struct ImageCesium; namespace cesium::omniverse { class FabricTexture { public: - FabricTexture(const std::string& name); + FabricTexture(const std::string& name, uint64_t index); ~FabricTexture(); void setImage(const CesiumGltf::ImageCesium& image); @@ -25,11 +25,13 @@ class FabricTexture { void setActive(bool active); [[nodiscard]] const pxr::TfToken& getAssetPathToken() const; + [[nodiscard]] uint64_t getIndex() const; private: void reset(); std::unique_ptr _texture; pxr::TfToken _assetPathToken; + uint64_t _index; }; } // namespace cesium::omniverse diff --git a/src/core/include/cesium/omniverse/Tokens.h b/src/core/include/cesium/omniverse/Tokens.h index c16bd1b58..39eb3b826 100644 --- a/src/core/include/cesium/omniverse/Tokens.h +++ b/src/core/include/cesium/omniverse/Tokens.h @@ -15,6 +15,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) #define USD_TOKENS \ (baseColorTexture) \ (cesium_material) \ + (cesium_texture_array_lookup) \ (cesium_texture_lookup) \ (constant) \ (doubleSided) \ @@ -60,6 +61,9 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) ((inputs_scale, "inputs:scale")) \ ((inputs_tex_coord_index, "inputs:tex_coord_index")) \ ((inputs_texture, "inputs:texture")) \ + ((inputs_texture_0, "inputs:texture_0")) \ + ((inputs_texture_1, "inputs:texture_1")) \ + ((inputs_texture_2, "inputs:texture_2")) \ ((inputs_vertex_color_name, "inputs:vertex_color_name")) \ ((inputs_wrap_s, "inputs:wrap_s")) \ ((inputs_wrap_t, "inputs:wrap_t")) \ @@ -72,6 +76,7 @@ __pragma(warning(push)) __pragma(warning(disable : 4003)) ((primvars_displayOpacity, "primvars:displayOpacity")) \ ((primvars_normals, "primvars:normals")) \ ((primvars_st, "primvars:st")) \ + ((primvars_textureIndex, "primvars:textureIndex")) \ ((primvars_vertexColor, "primvars:vertexColor")) TF_DECLARE_PUBLIC_TOKENS(UsdTokens, USD_TOKENS); @@ -140,6 +145,7 @@ const omni::fabric::Type primvars_displayColor(omni::fabric::BaseDataType::eFloa const omni::fabric::Type primvars_displayOpacity(omni::fabric::BaseDataType::eFloat, 1, 1, omni::fabric::AttributeRole::eNone); const omni::fabric::Type primvars_normals(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eNormal); const omni::fabric::Type primvars_st(omni::fabric::BaseDataType::eFloat, 2, 1, omni::fabric::AttributeRole::eTexCoord); +const omni::fabric::Type primvars_textureIndex(omni::fabric::BaseDataType::eInt, 1, 1, omni::fabric::AttributeRole::eNone); const omni::fabric::Type primvars_vertexColor(omni::fabric::BaseDataType::eFloat, 3, 1, omni::fabric::AttributeRole::eColor); const omni::fabric::Type Shader(omni::fabric::BaseDataType::eTag, 1, 0, omni::fabric::AttributeRole::ePrimTypeName); const omni::fabric::Type subdivisionScheme(omni::fabric::BaseDataType::eToken, 1, 0, omni::fabric::AttributeRole::eNone); diff --git a/src/core/src/FabricGeometry.cpp b/src/core/src/FabricGeometry.cpp index 09eb99d03..be167e14a 100644 --- a/src/core/src/FabricGeometry.cpp +++ b/src/core/src/FabricGeometry.cpp @@ -101,6 +101,16 @@ void FabricGeometry::setMaterial(const omni::fabric::Path& materialPath) { materialBindingFabric[0] = materialPath; } +void FabricGeometry::setTextureIndex(uint64_t textureIndex) { + if (stageDestroyed()) { + return; + } + + auto srw = UsdUtil::getFabricStageReaderWriter(); + auto textureIndexFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars_textureIndex); + textureIndexFabric[0] = static_cast(textureIndex); +} + void FabricGeometry::initialize() { const auto hasTexcoords = _geometryDefinition.hasTexcoords(); const auto hasNormals = _geometryDefinition.hasNormals(); @@ -134,6 +144,7 @@ void FabricGeometry::initialize() { if (hasTexcoords) { attributes.addAttribute(FabricTypes::primvars_st, FabricTokens::primvars_st); + attributes.addAttribute(FabricTypes::primvars_textureIndex, FabricTokens::primvars_textureIndex); } if (hasNormals) { @@ -157,6 +168,7 @@ void FabricGeometry::initialize() { // Initialize primvars size_t primvarsCount = 0; size_t primvarIndexSt = 0; + size_t primvarTextureIndex = 0; size_t primvarIndexNormal = 0; size_t primvarIndexVertexColor = 0; @@ -165,6 +177,7 @@ void FabricGeometry::initialize() { if (hasTexcoords) { primvarIndexSt = primvarsCount++; + primvarTextureIndex = primvarsCount++; } if (hasNormals) { @@ -180,6 +193,10 @@ void FabricGeometry::initialize() { srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayColor, 1); srw.setArrayAttributeSize(_path, FabricTokens::primvars_displayOpacity, 1); + if (hasTexcoords) { + srw.setArrayAttributeSize(_path, FabricTokens::primvars_textureIndex, 1); + } + // clang-format off auto primvarsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvars); auto primvarInterpolationsFabric = srw.getArrayAttributeWr(_path, FabricTokens::primvarInterpolations); @@ -194,6 +211,8 @@ void FabricGeometry::initialize() { if (hasTexcoords) { primvarsFabric[primvarIndexSt] = FabricTokens::primvars_st; primvarInterpolationsFabric[primvarIndexSt] = FabricTokens::vertex; + primvarsFabric[primvarTextureIndex] = FabricTokens::primvars_textureIndex; + primvarInterpolationsFabric[primvarTextureIndex] = FabricTokens::constant; } if (hasNormals) { @@ -245,6 +264,7 @@ void FabricGeometry::reset() { if (hasTexcoords) { srw.setArrayAttributeSize(_path, FabricTokens::primvars_st, 0); + srw.setArrayAttributeSize(_path, FabricTokens::primvars_textureIndex, 0); } if (hasNormals) { diff --git a/src/core/src/FabricMaterial.cpp b/src/core/src/FabricMaterial.cpp index f5ccf6cc6..fd7554d16 100644 --- a/src/core/src/FabricMaterial.cpp +++ b/src/core/src/FabricMaterial.cpp @@ -16,11 +16,15 @@ FabricMaterial::FabricMaterial( const omni::fabric::Path& path, const FabricMaterialDefinition& materialDefinition, const pxr::TfToken& defaultTextureAssetPathToken, - long stageId) + long stageId, + bool usesTextureArray, + uint64_t textureArrayLength) : _materialPath(path) , _materialDefinition(materialDefinition) , _defaultTextureAssetPathToken(defaultTextureAssetPathToken) - , _stageId(stageId) { + , _stageId(stageId) + , _usesTextureArray(usesTextureArray) + , _textureArrayLength(textureArrayLength) { if (stageDestroyed()) { return; @@ -61,6 +65,10 @@ const FabricMaterialDefinition& FabricMaterial::getMaterialDefinition() const { return _materialDefinition; } +bool FabricMaterial::usesTextureArray() const { + return _usesTextureArray; +} + void FabricMaterial::initialize() { const auto hasBaseColorTexture = _materialDefinition.hasBaseColorTexture(); @@ -80,7 +88,23 @@ void FabricMaterial::initialize() { createShader(shaderPath, materialPath); if (hasBaseColorTexture) { - createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture); + if (!_usesTextureArray) { + createTexture(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture); + } else { + createTextureArray(baseColorTexturePath, shaderPath, FabricTokens::inputs_base_color_texture); + + // TODO: temp + auto textureAssetPathTokens = std::vector(); + textureAssetPathTokens.reserve(_textureArrayLength); + + for (uint64_t i = 0; i < _textureArrayLength; i++) { + const auto name = fmt::format("/fabric_texture_pool_{}_object_{}", 0, i); + auto assetPath = UsdUtil::getDynamicTextureProviderAssetPathToken(name); + textureAssetPathTokens.emplace_back(std::move(assetPath)); + } + + setTextureArrayValues(baseColorTexturePath, textureAssetPathTokens); + } } } @@ -224,6 +248,70 @@ void FabricMaterial::createTexture( srw.createConnection(shaderPath, shaderInput, omni::fabric::Connection{texturePath, FabricTokens::outputs_out}); } +void FabricMaterial::createTextureArray( + const omni::fabric::Path& texturePath, + const omni::fabric::Path& shaderPath, + const omni::fabric::Token& shaderInput) { + + const auto inputTextureTokens = std::vector{ + FabricTokens::inputs_texture_0, + FabricTokens::inputs_texture_1, + FabricTokens::inputs_texture_2, + }; + + assert(inputTextureTokens.size() == _textureArrayLength); + + auto srw = UsdUtil::getFabricStageReaderWriter(); + + srw.createPrim(texturePath); + + FabricAttributesBuilder attributes; + + for (uint64_t i = 0; i < _textureArrayLength; i++) { + attributes.addAttribute(FabricTypes::inputs_texture, inputTextureTokens[i]); + } + + // clang-format off + attributes.addAttribute(FabricTypes::inputs_excludeFromWhiteMode, FabricTokens::inputs_excludeFromWhiteMode); + attributes.addAttribute(FabricTypes::outputs_out, FabricTokens::outputs_out); + attributes.addAttribute(FabricTypes::info_implementationSource, FabricTokens::info_implementationSource); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset, FabricTokens::info_mdl_sourceAsset); + attributes.addAttribute(FabricTypes::info_mdl_sourceAsset_subIdentifier, FabricTokens::info_mdl_sourceAsset_subIdentifier); + attributes.addAttribute(FabricTypes::_paramColorSpace, FabricTokens::_paramColorSpace); + attributes.addAttribute(FabricTypes::_sdrMetadata, FabricTokens::_sdrMetadata); + attributes.addAttribute(FabricTypes::Shader, FabricTokens::Shader); + attributes.addAttribute(FabricTypes::_cesium_tilesetId, FabricTokens::_cesium_tilesetId); + // clang-format on + + attributes.createAttributes(texturePath); + + // _paramColorSpace is an array of pairs: [texture_parameter_token, color_space_enum], [texture_parameter_token, color_space_enum], ... + srw.setArrayAttributeSize(texturePath, FabricTokens::_paramColorSpace, _textureArrayLength * 2); + srw.setArrayAttributeSize(texturePath, FabricTokens::_sdrMetadata, 0); + + // clang-format off + auto inputsExcludeFromWhiteModeFabric = srw.getAttributeWr(texturePath, FabricTokens::inputs_excludeFromWhiteMode); + auto infoImplementationSourceFabric = srw.getAttributeWr(texturePath, FabricTokens::info_implementationSource); + auto infoMdlSourceAssetFabric = srw.getAttributeWr(texturePath, FabricTokens::info_mdl_sourceAsset); + auto infoMdlSourceAssetSubIdentifierFabric = srw.getAttributeWr(texturePath, FabricTokens::info_mdl_sourceAsset_subIdentifier); + auto paramColorSpaceFabric = srw.getArrayAttributeWr(texturePath, FabricTokens::_paramColorSpace); + // clang-format on + + *inputsExcludeFromWhiteModeFabric = false; + *infoImplementationSourceFabric = FabricTokens::sourceAsset; + infoMdlSourceAssetFabric->assetPath = Context::instance().getCesiumMdlPathToken(); + infoMdlSourceAssetFabric->resolvedPath = pxr::TfToken(); + *infoMdlSourceAssetSubIdentifierFabric = FabricTokens::cesium_texture_array_lookup; + + for (uint64_t i = 0; i < _textureArrayLength; i++) { + paramColorSpaceFabric[i * 2] = inputTextureTokens[i]; + paramColorSpaceFabric[i * 2 + 1] = FabricTokens::_auto; + } + + // Create connection from shader to texture. + srw.createConnection(shaderPath, shaderInput, omni::fabric::Connection{texturePath, FabricTokens::outputs_out}); +} + void FabricMaterial::reset() { clearMaterial(); clearBaseColorTexture(); @@ -241,6 +329,8 @@ void FabricMaterial::setMaterial(int64_t tilesetId, const MaterialInfo& material } void FabricMaterial::setBaseColorTexture(const pxr::TfToken& textureAssetPathToken, const TextureInfo& textureInfo) { + assert(!_usesTextureArray); + if (stageDestroyed()) { return; } @@ -257,7 +347,13 @@ void FabricMaterial::clearMaterial() { } void FabricMaterial::clearBaseColorTexture() { - setBaseColorTexture(_defaultTextureAssetPathToken, GltfUtil::getDefaultTextureInfo()); + if (!_usesTextureArray) { + setBaseColorTexture(_defaultTextureAssetPathToken, GltfUtil::getDefaultTextureInfo()); + } else { + const auto textureAssetPathTokens = + std::vector(_textureArrayLength, _defaultTextureAssetPathToken); + setTextureArrayValues(_baseColorTexturePath, textureAssetPathTokens); + } } void FabricMaterial::setTilesetId(int64_t tilesetId) { @@ -325,6 +421,28 @@ void FabricMaterial::setTextureValues( *scaleFabric = UsdUtil::glmToUsdVector(glm::fvec2(scale)); } +void FabricMaterial::setTextureArrayValues( + const omni::fabric::Path& texturePath, + const std::vector& textureAssetPathTokens) { + auto srw = UsdUtil::getFabricStageReaderWriter(); + + assert(textureAssetPathTokens.size() == _textureArrayLength); + + const auto inputTextureTokens = std::vector{ + FabricTokens::inputs_texture_0, + FabricTokens::inputs_texture_1, + FabricTokens::inputs_texture_2, + }; + + assert(inputTextureTokens.size() == _textureArrayLength); + + for (uint64_t i = 0; i < textureAssetPathTokens.size(); i++) { + auto textureFabric = srw.getAttributeWr(texturePath, inputTextureTokens[i]); + textureFabric->assetPath = textureAssetPathTokens[i]; + textureFabric->resolvedPath = pxr::TfToken(); + } +} + bool FabricMaterial::stageDestroyed() { // Add this guard to all public member functions, including constructors and destructors. Tile render resources can // continue to be processed asynchronously even after the tileset and USD stage have been destroyed, so prevent any diff --git a/src/core/src/FabricMaterialPool.cpp b/src/core/src/FabricMaterialPool.cpp index 3d4058b28..c1cb738c0 100644 --- a/src/core/src/FabricMaterialPool.cpp +++ b/src/core/src/FabricMaterialPool.cpp @@ -25,7 +25,8 @@ const FabricMaterialDefinition& FabricMaterialPool::getMaterialDefinition() cons std::shared_ptr FabricMaterialPool::createObject(uint64_t objectId) { const auto pathStr = fmt::format("/fabric_material_pool_{}_object_{}", _poolId, objectId); const auto path = omni::fabric::Path(pathStr.c_str()); - return std::make_shared(path, _materialDefinition, _defaultTextureAssetPathToken, _stageId); + return std::make_shared( + path, _materialDefinition, _defaultTextureAssetPathToken, _stageId, false, 0); } void FabricMaterialPool::setActive(std::shared_ptr material, bool active) { diff --git a/src/core/src/FabricPrepareRenderResources.cpp b/src/core/src/FabricPrepareRenderResources.cpp index 963a46122..4d5412c22 100644 --- a/src/core/src/FabricPrepareRenderResources.cpp +++ b/src/core/src/FabricPrepareRenderResources.cpp @@ -190,8 +190,12 @@ void setFabricMeshes( geometry->setMaterial(material->getPath()); if (baseColorTexture != nullptr && materialInfo.baseColorTexture.has_value()) { - material->setBaseColorTexture( - baseColorTexture->getAssetPathToken(), materialInfo.baseColorTexture.value()); + if (material->usesTextureArray()) { + geometry->setTextureIndex(baseColorTexture->getIndex()); + } else { + material->setBaseColorTexture( + baseColorTexture->getAssetPathToken(), materialInfo.baseColorTexture.value()); + } } } else if (!tilesetMaterialPath.IsEmpty()) { geometry->setMaterial(FabricUtil::toFabricPath(tilesetMaterialPath)); diff --git a/src/core/src/FabricResourceManager.cpp b/src/core/src/FabricResourceManager.cpp index a163069fb..9571a28aa 100644 --- a/src/core/src/FabricResourceManager.cpp +++ b/src/core/src/FabricResourceManager.cpp @@ -79,9 +79,9 @@ std::shared_ptr FabricResourceManager::acquireGeometry( return geometry; } -bool useSharedMaterial(const FabricMaterialDefinition& materialDefinition) { +bool useSharedMaterial(const FabricMaterialDefinition& materialDefinition, bool usesTextureArray) { if (materialDefinition.hasBaseColorTexture()) { - return false; + return usesTextureArray; } return true; @@ -91,7 +91,8 @@ std::shared_ptr FabricResourceManager::createMaterial(const FabricMaterialDefinition& materialDefinition, long stageId) { const auto pathStr = fmt::format("/fabric_material_{}", getNextMaterialId()); const auto path = omni::fabric::Path(pathStr.c_str()); - return std::make_shared(path, materialDefinition, _defaultTextureAssetPathToken, stageId); + return std::make_shared( + path, materialDefinition, _defaultTextureAssetPathToken, stageId, _usesTextureArray, 3); } void FabricResourceManager::removeSharedMaterial(const SharedMaterial& sharedMaterial) { @@ -168,7 +169,7 @@ std::shared_ptr FabricResourceManager::acquireMaterial( int64_t tilesetId) { FabricMaterialDefinition materialDefinition(materialInfo, hasImagery, _disableTextures); - if (useSharedMaterial(materialDefinition)) { + if (useSharedMaterial(materialDefinition, _usesTextureArray)) { return acquireSharedMaterial(materialInfo, materialDefinition, stageId, tilesetId); } @@ -191,8 +192,9 @@ std::shared_ptr FabricResourceManager::acquireMaterial( std::shared_ptr FabricResourceManager::acquireTexture() { if (_disableTexturePool) { - const auto name = fmt::format("/fabric_texture_{}", getNextTextureId()); - return std::make_shared(name); + const auto id = getNextTextureId(); + const auto name = fmt::format("/fabric_texture_{}", id); + return std::make_shared(name, id); } std::scoped_lock lock(_poolMutex); @@ -223,7 +225,7 @@ void FabricResourceManager::releaseGeometry(const std::shared_ptr& material) { const auto& materialDefinition = material->getMaterialDefinition(); - if (useSharedMaterial(materialDefinition)) { + if (useSharedMaterial(materialDefinition, _usesTextureArray)) { releaseSharedMaterial(material); return; } diff --git a/src/core/src/FabricTexture.cpp b/src/core/src/FabricTexture.cpp index a549b4b61..7a336692d 100644 --- a/src/core/src/FabricTexture.cpp +++ b/src/core/src/FabricTexture.cpp @@ -32,9 +32,10 @@ carb::Format getCompressedImageFormat(CesiumGltf::GpuCompressedPixelFormat pixel } // namespace -FabricTexture::FabricTexture(const std::string& name) +FabricTexture::FabricTexture(const std::string& name, uint64_t index) : _texture(std::make_unique(name)) - , _assetPathToken(UsdUtil::getDynamicTextureProviderAssetPathToken(name)) { + , _assetPathToken(UsdUtil::getDynamicTextureProviderAssetPathToken(name)) + , _index(index) { reset(); } @@ -50,6 +51,10 @@ const pxr::TfToken& FabricTexture::getAssetPathToken() const { return _assetPathToken; } +uint64_t FabricTexture::getIndex() const { + return _index; +} + void FabricTexture::reset() { const auto bytes = std::array{{255, 255, 255, 255}}; const auto size = carb::Uint2{1, 1}; diff --git a/src/core/src/FabricTexturePool.cpp b/src/core/src/FabricTexturePool.cpp index ce195787f..299ff903a 100644 --- a/src/core/src/FabricTexturePool.cpp +++ b/src/core/src/FabricTexturePool.cpp @@ -12,7 +12,7 @@ FabricTexturePool::FabricTexturePool(uint64_t poolId, uint64_t initialCapacity) std::shared_ptr FabricTexturePool::createObject(uint64_t objectId) { const auto name = fmt::format("/fabric_texture_pool_{}_object_{}", _poolId, objectId); - return std::make_shared(name); + return std::make_shared(name, objectId); } void FabricTexturePool::setActive(std::shared_ptr texture, bool active) {