From 6e88839652a266847a8f4db24431adcb9cf639f2 Mon Sep 17 00:00:00 2001 From: Pierre Wang Date: Thu, 2 Dec 2021 18:59:07 +0800 Subject: [PATCH] Finish most of the APIs for implement test (#79) (cherry picked from commit 33226577edfd040e79626e895491354c0ff5179b) --- build_scripts/build_usd.py | 24 + cmake/modules/FindTextSystem.cmake | 86 ++++ pxr/imaging/hd/simpleText.cpp | 3 +- pxr/imaging/hd/simpleTextTopology.cpp | 41 +- pxr/imaging/hd/simpleTextTopology.h | 69 ++- pxr/imaging/hd/tokens.h | 7 +- pxr/imaging/hdSt/CMakeLists.txt | 2 + pxr/imaging/hdSt/resourceRegistry.cpp | 29 ++ pxr/imaging/hdSt/resourceRegistry.h | 18 + pxr/imaging/hdSt/simpleText.cpp | 474 +++++++++++++++++- pxr/imaging/hdSt/simpleText.h | 28 +- pxr/imaging/hdSt/simpleTextShaderKey.cpp | 7 +- pxr/imaging/hdSt/simpleTextShaderKey.h | 5 + pxr/imaging/hdSt/simpleTextTopology.cpp | 12 +- pxr/usd/usdGeom/schema.usda | 8 +- pxr/usd/usdGeom/simpleText.cpp | 18 +- pxr/usd/usdGeom/simpleText.h | 24 +- pxr/usd/usdGeom/wrapSimpleText.cpp | 22 +- .../usdImaging/simpleTextAdapter.cpp | 116 +---- 19 files changed, 804 insertions(+), 189 deletions(-) create mode 100644 cmake/modules/FindTextSystem.cmake diff --git a/build_scripts/build_usd.py b/build_scripts/build_usd.py index d972749492..ffeae9e928 100644 --- a/build_scripts/build_usd.py +++ b/build_scripts/build_usd.py @@ -1477,6 +1477,29 @@ def InstallOpenSubdiv(context, force, buildArgs): OPENSUBDIV = Dependency("OpenSubdiv", InstallOpenSubdiv, "include/opensubdiv/version.h") +############################################################ +# TextSystem + +def InstallTextSystem(context, force, buildArgs): + extraArgs = buildArgs + + oldGenerator = context.cmakeGenerator + if oldGenerator == "Ninja" and Windows(): + context.cmakeGenerator = None + + oldNumJobs = context.numJobs + if MacOS(): + context.numJobs = 1 + + try: + RunCMake(context, force, extraArgs) + finally: + context.cmakeGenerator = oldGenerator + context.numJobs = oldNumJobs + +TEXTSYSTEM = Dependency("TextSystem", InstallTextSystem, + "include/TextSystem/TextSystem.h") + ############################################################ # PyOpenGL @@ -2302,6 +2325,7 @@ def ForceBuildDependency(self, dep): requiredDependencies += [PTEX] requiredDependencies += [OPENSUBDIV] + requiredDependencies += [TEXTSYSTEM] if context.enableOpenVDB: requiredDependencies += [BLOSC, BOOST, OPENEXR, OPENVDB, TBB] diff --git a/cmake/modules/FindTextSystem.cmake b/cmake/modules/FindTextSystem.cmake new file mode 100644 index 0000000000..53dc73a3b0 --- /dev/null +++ b/cmake/modules/FindTextSystem.cmake @@ -0,0 +1,86 @@ +# - Find TextSystem library +# Find the native TextSystem includes and library +# This module defines +# TEXTSYSTEM_INCLUDE_DIRS, where to find TextSystem headers, Set when +# TEXTSYSTEM_INCLUDE_DIR is found. +# TEXTSYSTEM_LIBRARIES, libraries to link against to use TextSystem. +# TEXTSYSTEM_ROOT_DIR, the base directory to search for TextSystem. +# This can also be an environment variable. +# TEXTSYSTEM_FOUND, if false, do not try to use TextSystem. +# +# also defined, but not for general use are +# TEXTSYSTEM_LIBRARY, where to find the TextSystem library. + +#============================================================================= +# Copyright 2021 Blender Foundation. +# +# Distributed under the OSI-approved BSD License (the "License"); +# see accompanying file Copyright.txt for details. +# +# This software is distributed WITHOUT ANY WARRANTY; without even the +# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the License for more information. +#============================================================================= + +# If TEXTSYSTEM_ROOT_DIR was defined in the environment, use it. +IF(NOT TEXTSYSTEM_ROOT_DIR AND NOT $ENV{TEXTSYSTEM_ROOT_DIR} STREQUAL "") + SET(TEXTSYSTEM_ROOT_DIR $ENV{TEXTSYSTEM_ROOT_DIR}) +ENDIF() + +SET(TEXTSYSTEM_FIND_COMPONENTS + text_system +) + +SET(TEXTSYSTEM_SEARCH_DIRS + ${TEXTSYSTEM_ROOT_DIR} +) + +FIND_PATH(TEXTSYSTEM_INCLUDE_DIR + NAMES + TextSystem/TextSystem.h + HINTS + ${TEXTSYSTEM_SEARCH_DIRS} + PATH_SUFFIXES + include +) + +SET(TEXTSYSTEM_LIBRARIES) +FOREACH(COMPONENT ${TEXTSYSTEM_FIND_COMPONENTS}) + STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) + FIND_LIBRARY(TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY + NAMES + ${COMPONENT} + HINTS + ${TEXTSYSTEM_SEARCH_DIRS} + PATH_SUFFIXES + lib64 lib + ) + if(DEFINED TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY) + LIST(APPEND + TEXTSYSTEM_LIBRARIES + "${TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY}") + set(TEXTSYSTEM_FOUND TRUE) + endif() +ENDFOREACH() + +IF(TEXTSYSTEM_FOUND) + SET(TEXTSYSTEM_LIBRARIES ${TEXTSYSTEM_LIBRARIES}) + SET(TEXTSYSTEM_INCLUDE_DIRS ${TEXTSYSTEM_INCLUDE_DIR}) +ENDIF(TEXTSYSTEM_FOUND) + +MARK_AS_ADVANCED( + TEXTSYSTEM_INCLUDE_DIR +) +FOREACH(COMPONENT ${TEXTSYSTEM_FIND_COMPONENTS}) + STRING(TOUPPER ${COMPONENT} UPPERCOMPONENT) + MARK_AS_ADVANCED(TEXTSYSTEM_${UPPERCOMPONENT}_LIBRARY) +ENDFOREACH() + +# handle the QUIETLY and REQUIRED arguments and set TEXTSYSTEM_FOUND to TRUE if +# all listed variables are TRUE +INCLUDE(FindPackageHandleStandardArgs) +FIND_PACKAGE_HANDLE_STANDARD_ARGS(TEXTSYSTEM + REQUIRED_VARS + TEXTSYSTEM_INCLUDE_DIR + TEXTSYSTEM_LIBRARIES +) diff --git a/pxr/imaging/hd/simpleText.cpp b/pxr/imaging/hd/simpleText.cpp index 69fc877def..dae3573e80 100644 --- a/pxr/imaging/hd/simpleText.cpp +++ b/pxr/imaging/hd/simpleText.cpp @@ -45,8 +45,7 @@ HdSimpleText::GetBuiltinPrimvarNames() const { static const TfTokenVector primvarNames = { HdTokens->points, - HdTokens->normals, - HdTokens->widths + HdTokens->textTextureUV }; return primvarNames; } diff --git a/pxr/imaging/hd/simpleTextTopology.cpp b/pxr/imaging/hd/simpleTextTopology.cpp index 7fb7107df7..65cb5f76da 100644 --- a/pxr/imaging/hd/simpleTextTopology.cpp +++ b/pxr/imaging/hd/simpleTextTopology.cpp @@ -29,32 +29,51 @@ PXR_NAMESPACE_OPEN_SCOPE - HdSimpleTextTopology::HdSimpleTextTopology() - : HdTopology() + : HdTopology() + , _textData("") + , _textEncoding(TfToken()) + , _textHeight(22) + , _textWidthFactor(1.0f) + , _bold(false) + , _italic(false) +{ + HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology); +} +HdSimpleTextTopology::HdSimpleTextTopology(const std::string& textData, + const TfToken& textEncoding, int textHeight, float textWidthFactor, + bool bold, bool italic) + : HdTopology(), _textData(textData), _textEncoding(textEncoding), + _textHeight(textHeight), _textWidthFactor(textWidthFactor), + _bold(bold), _italic(italic) { - HD_PERF_COUNTER_INCR(HdPerfTokens->singleTextTopology); + HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology); } HdSimpleTextTopology::HdSimpleTextTopology(const HdSimpleTextTopology& src) : HdTopology(src) { - HD_PERF_COUNTER_INCR(HdPerfTokens->singleTextTopology); + HD_PERF_COUNTER_INCR(HdPerfTokens->simpleTextTopology); } HdSimpleTextTopology::~HdSimpleTextTopology() { - HD_PERF_COUNTER_DECR(HdPerfTokens->singleTextTopology); + HD_PERF_COUNTER_DECR(HdPerfTokens->simpleTextTopology); } bool -HdSimpleTextTopology::operator==(HdSimpleTextTopology const &/*other*/) const +HdSimpleTextTopology::operator==(HdSimpleTextTopology const &other) const { HD_TRACE_FUNCTION(); // no need to compare _adajency and _quadInfo - return true; + return (_textData == other._textData && + _textEncoding == other._textEncoding && + _textHeight == other._textHeight && + _textWidthFactor == other._textWidthFactor && + _bold == other._bold && + _italic == other._italic); } bool @@ -69,7 +88,13 @@ HdSimpleTextTopology::ComputeHash() const HD_TRACE_FUNCTION(); HdTopology::ID hash = 0; - + hash = ArchHash64((const char*)_textData.data(), _textData.length(), hash); + hash = ArchHash64((const char*)&_textEncoding, sizeof(TfToken), hash); + hash = ArchHash64((const char*)&_textHeight, sizeof(int), hash); + hash = ArchHash64((const char*)&_textWidthFactor, sizeof(float), hash); + hash = ArchHash64((const char*)&_bold, sizeof(bool), hash); + hash = ArchHash64((const char*)&_italic, sizeof(bool), hash); + // Note: We don't hash topological visibility, because it is treated as a // per-prim opinion, and hence, shouldn't break topology sharing. return hash; diff --git a/pxr/imaging/hd/simpleTextTopology.h b/pxr/imaging/hd/simpleTextTopology.h index f8eb22e132..db28ac7b8a 100644 --- a/pxr/imaging/hd/simpleTextTopology.h +++ b/pxr/imaging/hd/simpleTextTopology.h @@ -37,46 +37,14 @@ PXR_NAMESPACE_OPEN_SCOPE -/// \class HdBasisCurvesTopology -/// -/// Topology data for basisCurves. -/// -/// HdBasisCurvesTopology holds the raw input topology data for basisCurves -/// -/// The Type, Basis and Wrap mode combined describe the curve and it's -/// segments. -/// -/// If Type == linear, the curve is a bunch of line segments and basis is -/// ignored. -/// -/// The wrap mode defines how the curve segments are specified: -/// -/// If Wrap == segmented, this is equivalent to GL_LINES and curve vertex -/// counts is 2 * number of segments (multiple entries in curve vertex -/// array is optional). -/// -/// If Wrap == nonperiodic, this is equivalent to GL_LINE_STRIP and curve -/// counts is an array where each entry is the number of vertices in that -/// line segment. The first and last vertex in the segment are not joined. -/// -/// If Wrap == periodic, this is equivalent to GL_LINE_LOOP and curve counts -/// is an array where each entry is the number of vertices in that line -/// segment. An additional line is place between the first and last vertex -/// in each segment. -/// -/// If Type == cubic, the type of curve is specified by basis: -/// The Basis can be bezier, bspline or catmullRom. -/// -/// Wrap can be either periodic or nonperiodic (segmented is unsupported). -/// -/// For each type of line, the generated vertex indices can pass through an -/// optional index buffer to map the generated indices to actual indices in -/// the vertex buffer. -/// class HdSimpleTextTopology : public HdTopology { public: HD_API HdSimpleTextTopology(); + HD_API + HdSimpleTextTopology(const std::string& textData, + const TfToken& textEncoding, int textHeight, float textWidthFactor, + bool bold, bool italic); HD_API HdSimpleTextTopology(const HdSimpleTextTopology& src); HD_API @@ -86,12 +54,39 @@ class HdSimpleTextTopology : public HdTopology { HD_API virtual ID ComputeHash() const; + /// Returns segment vertex counts. + std::string GetTextData() const { + return _textData; + } + + /// Returns indices. + TfToken GetTextEncoding() const { + return _textEncoding; + } + + /// Returns the number of curves + int GetTextHeight() const { + return _textHeight; + } + + /// See class documentation for valid combination of values + float GetTextWidthFactor() const { return _textWidthFactor; } + bool GetBold() const { return _bold; } + bool GetItalic() const { return _italic; } + + /// Equality check between two basisCurves topologies. HD_API bool operator==(HdSimpleTextTopology const &other) const; HD_API bool operator!=(HdSimpleTextTopology const &other) const; - +private: + std::string _textData; + TfToken _textEncoding; + int _textHeight; + float _textWidthFactor; + bool _bold; + bool _italic; }; HD_API diff --git a/pxr/imaging/hd/tokens.h b/pxr/imaging/hd/tokens.h index 8178e4ed10..0190a991d2 100644 --- a/pxr/imaging/hd/tokens.h +++ b/pxr/imaging/hd/tokens.h @@ -103,13 +103,12 @@ PXR_NAMESPACE_OPEN_SCOPE (subdivTags) \ (taskState) \ (taskParams) \ - (textData) \ + (textTextureUV) \ (topology) \ (topologyVisibility) \ (totalItemCount) \ (transform) \ (transformInverse) \ - (typeface) \ (velocities) \ (visibility) \ (widths) \ @@ -168,6 +167,8 @@ PXR_NAMESPACE_OPEN_SCOPE (instMeshTopology) \ (instMeshTopologyRange) \ (instPrimvarRange) \ + (instSimpleTextTopology) \ + (instSimpleTextTopologyRange) \ (instVertexAdjacency) \ (meshTopology) \ (nonUniformSize) \ @@ -177,7 +178,7 @@ PXR_NAMESPACE_OPEN_SCOPE (quadrangulateFaceVarying) \ (quadrangulatedVerts) \ (rebuildBatches) \ - (singleTextTopology) \ + (simpleTextTopology) \ (singleBufferSize) \ (ssboSize) \ (skipInvisibleRprimSync) \ diff --git a/pxr/imaging/hdSt/CMakeLists.txt b/pxr/imaging/hdSt/CMakeLists.txt index 8c85f64510..92fc6d4edc 100644 --- a/pxr/imaging/hdSt/CMakeLists.txt +++ b/pxr/imaging/hdSt/CMakeLists.txt @@ -46,10 +46,12 @@ pxr_library(hdSt tf trace ${OPENSUBDIV_LIBRARIES} + ${TEXTSYSTEM_LIBRARIES} ${optionalLibs} INCLUDE_DIRS ${OPENSUBDIV_INCLUDE_DIR} + ${TEXTSYSTEM_INCLUDE_DIRS} ${optionalIncludeDirs} PUBLIC_CLASSES diff --git a/pxr/imaging/hdSt/resourceRegistry.cpp b/pxr/imaging/hdSt/resourceRegistry.cpp index 0b1f2e83c8..0c423b81ba 100644 --- a/pxr/imaging/hdSt/resourceRegistry.cpp +++ b/pxr/imaging/hdSt/resourceRegistry.cpp @@ -600,6 +600,14 @@ HdStResourceRegistry::RegisterBasisCurvesTopology( HdPerfTokens->instBasisCurvesTopology); } +HdInstance +HdStResourceRegistry::RegisterSimpleTextTopology( + HdInstance::ID id) +{ + return _Register(id, _simpleTextTopologyRegistry, + HdPerfTokens->instSimpleTextTopology); +} + HdInstance HdStResourceRegistry::RegisterVertexAdjacency( HdInstance::ID id) @@ -624,6 +632,14 @@ HdStResourceRegistry::RegisterBasisCurvesIndexRange( HdPerfTokens->instBasisCurvesTopologyRange); } +HdInstance +HdStResourceRegistry::RegisterSimpleTextIndexRange( + HdInstance::ID id, TfToken const &name) +{ + return _Register(id, _simpleTextTopologyIndexRangeRegistry[name], + HdPerfTokens->instSimpleTextTopologyRange); +} + HdInstance HdStResourceRegistry::RegisterPrimvarRange( HdInstance::ID id) @@ -1058,6 +1074,11 @@ HdStResourceRegistry::_GarbageCollect() HD_PERF_COUNTER_SET(HdPerfTokens->instBasisCurvesTopology, count); } + { + size_t count = _simpleTextTopologyRegistry.GarbageCollect(); + HD_PERF_COUNTER_SET(HdPerfTokens->instSimpleTextTopology, count); + } + { size_t count = _vertexAdjacencyRegistry.GarbageCollect(); HD_PERF_COUNTER_SET(HdPerfTokens->instVertexAdjacency, count); @@ -1079,6 +1100,14 @@ HdStResourceRegistry::_GarbageCollect() HD_PERF_COUNTER_SET(HdPerfTokens->instBasisCurvesTopologyRange, count); } + { + size_t count = 0; + for (auto & it : _simpleTextTopologyIndexRangeRegistry) { + count += it.second.GarbageCollect(); + } + HD_PERF_COUNTER_SET(HdPerfTokens->instSimpleTextTopologyRange, count); + } + { size_t count = _primvarRangeRegistry.GarbageCollect(); HD_PERF_COUNTER_SET(HdPerfTokens->instPrimvarRange, count); diff --git a/pxr/imaging/hdSt/resourceRegistry.h b/pxr/imaging/hdSt/resourceRegistry.h index e3207e972d..5189aaee02 100644 --- a/pxr/imaging/hdSt/resourceRegistry.h +++ b/pxr/imaging/hdSt/resourceRegistry.h @@ -62,6 +62,9 @@ using HioGlslfxSharedPtr = std::shared_ptr; using HdSt_BasisCurvesTopologySharedPtr = std::shared_ptr; +using HdSt_SimpleTextTopologySharedPtr = + std::shared_ptr; + using HdStShaderCodePtr = std::weak_ptr; using HdSt_GeometricShaderSharedPtr = @@ -369,6 +372,11 @@ class HdStResourceRegistry final : public HdResourceRegistry RegisterBasisCurvesTopology( HdInstance::ID id); + HDST_API + HdInstance + RegisterSimpleTextTopology( + HdInstance::ID id); + HDST_API HdInstance RegisterVertexAdjacency(HdInstance::ID id); @@ -387,6 +395,11 @@ class HdStResourceRegistry final : public HdResourceRegistry RegisterBasisCurvesIndexRange( HdInstance::ID id, TfToken const &name); + HDST_API + HdInstance + RegisterSimpleTextIndexRange( + HdInstance::ID id, TfToken const &name); + /// Primvar array range instancing /// Returns the HdInstance pointing to shared HdBufferArrayRange, /// distinguished by given ID. @@ -633,6 +646,10 @@ class HdStResourceRegistry final : public HdResourceRegistry HdInstanceRegistry _basisCurvesTopologyRegistry; + // Register SimpleText topology. + HdInstanceRegistry + _simpleTextTopologyRegistry; + // Register vertex adjacency. HdInstanceRegistry _vertexAdjacencyRegistry; @@ -647,6 +664,7 @@ class HdStResourceRegistry final : public HdResourceRegistry _TopologyIndexRangeInstanceRegMap _meshTopologyIndexRangeRegistry; _TopologyIndexRangeInstanceRegMap _basisCurvesTopologyIndexRangeRegistry; + _TopologyIndexRangeInstanceRegMap _simpleTextTopologyIndexRangeRegistry; // Register shared primvar buffers. HdInstanceRegistry diff --git a/pxr/imaging/hdSt/simpleText.cpp b/pxr/imaging/hdSt/simpleText.cpp index ebba693777..5f5e8d95d0 100644 --- a/pxr/imaging/hdSt/simpleText.cpp +++ b/pxr/imaging/hdSt/simpleText.cpp @@ -47,6 +47,7 @@ #include "pxr/imaging/hd/computation.h" #include "pxr/imaging/hd/repr.h" #include "pxr/imaging/hd/vertexAdjacency.h" +#include "pxr/imaging/hd/vtBufferSource.h" #include "pxr/base/vt/value.h" PXR_NAMESPACE_OPEN_SCOPE @@ -55,7 +56,8 @@ HdStSimpleText::HdStSimpleText(SdfPath const& id) : HdSimpleText(id) , _topology() , _topologyId(0) - , _customDirtyBitsInUse(0) + , _refineLevel(0) + , _displayOpacity(false) { /*NOTHING*/ } @@ -69,6 +71,456 @@ HdStSimpleText::Sync(HdSceneDelegate *delegate, HdDirtyBits *dirtyBits, TfToken const &reprToken) { + bool updateMaterialTag = false; + if (*dirtyBits & HdChangeTracker::DirtyMaterialId) { + HdStSetMaterialId(delegate, renderParam, this); + updateMaterialTag = true; + } + if (*dirtyBits & HdChangeTracker::DirtyDisplayStyle) { + updateMaterialTag = true; + } + + // Check if either the material or geometric shaders need updating for + // draw items of all the reprs. + bool updateMaterialShader = false; + if (*dirtyBits & (HdChangeTracker::DirtyMaterialId | + HdChangeTracker::NewRepr)) { + updateMaterialShader = true; + } + + bool updateGeometricShader = false; + if (*dirtyBits & (HdChangeTracker::DirtyDisplayStyle | + HdChangeTracker::DirtyMaterialId | + HdChangeTracker::NewRepr)) { + updateGeometricShader = true; + } + + bool displayOpacity = _displayOpacity; + _UpdateRepr(delegate, renderParam, reprToken, dirtyBits); + + if (updateMaterialTag || + (GetMaterialId().IsEmpty() && displayOpacity != _displayOpacity)) { + + HdStSetMaterialTag(delegate, renderParam, this, _displayOpacity, + false); + } + + if (updateMaterialShader || updateGeometricShader) { + _UpdateShadersForAllReprs(delegate, renderParam, + updateMaterialShader, updateGeometricShader); + } + + // This clears all the non-custom dirty bits. This ensures that the rprim + // doesn't have pending dirty bits that add it to the dirty list every + // frame. + // XXX: GetInitialDirtyBitsMask sets certain dirty bits that aren't + // reset (e.g. DirtyExtent, DirtyPrimID) that make this necessary. + *dirtyBits &= ~HdChangeTracker::AllSceneDirtyBits; +} + +void +HdStSimpleText::_UpdateDrawItem(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits) +{ + HD_TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + SdfPath const& id = GetId(); + + /* VISIBILITY */ + _UpdateVisibility(sceneDelegate, dirtyBits); + + /* MATERIAL SHADER (may affect subsequent primvar population) */ + if ((*dirtyBits & HdChangeTracker::NewRepr) || + HdChangeTracker::IsAnyPrimvarDirty(*dirtyBits, id)) { + drawItem->SetMaterialShader(HdStGetMaterialShader(this, sceneDelegate)); + } + + // Reset value of _displayOpacity + if (HdChangeTracker::IsAnyPrimvarDirty(*dirtyBits, id)) { + _displayOpacity = false; + } + + /* INSTANCE PRIMVARS */ + _UpdateInstancer(sceneDelegate, dirtyBits); + HdStUpdateInstancerData(sceneDelegate->GetRenderIndex(), + renderParam, + this, + drawItem, + &_sharedData, + *dirtyBits); + + _displayOpacity = _displayOpacity || + HdStIsInstancePrimvarExistentAndValid( + sceneDelegate->GetRenderIndex(), this, HdTokens->displayOpacity); + + /* CONSTANT PRIMVARS, TRANSFORM, EXTENT AND PRIMID */ + if (HdStShouldPopulateConstantPrimvars(dirtyBits, id)) { + HdPrimvarDescriptorVector constantPrimvars = + HdStGetPrimvarDescriptors(this, drawItem, sceneDelegate, + HdInterpolationConstant); + + HdStPopulateConstantPrimvars(this, + &_sharedData, + sceneDelegate, + renderParam, + drawItem, + dirtyBits, + constantPrimvars); + + _displayOpacity = _displayOpacity || + HdStIsPrimvarExistentAndValid(this, sceneDelegate, + constantPrimvars, HdTokens->displayOpacity); + } + + /* TOPOLOGY */ + // XXX: _PopulateTopology should be split into two phase + // for scene dirtybits and for repr dirtybits. + if (*dirtyBits & (HdChangeTracker::DirtyTopology + | HdChangeTracker::DirtyDisplayStyle)) { + _PopulateTopology( + sceneDelegate, renderParam, drawItem, dirtyBits); + } + + /* PRIMVAR */ + if ((*dirtyBits & HdChangeTracker::NewRepr) || + HdChangeTracker::IsAnyPrimvarDirty(*dirtyBits, id)) { + // XXX: curves don't use refined vertex primvars, however, + // the refined renderpass masks the dirtiness of non-refined vertex + // primvars, so we need to see refined dirty for updating coarse + // vertex primvars if there is only refined reprs being updated. + // we'll fix the change tracking in order to address this craziness. + _PopulateVertexPrimvars( + sceneDelegate, renderParam, drawItem, dirtyBits); + } + + // When we have multiple drawitems for the same prim we need to clean the + // bits for all the data fields touched in this function, otherwise it + // will try to extract topology (for instance) twice, and this won't + // work with delegates that don't keep information around once extracted. + *dirtyBits &= ~HdChangeTracker::AllSceneDirtyBits; + + // Topology and VertexPrimvar may be null, if the curve has zero line + // segments. + TF_VERIFY(drawItem->GetConstantPrimvarRange()); +} + +void +HdStSimpleText::_PopulateTopology(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits) +{ + HD_TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + SdfPath const& id = GetId(); + HdStResourceRegistrySharedPtr const& resourceRegistry = + std::static_pointer_cast( + sceneDelegate->GetRenderIndex().GetResourceRegistry()); + HdChangeTracker &changeTracker = + sceneDelegate->GetRenderIndex().GetChangeTracker(); + + if (*dirtyBits & HdChangeTracker::DirtyDisplayStyle) { + HdDisplayStyle ds = GetDisplayStyle(sceneDelegate); + _refineLevel = ds.refineLevel; + } + + // XXX: is it safe to get topology even if it's not dirty? + bool dirtyTopology = HdChangeTracker::IsTopologyDirty(*dirtyBits, id); + + if (dirtyTopology || HdChangeTracker::IsDisplayStyleDirty(*dirtyBits, id)) { + + const HdSimpleTextTopology &srcTopology = + GetSimpleTextTopology(sceneDelegate); + + // compute id. + _topologyId = srcTopology.ComputeHash(); + bool refined = (_refineLevel>0); + _topologyId = ArchHash64((const char*)&refined, sizeof(refined), + _topologyId); + + // ask the registry if there is a sharable basisCurves topology + HdInstance topologyInstance = + resourceRegistry->RegisterSimpleTextTopology(_topologyId); + + if (topologyInstance.IsFirstInstance()) { + // if this is the first instance, create a new stream topology + // representation and use that. + HdSt_SimpleTextTopologySharedPtr topology = + HdSt_SimpleTextTopology::New(srcTopology); + + topologyInstance.SetValue(topology); + } + + _topology = topologyInstance.GetValue(); + TF_VERIFY(_topology); + + // hash collision check + if (TfDebug::IsEnabled(HD_SAFE_MODE)) { + TF_VERIFY(srcTopology == *_topology); + } + } + + TfToken indexToken; + indexToken = HdTokens->indices; + + HdInstance rangeInstance = + resourceRegistry->RegisterSimpleTextIndexRange( + _topologyId, indexToken); + + if (rangeInstance.IsFirstInstance()) { + HdBufferSourceSharedPtrVector sources; + HdBufferSpecVector bufferSpecs; + + sources.push_back( + _topology->GetPointsIndexBuilderComputation()); + + HdBufferSpec::GetBufferSpecs(sources, &bufferSpecs); + + // Set up the usage hints to mark topology as varying if + // there is a previously set range. + HdBufferArrayUsageHint usageHint; + usageHint.bits.sizeVarying = drawItem->GetTopologyRange() ? 1 : 0; + + // allocate new range + HdBufferArrayRangeSharedPtr range + = resourceRegistry->AllocateNonUniformBufferArrayRange( + HdTokens->topology, bufferSpecs, usageHint); + + // add sources to update queue + resourceRegistry->AddSources(range, std::move(sources)); + rangeInstance.SetValue(range); + } + + HdBufferArrayRangeSharedPtr const& newRange = rangeInstance.GetValue(); + + HdStUpdateDrawItemBAR( + newRange, + drawItem->GetDrawingCoord()->GetTopologyIndex(), + &_sharedData, + renderParam, + &changeTracker); +} + +void +HdStSimpleText::_PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits) +{ + HD_TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + SdfPath const& id = GetId(); + HdStResourceRegistrySharedPtr const& resourceRegistry = + std::static_pointer_cast( + sceneDelegate->GetRenderIndex().GetResourceRegistry()); + + // The "points" attribute is expected to be in this list. + HdPrimvarDescriptorVector primvars = + HdStGetPrimvarDescriptors(this, drawItem, sceneDelegate, + HdInterpolationVertex); + + HdExtComputationPrimvarDescriptorVector compPrimvars = + sceneDelegate->GetExtComputationPrimvarDescriptors(id, + HdInterpolationVertex); + + HdBufferSourceSharedPtrVector sources; + HdBufferSourceSharedPtrVector reserveOnlySources; + HdBufferSourceSharedPtrVector separateComputationSources; + HdStComputationSharedPtrVector computations; + sources.reserve(primvars.size()); + + HdSt_GetExtComputationPrimvarsComputations( + id, + sceneDelegate, + compPrimvars, + *dirtyBits, + &sources, + &reserveOnlySources, + &separateComputationSources, + &computations); + + for (HdPrimvarDescriptor const& primvar : primvars) { + if (!HdChangeTracker::IsPrimvarDirty(*dirtyBits, id, primvar.name)) + continue; + + // TODO: We don't need to pull primvar metadata every time a value + // changes, but we need support from the delegate. + + // Having a null topology is possible, but shouldn't happen when there + // are points + if (!_topology) { + if (primvar.name == HdTokens->points) { + TF_CODING_ERROR("No topology set for BasisCurve %s", + id.GetName().c_str()); + break; + } + continue; + } + + //assert name not in range.bufferArray.GetResources() + VtValue value = GetPrimvar(sceneDelegate, primvar.name); + if (!value.IsEmpty()) { + HdBufferSourceSharedPtr source( + new HdVtBufferSource(primvar.name, value)); + sources.push_back(source); + } + } + + HdBufferArrayRangeSharedPtr const& bar = drawItem->GetVertexPrimvarRange(); + + if (HdStCanSkipBARAllocationOrUpdate(sources, computations, bar, + *dirtyBits)) { + return; + } + + // XXX: This should be based off the DirtyPrimvarDesc bit. + bool hasDirtyPrimvarDesc = (*dirtyBits & HdChangeTracker::DirtyPrimvar); + HdBufferSpecVector removedSpecs; + if (hasDirtyPrimvarDesc) { + TfTokenVector internallyGeneratedPrimvars; // none + removedSpecs = HdStGetRemovedPrimvarBufferSpecs(bar, primvars, + compPrimvars, internallyGeneratedPrimvars, id); + } + + HdBufferSpecVector bufferSpecs; + HdBufferSpec::GetBufferSpecs(sources, &bufferSpecs); + HdBufferSpec::GetBufferSpecs(reserveOnlySources, &bufferSpecs); + HdStGetBufferSpecsFromCompuations(computations, &bufferSpecs); + + HdBufferArrayRangeSharedPtr range = + resourceRegistry->UpdateNonUniformBufferArrayRange( + HdTokens->primvar, bar, bufferSpecs, removedSpecs, + HdBufferArrayUsageHint()); + + HdStUpdateDrawItemBAR( + range, + drawItem->GetDrawingCoord()->GetVertexPrimvarIndex(), + &_sharedData, + renderParam, + &(sceneDelegate->GetRenderIndex().GetChangeTracker())); + + if (!sources.empty() || !computations.empty()) { + // If sources or computations are to be queued against the resulting + // BAR, we expect it to be valid. + if (!TF_VERIFY(drawItem->GetVertexPrimvarRange()->IsValid())) { + return; + } + } + + // add sources to update queue + if (!sources.empty()) { + resourceRegistry->AddSources(drawItem->GetVertexPrimvarRange(), + std::move(sources)); + } + // add gpu computations to queue. + for (auto const& compQueuePair : computations) { + HdComputationSharedPtr const& comp = compQueuePair.first; + HdStComputeQueue queue = compQueuePair.second; + resourceRegistry->AddComputation( + drawItem->GetVertexPrimvarRange(), comp, queue); + } + if (!separateComputationSources.empty()) { + TF_FOR_ALL(it, separateComputationSources) { + resourceRegistry->AddSource(*it); + } + } +} + +void +HdStSimpleText::_UpdateRepr(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + TfToken const &reprToken, + HdDirtyBits *dirtyBits) +{ + HD_TRACE_FUNCTION(); + HF_MALLOC_TAG_FUNCTION(); + + HdReprSharedPtr const &curRepr = _GetRepr(reprToken); + if (!curRepr) { + return; + } + + // Filter custom dirty bits to only those in use. + *dirtyBits &= (HdChangeTracker::AllSceneDirtyBits | + HdChangeTracker::NewRepr); + + if (TfDebug::IsEnabled(HD_RPRIM_UPDATED)) { + TfDebug::Helper().Msg( + "HdStBasisCurves::_UpdateRepr for %s : Repr = %s\n", + GetId().GetText(), reprToken.GetText()); + HdChangeTracker::DumpDirtyBits(*dirtyBits); + } + + HdStDrawItem *drawItem = static_cast( + curRepr->GetDrawItem(0)); + + if (HdChangeTracker::IsDirty(*dirtyBits)) { + _UpdateDrawItem(sceneDelegate, renderParam, + drawItem, dirtyBits); + } + + *dirtyBits &= ~HdChangeTracker::NewRepr; +} + +void +HdStSimpleText::_UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + bool updateMaterialShader, + bool updateGeometricShader) +{ + TF_DEBUG(HD_RPRIM_UPDATED).Msg( + "(%s) - Updating geometric and material shaders for draw " + "items of all reprs.\n", GetId().GetText()); + + HdStShaderCodeSharedPtr materialShader; + if (updateMaterialShader) { + materialShader = HdStGetMaterialShader(this, sceneDelegate); + } + + for (auto const& reprPair : _reprs) { + const TfToken &reprToken = reprPair.first; + HdReprSharedPtr repr = reprPair.second; + int drawItemIndex = 0; + HdStDrawItem *drawItem = static_cast( + repr->GetDrawItem(0)); + + if (updateMaterialShader) { + drawItem->SetMaterialShader(materialShader); + } + if (updateGeometricShader) { + if (!TF_VERIFY(_topology)) return; + HdRenderIndex &renderIndex = sceneDelegate->GetRenderIndex(); + + HdSt_SimpleTextShaderKey shaderKey; + + HdStResourceRegistrySharedPtr resourceRegistry = + std::static_pointer_cast( + renderIndex.GetResourceRegistry()); + + HdSt_GeometricShaderSharedPtr geomShader = + HdSt_GeometricShader::Create(shaderKey, resourceRegistry); + + TF_VERIFY(geomShader); + + if (geomShader != drawItem->GetGeometricShader()) + { + drawItem->SetGeometricShader(geomShader); + + // If the gometric shader changes, we need to do a deep validation of + // batches, so they can be rebuilt if necessary. + HdStMarkDrawBatchesDirty(renderParam); + + TF_DEBUG(HD_RPRIM_UPDATED).Msg( + "%s: Marking all batches dirty to trigger deep validation because" + " the geometric shader was updated.\n", GetId().GetText()); + } + } + } } void @@ -81,17 +533,27 @@ HdStSimpleText::Finalize(HdRenderParam *renderParam) HdDirtyBits HdStSimpleText::_PropagateDirtyBits(HdDirtyBits bits) const { - // propagate scene-based dirtyBits into rprim-custom dirtyBits - if (bits & HdChangeTracker::DirtyTopology) { - bits |= _customDirtyBitsInUse; - } - return bits; } void HdStSimpleText::_InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits) { + _ReprVector::iterator it = std::find_if(_reprs.begin(), _reprs.end(), + _ReprComparator(reprToken)); + bool isNew = it == _reprs.end(); + if (isNew) { + // add new repr + _reprs.emplace_back(reprToken, std::make_shared()); + HdReprSharedPtr &repr = _reprs.back().second; + + *dirtyBits |= HdChangeTracker::NewRepr; + + HdRepr::DrawItemUniquePtr drawItem = + std::make_unique(&_sharedData); + HdDrawingCoord *drawingCoord = drawItem->GetDrawingCoord(); + repr->AddDrawItem(std::move(drawItem)); + } } diff --git a/pxr/imaging/hdSt/simpleText.h b/pxr/imaging/hdSt/simpleText.h index c65ac31c52..71dfbc099f 100644 --- a/pxr/imaging/hdSt/simpleText.h +++ b/pxr/imaging/hdSt/simpleText.h @@ -98,11 +98,37 @@ class HdStSimpleText final: public HdSimpleText HDST_API HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const override; + void _UpdateRepr(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + TfToken const &reprToken, + HdDirtyBits *dirtyBitsState); + + void _PopulateTopology(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits); + + + void _PopulateVertexPrimvars(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits); + + void _UpdateShadersForAllReprs(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + bool updateMaterialShader, + bool updateGeometricShader); + private: + void _UpdateDrawItem(HdSceneDelegate *sceneDelegate, + HdRenderParam *renderParam, + HdStDrawItem *drawItem, + HdDirtyBits *dirtyBits); HdSt_SimpleTextTopologySharedPtr _topology; HdTopology::ID _topologyId; - HdDirtyBits _customDirtyBitsInUse; + int _refineLevel; // XXX: could be moved into HdBasisCurveTopology. + bool _displayOpacity : 1; }; diff --git a/pxr/imaging/hdSt/simpleTextShaderKey.cpp b/pxr/imaging/hdSt/simpleTextShaderKey.cpp index 95f3db9aba..96ff9d9011 100644 --- a/pxr/imaging/hdSt/simpleTextShaderKey.cpp +++ b/pxr/imaging/hdSt/simpleTextShaderKey.cpp @@ -33,13 +33,18 @@ PXR_NAMESPACE_OPEN_SCOPE TF_DEFINE_PRIVATE_TOKENS( _tokens, - ((baseGLSLFX, "text.glslfx")) + ((baseGLSLFX, "text.glslfx")) + ((vsTextureText, "VSTextureText")) + ((psTextureText, "PSTextureText")) ); HdSt_SimpleTextShaderKey::HdSt_SimpleTextShaderKey() : glslfx(_tokens->baseGLSLFX) { primType = HdSt_GeometricShader::PrimitiveType::PRIM_MESH_COARSE_TRIANGLES; + VS[0] = _tokens->vsTextureText; + FS[0] = _tokens->psTextureText; + } HdSt_SimpleTextShaderKey::~HdSt_SimpleTextShaderKey() diff --git a/pxr/imaging/hdSt/simpleTextShaderKey.h b/pxr/imaging/hdSt/simpleTextShaderKey.h index 0a5b187e36..8f67a4e6ea 100644 --- a/pxr/imaging/hdSt/simpleTextShaderKey.h +++ b/pxr/imaging/hdSt/simpleTextShaderKey.h @@ -59,12 +59,17 @@ struct HdSt_SimpleTextShaderKey : public HdSt_ShaderKey ~HdSt_SimpleTextShaderKey(); TfToken const &GetGlslfxFilename() const override { return glslfx; } + TfToken const *GetVS() const override { return VS; } + TfToken const *GetFS() const override { return FS; } + HdSt_GeometricShader::PrimitiveType GetPrimitiveType() const override { return primType; } HdSt_GeometricShader::PrimitiveType primType; TfToken glslfx; + TfToken VS[1]; + TfToken FS[1]; }; diff --git a/pxr/imaging/hdSt/simpleTextTopology.cpp b/pxr/imaging/hdSt/simpleTextTopology.cpp index 7189032c0f..25efa438eb 100644 --- a/pxr/imaging/hdSt/simpleTextTopology.cpp +++ b/pxr/imaging/hdSt/simpleTextTopology.cpp @@ -51,7 +51,17 @@ HdSt_SimpleTextTopology::~HdSt_SimpleTextTopology() HdBufferSourceSharedPtr HdSt_SimpleTextTopology::GetPointsIndexBuilderComputation() { - VtIntArray finalIndices(0); + size_t characterCount = GetTextData().length(); + VtIntArray finalIndices(characterCount * 6); + for (size_t i = 0; i < characterCount; i++) + { + finalIndices.emplace_back(i * 6); + finalIndices.emplace_back(i * 6 + 1); + finalIndices.emplace_back(i * 6 + 2); + finalIndices.emplace_back(i * 6 + 3); + finalIndices.emplace_back(i * 6 + 4); + finalIndices.emplace_back(i * 6 + 5); + } // Note: The primitive param buffer isn't bound. return HdBufferSourceSharedPtr( diff --git a/pxr/usd/usdGeom/schema.usda b/pxr/usd/usdGeom/schema.usda index ef2f982c4c..dd6ebd06e4 100644 --- a/pxr/usd/usdGeom/schema.usda +++ b/pxr/usd/usdGeom/schema.usda @@ -876,14 +876,14 @@ class SimpleText "SimpleText" ( doc = """The typeface.""" ) - bool italic = false ( - doc = """Italic.""" - ) - bool bold = false ( doc = """Bold.""" ) + bool italic = false ( + doc = """Italic.""" + ) + int textHeight ( doc = """Size.""" ) diff --git a/pxr/usd/usdGeom/simpleText.cpp b/pxr/usd/usdGeom/simpleText.cpp index f0abad7a2f..384e8de0a3 100644 --- a/pxr/usd/usdGeom/simpleText.cpp +++ b/pxr/usd/usdGeom/simpleText.cpp @@ -125,15 +125,15 @@ UsdGeomSimpleText::CreateTypefaceAttr(VtValue const &defaultValue, bool writeSpa } UsdAttribute -UsdGeomSimpleText::GetItalicAttr() const +UsdGeomSimpleText::GetBoldAttr() const { - return GetPrim().GetAttribute(UsdGeomTokens->italic); + return GetPrim().GetAttribute(UsdGeomTokens->bold); } UsdAttribute -UsdGeomSimpleText::CreateItalicAttr(VtValue const &defaultValue, bool writeSparsely) const +UsdGeomSimpleText::CreateBoldAttr(VtValue const &defaultValue, bool writeSparsely) const { - return UsdSchemaBase::_CreateAttr(UsdGeomTokens->italic, + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->bold, SdfValueTypeNames->Bool, /* custom = */ false, SdfVariabilityVarying, @@ -142,15 +142,15 @@ UsdGeomSimpleText::CreateItalicAttr(VtValue const &defaultValue, bool writeSpars } UsdAttribute -UsdGeomSimpleText::GetBoldAttr() const +UsdGeomSimpleText::GetItalicAttr() const { - return GetPrim().GetAttribute(UsdGeomTokens->bold); + return GetPrim().GetAttribute(UsdGeomTokens->italic); } UsdAttribute -UsdGeomSimpleText::CreateBoldAttr(VtValue const &defaultValue, bool writeSparsely) const +UsdGeomSimpleText::CreateItalicAttr(VtValue const &defaultValue, bool writeSparsely) const { - return UsdSchemaBase::_CreateAttr(UsdGeomTokens->bold, + return UsdSchemaBase::_CreateAttr(UsdGeomTokens->italic, SdfValueTypeNames->Bool, /* custom = */ false, SdfVariabilityVarying, @@ -295,8 +295,8 @@ UsdGeomSimpleText::GetSchemaAttributeNames(bool includeInherited) { static TfTokenVector localNames = { UsdGeomTokens->typeface, - UsdGeomTokens->italic, UsdGeomTokens->bold, + UsdGeomTokens->italic, UsdGeomTokens->textHeight, UsdGeomTokens->textWidthFactor, UsdGeomTokens->textData, diff --git a/pxr/usd/usdGeom/simpleText.h b/pxr/usd/usdGeom/simpleText.h index fd945b89a1..4b1691c66e 100644 --- a/pxr/usd/usdGeom/simpleText.h +++ b/pxr/usd/usdGeom/simpleText.h @@ -188,47 +188,47 @@ class UsdGeomSimpleText : public UsdGeomGprim public: // --------------------------------------------------------------------- // - // ITALIC + // BOLD // --------------------------------------------------------------------- // - /// Italic. + /// Bold. /// /// | || /// | -- | -- | - /// | Declaration | `bool italic = 0` | + /// | Declaration | `bool bold = 0` | /// | C++ Type | bool | /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool | USDGEOM_API - UsdAttribute GetItalicAttr() const; + UsdAttribute GetBoldAttr() const; - /// See GetItalicAttr(), and also + /// See GetBoldAttr(), and also /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. /// If specified, author \p defaultValue as the attribute's default, /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - /// the default for \p writeSparsely is \c false. USDGEOM_API - UsdAttribute CreateItalicAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + UsdAttribute CreateBoldAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; public: // --------------------------------------------------------------------- // - // BOLD + // ITALIC // --------------------------------------------------------------------- // - /// Bold. + /// Italic. /// /// | || /// | -- | -- | - /// | Declaration | `bool bold = 0` | + /// | Declaration | `bool italic = 0` | /// | C++ Type | bool | /// | \ref Usd_Datatypes "Usd Type" | SdfValueTypeNames->Bool | USDGEOM_API - UsdAttribute GetBoldAttr() const; + UsdAttribute GetItalicAttr() const; - /// See GetBoldAttr(), and also + /// See GetItalicAttr(), and also /// \ref Usd_Create_Or_Get_Property for when to use Get vs Create. /// If specified, author \p defaultValue as the attribute's default, /// sparsely (when it makes sense to do so) if \p writeSparsely is \c true - /// the default for \p writeSparsely is \c false. USDGEOM_API - UsdAttribute CreateBoldAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; + UsdAttribute CreateItalicAttr(VtValue const &defaultValue = VtValue(), bool writeSparsely=false) const; public: // --------------------------------------------------------------------- // diff --git a/pxr/usd/usdGeom/wrapSimpleText.cpp b/pxr/usd/usdGeom/wrapSimpleText.cpp index 357ff920fb..5f3e875c33 100644 --- a/pxr/usd/usdGeom/wrapSimpleText.cpp +++ b/pxr/usd/usdGeom/wrapSimpleText.cpp @@ -57,16 +57,16 @@ _CreateTypefaceAttr(UsdGeomSimpleText &self, } static UsdAttribute -_CreateItalicAttr(UsdGeomSimpleText &self, +_CreateBoldAttr(UsdGeomSimpleText &self, object defaultVal, bool writeSparsely) { - return self.CreateItalicAttr( + return self.CreateBoldAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely); } static UsdAttribute -_CreateBoldAttr(UsdGeomSimpleText &self, +_CreateItalicAttr(UsdGeomSimpleText &self, object defaultVal, bool writeSparsely) { - return self.CreateBoldAttr( + return self.CreateItalicAttr( UsdPythonToSdfType(defaultVal, SdfValueTypeNames->Bool), writeSparsely); } @@ -168,13 +168,6 @@ void wrapUsdGeomSimpleText() (arg("defaultValue")=object(), arg("writeSparsely")=false)) - .def("GetItalicAttr", - &This::GetItalicAttr) - .def("CreateItalicAttr", - &_CreateItalicAttr, - (arg("defaultValue")=object(), - arg("writeSparsely")=false)) - .def("GetBoldAttr", &This::GetBoldAttr) .def("CreateBoldAttr", @@ -182,6 +175,13 @@ void wrapUsdGeomSimpleText() (arg("defaultValue")=object(), arg("writeSparsely")=false)) + .def("GetItalicAttr", + &This::GetItalicAttr) + .def("CreateItalicAttr", + &_CreateItalicAttr, + (arg("defaultValue")=object(), + arg("writeSparsely")=false)) + .def("GetTextHeightAttr", &This::GetTextHeightAttr) .def("CreateTextHeightAttr", diff --git a/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp b/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp index 1399c2c425..dbdc4eaa23 100644 --- a/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp +++ b/pxr/usdImaging/usdImaging/simpleTextAdapter.cpp @@ -76,65 +76,8 @@ UsdImagingSimpleTextAdapter::TrackVariability(UsdPrim const& prim, BaseAdapter::TrackVariability( prim, cachePath, timeVaryingBits, instancerContext); - // Check DirtyPoints before doing variability checks, to see if we can skip. if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->textData, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->typeface, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->italic, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->bold, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->textHeight, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->textWidthFactor, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->obliqueAngle, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->charSpacing, - HdChangeTracker::DirtyPoints, - UsdImagingTokens->usdVaryingPrimvar, - timeVaryingBits, /*inherited*/false); - } - - if ((*timeVaryingBits & HdChangeTracker::DirtyPoints) == 0) { - _IsVarying(prim, UsdGeomTokens->charPos, + _IsVarying(prim, HdTokens->textTextureUV, HdChangeTracker::DirtyPoints, UsdImagingTokens->usdVaryingPrimvar, timeVaryingBits, /*inherited*/false); @@ -144,7 +87,7 @@ UsdImagingSimpleTextAdapter::TrackVariability(UsdPrim const& prim, bool UsdImagingSimpleTextAdapter::_IsBuiltinPrimvar(TfToken const& primvarName) const { - return UsdImagingGprimAdapter::_IsBuiltinPrimvar(primvarName); + return (primvarName == HdTokens->textTextureUV || BaseAdapter::_IsBuiltinPrimvar(primvarName)); } void @@ -164,23 +107,8 @@ UsdImagingSimpleTextAdapter::UpdateForTime( HdPrimvarDescriptorVector& primvars = primvarDescCache->GetPrimvars(cachePath); - // We compute all of the below items together, since their derivations - // aren't easily separable. - HdDirtyBits geometryBits = HdChangeTracker::DirtyTopology | - HdChangeTracker::DirtyPoints | - HdChangeTracker::DirtyPrimvar | - HdChangeTracker::DirtyExtent; - if (requestedBits & HdChangeTracker::DirtyPoints) { - _MergePrimvar(&primvars, UsdGeomTokens->textData, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->typeface, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->italic, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->bold, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->textHeight, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->textWidthFactor, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->obliqueAngle, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->charSpacing, HdInterpolationVertex); - _MergePrimvar(&primvars, UsdGeomTokens->charPos, HdInterpolationVertex); + _MergePrimvar(&primvars, HdTokens->textTextureUV, HdInterpolationVertex); } } @@ -191,9 +119,9 @@ UsdImagingSimpleTextAdapter::ProcessPropertyChange(UsdPrim const& prim, { // Even though points is treated as a primvar, it is special and is always // treated as a vertex primvar. - if (propertyName == UsdGeomTokens->textData || propertyName == UsdGeomTokens->typeface - || propertyName == UsdGeomTokens->italic - || propertyName == UsdGeomTokens->bold || propertyName == UsdGeomTokens->textHeight + if (propertyName == UsdGeomTokens->textData || propertyName == UsdGeomTokens->textEncoding + || propertyName == UsdGeomTokens->typeface || propertyName == UsdGeomTokens->bold + || propertyName == UsdGeomTokens->italic || propertyName == UsdGeomTokens->textHeight || propertyName == UsdGeomTokens->textWidthFactor || propertyName == UsdGeomTokens->obliqueAngle || propertyName == UsdGeomTokens->charSpacing || propertyName == UsdGeomTokens->charPos) { return HdChangeTracker::DirtyPoints; @@ -211,8 +139,13 @@ UsdImagingSimpleTextAdapter::GetTopology(UsdPrim const& prim, { TRACE_FUNCTION(); HF_MALLOC_TAG_FUNCTION(); - - HdSimpleTextTopology topology; + + HdSimpleTextTopology topology(_Get(prim, UsdGeomTokens->textData, time), + _Get(prim, UsdGeomTokens->textEncoding, time), + _Get(prim, UsdGeomTokens->textHeight, time), + _Get(prim, UsdGeomTokens->textWidthFactor, time), + _Get(prim, UsdGeomTokens->bold, time), + _Get(prim, UsdGeomTokens->italic, time)); return VtValue(topology); } @@ -233,25 +166,20 @@ UsdImagingSimpleTextAdapter::Get(UsdPrim const& prim, return value; } - if (key == HdTokens->textData) { + if (key == HdTokens->points) { VtValue value; UsdGeomSimpleText text(prim); - std::string textData; - if (text && text.GetTextDataAttr().Get(&textData, time)) { - value = textData; - return value; - } - - } else if (key == HdTokens->typeface) { + VtVec3fArray points; + value = points; + return value; + } + else if (key == HdTokens->textTextureUV) { VtValue value; UsdGeomSimpleText text(prim); - std::string typeface; - if (text && text.GetTypefaceAttr().Get(&typeface, time)) { - value = typeface; - return value; - } + VtVec2fArray uvs; + value = uvs; + return value; } - return BaseAdapter::Get(prim, cachePath, key, time, outIndices); }