This document is for a version of USD that is under development. See this page for the current release.
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
rprim.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_RPRIM_H
8#define PXR_IMAGING_HD_RPRIM_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/rprimSharedData.h"
14#include "pxr/imaging/hd/repr.h"
15#include "pxr/imaging/hd/sceneDelegate.h"
16#include "pxr/imaging/hd/types.h"
17#include "pxr/usd/sdf/path.h"
18#include "pxr/base/gf/range3d.h"
20
21#include <memory>
22#include <vector>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26class HdChangeTracker;
27class HdRenderIndex;
28class HdRenderParam;
29
30using HdReprSharedPtr = std::shared_ptr<HdRepr>;
31
38{
39public:
40 HD_API
41 HdRprim(SdfPath const& id);
42
43 HD_API
44 virtual ~HdRprim();
45
46 // ---------------------------------------------------------------------- //
48 // ---------------------------------------------------------------------- //
49
52 virtual HdDirtyBits GetInitialDirtyBitsMask() const = 0;
53
59 HD_API
60 bool CanSkipDirtyBitPropagationAndSync(HdDirtyBits bits) const;
61
69 HD_API
70 HdDirtyBits PropagateRprimDirtyBits(HdDirtyBits bits);
71
80 HD_API
81 void InitRepr(HdSceneDelegate* delegate,
82 TfToken const &reprToken,
83 HdDirtyBits *dirtyBits);
84
114 virtual void Sync(HdSceneDelegate *delegate,
115 HdRenderParam *renderParam,
116 HdDirtyBits *dirtyBits,
117 TfToken const &reprToken) = 0;
118 // ---------------------------------------------------------------------- //
120 // ---------------------------------------------------------------------- //
121
126 HD_API
127 const HdRepr::DrawItemUniquePtrVector &
128 GetDrawItems(TfToken const& reprToken) const;
129
130 // ---------------------------------------------------------------------- //
132 // ---------------------------------------------------------------------- //
136 HD_API
137 virtual void Finalize(HdRenderParam *renderParam);
138
139 // ---------------------------------------------------------------------- //
141 // ---------------------------------------------------------------------- //
142
146 SdfPath const& GetId() const { return _sharedData.rprimID; }
147
149 int32_t GetPrimId() const { return _primId; };
150
152 HD_API
153 void SetPrimId(int32_t primId);
154
157 SdfPath const& GetInstancerId() const { return _instancerId; }
158
162 SdfPath const& GetMaterialId() const { return _materialId; }
163
165 HD_API
166 void SetMaterialId(SdfPath const& materialId);
167
168 HdReprSelector const& GetReprSelector() const {
169 return _authoredReprSelector;
170 }
171
172 TfToken const& GetRenderTag() const {
173 return _renderTag;
174 }
175
177 inline TfToken GetRenderTag(HdSceneDelegate* delegate) const;
178
180 inline GfRange3d GetExtent(HdSceneDelegate* delegate) const;
181
183 inline HdPrimvarDescriptorVector
185 HdInterpolation interpolation) const;
186
189 HD_API
190 virtual TfTokenVector const & GetBuiltinPrimvarNames() const = 0;
191
192 inline VtValue
193 GetPrimvar(HdSceneDelegate* delegate, const TfToken &name) const;
194
195 inline VtValue
196 GetIndexedPrimvar(HdSceneDelegate* delegate, const TfToken &name,
197 VtIntArray *indices) const;
198
199 HD_API
200 VtMatrix4dArray GetInstancerTransforms(HdSceneDelegate* delegate);
201
203 HD_API
204 bool IsDirty(HdChangeTracker &changeTracker) const;
205
207 bool IsVisible() const { return _sharedData.visible; }
208
209 HD_API
210 void UpdateReprSelector(HdSceneDelegate* delegate,
211 HdDirtyBits *dirtyBits);
212
213 HD_API
214 virtual void UpdateRenderTag(HdSceneDelegate *delegate,
215 HdRenderParam *renderParam);
216
217protected:
218 // ---------------------------------------------------------------------- //
220 // ---------------------------------------------------------------------- //
221
232 virtual HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const = 0;
233
246 virtual void _InitRepr(TfToken const &reprToken,
247 HdDirtyBits *dirtyBits) = 0;
248
249 // ---------------------------------------------------------------------- //
251 // ---------------------------------------------------------------------- //
252 HD_API
253 HdReprSharedPtr const & _GetRepr(TfToken const &reprToken) const;
254
255 HD_API
256 void _UpdateVisibility(HdSceneDelegate *sceneDelegate,
257 HdDirtyBits *dirtyBits);
258
259 HD_API
260 void _UpdateInstancer(HdSceneDelegate *sceneDelegate,
261 HdDirtyBits *dirtyBits);
262
263private:
264 SdfPath _instancerId;
265 SdfPath _materialId;
266
267 // Used for id renders.
268 int32_t _primId;
269
270protected:
271 // shared data across reprs: bufferArrayRanges, bounds, visibility
272 HdRprimSharedData _sharedData;
273
274 // authored repr selector
275 HdReprSelector _authoredReprSelector;
276
277 // authored render tag
278 TfToken _renderTag;
279
280 // total number of reprs is relatively small (less than 5 or so
281 // in most case), we use linear container for efficiency.
282 using _ReprVector = std::vector<std::pair<TfToken, HdReprSharedPtr>>;
283 _ReprVector _reprs;
284
285 struct _ReprComparator
286 {
287 _ReprComparator(TfToken const &name) : _name(name) {}
288 bool operator() (const std::pair<TfToken, HdReprSharedPtr> &e) const {
289 return _name == e.first;
290 }
291 private:
292 TfToken _name;
293 };
294
295
296 // Repr configuration descriptors. All concrete types (HdMesh, HdPoints ..)
297 // have this static map to lookup descriptors for the given reprToken.
298 //
299 // N : # of descriptors for the repr.
300 //
301 template<typename DESC_TYPE, int N=1>
302 struct _ReprDescConfigs
303 {
304 using DescArray = std::array<DESC_TYPE, N>;
305 static const int MAX_DESCS = N;
306
307 DescArray Find(TfToken const &reprToken) const {
308 // linear search, we expect only a handful reprs configured.
309 TF_FOR_ALL (it, _configs) {
310 if (it->first == reprToken) return it->second;
311 }
312 TF_CODING_ERROR("Repr %s not found", reprToken.GetText());
313 return DescArray();
314 }
315 void AddOrUpdate(TfToken const &reprToken, DescArray descs) {
316 for (auto& config : _configs) {
317 if (config.first == reprToken) {
318 // Overrwrite the existing entry.
319 config.second = descs;
320 return;
321 }
322 }
323 _configs.push_back(std::make_pair(reprToken, descs));
324 }
325 std::vector<std::pair<TfToken, DescArray> > _configs;
326 };
327
328};
329
331//
332// Delegate API Wrappers
333//
335HdRprim::GetRenderTag(HdSceneDelegate* delegate) const
336{
337 return delegate->GetRenderTag(GetId());
338}
339
342{
343 return delegate->GetExtent(GetId());
344}
345
346inline HdPrimvarDescriptorVector
348 HdInterpolation interpolation) const
349{
350 return delegate->GetPrimvarDescriptors(GetId(), interpolation);
351}
352
353inline VtValue
354HdRprim::GetPrimvar(HdSceneDelegate* delegate, const TfToken &name) const
355{
356 return delegate->Get(GetId(), name);
357}
358
359inline VtValue
360HdRprim::GetIndexedPrimvar(HdSceneDelegate* delegate, const TfToken &name,
361 VtIntArray *indices) const
362{
363 return delegate->GetIndexedPrimvar(GetId(), name, indices);
364}
365
366PXR_NAMESPACE_CLOSE_SCOPE
367
368#endif //PXR_IMAGING_HD_RPRIM_H
Basic type: 3-dimensional floating point range.
Definition: range3d.h:47
Tracks changes from the HdSceneDelegate, providing invalidation cues to the render engine.
Definition: changeTracker.h:35
The Hydra render index is a flattened representation of the client scene graph, which may be composed...
Definition: renderIndex.h:104
The HdRenderParam is an opaque (to core Hydra) handle, to an object that is obtained from the render ...
Describes one or more authored display representations for an rprim.
Definition: repr.h:32
The render engine state for a given rprim from the scene graph.
Definition: rprim.h:38
virtual HD_API TfTokenVector const & GetBuiltinPrimvarNames() const =0
Returns the names of built-in primvars, i.e.
HD_API void SetPrimId(int32_t primId)
Set the unique instance id.
SdfPath const & GetMaterialId() const
Returns the path of the material to which this Rprim is bound.
Definition: rprim.h:162
virtual HD_API void Finalize(HdRenderParam *renderParam)
Finalizes object resources.
HD_API const HdRepr::DrawItemUniquePtrVector & GetDrawItems(TfToken const &reprToken) const
Returns the draw items for the requested repr token, if any.
SdfPath const & GetId() const
Returns the identifier of this Rprim.
Definition: rprim.h:146
GfRange3d GetExtent(HdSceneDelegate *delegate) const
Returns the bounds of the rprim in local, untransformed space.
Definition: rprim.h:341
bool IsVisible() const
Is the prim itself visible.
Definition: rprim.h:207
virtual HdDirtyBits _PropagateDirtyBits(HdDirtyBits bits) const =0
This callback from Rprim gives the prim an opportunity to set additional dirty bits based on those al...
HdPrimvarDescriptorVector GetPrimvarDescriptors(HdSceneDelegate *delegate, HdInterpolation interpolation) const
Primvar Query.
Definition: rprim.h:347
HD_API bool IsDirty(HdChangeTracker &changeTracker) const
Returns true if any dirty flags are set for this rprim.
HD_API void SetMaterialId(SdfPath const &materialId)
Sets a new material binding to be used by this rprim.
virtual HdDirtyBits GetInitialDirtyBitsMask() const =0
Returns the set of dirty bits that should be added to the change tracker for this prim,...
HD_API bool CanSkipDirtyBitPropagationAndSync(HdDirtyBits bits) const
This function gives an Rprim the chance to "early exit" from dirty bit propagation,...
virtual void Sync(HdSceneDelegate *delegate, HdRenderParam *renderParam, HdDirtyBits *dirtyBits, TfToken const &reprToken)=0
Pull invalidated scene data and prepare/update the renderable representation.
SdfPath const & GetInstancerId() const
Returns the identifier of the instancer (if any) for this Rprim.
Definition: rprim.h:157
int32_t GetPrimId() const
Return the unique instance id.
Definition: rprim.h:149
virtual void _InitRepr(TfToken const &reprToken, HdDirtyBits *dirtyBits)=0
Initialize the given representation of this Rprim.
HD_API void InitRepr(HdSceneDelegate *delegate, TfToken const &reprToken, HdDirtyBits *dirtyBits)
Initialize the representation of this Rprim by calling _InitRepr.
HD_API HdDirtyBits PropagateRprimDirtyBits(HdDirtyBits bits)
This function gives an Rprim the chance to set additional dirty bits based on those set in the change...
Adapter class providing data exchange with the client scene graph.
virtual HD_API TfToken GetRenderTag(SdfPath const &id)
Returns the render tag that will be used to bucket prims during render pass bucketing.
virtual HD_API HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation)
Returns descriptors for all primvars of the given interpolation type.
virtual HD_API GfRange3d GetExtent(SdfPath const &id)
Gets the axis aligned bounds of a prim.
virtual HD_API VtValue Get(SdfPath const &id, TfToken const &key)
Returns a named value.
virtual HD_API VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices)
Returns a named primvar value.
A path value used to locate objects in layers or scenegraphs.
Definition: path.h:274
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
char const * GetText() const
Return the text that this token represents.
Definition: token.h:179
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
#define TF_FOR_ALL(iter, c)
Macro for iterating over a container.
Definition: iterator.h:373
#define TF_CODING_ERROR(fmt, args)
Issue an internal programming error, but continue execution.
Definition: diagnostic.h:68
Define integral types.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:440