HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
repr.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_HD_REPR_H
25 #define PXR_IMAGING_HD_REPR_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
30 #include "pxr/imaging/hd/tokens.h"
31 #include <vector>
32 
34 
35 
36 /// \class HdReprSelector
37 ///
38 /// Describes one or more authored display representations for an rprim.
39 /// Display opinions are separated by the topology index they represent.
40 /// This allows the application to specify one or more topological
41 /// representations for a given HdRprim.
42 /// For some visualizations, an application may choose to provide an opinion for
43 /// the display of the refined surface, the unrefined hull and the points
44 /// separately from the rprim's authored opinions.
45 /// HdReprSelector allows these opinions to compose/merge into a final composite
46 /// representation to be used for rendering.
47 ///
49 {
50 public:
51  explicit HdReprSelector()
52  : refinedToken()
53  , unrefinedToken()
54  , pointsToken() { }
55 
56  explicit HdReprSelector(TfToken const &token)
57  : refinedToken(token)
58  , unrefinedToken()
59  , pointsToken() { }
60 
61  explicit HdReprSelector(
62  TfToken const &refined,
63  TfToken const &unrefined)
64  : refinedToken(refined)
65  , unrefinedToken(unrefined)
66  , pointsToken() { }
67 
68  explicit HdReprSelector(
69  TfToken const &refined,
70  TfToken const &unrefined,
71  TfToken const &points)
72  : refinedToken(refined)
73  , unrefinedToken(unrefined)
74  , pointsToken(points) { }
75 
76  /// Currenly support upto 3 topology tokens.
77  static const size_t MAX_TOPOLOGY_REPRS = 3;
78 
79  /// Returns true if the passed in reprToken is in the set of tokens
80  /// for any topology index.
81  HD_API
82  bool Contains(const TfToken &reprToken) const;
83 
84  /// Returns true if the topology token at an index is active, i.e., neither
85  /// empty nor disabled.
86  HD_API
87  bool IsActiveRepr(size_t topologyIndex) const;
88 
89  /// Returns true if any of the topology tokens is valid, i.e., neither
90  /// empty nor disabled.
91  HD_API
92  bool AnyActiveRepr() const;
93 
94  /// Returns a selector that is the composite of this selector 'over'
95  /// the passed in selector.
96  /// For each token that IsEmpty in this selector return the corresponding
97  /// token in the passed in selector.
98  /// Effectively this performs a merge operation where this selector wins
99  /// for each topological index it has an opinion on.
100  HD_API
101  HdReprSelector CompositeOver(const HdReprSelector &under) const;
102 
103  HD_API
104  bool operator==(const HdReprSelector &rhs) const;
105 
106  HD_API
107  bool operator!=(const HdReprSelector &rhs) const;
108 
109  HD_API
110  bool operator<(const HdReprSelector &rhs) const;
111 
112  HD_API
113  size_t Hash() const;
114 
115  HD_API
116  char const* GetText() const;
117 
118  HD_API
119  friend std::ostream &operator <<(std::ostream &stream,
120  HdReprSelector const& t);
121 
122 
123  HD_API
124  TfToken const &operator[](size_t topologyIndex) const;
125 
126 private:
127  // TfHash support.
128  template <class HashState>
129  friend void
130  TfHashAppend(HashState &h, HdReprSelector const &rs) {
131  h.Append(rs.refinedToken, rs.unrefinedToken, rs.pointsToken);
132  }
133 
134  TfToken refinedToken;
135  TfToken unrefinedToken;
136  TfToken pointsToken;
137 };
138 
139 
140 /// \class HdRepr
141 ///
142 /// An HdRepr refers to a (single) topological representation of an rprim, and
143 /// owns the draw item(s) that visually represent it. The draw items are
144 /// populated by the rprim.
145 /// The relevant compositional hierarchy is:
146 ///
147 /// HdRprim
148 /// |
149 /// +--HdRepr(s)
150 /// |
151 /// +--HdDrawItem(s)
152 ///
153 /// When multiple topological representations are required for an rprim, we use
154 /// HdReprSelector to compose the individual representations.
155 ///
156 class HdRepr final
157 {
158 public:
159  using DrawItemUniquePtr = std::unique_ptr<HdDrawItem>;
160  using DrawItemUniquePtrVector = std::vector<DrawItemUniquePtr>;
161 
162  HD_API
163  HdRepr();
164  HD_API
165  ~HdRepr();
166 
167  /// Returns the draw items for this representation.
169  return _drawItems;
170  }
171 
172  /// Transfers ownership of a draw item to this repr.
173  /// Do not use for adding geom subset draw items.
174  void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
175  _drawItems.insert(_drawItems.begin() + _geomSubsetsStart,
176  std::move(item));
177  _geomSubsetsStart++;
178  }
179 
180  /// Returns the draw item at the requested index.
181  ///
182  /// Note that the pointer returned is owned by this object and must not be
183  /// deleted.
184  HdDrawItem* GetDrawItem(size_t index) const {
185  return _drawItems[index].get();
186  }
187 
188  /// HdRepr can hold geom subset draw items, which are unique in that they
189  /// not created at the time the repr is created, but instead when populating
190  /// the mesh topology of a mesh rprim. The number of geom subset draw items
191  /// in a repr can change over time.
192  /// We make some assumptions when using these geom subset related functions.
193  /// We assume the geom subset draw items will only be added (or cleared)
194  /// after all of the main draw items for a repr have been added.
195  /// We also assume that the geom subset draw items for a repr desc are all
196  /// added one after the other before moving onto the next repr desc.
197  /// Thus the order of draw items in the _drawItems member might go something
198  /// like (assuming two repr descs and three geom subsets in this example):
199  /// [ main DI for desc 1, main DI for desc 2, GS1 DI for desc 1,
200  /// GS2 DI for desc 1, GS3 DI for desc 1, GS1 DI for desc 2,
201  /// GS2 DI for desc 2, GS3 DI for desc 2 ]
202  /// It is also possible for there to exist a main draw item for a particular
203  /// repr desc but no geom subsets for that repr desc, while having geom
204  /// subsets exist for a different repr desc.
205 
206  /// Transfers ownership of a draw item to this repr.
207  /// To be used only for geom subset draw items.
208  void AddGeomSubsetDrawItem(std::unique_ptr<HdDrawItem> &&item) {
209  _drawItems.push_back(std::move(item));
210  }
211 
212  /// Utility similar to GetDrawItem for getting geom subset draw items.
213  HdDrawItem* GetDrawItemForGeomSubset(size_t reprDescIndex,
214  size_t numGeomSubsets, size_t geomSubsetIndex) const {
215  return _drawItems[_geomSubsetsStart + reprDescIndex * numGeomSubsets +
216  geomSubsetIndex].get();
217  }
218 
219  /// Removes all of the geom subset draw items from the repr.
221  _drawItems.erase(
222  _drawItems.begin() + _geomSubsetsStart, _drawItems.end());
223  }
224 
225 private:
226  // Noncopyable
227  HdRepr(const HdRepr&) = delete;
228  HdRepr& operator=(const HdRepr&) = delete;
229 
230 private:
231  // Contains normal draw items first, potentially followed by geom subset
232  // draw items
233  DrawItemUniquePtrVector _drawItems;
234 
235  // Index into _drawItems indicating where the geom subset draw items begin.
236  size_t _geomSubsetsStart;
237 };
238 
239 
241 
242 #endif //PXR_IMAGING_HD_REPR_H
GLuint GLuint stream
Definition: glcorearb.h:1832
void ClearGeomSubsetDrawItems()
Removes all of the geom subset draw items from the repr.
Definition: repr.h:220
GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glad.h:2676
std::unique_ptr< HdDrawItem > DrawItemUniquePtr
Definition: repr.h:159
HD_API bool operator<(const HdReprSelector &rhs) const
HD_API friend std::ostream & operator<<(std::ostream &stream, HdReprSelector const &t)
HD_API bool operator==(const HdReprSelector &rhs) const
#define HD_API
Definition: api.h:40
friend void TfHashAppend(HashState &h, HdReprSelector const &rs)
Definition: repr.h:130
HD_API TfToken const & operator[](size_t topologyIndex) const
HdDrawItem * GetDrawItem(size_t index) const
Definition: repr.h:184
Definition: token.h:87
HdReprSelector(TfToken const &token)
Definition: repr.h:56
HD_API size_t Hash() const
HdReprSelector()
Definition: repr.h:51
HD_API bool operator!=(const HdReprSelector &rhs) const
static const size_t MAX_TOPOLOGY_REPRS
Currenly support upto 3 topology tokens.
Definition: repr.h:77
HD_API bool Contains(const TfToken &reprToken) const
HdReprSelector(TfToken const &refined, TfToken const &unrefined, TfToken const &points)
Definition: repr.h:68
GLdouble t
Definition: glad.h:2397
HdDrawItem * GetDrawItemForGeomSubset(size_t reprDescIndex, size_t numGeomSubsets, size_t geomSubsetIndex) const
Utility similar to GetDrawItem for getting geom subset draw items.
Definition: repr.h:213
HD_API char const * GetText() const
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
HD_API bool AnyActiveRepr() const
HD_API bool IsActiveRepr(size_t topologyIndex) const
std::vector< DrawItemUniquePtr > DrawItemUniquePtrVector
Definition: repr.h:160
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
HD_API HdReprSelector CompositeOver(const HdReprSelector &under) const
GLuint index
Definition: glcorearb.h:786
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
HdReprSelector(TfToken const &refined, TfToken const &unrefined)
Definition: repr.h:61
HD_API HdRepr()
const DrawItemUniquePtrVector & GetDrawItems() const
Returns the draw items for this representation.
Definition: repr.h:168
void AddDrawItem(std::unique_ptr< HdDrawItem > &&item)
Definition: repr.h:174
Definition: repr.h:156
HD_API ~HdRepr()
void AddGeomSubsetDrawItem(std::unique_ptr< HdDrawItem > &&item)
Definition: repr.h:208