Loading...
Searching...
No Matches
primDataSourceOverlayCache.h
1//
2// Copyright 2021 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
8#define PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
9
10#include "pxr/imaging/hd/sceneIndex.h"
11#include "pxr/imaging/hd/dataSource.h"
12
13#include "pxr/usd/sdf/pathTable.h"
14
15PXR_NAMESPACE_OPEN_SCOPE
16
17// ----------------------------------------------------------------------------
18
19// A utility class to handle caching of datasource overlays, along with
20// invalidation functions to clear the cache.
21
22class HdPrimDataSourceOverlayCache :
23 public std::enable_shared_from_this<HdPrimDataSourceOverlayCache>
24{
25public:
26 virtual ~HdPrimDataSourceOverlayCache();
27
28 HdSceneIndexPrim GetPrim(const SdfPath &primPath) const;
29
30 void HandlePrimsAdded(
32 const HdSceneIndexBaseRefPtr &source);
33 void HandlePrimsRemoved(
35 void HandlePrimsDirtied(
38
39protected:
40 HdPrimDataSourceOverlayCache() = default;
41
42 // This struct provides a way for users of the cache to describe the
43 // structure of synthetic attributes. For example, if you compute
44 // "xformInverse" from "xform", the topology would look like:
45 // OverlayTopology topo = { "xformInverse" ->
46 // { .onPrim = { "xform" }, .onParent = { }, false }
47 // }
48 // ... notably, this tells us what attributes we're adding (xformInverse,
49 // but only when xform is present); and also to dirty xformInverse when
50 // xform is dirty.
51 //
52 // For attributes we always want to add (even if their dependents are not
53 // present), dependenciesOptional lets us say as much.
54 //
55 // Note: _ComputeOverlayDataSource should respect this topology, or behavior
56 // is undefined...
57 //
58 // XXX: the "onParent" dependencies here are to support eventual inherited
59 // attribute caching, but this feature hasn't been implemented yet.
60 struct _OverlayDependencies
61 {
62 _OverlayDependencies()
63 : onPrim(), onParent(), dependenciesOptional(false) {}
64
67 bool dependenciesOptional;
68 };
69 using _OverlayTopology = std::map<TfToken, _OverlayDependencies>;
70
71
72 // Topology should be set once, from the derived class constructor.
73 void _SetOverlayTopology(const _OverlayTopology &topology) {
74 _overlayTopology = topology;
75 }
76
77 // Compute the named datasource. Note that inputDataSource comes from the
78 // source scene index, while parentOverlayDataSource comes from the cache
79 // and is consequently recursively composed.
80 //
81 // XXX: the "parentOverlayDataSource" is here to support eventual inherited
82 // attribute caching, but this feature hasn't been implemented yet. For now,
83 // it will always be null.
84 virtual HdDataSourceBaseHandle _ComputeOverlayDataSource(
85 const TfToken &name,
86 HdContainerDataSourceHandle inputDataSource,
87 HdContainerDataSourceHandle parentOverlayDataSource) const = 0;
88
89private:
90 class _HdPrimDataSourceOverlay : public HdContainerDataSource
91 {
92 public:
93 HD_DECLARE_DATASOURCE(_HdPrimDataSourceOverlay);
94
95 _HdPrimDataSourceOverlay(
96 HdContainerDataSourceHandle inputDataSource,
97 HdContainerDataSourceHandle parentOverlayDataSource,
98 const std::weak_ptr<const HdPrimDataSourceOverlayCache> cache);
99
100 void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
101
102 void PrimDirtied(const HdDataSourceLocatorSet &dirtyAttributes);
103
104 TfTokenVector GetNames() override;
105 HdDataSourceBaseHandle Get(const TfToken &name) override;
106
107 private:
108 HdContainerDataSourceHandle _inputDataSource;
109 HdContainerDataSourceHandle _parentOverlayDataSource;
110 const std::weak_ptr<const HdPrimDataSourceOverlayCache> _cache;
111
112 using _OverlayMap = std::map<TfToken, HdDataSourceBaseHandle>;
113
114 _OverlayMap _overlayMap;
115 };
116
118 _OverlayTopology _overlayTopology;
119};
120
121PXR_NAMESPACE_CLOSE_SCOPE
122
123#endif
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
Definition: dataSource.h:99
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
A convenience function: given container, return the descendant identified by locator,...
Represents a set of data source locators closed under descendancy.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
A mapping from SdfPath to MappedType, somewhat similar to map<SdfPath, MappedType> and TfHashMap<SdfP...
Definition: pathTable.h:66
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440