HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
selectionTracker.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 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_HDX_SELECTION_TRACKER_H
8 #define PXR_IMAGING_HDX_SELECTION_TRACKER_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hdx/api.h"
14 #include "pxr/base/vt/array.h"
15 #include <vector>
16 #include <memory>
17 
19 
20 
21 class HdRenderIndex;
22 
24  std::shared_ptr<class HdxSelectionTracker>;
25 
26 /// ----------------------------------------------------------------------------
27 /// Selection highlighting in Hydra:
28 ///
29 /// Hydra Storm (*) supports selection highlighting of:
30 /// (a) a set of rprims, wherein each rprim is entirely highlighted
31 /// (b) a set of instances of an rprim, wherein each instance is highlighted
32 /// (c) a set of subprimitives of an rprim, wherein each subprim is highlighted.
33 /// Subprimitives support is limited to elements (faces of meshes, or
34 /// individual curves of basis curves), edges of meshes/curves,
35 /// and points of meshes.
36 ///
37 /// * While the goal is have an architecture that is extensible by rendering
38 /// backends, the current implementation is heavily influenced by the Storm
39 /// backend.
40 ///
41 /// Background:
42 /// The current selection implementation is, in a sense, global in nature.
43 /// If there are no selected objects, we do not bind any selection-related
44 /// resources, nor does the shader execute any selection-related operations.
45 ///
46 /// If there are one or more selected objects, we *don't* choose to have them
47 /// in a separate 'selection' collection.
48 /// Instead, we stick by AZDO principles and avoid command buffer changes as
49 /// a result of selection updates (which would involve removal of draw items
50 /// corresponding to the selected objects from each render pass' command buffer
51 /// and building the selection pass' command buffer).
52 /// We build an integer buffer encoding of the selected items, for use in the
53 /// fragment shader, that allows us to perform a small number of lookups to
54 /// quickly tell us if a fragment needs to be highlighted.
55 ///
56 /// For scene indices, the HdxSelectionTracker uses the HdSelectionsSchema
57 /// (instaniated with GetFromParent of a prim data source) for a prim to
58 /// determine the prim's selection status. However, to support scene delegates,
59 /// we do support settings the selection directly with SetSelection.
60 /// If both are used, the union of the selections is taken.
61 ///
62 /// Conceptually, the implementation is split into:
63 /// (a) HdSelection (for clients using scene delegates) : Client facing API
64 /// that builds a collection of selected items. This is agnostic of the
65 /// rendering backend.
66 /// HdSelectionsSchema (for clients using scene indices) : Scene indices
67 /// can populate this schema for each selected prim.
68 /// (b) HdxSelectionTracker: Base class that observes (a) and encodes it as
69 /// needed by (c). This may be specialized to be backend specific.
70 /// (c) HdxSelectionTask : A scene task that, currently, only syncs resources
71 /// related to selection highlighting. Currently, this is tied to Storm.
72 /// (d) HdxRenderSetupTask : A scene task that sets up the render pass shader
73 /// to use the selection highlighting mixin in the render pass(es) of
74 /// HdxRenderTask. This is relevant only to Storm.
75 ///
76 /// ----------------------------------------------------------------------------
77 
78 
79 /// \class HdxSelectionTracker
80 ///
81 /// HdxSelectionTracker takes HdSelection and generates a GPU buffer to be used
82 /// \class HdxSelectionTracker
83 ///
84 /// HdxSelectionTracker is a base class for observing selection state and
85 /// providing selection highlighting details to interested clients.
86 ///
87 /// Applications may use HdxSelectionTracker as-is, or extend it as needed.
88 ///
89 /// HdxSelectionTask takes HdxSelectionTracker as a task parameter, and uploads
90 /// the selection buffer encoding to the GPU.
91 ///
93 {
94 public:
95  HDX_API
97 
98  HDX_API
99  virtual ~HdxSelectionTracker();
100 
101  /// Optional override to update the selection (either compute HdSelection and
102  /// call SetSelection or update a scene index with selection information using
103  /// the HdSelectionsSchema) during HdxSelectionTask::Prepare.
104  HDX_API
105  virtual void UpdateSelection(HdRenderIndex *index);
106 
107  /// Encodes the selection state (HdxSelection) as an integer array. This is
108  /// uploaded to the GPU and decoded in the fragment shader to provide
109  /// selection highlighting behavior. See HdxSelectionTask.
110  /// Returns true if offsets has anything selected.
111  /// \p enableSelectionHighlight will populate selection buffer for any
112  /// active selection highlighting if true.
113  /// \p enableLocateHighlight will populate selection buffer for any active
114  /// locate (rollover) highlighting if true.
115  HDX_API
116  virtual bool GetSelectionOffsetBuffer(const HdRenderIndex *index,
117  bool enableSelectionHighlight,
118  bool enableLocateHighlight,
119  VtIntArray *offsets) const;
120 
121  HDX_API
122  virtual VtVec4fArray GetSelectedPointColors(const HdRenderIndex *index);
123 
124  /// Returns a monotonically increasing version number, which increments
125  /// whenever the result of GetBuffers has changed. Note that this number may
126  /// overflow and become negative, thus clients should use a not-equal
127  /// comparison.
128  HDX_API
129  int GetVersion() const;
130 
131  /// Set the collection of selected objects. The ultimate selection (used for
132  /// selection highlighting) will be the union of the collection set here and
133  /// the one computed by querying the scene indices (using the
134  /// HdxSelectionSceneIndexObserver).
135  HDX_API
137 
138  /// Returns selection set with SetSelection.
139  ///
140  /// XXX: Rename to GetSelection
141  HDX_API
142  HdSelectionSharedPtr const &GetSelectionMap() const;
143 
144 protected:
145  /// Increments the internal selection state version, used for invalidation
146  /// via GetVersion().
147  HDX_API
148  void _IncrementVersion();
149 
150 private:
151  bool _GetSelectionOffsets(HdSelectionSharedPtr const &selection,
153  const HdRenderIndex *index,
154  size_t modeOffset,
155  std::vector<int>* offsets) const;
156 
157  // A helper class to obtain the union of the selection computed
158  // by querying the scene indices (with the HdxSelectionSceneIndexObserver)
159  // and the selection set with SetSelection.
160  class _MergedSelection;
161  std::unique_ptr<_MergedSelection> _mergedSelection;
162 };
163 
164 
166 
167 #endif //PXR_IMAGING_HDX_SELECTION_TRACKER_H
GT_API const UT_StringHolder selection
HDX_API HdSelectionSharedPtr const & GetSelectionMap() const
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:39
#define HDX_API
Definition: api.h:23
std::shared_ptr< class HdxSelectionTracker > HdxSelectionTrackerSharedPtr
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2621
virtual HDX_API bool GetSelectionOffsetBuffer(const HdRenderIndex *index, bool enableSelectionHighlight, bool enableLocateHighlight, VtIntArray *offsets) const
virtual HDX_API VtVec4fArray GetSelectedPointColors(const HdRenderIndex *index)
GLenum mode
Definition: glcorearb.h:99
virtual HDX_API void UpdateSelection(HdRenderIndex *index)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
GLuint index
Definition: glcorearb.h:786
HDX_API int GetVersion() const
virtual HDX_API ~HdxSelectionTracker()
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
HDX_API HdxSelectionTracker()
HDX_API void _IncrementVersion()
std::shared_ptr< class HdSelection > HdSelectionSharedPtr
Definition: selection.h:23
HDX_API void SetSelection(HdSelectionSharedPtr const &selection)