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  TfToken refinedToken;
128  TfToken unrefinedToken;
129  TfToken pointsToken;
130 };
131 
132 /// \class HdRepr
133 ///
134 /// An HdRepr refers to a (single) topological representation of an rprim, and
135 /// owns the draw item(s) that visually represent it. The draw items are
136 /// populated by the rprim.
137 /// The relevant compositional hierarchy is:
138 ///
139 /// HdRprim
140 /// |
141 /// +--HdRepr(s)
142 /// |
143 /// +--HdDrawItem(s)
144 ///
145 /// When multiple topological representations are required for an rprim, we use
146 /// HdReprSelector to compose the individual representations.
147 ///
148 class HdRepr final
149 {
150 public:
151  using DrawItemUniquePtr = std::unique_ptr<HdDrawItem>;
152  using DrawItemUniquePtrVector = std::vector<DrawItemUniquePtr>;
153 
154  HD_API
155  HdRepr();
156  HD_API
157  ~HdRepr();
158 
159  /// Returns the draw items for this representation.
161  return _drawItems;
162  }
163 
164  /// Transfers ownership of a draw item to this repr.
165  void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
166  _drawItems.push_back(std::move(item));
167  }
168 
169  /// Returns the draw item at the requested index.
170  ///
171  /// Note that the pointer returned is owned by this object and must not be
172  /// deleted.
173  HdDrawItem* GetDrawItem(size_t index) const {
174  return _drawItems[index].get();
175  }
176 
177 private:
178  // Noncopyable
179  HdRepr(const HdRepr&) = delete;
180  HdRepr& operator=(const HdRepr&) = delete;
181 
182 private:
183  DrawItemUniquePtrVector _drawItems;
184 };
185 
186 
188 
189 #endif //PXR_IMAGING_HD_REPR_H
GLuint GLuint stream
Definition: glew.h:7265
std::unique_ptr< HdDrawItem > DrawItemUniquePtr
Definition: repr.h:151
GLuint index
Definition: glew.h:1814
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
HD_API TfToken const & operator[](size_t topologyIndex) const
HdDrawItem * GetDrawItem(size_t index) const
Definition: repr.h:173
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
HD_API char const * GetText() const
HD_API bool AnyActiveRepr() const
HD_API bool IsActiveRepr(size_t topologyIndex) const
std::vector< DrawItemUniquePtr > DrawItemUniquePtrVector
Definition: repr.h:152
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1346
HD_API HdReprSelector CompositeOver(const HdReprSelector &under) const
GLuint GLdouble GLdouble GLint GLint const GLdouble * points
Definition: glew.h:3446
#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:160
void AddDrawItem(std::unique_ptr< HdDrawItem > &&item)
Transfers ownership of a draw item to this repr.
Definition: repr.h:165
Definition: repr.h:148
GLdouble GLdouble t
Definition: glew.h:1398
HD_API ~HdRepr()