All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
repr.h
1//
2// Copyright 2016 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7#ifndef PXR_IMAGING_HD_REPR_H
8#define PXR_IMAGING_HD_REPR_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/drawItem.h"
13#include "pxr/imaging/hd/tokens.h"
14#include <vector>
15
16PXR_NAMESPACE_OPEN_SCOPE
17
18
32{
33public:
34 explicit HdReprSelector()
35 : refinedToken()
36 , unrefinedToken()
37 , pointsToken() { }
38
39 explicit HdReprSelector(TfToken const &token)
40 : refinedToken(token)
41 , unrefinedToken()
42 , pointsToken() { }
43
44 explicit HdReprSelector(
45 TfToken const &refined,
46 TfToken const &unrefined)
47 : refinedToken(refined)
48 , unrefinedToken(unrefined)
49 , pointsToken() { }
50
51 explicit HdReprSelector(
52 TfToken const &refined,
53 TfToken const &unrefined,
54 TfToken const &points)
55 : refinedToken(refined)
56 , unrefinedToken(unrefined)
57 , pointsToken(points) { }
58
60 static const size_t MAX_TOPOLOGY_REPRS = 3;
61
64 HD_API
65 bool Contains(const TfToken &reprToken) const;
66
69 HD_API
70 bool IsActiveRepr(size_t topologyIndex) const;
71
74 HD_API
75 bool AnyActiveRepr() const;
76
83 HD_API
85
86 HD_API
87 bool operator==(const HdReprSelector &rhs) const;
88
89 HD_API
90 bool operator!=(const HdReprSelector &rhs) const;
91
92 HD_API
93 bool operator<(const HdReprSelector &rhs) const;
94
95 HD_API
96 size_t Hash() const;
97
98 HD_API
99 char const* GetText() const;
100
101 HD_API
102 friend std::ostream &operator <<(std::ostream &stream,
103 HdReprSelector const& t);
104
105
106 HD_API
107 TfToken const &operator[](size_t topologyIndex) const;
108
109private:
110 // TfHash support.
111 template <class HashState>
112 friend void
113 TfHashAppend(HashState &h, HdReprSelector const &rs) {
114 h.Append(rs.refinedToken, rs.unrefinedToken, rs.pointsToken);
115 }
116
117 TfToken refinedToken;
118 TfToken unrefinedToken;
119 TfToken pointsToken;
120};
121
122
139class HdRepr final
140{
141public:
142 using DrawItemUniquePtr = std::unique_ptr<HdDrawItem>;
143 using DrawItemUniquePtrVector = std::vector<DrawItemUniquePtr>;
144
145 HD_API
146 HdRepr();
147 HD_API
148 ~HdRepr();
149
151 const DrawItemUniquePtrVector& GetDrawItems() const {
152 return _drawItems;
153 }
154
157 void AddDrawItem(std::unique_ptr<HdDrawItem> &&item) {
158 _drawItems.insert(_drawItems.begin() + _geomSubsetsStart,
159 std::move(item));
160 _geomSubsetsStart++;
161 }
162
167 HdDrawItem* GetDrawItem(size_t index) const {
168 return _drawItems[index].get();
169 }
170
188
191 void AddGeomSubsetDrawItem(std::unique_ptr<HdDrawItem> &&item) {
192 _drawItems.push_back(std::move(item));
193 }
194
196 HdDrawItem* GetDrawItemForGeomSubset(size_t reprDescIndex,
197 size_t numGeomSubsets, size_t geomSubsetIndex) const {
198 return _drawItems[_geomSubsetsStart + reprDescIndex * numGeomSubsets +
199 geomSubsetIndex].get();
200 }
201
204 _drawItems.erase(
205 _drawItems.begin() + _geomSubsetsStart, _drawItems.end());
206 }
207
208private:
209 // Noncopyable
210 HdRepr(const HdRepr&) = delete;
211 HdRepr& operator=(const HdRepr&) = delete;
212
213private:
214 // Contains normal draw items first, potentially followed by geom subset
215 // draw items
216 DrawItemUniquePtrVector _drawItems;
217
218 // Index into _drawItems indicating where the geom subset draw items begin.
219 size_t _geomSubsetsStart;
220};
221
222
223PXR_NAMESPACE_CLOSE_SCOPE
224
225#endif //PXR_IMAGING_HD_REPR_H
A draw item is a light-weight representation of an HdRprim's resources and material to be used for re...
Definition: drawItem.h:48
An HdRepr refers to a (single) topological representation of an rprim, and owns the draw item(s) that...
Definition: repr.h:140
void ClearGeomSubsetDrawItems()
Removes all of the geom subset draw items from the repr.
Definition: repr.h:203
void AddDrawItem(std::unique_ptr< HdDrawItem > &&item)
Transfers ownership of a draw item to this repr.
Definition: repr.h:157
HdDrawItem * GetDrawItem(size_t index) const
Returns the draw item at the requested index.
Definition: repr.h:167
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:191
const DrawItemUniquePtrVector & GetDrawItems() const
Returns the draw items for this representation.
Definition: repr.h:151
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:196
Describes one or more authored display representations for an rprim.
Definition: repr.h:32
static const size_t MAX_TOPOLOGY_REPRS
Currenly support upto 3 topology tokens.
Definition: repr.h:60
HD_API bool AnyActiveRepr() const
Returns true if any of the topology tokens is valid, i.e., neither empty nor disabled.
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 HdReprSelector CompositeOver(const HdReprSelector &under) const
Returns a selector that is the composite of this selector 'over' the passed in selector.
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.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71