switchingSceneIndex.h
1 //
2 // Copyright 2024 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 #ifndef PXR_IMAGING_HDSI_SWITCHING_SCENE_INDEX_H
7 #define PXR_IMAGING_HDSI_SWITCHING_SCENE_INDEX_H
8 
9 #include "pxr/pxr.h"
10 
11 #include "pxr/imaging/hd/filteringSceneIndex.h"
12 #include "pxr/imaging/hdsi/api.h"
13 #include "pxr/imaging/hdsi/computeSceneIndexDiff.h"
14 
15 PXR_NAMESPACE_OPEN_SCOPE
16 
19 
27 {
28 public:
29  using ComputeDiffFn = HdsiComputeSceneIndexDiff;
30 
31  static HdsiSwitchingSceneIndexRefPtr
32  New(const std::vector<HdSceneIndexBaseRefPtr>& inputs,
33  size_t initialIndex = 0,
34  ComputeDiffFn computeDiffFn = HdsiComputeSceneIndexDiffDelta)
35  {
36  return TfCreateRefPtr(new HdsiSwitchingSceneIndex(
37  inputs, initialIndex, std::move(computeDiffFn)));
38  }
39 
40 protected:
41  HDSI_API
43  const std::vector<HdSceneIndexBaseRefPtr>& inputs,
44  size_t initialIndex,
45  ComputeDiffFn computeDiffFn);
46 
47 public:
49  HDSI_API
50  size_t GetIndex() const;
51 
55  HDSI_API
56  void SetIndex(size_t index);
57 
58 public: // satisfying HdFilteringSceneIndexBase
59  HDSI_API
60  std::vector<HdSceneIndexBaseRefPtr> GetInputScenes() const override;
61 
62 public: // satisfying HdSceneIndexBase
63  HDSI_API
64  HdSceneIndexPrim GetPrim(const SdfPath& primPath) const override;
65 
66  HDSI_API
67  SdfPathVector GetChildPrimPaths(const SdfPath& primPath) const override;
68 
69 private:
70  void _UpdateCurrentSceneIndex(size_t index);
71 
72  void _PrimsAdded(
73  const HdSceneIndexBase& sender,
75 
76  void _PrimsRemoved(
77  const HdSceneIndexBase& sender,
79 
80  void _PrimsDirtied(
81  const HdSceneIndexBase& sender,
83 
84  void _PrimsRenamed(
85  const HdSceneIndexBase& sender,
87 
88  friend class _Observer;
89  class _Observer final : public HdSceneIndexObserver
90  {
91  public:
92  _Observer(HdsiSwitchingSceneIndex* owner)
93  : _owner(owner)
94  {
95  }
96 
97  public: // satisfying HdSceneIndexObserver
98  void PrimsAdded(
99  const HdSceneIndexBase& sender,
100  const AddedPrimEntries& entries) override;
101  void PrimsRemoved(
102  const HdSceneIndexBase& sender,
103  const RemovedPrimEntries& entries) override;
104  void PrimsDirtied(
105  const HdSceneIndexBase& sender,
106  const DirtiedPrimEntries& entries) override;
107  void PrimsRenamed(
108  const HdSceneIndexBase& sender,
109  const RenamedPrimEntries& entries) override;
110 
111  private:
112  HdsiSwitchingSceneIndex* _owner;
113  };
114 
115  _Observer _observer;
116 
117  std::vector<HdSceneIndexBaseRefPtr> _inputs;
118  size_t _index = 0;
119  HdSceneIndexBaseRefPtr _currentSceneIndex;
120 
121  ComputeDiffFn _computeDiffFn;
122 };
123 
124 PXR_NAMESPACE_CLOSE_SCOPE
125 
126 #endif
This is a scene index that can switch between multiple inputs (which are fixed at construction time).
HDSI_API size_t GetIndex() const
Returns the current index.
Small struct representing a 'prim' in the Hydra scene index.
Definition: sceneIndex.h:35
Observer of scene data.
Abstract interface to scene data.
Definition: sceneIndex.h:54
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:280
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
Returns the paths of all scene index prims located immediately below primPath.
An abstract base class for scene indexes that have one or more input scene indexes which serve as a b...
#define TF_DECLARE_REF_PTRS(type)
Define standard ref pointer types.
Definition: declarePtrs.h:58
HDSI_API void SetIndex(size_t index)
Sets the current index.
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
Returns a pair of (prim type, datasource).