HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
primDataSourceOverlayCache.h
Go to the documentation of this file.
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 
12 
13 #include "pxr/usd/sdf/pathTable.h"
14 
16 
17 // ----------------------------------------------------------------------------
18 
19 // A utility class to handle caching of datasource overlays, along with
20 // invalidation functions to clear the cache.
21 
23  public std::enable_shared_from_this<HdPrimDataSourceOverlayCache>
24 {
25 public:
27 
28  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const;
29 
30  void HandlePrimsAdded(
32  const HdSceneIndexBaseRefPtr &source);
33  void HandlePrimsRemoved(
35  void HandlePrimsDirtied(
37  HdSceneIndexObserver::DirtiedPrimEntries *additionalDirtied);
38 
39 protected:
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.
61  {
63  : onPrim(), onParent(), dependenciesOptional(false) {}
64 
68  };
69  using _OverlayTopology = std::map<TfToken, _OverlayDependencies>;
70 
71 
72  // Topology should be set once, from the derived class constructor.
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 
89 private:
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 
122 
123 #endif
virtual HdDataSourceBaseHandle _ComputeOverlayDataSource(const TfToken &name, HdContainerDataSourceHandle inputDataSource, HdContainerDataSourceHandle parentOverlayDataSource) const =0
HdSceneIndexPrim GetPrim(const SdfPath &primPath) const
#define HD_DECLARE_DATASOURCE(type)
Definition: dataSource.h:52
Definition: token.h:70
void HandlePrimsAdded(const HdSceneIndexObserver::AddedPrimEntries &entries, const HdSceneIndexBaseRefPtr &source)
GT_API const UT_StringHolder topology
GLsizei GLsizei GLchar * source
Definition: glcorearb.h:803
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440
void HandlePrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:273
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
void HandlePrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries, HdSceneIndexObserver::DirtiedPrimEntries *additionalDirtied)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
void _SetOverlayTopology(const _OverlayTopology &topology)
std::map< TfToken, _OverlayDependencies > _OverlayTopology