repr.h
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"
29 #include "pxr/imaging/hd/drawItem.h"
30 #include "pxr/imaging/hd/tokens.h"
31 #include <vector>
32 
33 PXR_NAMESPACE_OPEN_SCOPE
34 
35 
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 
77  static const size_t MAX_TOPOLOGY_REPRS = 3;
78 
81  HD_API
82  bool Contains(const TfToken &reprToken) const;
83 
86  HD_API
87  bool IsActiveRepr(size_t topologyIndex) const;
88 
91  HD_API
92  bool AnyActiveRepr() const;
93 
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 
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 
168  const DrawItemUniquePtrVector& GetDrawItems() const {
169  return _drawItems;
170  }
171 
174  void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
175  _drawItems.insert(_drawItems.begin() + _geomSubsetsStart,
176  std::move(item));
177  _geomSubsetsStart++;
178  }
179 
184  HdDrawItem* GetDrawItem(size_t index) const {
185  return _drawItems[index].get();
186  }
187 
205 
208  void AddGeomSubsetDrawItem(std::unique_ptr<HdDrawItem> &&item) {
209  _drawItems.push_back(std::move(item));
210  }
211 
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 
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 
240 PXR_NAMESPACE_CLOSE_SCOPE
241 
242 #endif //PXR_IMAGING_HD_REPR_H
HD_API bool IsActiveRepr(size_t topologyIndex) const
Returns true if the topology token at an index is active, i.e., neither empty nor disabled.
HD_API bool Contains(const TfToken &reprToken) const
Returns true if the passed in reprToken is in the set of tokens for any topology index.
void AddDrawItem(std::unique_ptr< HdDrawItem > &&item)
Transfers ownership of a draw item to this repr.
Definition: repr.h:174
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
void ClearGeomSubsetDrawItems()
Removes all of the geom subset draw items from the repr.
Definition: repr.h:220
const DrawItemUniquePtrVector & GetDrawItems() const
Returns the draw items for this representation.
Definition: repr.h:168
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
Definition: drawItem.h:64
void AddGeomSubsetDrawItem(std::unique_ptr< HdDrawItem > &&item)
HdRepr can hold geom subset draw items, which are unique in that they not created at the time the rep...
Definition: repr.h:208
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
HD_API bool AnyActiveRepr() const
Returns true if any of the topology tokens is valid, i.e., neither empty nor disabled.
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 HdReprSelector CompositeOver(const HdReprSelector &under) const
Returns a selector that is the composite of this selector 'over' the passed in selector.
static const size_t MAX_TOPOLOGY_REPRS
Currenly support upto 3 topology tokens.
Definition: repr.h:77
HdDrawItem * GetDrawItem(size_t index) const
Returns the draw item at the requested index.
Definition: repr.h:184
An HdRepr refers to a (single) topological representation of an rprim, and owns the draw item(s) that...
Definition: repr.h:156