HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
switchingSceneIndex.h
Go to the documentation of this file.
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 
12 #include "pxr/imaging/hdsi/api.h"
14 
16 
19 
20 /// This is a scene index that can switch between multiple inputs (which are
21 /// fixed at construction time).
22 ///
23 /// By default, this scene index will use `HdsiComputeSceneIndexDelta` to
24 /// compute notices to send when the index is changed. If you know more about
25 /// the input scenes, you can likely provide a more efficient/specialized one.
27 {
28 public:
30 
31  static HdsiSwitchingSceneIndexRefPtr
32  New(const std::vector<HdSceneIndexBaseRefPtr>& inputs,
33  size_t initialIndex = 0,
35  {
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:
48  /// Returns the current index.
49  HDSI_API
50  size_t GetIndex() const;
51 
52  /// Sets the current index.
53  ///
54  /// Index must be in `[0, GetInputScenes().size())`.
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:
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 
125 
126 #endif
HdsiComputeSceneIndexDiff ComputeDiffFn
TfRefPtr< T > TfCreateRefPtr(T *ptr)
Definition: refPtr.h:1190
HDSI_API void HdsiComputeSceneIndexDiffDelta(const HdSceneIndexBaseRefPtr &siA, const HdSceneIndexBaseRefPtr &siB, HdSceneIndexObserver::RemovedPrimEntries *removedEntries, HdSceneIndexObserver::AddedPrimEntries *addedEntries, HdSceneIndexObserver::RenamedPrimEntries *renamedEntries, HdSceneIndexObserver::DirtiedPrimEntries *dirtiedEntries)
std::function< void(const HdSceneIndexBaseRefPtr &siA, const HdSceneIndexBaseRefPtr &siB, HdSceneIndexObserver::RemovedPrimEntries *removedEntries, HdSceneIndexObserver::AddedPrimEntries *addedEntries, HdSceneIndexObserver::RenamedPrimEntries *renamedEntries, HdSceneIndexObserver::DirtiedPrimEntries *dirtiedEntries)> HdsiComputeSceneIndexDiff
HDSI_API HdSceneIndexPrim GetPrim(const SdfPath &primPath) const override
HDSI_API SdfPathVector GetChildPrimPaths(const SdfPath &primPath) const override
HDSI_API HdsiSwitchingSceneIndex(const std::vector< HdSceneIndexBaseRefPtr > &inputs, size_t initialIndex, ComputeDiffFn computeDiffFn)
HDSI_API size_t GetIndex() const
Returns the current index.
TF_DECLARE_REF_PTRS(HdsiSwitchingSceneIndex)
std::vector< class SdfPath > SdfPathVector
HDSI_API std::vector< HdSceneIndexBaseRefPtr > GetInputScenes() const override
Definition: path.h:273
#define HDSI_API
Definition: api.h:23
static HdsiSwitchingSceneIndexRefPtr New(const std::vector< HdSceneIndexBaseRefPtr > &inputs, size_t initialIndex=0, ComputeDiffFn computeDiffFn=HdsiComputeSceneIndexDiffDelta)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDSI_API void SetIndex(size_t index)