Skip to content

Commit

Permalink
Fix text display problem after usd 21.11 is upgraded (PixarAnimationS…
Browse files Browse the repository at this point in the history
…tudios#109)

Description of Change(s)
Fix text display problem after usd 21.11 is upgraded

Fixes Issue(s)

(cherry picked from commit c44c9fcc58fed55a461913a63db1d2ca237f0c83)
  • Loading branch information
PierreWang committed May 26, 2022
1 parent e584362 commit d513ce5
Show file tree
Hide file tree
Showing 11 changed files with 770 additions and 25 deletions.
7 changes: 6 additions & 1 deletion pxr/imaging/hd/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ set(PXR_PACKAGE hd)

set(optionalPublicClasses "")
if (PXR_ENABLE_TEXT_SUPPORT)
list(APPEND optionalPublicClasses simpleText simpleTextTopology)
list(APPEND optionalPublicClasses
simpleText
simpleTextTopology
simpleTextSchema
simpleTextTopologySchema
)
endif()

pxr_library(hd
Expand Down
207 changes: 207 additions & 0 deletions pxr/imaging/hd/dataSourceLegacyPrim.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,8 @@
#include "pxr/imaging/hd/primvarsSchema.h"
#include "pxr/imaging/hd/purposeSchema.h"
#include "pxr/imaging/hd/renderBufferSchema.h"
#include "pxr/imaging/hd/simpleTextSchema.h"
#include "pxr/imaging/hd/simpleTextTopologySchema.h"
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
#include "pxr/imaging/hd/visibilitySchema.h"
#include "pxr/imaging/hd/volumeFieldBindingSchema.h"
Expand Down Expand Up @@ -1105,6 +1107,197 @@ class Hd_DataSourceBasisCurves : public HdContainerDataSource

// ----------------------------------------------------------------------------

using Hd_SimpleTextTopologyStoreSharedPtr =
std::shared_ptr<class Hd_SimpleTextTopologyStore>;
using HdSimpleTextTopologySharedPtr = std::shared_ptr<HdSimpleTextTopology>;

class Hd_SimpleTextTopologyStore
{
public:
Hd_SimpleTextTopologyStore(
const SdfPath &id, HdSceneDelegate *sceneDelegate)
: _id(id)
, _sceneDelegate(sceneDelegate)
{
}

HdSimpleTextTopologySharedPtr Get()
{
HdSimpleTextTopologySharedPtr stt = std::atomic_load(
&_simpleTextTopology);
if (stt) {
return stt;
}

stt = std::make_shared<HdSimpleTextTopology>(
_sceneDelegate->GetSimpleTextTopology(_id));
std::atomic_store(&_simpleTextTopology, stt);
return stt;
}

void Invalidate()
{
HdSimpleTextTopologySharedPtr nullstt;
std::atomic_store(&_simpleTextTopology, nullstt);
}

template <typename T>
class MemberDataSource : public HdTypedSampledDataSource<T>
{
public:
HD_DECLARE_DATASOURCE_ABSTRACT(MemberDataSource<T>);

T GetTypedValue(HdSampledDataSource::Time shutterOffset) override = 0;

VtValue GetValue(HdSampledDataSource::Time shutterOffset) override
{
return VtValue(GetTypedValue(shutterOffset));
}

bool GetContributingSampleTimesForInterval(
HdSampledDataSource::Time startTime,
HdSampledDataSource::Time endTime,
std::vector<HdSampledDataSource::Time> * outSampleTimes)
override
{
return false;
}

MemberDataSource(const Hd_SimpleTextTopologyStoreSharedPtr &stts)
: _stts(stts)
{
}

protected:
Hd_SimpleTextTopologyStoreSharedPtr _stts;
};

#define DEFINE_SIMPLETEXT_TOPOLOGY_ACCESSOR_DATASOURCE(N, T, A) \
class N : public MemberDataSource<T> \
{ \
public: \
HD_DECLARE_DATASOURCE(N); \
\
N(const Hd_SimpleTextTopologyStoreSharedPtr &stts) \
: MemberDataSource(stts) {} \
\
T GetTypedValue(HdSampledDataSource::Time shutterOffset) override \
{ \
return _stts->Get()->A(); \
} \
};

DEFINE_SIMPLETEXT_TOPOLOGY_ACCESSOR_DATASOURCE(
PointCountDataSource, int, GetPointCount);

private:
SdfPath _id;
HdSceneDelegate *_sceneDelegate;
HdSimpleTextTopologySharedPtr _simpleTextTopology;
};



class Hd_DataSourceSimpleTextTopology : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(Hd_DataSourceSimpleTextTopology);
Hd_DataSourceSimpleTextTopology(const Hd_SimpleTextTopologyStoreSharedPtr &stts)
: _stts(stts)
{
}

bool Has(const TfToken &name) override
{
if (name == HdSimpleTextTopologySchemaTokens->pointCount) {
return true;
}
return false;
}

TfTokenVector GetNames() override
{
return{
HdSimpleTextTopologySchemaTokens->pointCount,
};
}

HdDataSourceBaseHandle Get(const TfToken &name) override
{
if (name == HdSimpleTextTopologySchemaTokens->pointCount) {
return Hd_SimpleTextTopologyStore::
PointCountDataSource::New(_stts);
}
return nullptr;
}

private:
Hd_SimpleTextTopologyStoreSharedPtr _stts;
};

class Hd_DataSourceSimpleText : public HdContainerDataSource
{
public:
HD_DECLARE_DATASOURCE(Hd_DataSourceSimpleText);

Hd_DataSourceSimpleText(const SdfPath &id, HdSceneDelegate *sceneDelegate)
: _id(id)
, _sceneDelegate(sceneDelegate)
{
}


bool Has(const TfToken &name) override
{
if (name == HdSimpleTextSchemaTokens->topology) {
return true;
}

return false;
}

TfTokenVector GetNames() override
{
return{
HdSimpleTextSchemaTokens->topology,

};
}

HdDataSourceBaseHandle Get(const TfToken &name) override
{
if (name == HdSimpleTextSchemaTokens->topology) {
return Hd_DataSourceSimpleTextTopology::New(
_GetSimpleTextTopologyStore());
}

return nullptr;
}
private:

Hd_SimpleTextTopologyStoreSharedPtr _GetSimpleTextTopologyStore()
{
Hd_SimpleTextTopologyStoreSharedPtr stts =
std::atomic_load(&_simpleTextTopologyStore);
if (stts) {
return stts;
}

stts =
std::make_shared<Hd_SimpleTextTopologyStore>(_id, _sceneDelegate);
std::atomic_store(&_simpleTextTopologyStore, stts);

return stts;
}

SdfPath _id;
HdSceneDelegate *_sceneDelegate;
Hd_SimpleTextTopologyStoreSharedPtr _simpleTextTopologyStore;

};

// ----------------------------------------------------------------------------

template <typename T>
class Hd_TypedDataSourceLegacyCameraParamValue : public HdTypedSampledDataSource<T>
{
Expand Down Expand Up @@ -2265,6 +2458,12 @@ HdDataSourceLegacyPrim::Has(const TfToken &name)
}
}

