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 Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 #ifndef PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
25 #define PXR_IMAGING_HD_PRIM_DATA_SOURCE_OVERLAY_CACHE_H
26 
29 
30 #include "pxr/usd/sdf/pathTable.h"
31 
33 
34 // ----------------------------------------------------------------------------
35 
36 // A utility class to handle caching of datasource overlays, along with
37 // invalidation functions to clear the cache.
38 
40  public std::enable_shared_from_this<HdPrimDataSourceOverlayCache>
41 {
42 public:
44 
45  HdSceneIndexPrim GetPrim(const SdfPath &primPath) const;
46 
47  void HandlePrimsAdded(
49  const HdSceneIndexBaseRefPtr &source);
50  void HandlePrimsRemoved(
52  void HandlePrimsDirtied(
54  HdSceneIndexObserver::DirtiedPrimEntries *additionalDirtied);
55 
56 protected:
57  HdPrimDataSourceOverlayCache() = default;
58 
59  // This struct provides a way for users of the cache to describe the
60  // structure of synthetic attributes. For example, if you compute
61  // "xformInverse" from "xform", the topology would look like:
62  // OverlayTopology topo = { "xformInverse" ->
63  // { .onPrim = { "xform" }, .onParent = { }, false }
64  // }
65  // ... notably, this tells us what attributes we're adding (xformInverse,
66  // but only when xform is present); and also to dirty xformInverse when
67  // xform is dirty.
68  //
69  // For attributes we always want to add (even if their dependents are not
70  // present), dependenciesOptional lets us say as much.
71  //
72  // Note: _ComputeOverlayDataSource should respect this topology, or behavior
73  // is undefined...
74  //
75  // XXX: the "onParent" dependencies here are to support eventual inherited
76  // attribute caching, but this feature hasn't been implemented yet.
78  {
80  : onPrim(), onParent(), dependenciesOptional(false) {}
81 
85  };
86  using _OverlayTopology = std::map<TfToken, _OverlayDependencies>;
87 
88 
89  // Topology should be set once, from the derived class constructor.
91  _overlayTopology = topology;
92  }
93 
94  // Compute the named datasource. Note that inputDataSource comes from the
95  // source scene index, while parentOverlayDataSource comes from the cache
96  // and is consequently recursively composed.
97  //
98  // XXX: the "parentOverlayDataSource" is here to support eventual inherited
99  // attribute caching, but this feature hasn't been implemented yet. For now,
100  // it will always be null.
101  virtual HdDataSourceBaseHandle _ComputeOverlayDataSource(
102  const TfToken &name,
103  HdContainerDataSourceHandle inputDataSource,
104  HdContainerDataSourceHandle parentOverlayDataSource) const = 0;
105 
106 private:
107  class _HdPrimDataSourceOverlay : public HdContainerDataSource
108  {
109  public:
110  HD_DECLARE_DATASOURCE(_HdPrimDataSourceOverlay);
111 
112  _HdPrimDataSourceOverlay(
113  HdContainerDataSourceHandle inputDataSource,
114  HdContainerDataSourceHandle parentOverlayDataSource,
115  const std::weak_ptr<const HdPrimDataSourceOverlayCache> cache);
116 
117  void UpdateInputDataSource(HdContainerDataSourceHandle inputDataSource);
118 
119  void PrimDirtied(const HdDataSourceLocatorSet &dirtyAttributes);
120 
121  TfTokenVector GetNames() override;
122  HdDataSourceBaseHandle Get(const TfToken &name) override;
123 
124  private:
125  HdContainerDataSourceHandle _inputDataSource;
126  HdContainerDataSourceHandle _parentOverlayDataSource;
127  const std::weak_ptr<const HdPrimDataSourceOverlayCache> _cache;
128 
129  using _OverlayMap = std::map<TfToken, HdDataSourceBaseHandle>;
130 
131  _OverlayMap _overlayMap;
132  };
133 
135  _OverlayTopology _overlayTopology;
136 };
137 
139 
140 #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:69
Definition: token.h:87
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:457
void HandlePrimsRemoved(const HdSceneIndexObserver::RemovedPrimEntries &entries)
GLuint const GLchar * name
Definition: glcorearb.h:786
Definition: path.h:290
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
void HandlePrimsDirtied(const HdSceneIndexObserver::DirtiedPrimEntries &entries, HdSceneIndexObserver::DirtiedPrimEntries *additionalDirtied)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
void _SetOverlayTopology(const _OverlayTopology &topology)
std::map< TfToken, _OverlayDependencies > _OverlayTopology