All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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 
173  void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
174  _drawItems.push_back(std::move(item));
175  }
176 
181  HdDrawItem* GetDrawItem(size_t index) const {
182  return _drawItems[index].get();
183  }
184 
185 private:
186  // Noncopyable
187  HdRepr(const HdRepr&) = delete;
188  HdRepr& operator=(const HdRepr&) = delete;
189 
190 private:
191  DrawItemUniquePtrVector _drawItems;
192 };
193 
194 
195 PXR_NAMESPACE_CLOSE_SCOPE
196 
197 #endif //PXR_IMAGING_HD_REPR_H
void AddDrawItem(std::unique_ptr< HdDrawItem > &&item)
Transfers ownership of a draw item to this repr.
Definition: repr.h:173
const DrawItemUniquePtrVector & GetDrawItems() const
Returns the draw items for this representation.
Definition: repr.h:168
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
HD_API bool AnyActiveRepr() const
Returns true if any of the topology tokens is valid, i.e., neither empty nor disabled.
A draw item is a light-weight representation of an HdRprim&#39;s resources and material to be used for re...
Definition: drawItem.h:66
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...
Describes one or more authored display representations for an rprim.
Definition: repr.h:48
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
Returns true if the passed in reprToken is in the set of tokens for any topology index.
HD_API HdReprSelector CompositeOver(const HdReprSelector &under) const
Returns a selector that is the composite of this selector &#39;over&#39; the passed in selector.
HdDrawItem * GetDrawItem(size_t index) const
Returns the draw item at the requested index.
Definition: repr.h:181
An HdRepr refers to a (single) topological representation of an rprim, and owns the draw item(s) that...
Definition: repr.h:156