if (_type == HdPrimTypeTokens->simpleText) {
if (name == HdPrimTypeTokens->simpleText) {
return true;
}
}

if (HdPrimTypeIsGprim(_type)) {
if (name == HdPrimvarsSchemaTokens->primvars ||
name == HdExtComputationPrimvarsSchemaTokens->extComputationPrimvars ||
Expand Down Expand Up @@ -2381,6 +2580,10 @@ HdDataSourceLegacyPrim::GetNames()
result.push_back(HdBasisCurvesSchemaTokens->basisCurves);
}

if (_type == HdPrimTypeTokens->simpleText) {
result.push_back(HdSimpleTextSchemaTokens->simpleText);
}

if (HdPrimTypeIsGprim(_type)) {
result.push_back(HdPrimvarsSchemaTokens->primvars);
result.push_back(HdExtComputationPrimvarsSchemaTokens->extComputationPrimvars);
Expand Down Expand Up @@ -2899,6 +3102,10 @@ HdDataSourceLegacyPrim::Get(const TfToken &name)
if (_type == HdPrimTypeTokens->basisCurves) {
return Hd_DataSourceBasisCurves::New(_id, _sceneDelegate);
}
} else if (name == HdSimpleTextSchemaTokens->simpleText) {
if (_type == HdPrimTypeTokens->simpleText) {
return Hd_DataSourceSimpleText::New(_id, _sceneDelegate);
}
} else if (name == HdPrimvarsSchemaTokens->primvars) {
return _GetPrimvarsDataSource();
} else if (
Expand Down
16 changes: 16 additions & 0 deletions pxr/imaging/hd/dirtyBitsTranslator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@
#include "pxr/imaging/hd/primvarsSchema.h"
#include "pxr/imaging/hd/purposeSchema.h"
#include "pxr/imaging/hd/renderBufferSchema.h"
#include "pxr/imaging/hd/simpleTextSchema.h"
#include "pxr/imaging/hd/simpleTextTopologySchema.h"
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
#include "pxr/imaging/hd/visibilitySchema.h"
#include "pxr/imaging/hd/volumeFieldBindingSchema.h"
Expand Down Expand Up @@ -97,6 +99,13 @@ HdDirtyBitsTranslator::RprimDirtyBitsToLocatorSet(TfToken const& primType,
}
}

if (primType == HdPrimTypeTokens->simpleText) {
if (bits & HdChangeTracker::DirtyTopology) {
// could either be topology or geomsubsets
set->append(HdSimpleTextSchema::GetDefaultLocator());
}
}

if (bits & HdChangeTracker::DirtyDisplayStyle) {
set->append(HdLegacyDisplayStyleSchema::GetDefaultLocator());
} else {
Expand Down Expand Up @@ -406,6 +415,13 @@ HdDirtyBitsTranslator::RprimLocatorSetToDirtyBits(
}
}

if (primType == HdPrimTypeTokens->simpleText) {
if (_FindLocator(HdSimpleTextTopologySchema::GetDefaultLocator(),
end, &it)) {
bits |= HdChangeTracker::DirtyTopology;
}
}

// _FindLocator here is called with advanceToNext = false. It will advance
// "it" from the current position to the first element where either
// it.Intersects(locator) OR (it > locator and !it.HasPrefix), returning
Expand Down
32 changes: 32 additions & 0 deletions pxr/imaging/hd/sceneIndexAdapterSceneDelegate.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,8 @@
#include "pxr/imaging/hd/primvarsSchema.h"
#include "pxr/imaging/hd/purposeSchema.h"
#include "pxr/imaging/hd/renderBufferSchema.h"
#include "pxr/imaging/hd/simpleTextSchema.h"
#include "pxr/imaging/hd/simpleTextTopologySchema.h"
#include "pxr/imaging/hd/subdivisionTagsSchema.h"
#include "pxr/imaging/hd/visibilitySchema.h"
#include "pxr/imaging/hd/volumeFieldBindingSchema.h"
Expand Down Expand Up @@ -740,6 +742,36 @@ HdSceneIndexAdapterSceneDelegate::GetBasisCurvesTopology(SdfPath const &id)
return result;
}

