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 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_HDX_SELECTION_TRACKER_H
25 #define PXR_IMAGING_HDX_SELECTION_TRACKER_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hdx/api.h"
31 #include "pxr/base/vt/array.h"
32 #include <vector>
33 #include <memory>
34 
36 
37 
38 class HdRenderIndex;
39 
41  std::shared_ptr<class HdxSelectionTracker>;
42 
43 /// ----------------------------------------------------------------------------
44 /// Selection highlighting in Hydra:
45 ///
46 /// Hydra Storm (*) supports selection highlighting of:
47 /// (a) a set of rprims, wherein each rprim is entirely highlighted
48 /// (b) a set of instances of an rprim, wherein each instance is highlighted
49 /// (c) a set of subprimitives of an rprim, wherein each subprim is highlighted.
50 /// Subprimitives support is limited to elements (faces of meshes, or
51 /// individual curves of basis curves), edges of meshes/curves,
52 /// and points of meshes.
53 ///
54 /// * While the goal is have an architecture that is extensible by rendering
55 /// backends, the current implementation is heavily influenced by the Storm
56 /// backend.
57 ///
58 /// Background:
59 /// The current selection implementation is, in a sense, global in nature.
60 /// If there are no selected objects, we do not bind any selection-related
61 /// resources, nor does the shader execute any selection-related operations.
62 ///
63 /// If there are one or more selected objects, we *don't* choose to have them
64 /// in a separate 'selection' collection.
65 /// Instead, we stick by AZDO principles and avoid command buffer changes as
66 /// a result of selection updates (which would involve removal of draw items
67 /// corresponding to the selected objects from each render pass' command buffer
68 /// and building the selection pass' command buffer).
69 /// We build an integer buffer encoding of the selected items, for use in the
70 /// fragment shader, that allows us to perform a small number of lookups to
71 /// quickly tell us if a fragment needs to be highlighted.
72 ///
73 /// Conceptually, the implementation is split into:
74 /// (a) HdSelection : Client facing API that builds a collection of selected
75 /// items. This is agnostic of the rendering backend.
76 /// (b) HdxSelectionTracker: Base class that observes (a) and encodes it as
77 /// needed by (c). This may be specialized to be backend specific.
78 /// (c) HdxSelectionTask : A scene task that, currently, only syncs resources
79 /// related to selection highlighting. Currently, this is tied to Storm.
80 /// (d) HdxRenderSetupTask : A scene task that sets up the render pass shader
81 /// to use the selection highlighting mixin in the render pass(es) of
82 /// HdxRenderTask. This is relevant only to Storm.
83 ///
84 /// ----------------------------------------------------------------------------
85 
86 
87 /// \class HdxSelectionTracker
88 ///
89 /// HdxSelectionTracker takes HdSelection and generates a GPU buffer to be used
90 /// \class HdxSelectionTracker
91 ///
92 /// HdxSelectionTracker is a base class for observing selection state and
93 /// providing selection highlighting details to interested clients.
94 ///
95 /// Applications may use HdxSelectionTracker as-is, or extend it as needed.
96 ///
97 /// HdxSelectionTask takes HdxSelectionTracker as a task parameter, and uploads
98 /// the selection buffer encoding to the GPU.
99 ///
101 {
102 public:
103  HDX_API
105  virtual ~HdxSelectionTracker();
106 
107  /// Optional override to update the HdSelection during
108  /// HdxSelectionTask::Prepare.
109  HDX_API
110  virtual void UpdateSelection(HdRenderIndex *index);
111 
112  /// Encodes the selection state (HdxSelection) as an integer array. This is
113  /// uploaded to the GPU and decoded in the fragment shader to provide
114  /// selection highlighting behavior. See HdxSelectionTask.
115  /// Returns true if offsets has anything selected.
116  /// \p enableSelection is a global on/off switch for selection; if it's
117  /// false, nothing will be encoded.
118  HDX_API
119  virtual bool GetSelectionOffsetBuffer(HdRenderIndex const *index,
120  bool enableSelection,
121  VtIntArray *offsets) const;
122 
123  HDX_API
124  virtual VtVec4fArray GetSelectedPointColors() const;
125 
126  /// Returns a monotonically increasing version number, which increments
127  /// whenever the result of GetBuffers has changed. Note that this number may
128  /// overflow and become negative, thus clients should use a not-equal
129  /// comparison.
130  HDX_API
131  int GetVersion() const;
132 
133  /// The collection of selected objects is expected to be created externally
134  /// and set via SetSelection.
135  HDX_API
137  _selection = selection;
139  }
140 
141  /// XXX: Rename to GetSelection
142  HDX_API
144  return _selection;
145  }
146 
147 protected:
148  /// Increments the internal selection state version, used for invalidation
149  /// via GetVersion().
150  HDX_API
151  void _IncrementVersion();
152 
153  HDX_API
155  HdRenderIndex const* index,
156  size_t modeOffset,
157  std::vector<int>* offsets) const;
158 
159 private:
160  int _version;
161  HdSelectionSharedPtr _selection;
162 };
163 
164 
166 
167 #endif //PXR_IMAGING_HDX_SELECTION_TRACKER_H
GT_API const UT_StringHolder selection
HDX_API HdSelectionSharedPtr const & GetSelectionMap() const
XXX: Rename to GetSelection.
virtual ~HdxSelectionTracker()
virtual HDX_API bool _GetSelectionOffsets(HdSelection::HighlightMode const &mode, HdRenderIndex const *index, size_t modeOffset, std::vector< int > *offsets) const
GLuint GLsizei const GLuint const GLintptr * offsets
Definition: glcorearb.h:2620
#define HDX_API
Definition: api.h:40
std::shared_ptr< class HdxSelectionTracker > HdxSelectionTrackerSharedPtr
virtual HDX_API VtVec4fArray GetSelectedPointColors() const
HighlightMode
Selection modes allow differentiation in selection highlight behavior.
Definition: selection.h:55
GLenum mode
Definition: glcorearb.h:98
virtual HDX_API void UpdateSelection(HdRenderIndex *index)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1375
GLuint index
Definition: glcorearb.h:785
HDX_API int GetVersion() const
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HDX_API HdxSelectionTracker()
HDX_API void _IncrementVersion()
virtual HDX_API bool GetSelectionOffsetBuffer(HdRenderIndex const *index, bool enableSelection, VtIntArray *offsets) const
std::shared_ptr< class HdSelection > HdSelectionSharedPtr
Definition: selection.h:40
HDX_API void SetSelection(HdSelectionSharedPtr const &selection)