HdSimpleTextTopology
HdSceneIndexAdapterSceneDelegate::GetSimpleTextTopology(SdfPath const &id)
{
TRACE_FUNCTION();
HF_MALLOC_TAG_FUNCTION();
HdSceneIndexPrim prim = _inputSceneIndex->GetPrim(id);

HdSimpleTextSchema simpleTextSchema =
HdSimpleTextSchema::GetFromParent(prim.dataSource);

HdSimpleTextTopologySchema stTopologySchema =
simpleTextSchema.GetTopology();

if (!stTopologySchema.IsDefined()) {
return HdSimpleTextTopology();
}

HdIntDataSourceHandle pointCountDataSource =
stTopologySchema.GetPointCount();

if (!pointCountDataSource) {
return HdSimpleTextTopology();
}

HdSimpleTextTopology result(
pointCountDataSource->GetTypedValue(0.0f));

return result;
}

VtArray<TfToken>
HdSceneIndexAdapterSceneDelegate::GetCategories(SdfPath const &id)
{
Expand Down
1 change: 1 addition & 0 deletions pxr/imaging/hd/sceneIndexAdapterSceneDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class HdSceneIndexAdapterSceneDelegate

HdMeshTopology GetMeshTopology(SdfPath const &id) override;
HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id) override;
HdSimpleTextTopology GetSimpleTextTopology(SdfPath const &id) override;
PxOsdSubdivTags GetSubdivTags(SdfPath const &id) override;
GfRange3d GetExtent(SdfPath const &id) override;
bool GetVisible(SdfPath const &id) override;
Expand Down
Loading

0 comments on commit d513ce5

Please sign in to comment.