HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
sceneDelegate.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_SCENE_DELEGATE_H
25 #define PXR_IMAGING_HD_SCENE_DELEGATE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 
31 #include "pxr/imaging/hd/aov.h"
33 #include "pxr/imaging/hd/enums.h"
36 #include "pxr/imaging/hd/repr.h"
38 
40 
41 #include "pxr/base/vt/array.h"
42 #include "pxr/base/vt/dictionary.h"
43 #include "pxr/base/vt/value.h"
44 #include "pxr/usd/sdf/assetPath.h"
45 #include "pxr/usd/sdf/path.h"
46 
47 #include "pxr/base/gf/vec2i.h"
48 #include "pxr/base/tf/hash.h"
49 
50 #include <memory>
51 #include <vector>
52 
54 
56 
57 /// A shared pointer to a vector of id's.
58 typedef std::shared_ptr<SdfPathVector> HdIdVectorSharedPtr;
59 
60 /// Instancer context: a pair of instancer paths and instance indices.
61 typedef std::vector<std::pair<SdfPath, int>> HdInstancerContext;
62 
63 /// \class HdSyncRequestVector
64 ///
65 /// The SceneDelegate is requested to synchronize prims as the result of
66 /// executing a specific render pass, the following data structure is passed
67 /// back to the delegate to drive synchronization.
68 ///
70  // The Prims to synchronize in this request.
72 
73  // The HdChangeTracker::DirtyBits that are set for each Prim.
74  std::vector<HdDirtyBits> dirtyBits;
75 };
76 
77 /// \struct HdDisplayStyle
78 ///
79 /// Describes how the geometry of a prim should be displayed.
80 ///
82  /// The prim refine level, in the range [0, 8].
84 
85  /// Is the prim flat shaded.
87 
88  /// Is the prim displacement shaded.
90 
91  /// Does the prim act "transparent" to allow occluded selection to show
92  /// through?
94 
95  /// Should the prim's points get shaded like surfaces, as opposed to
96  /// constant shaded?
98 
99  /// Is this prim exempt from having its material disabled or overridden,
100  /// for example, when a renderer chooses to ignore all scene materials?
102 
103  /// Creates a default DisplayStyle.
104  /// - refineLevel is 0.
105  /// - flatShading is disabled.
106  /// - displacement is enabled.
107  /// - occludedSelectionShowsThrough is disabled.
108  /// - pointsShading is disabled.
110  : refineLevel(0)
111  , flatShadingEnabled(false)
112  , displacementEnabled(true)
114  , pointsShadingEnabled(false)
115  , materialIsFinal(false)
116  { }
117 
118  /// Creates a DisplayStyle.
119  /// \param refineLevel_ the refine level to display.
120  /// Valid range is [0, 8].
121  /// \param flatShading enables flat shading, defaults to false.
122  /// \param displacement enables displacement shading, defaults to false.
123  /// \param occludedSelectionShowsThrough controls whether the prim lets
124  /// occluded selection show through it, defaults to false.
125  /// \param pointsShadingEnabled controls whether the prim's points
126  /// are shaded as surfaces or constant-shaded, defaults to false.
127  /// \param materialisFinal controls whether the prim's material should be
128  /// exempt from override or disabling, such as when a renderer
129  /// wants to ignore all scene materials.
130  HdDisplayStyle(int refineLevel_,
131  bool flatShading = false,
132  bool displacement = true,
133  bool occludedSelectionShowsThrough_ = false,
134  bool pointsShadingEnabled_ = false,
135  bool materialIsFinal_ = false)
136  : refineLevel(std::max(0, refineLevel_))
137  , flatShadingEnabled(flatShading)
138  , displacementEnabled(displacement)
139  , occludedSelectionShowsThrough(occludedSelectionShowsThrough_)
140  , pointsShadingEnabled(pointsShadingEnabled_)
141  , materialIsFinal(materialIsFinal_)
142  {
143  if (refineLevel_ < 0) {
144  TF_CODING_ERROR("negative refine level is not supported");
145  } else if (refineLevel_ > 8) {
146  TF_CODING_ERROR("refine level > 8 is not supported");
147  }
148  }
149 
150  HdDisplayStyle(HdDisplayStyle const& rhs) = default;
151  ~HdDisplayStyle() = default;
152 
153  bool operator==(HdDisplayStyle const& rhs) const {
154  return refineLevel == rhs.refineLevel
161  }
162  bool operator!=(HdDisplayStyle const& rhs) const {
163  return !(*this == rhs);
164  }
165 };
166 
167 /// \struct HdPrimvarDescriptor
168 ///
169 /// Describes a primvar.
171  /// Name of the primvar.
173  /// Interpolation (data-sampling rate) of the primvar.
175  /// Optional "role" indicating a desired interpretation --
176  /// for example, to distinguish color/vector/point/normal.
177  /// See HdPrimvarRoleTokens; default is HdPrimvarRoleTokens->none.
179  /// Optional bool, true if primvar is indexed. This value should be checked
180  /// before calling "GetIndexedPrimvar"
181  bool indexed;
182 
185  , role(HdPrimvarRoleTokens->none)
186  , indexed(false)
187  {}
189  HdInterpolation interp_,
190  TfToken const& role_=HdPrimvarRoleTokens->none,
191  bool indexed_=false)
192  : name(name_), interpolation(interp_), role(role_), indexed(indexed_)
193  { }
194  bool operator==(HdPrimvarDescriptor const& rhs) const {
195  return name == rhs.name && role == rhs.role
196  && interpolation == rhs.interpolation;
197  }
198  bool operator!=(HdPrimvarDescriptor const& rhs) const {
199  return !(*this == rhs);
200  }
201 };
202 
203 typedef std::vector<HdPrimvarDescriptor> HdPrimvarDescriptorVector;
204 
205 /// \struct HdModelDrawMode
206 ///
207 /// Describes optional alternative imaging behavior for prims.
208 ///
209 /// Some scene delegates, like the UsdImagingDelegate, will pre-flatten this
210 /// data, but other scene delegates may wish to use this to pipe the data
211 /// through to a draw mode resolving scene index (see
212 /// UsdImagingDrawModeSceneIndex as an example of such a scene index).
213 ///
214 /// There is currently no plan to add emulation support for this information,
215 /// such as via HdLegacyPrimSceneIndex or HdSceneIndexAdapterSceneDelegate.
216 ///
218  // Alternate imaging mode. Options are origin, bounds, cards, default, and
219  // inherited.
221  // Specifies whether to apply the alternative imaging mode or not.
223  // The color in which to draw the geometry.
225  // The specific geometry to use in cards mode. Options are cross, box, and
226  // fromTexture.
228  // The textures applied to the respective quads in cards mode.
235 
237  : drawMode(HdModelDrawModeTokens->inherited)
238  , applyDrawMode(false)
239  , drawModeColor(GfVec3f(0.18))
240  , cardGeometry(HdModelDrawModeTokens->cross)
241  {}
242 
244  TfToken const& drawMode_,
245  bool applyDrawMode_=false,
246  GfVec3f drawModeColor_=GfVec3f(0.18),
247  TfToken const& cardGeometry_=HdModelDrawModeTokens->cross,
248  SdfAssetPath cardTextureXPos_=SdfAssetPath(),
249  SdfAssetPath cardTextureYPos_=SdfAssetPath(),
250  SdfAssetPath cardTextureZPos_=SdfAssetPath(),
251  SdfAssetPath cardTextureXNeg_=SdfAssetPath(),
252  SdfAssetPath cardTextureYNeg_=SdfAssetPath(),
253  SdfAssetPath cardTextureZNeg_=SdfAssetPath())
254  : drawMode(drawMode_), applyDrawMode(applyDrawMode_),
255  drawModeColor(drawModeColor_), cardGeometry(cardGeometry_),
256  cardTextureXPos(cardTextureXPos_), cardTextureYPos(cardTextureYPos_),
257  cardTextureZPos(cardTextureZPos_), cardTextureXNeg(cardTextureXNeg_),
258  cardTextureYNeg(cardTextureYNeg_), cardTextureZNeg(cardTextureZNeg_)
259  {}
260 
261  bool operator==(HdModelDrawMode const& rhs) const {
262  return drawMode == rhs.drawMode &&
263  applyDrawMode == rhs.applyDrawMode &&
264  drawModeColor == rhs.drawModeColor &&
265  cardGeometry == rhs.cardGeometry &&
272  }
273  bool operator!=(HdModelDrawMode const& rhs) const {
274  return !(*this == rhs);
275  }
276 };
277 
278 /// \struct HdExtComputationPrimvarDescriptor
279 ///
280 /// Extends HdPrimvarDescriptor to describe a primvar that takes
281 /// data from the output of an ExtComputation.
282 ///
283 /// The structure contains the id of the source ExtComputation in the
284 /// render index, the name of an output from that computation from which
285 /// the primvar will take data along with a valueType which describes
286 /// the type of the expected data.
291 
294  TfToken const& name_,
295  HdInterpolation interp_,
296  TfToken const & role_,
297  SdfPath const & sourceComputationId_,
298  TfToken const & sourceComputationOutputName_,
299  HdTupleType const & valueType_)
300  : HdPrimvarDescriptor(name_, interp_, role_, false)
301  , sourceComputationId(sourceComputationId_)
302  , sourceComputationOutputName(sourceComputationOutputName_)
303  , valueType(valueType_)
304  { }
306  return HdPrimvarDescriptor::operator==(rhs) &&
309  valueType == rhs.valueType;
310  }
312  return !(*this == rhs);
313  }
314 };
315 
316 typedef std::vector<HdExtComputationPrimvarDescriptor>
318 
319 /// \struct HdExtComputationInputDescriptor
320 ///
321 /// Describes an input to an ExtComputation that takes data from
322 /// the output of another ExtComputation.
323 ///
324 /// The structure contains the name of the input and the id of the
325 /// source ExtComputation in the render index, and which output of
326 /// that computation to bind the input to.
331 
334  TfToken const & name_,
335  SdfPath const & sourceComputationId_,
336  TfToken const & sourceComputationOutputName_)
337  : name(name_), sourceComputationId(sourceComputationId_)
338  , sourceComputationOutputName(sourceComputationOutputName_)
339  { }
340 
342  return name == rhs.name &&
345  }
347  return !(*this == rhs);
348  }
349 };
350 
351 typedef std::vector<HdExtComputationInputDescriptor>
353 
354 /// \struct HdExtComputationOutputDescriptor
355 ///
356 /// Describes an output of an ExtComputation.
357 ///
358 /// The structure contains the name of the output along with a valueType
359 /// which describes the type of the computation output data.
363 
366  TfToken const & name_,
367  HdTupleType const & valueType_)
368  : name(name_), valueType(valueType_)
369  { }
370 
372  return name == rhs.name &&
373  valueType == rhs.valueType;
374  }
376  return !(*this == rhs);
377  }
378 };
379 
380 typedef std::vector<HdExtComputationOutputDescriptor>
382 
383 /// \struct HdVolumeFieldDescriptor
384 ///
385 /// Description of a single field related to a volume primitive.
386 ///
391 
394  TfToken const & fieldName_,
395  TfToken const & fieldPrimType_,
396  SdfPath const & fieldId_)
397  : fieldName(fieldName_), fieldPrimType(fieldPrimType_), fieldId(fieldId_)
398  { }
399 };
400 
401 typedef std::vector<HdVolumeFieldDescriptor>
403 
404 /// \class HdSceneDelegate
405 ///
406 /// Adapter class providing data exchange with the client scene graph.
407 ///
409 public:
410  /// Constructor used for nested delegate objects which share a RenderIndex.
411  HD_API
412  HdSceneDelegate(HdRenderIndex *parentIndex,
413  SdfPath const& delegateID);
414 
415  HD_API
416  virtual ~HdSceneDelegate();
417 
418  /// Returns the RenderIndex owned by this delegate.
419  HdRenderIndex& GetRenderIndex() { return *_index; }
420 
421  /// Returns the ID of this delegate, which is used as a prefix for all
422  /// objects it creates in the RenderIndex.
423  ///
424  /// The default value is SdfPath::AbsoluteRootPath().
425  SdfPath const& GetDelegateID() const { return _delegateID; }
426 
427  /// Synchronizes the delegate state for the given request vector.
428  HD_API
429  virtual void Sync(HdSyncRequestVector* request);
430 
431  /// Opportunity for the delegate to clean itself up after
432  /// performing parallel work during sync phase
433  HD_API
434  virtual void PostSyncCleanup();
435 
436  // -----------------------------------------------------------------------//
437  /// \name Options
438  // -----------------------------------------------------------------------//
439 
440  /// Returns true if the named option is enabled by the delegate.
441  HD_API
442  virtual bool IsEnabled(TfToken const& option) const;
443 
444 
445  // -----------------------------------------------------------------------//
446  /// \name Rprim Aspects
447  // -----------------------------------------------------------------------//
448 
449  /// Gets the topological mesh data for a given prim.
450  HD_API
451  virtual HdMeshTopology GetMeshTopology(SdfPath const& id);
452 
453  /// Gets the topological curve data for a given prim.
454  HD_API
456 
457  /// Gets the subdivision surface tags (sharpness, holes, etc).
458  HD_API
459  virtual PxOsdSubdivTags GetSubdivTags(SdfPath const& id);
460 
461 
462  /// Gets the axis aligned bounds of a prim.
463  /// The returned bounds are in the local space of the prim
464  /// (transform is yet to be applied) and should contain the
465  /// bounds of any child prims.
466  ///
467  /// The returned bounds does not include any displacement that
468  /// might occur as the result of running shaders on the prim.
469  HD_API
470  virtual GfRange3d GetExtent(SdfPath const & id);
471 
472  /// Returns the object space transform, including all parent transforms.
473  HD_API
474  virtual GfMatrix4d GetTransform(SdfPath const & id);
475 
476  /// Returns the authored visible state of the prim.
477  HD_API
478  virtual bool GetVisible(SdfPath const & id);
479 
480  /// Returns the doubleSided state for the given prim.
481  HD_API
482  virtual bool GetDoubleSided(SdfPath const & id);
483 
484  /// Returns the cullstyle for the given prim.
485  HD_API
486  virtual HdCullStyle GetCullStyle(SdfPath const &id);
487 
488  /// Returns the shading style for the given prim.
489  HD_API
490  virtual VtValue GetShadingStyle(SdfPath const &id);
491 
492  /// Returns the refinement level for the given prim in the range [0,8].
493  ///
494  /// The refinement level indicates how many iterations to apply when
495  /// subdividing subdivision surfaces or other refinable primitives.
496  HD_API
497  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id);
498 
499  /// Returns a named value.
500  HD_API
501  virtual VtValue Get(SdfPath const& id, TfToken const& key);
502 
503  /// Returns a named primvar value. If \a *outIndices is not nullptr and the
504  /// primvar has indices, it will return the unflattened primvar and set
505  /// \a *outIndices to the primvar's associated indices, clearing the array
506  /// if the primvar is not indexed.
507  HD_API
508  virtual VtValue GetIndexedPrimvar(SdfPath const& id,
509  TfToken const& key,
510  VtIntArray *outIndices);
511 
512  /// Returns the authored repr (if any) for the given prim.
513  HD_API
514  virtual HdReprSelector GetReprSelector(SdfPath const &id);
515 
516  /// Returns the render tag that will be used to bucket prims during
517  /// render pass bucketing.
518  HD_API
519  virtual TfToken GetRenderTag(SdfPath const& id);
520 
521  /// Returns the prim categories.
522  HD_API
523  virtual VtArray<TfToken> GetCategories(SdfPath const& id);
524 
525  /// Returns the categories for all instances in the instancer.
526  HD_API
527  virtual std::vector<VtArray<TfToken>>
528  GetInstanceCategories(SdfPath const &instancerId);
529 
530  /// Returns the coordinate system bindings, or a nullptr if none are bound.
531  HD_API
533 
534  /// Returns the model draw mode object for the given prim.
535  HD_API
536  virtual HdModelDrawMode GetModelDrawMode(SdfPath const& id);
537 
538  // -----------------------------------------------------------------------//
539  /// \name Motion samples
540  // -----------------------------------------------------------------------//
541 
542  /// Store up to \a maxSampleCount transform samples in \a *sampleValues.
543  /// Returns the union of the authored samples and the boundaries
544  /// of the current camera shutter interval. If this number is greater
545  /// than maxSampleCount, you might want to call this function again
546  /// to get all the authored data.
547  /// Sample times are relative to the scene delegate's current time.
548  /// \see GetTransform()
549  HD_API
550  virtual size_t
551  SampleTransform(SdfPath const & id,
552  size_t maxSampleCount,
553  float *sampleTimes,
554  GfMatrix4d *sampleValues);
555 
556  /// Convenience form of SampleTransform() that takes an HdTimeSampleArray.
557  /// This function returns the union of the authored transform samples
558  /// and the boundaries of the current camera shutter interval.
559  template <unsigned int CAPACITY>
560  void
563  size_t authoredSamples =
564  SampleTransform(id, CAPACITY, sa->times.data(), sa->values.data());
565  if (authoredSamples > CAPACITY) {
566  sa->Resize(authoredSamples);
567  size_t authoredSamplesSecondAttempt =
569  id,
570  authoredSamples,
571  sa->times.data(),
572  sa->values.data());
573  // Number of samples should be consisntent through multiple
574  // invokations of the sampling function.
575  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
576  }
577  sa->count = authoredSamples;
578  }
579 
580  /// Store up to \a maxSampleCount transform samples in \a *sampleValues.
581  /// Returns the union of the authored samples and the boundaries
582  /// of the current camera shutter interval. If this number is greater
583  /// than maxSampleCount, you might want to call this function again
584  /// to get all the authored data.
585  /// Sample times are relative to the scene delegate's current time.
586  /// \see GetInstancerTransform()
587  HD_API
588  virtual size_t
589  SampleInstancerTransform(SdfPath const &instancerId,
590  size_t maxSampleCount,
591  float *sampleTimes,
592  GfMatrix4d *sampleValues);
593 
594  /// Convenience form of SampleInstancerTransform()
595  /// that takes an HdTimeSampleArray.
596  /// This function returns the union of the authored samples
597  /// and the boundaries of the current camera shutter interval.
598  template <unsigned int CAPACITY>
599  void
600  SampleInstancerTransform(SdfPath const &instancerId,
602  size_t authoredSamples =
604  instancerId,
605  CAPACITY,
606  sa->times.data(),
607  sa->values.data());
608  if (authoredSamples > CAPACITY) {
609  sa->Resize(authoredSamples);
610  size_t authoredSamplesSecondAttempt =
612  instancerId,
613  authoredSamples,
614  sa->times.data(),
615  sa->values.data());
616  // Number of samples should be consisntent through multiple
617  // invokations of the sampling function.
618  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
619  }
620  sa->count = authoredSamples;
621  }
622 
623  /// Store up to \a maxSampleCount primvar samples in \a *samplesValues.
624  /// Returns the union of the authored samples and the boundaries
625  /// of the current camera shutter interval. If this number is greater
626  /// than maxSampleCount, you might want to call this function again
627  /// to get all the authored data.
628  ///
629  /// Sample values that are array-valued will have a size described
630  /// by the HdPrimvarDescriptor as applied to the toplogy.
631  ///
632  /// For example, this means that a mesh that is fracturing over time
633  /// will return samples with the same number of points; the number
634  /// of points will change as the scene delegate is resynchronized
635  /// to represent the scene at a time with different topology.
636  ///
637  /// Sample times are relative to the scene delegate's current time.
638  ///
639  /// \see Get()
640  HD_API
641  virtual size_t
642  SamplePrimvar(SdfPath const& id,
643  TfToken const& key,
644  size_t maxSampleCount,
645  float *sampleTimes,
646  VtValue *sampleValues);
647 
648  /// Convenience form of SamplePrimvar() that takes an HdTimeSampleArray.
649  /// This function returns the union of the authored samples
650  /// and the boundaries of the current camera shutter interval.
651  template <unsigned int CAPACITY>
652  void
653  SamplePrimvar(SdfPath const &id,
654  TfToken const& key,
656 
657  /// SamplePrimvar() for getting an unflattened primvar and its indices. If
658  /// \a *sampleIndices is not nullptr and the primvar has indices, it will
659  /// return unflattened primvar samples in \a *sampleValues and the primvar's
660  /// sampled indices in \a *sampleIndices, clearing the \a *sampleIndices
661  /// array if the primvar is not indexed.
662  HD_API
663  virtual size_t
664  SampleIndexedPrimvar(SdfPath const& id,
665  TfToken const& key,
666  size_t maxSampleCount,
667  float *sampleTimes,
668  VtValue *sampleValues,
669  VtIntArray *sampleIndices);
670 
671  /// Convenience form of SampleIndexedPrimvar() that takes
672  /// HdTimeSampleArrays. This function returns the union of the authored
673  /// samples and the boundaries of the current camera shutter interval.
674  template <unsigned int CAPACITY>
675  void
676  SampleIndexedPrimvar(SdfPath const &id,
677  TfToken const& key,
679 
680  // -----------------------------------------------------------------------//
681  /// \name Instancer prototypes
682  // -----------------------------------------------------------------------//
683 
684  /// Gets the extracted indices array of the prototype id used in the
685  /// instancer.
686  ///
687  /// example
688  /// instances: 0, 1, 2, 3, 4, 5
689  /// protoypes: A, B, A, A, B, C
690  ///
691  /// GetInstanceIndices(A) : [0, 2, 3]
692  /// GetInstanceIndices(B) : [1, 4]
693  /// GetInstanceIndices(C) : [5]
694  /// GetInstanceIndices(D) : []
695  ///
696  HD_API
697  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
698  SdfPath const &prototypeId);
699 
700  /// Returns the instancer transform.
701  HD_API
702  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId);
703 
704  /// Returns the parent instancer of the given rprim or instancer.
705  HD_API
706  virtual SdfPath GetInstancerId(SdfPath const& primId);
707 
708  /// Returns a list of prototypes of this instancer. The intent is to let
709  /// renderers cache instance indices by giving them a complete set of prims
710  /// to call GetInstanceIndices(instancer, prototype) on.
711  /// XXX: This is currently unused, but may be used in the future.
712  HD_API
713  virtual SdfPathVector GetInstancerPrototypes(SdfPath const& instancerId);
714 
715  // -----------------------------------------------------------------------//
716  /// \name Path Translation
717  // -----------------------------------------------------------------------//
718 
719  /// Returns the scene address of the prim corresponding to the given
720  /// rprim/instance index. This is designed to give paths in scene namespace,
721  /// rather than hydra namespace, so it always strips the delegate ID.
722  /// \deprecated use GetScenePrimPaths
723  HD_API
724  virtual SdfPath GetScenePrimPath(SdfPath const& rprimId,
725  int instanceIndex,
726  HdInstancerContext *instancerContext = nullptr);
727 
728  /// A vectorized version of GetScenePrimPath that allows the prim adapter
729  /// to amortize expensive calculations across a number of path evaluations
730  /// in a single call. Note that only a single rprimId is supported. This
731  /// allows this call to be forwarded directly to a single prim adapter
732  /// rather than requiring a lot of data shuffling.
733  HD_API
734  virtual SdfPathVector GetScenePrimPaths(SdfPath const& rprimId,
735  std::vector<int> instanceIndices,
736  std::vector<HdInstancerContext> *instancerContexts = nullptr);
737 
738  /// Returns an identifier that can be used to share data between HdPrims
739  /// during a Sync operation. Any number of HdPrims of the same type may
740  /// return the same identifier. In this situation, the render delegate
741  /// can choose to share information between HdPrims rather than fetching
742  /// data for each HdPrim. For the UsdImagingSceneDelegate, this identifier
743  /// will be the path of the GetPrototype prim for the UsdPrim correspnding
744  /// to this HdPrim. Returns an empty SdfPath if this feature is no
745  /// supported or the UsdPrim has no prototype. Render delegates are free
746  /// to ignore this method completely if they aren't interested in the
747  /// additional level of data sharing enabled by this information.
748  HD_API
749  virtual SdfPath GetDataSharingId(SdfPath const& primId);
750 
751  // -----------------------------------------------------------------------//
752  /// \name Material Aspects
753  // -----------------------------------------------------------------------//
754 
755  /// Returns the material ID bound to the rprim \p rprimId.
756  HD_API
757  virtual SdfPath GetMaterialId(SdfPath const &rprimId);
758 
759  // Returns a material resource which contains the information
760  // needed to create a material.
761  HD_API
762  virtual VtValue GetMaterialResource(SdfPath const &materialId);
763 
764  // -----------------------------------------------------------------------//
765  /// \name Renderbuffer Aspects
766  // -----------------------------------------------------------------------//
767 
768  /// Returns the allocation descriptor for a given render buffer prim.
769  HD_API
771 
772  // -----------------------------------------------------------------------//
773  /// \name Light Aspects
774  // -----------------------------------------------------------------------//
775 
776  // Returns a single value for a given light and parameter.
777  HD_API
778  virtual VtValue GetLightParamValue(SdfPath const &id,
779  TfToken const &paramName);
780 
781  // -----------------------------------------------------------------------//
782  /// \name Camera Aspects
783  // -----------------------------------------------------------------------//
784 
785  /// Returns a single value for a given camera and parameter.
786  /// See HdCameraTokens for the list of paramters.
787  HD_API
788  virtual VtValue GetCameraParamValue(SdfPath const& cameraId,
789  TfToken const& paramName);
790 
791  // -----------------------------------------------------------------------//
792  /// \name Volume Aspects
793  // -----------------------------------------------------------------------//
794 
795  HD_API
797  GetVolumeFieldDescriptors(SdfPath const &volumeId);
798 
799  // -----------------------------------------------------------------------//
800  /// \name ExtComputation Aspects
801  // -----------------------------------------------------------------------//
802 
803  ///
804  /// For the given computation id, returns a list of inputs which
805  /// will be requested from the scene delegate using the Get() method.
806  ///
807  /// See GetExtComputationInputDescriptors and
808  /// GetExtComputationOutpuDescriptors for descriptions of other
809  /// computation inputs and outputs.
810  HD_API
811  virtual TfTokenVector
812  GetExtComputationSceneInputNames(SdfPath const& computationId);
813 
814  ///
815  /// For the given computation id, returns a list of computation
816  /// input descriptors.
817  ///
818  /// See HdExtComputationInputDecriptor
819  HD_API
821  GetExtComputationInputDescriptors(SdfPath const& computationId);
822 
823  /// For the given computation id, returns a list of computation
824  /// output descriptors.
825  ///
826  /// See HdExtComputationOutputDescriptor
827  HD_API
829  GetExtComputationOutputDescriptors(SdfPath const& computationId);
830 
831 
832  /// Returns a list of primvar names that should be bound to
833  /// a generated output from an ExtComputation for the given prim id and
834  /// interpolation mode. Binding information is obtained through
835  /// GetExtComputationPrimvarDesc()
836  /// Returns a structure describing source information for a primvar
837  /// that is bound to an ExtComputation. See HdExtComputationPrimvarDesc
838  /// for the expected information to be returned.
839  HD_API
842  HdInterpolation interpolationMode);
843 
844  /// Returns a single value for a given computation id and input token.
845  /// The token may be a computation input or a computation config parameter.
846  HD_API
847  virtual VtValue GetExtComputationInput(SdfPath const& computationId,
848  TfToken const& input);
849 
850  /// Return up to \a maxSampleCount samples for a given computation id and
851  /// input token.
852  /// The token may be a computation input or a computation config parameter.
853  /// Returns the union of the authored samples and the boundaries
854  /// of the current camera shutter interval. If this number is greater
855  /// than maxSampleCount, you might want to call this function again
856  /// to get all the authored data.
857  HD_API
858  virtual size_t SampleExtComputationInput(SdfPath const& computationId,
859  TfToken const& input,
860  size_t maxSampleCount,
861  float *sampleTimes,
862  VtValue *sampleValues);
863 
864  /// Convenience form of SampleExtComputationInput() that takes an
865  /// HdTimeSampleArray.
866  /// Returns the union of the authored samples and the boundaries
867  /// of the current camera shutter interval.
868  template <unsigned int CAPACITY>
869  void SampleExtComputationInput(SdfPath const& computationId,
870  TfToken const& input,
872  size_t authoredSamples = SampleExtComputationInput(
873  computationId, input, CAPACITY,
874  sa->times.data(), sa->values.data());
875 
876  if (authoredSamples > CAPACITY) {
877  sa->Resize(authoredSamples);
878  size_t authoredSamplesSecondAttempt = SampleExtComputationInput(
879  computationId, input, authoredSamples,
880  sa->times.data(), sa->values.data());
881  // Number of samples should be consisntent through multiple
882  // invokations of the sampling function.
883  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
884  }
885  sa->count = authoredSamples;
886  }
887 
888  /// Returns the kernel source assigned to the computation at the path id.
889  /// If the string is empty the computation has no GPU kernel and the
890  /// CPU callback should be used.
891  HD_API
892  virtual std::string GetExtComputationKernel(SdfPath const& computationId);
893 
894  /// Requests the scene delegate run the ExtComputation with the given id.
895  /// The context contains the input values that delegate requested through
896  /// GetExtComputationInputNames().
897  ///
898  /// The scene delegate is expected to set each output identified by
899  /// GetExtComputationOutputNames() on the context.
900  ///
901  /// Hydra may invoke the computation on a different thread from
902  /// what HdEngine::Execute() was called on. It may also invoke
903  /// many computations in parallel.
904  HD_API
905  virtual void InvokeExtComputation(SdfPath const& computationId,
906  HdExtComputationContext *context);
907 
908  // -----------------------------------------------------------------------//
909  /// \name Primitive Variables
910  // -----------------------------------------------------------------------//
911 
912  /// Returns descriptors for all primvars of the given interpolation type.
913  HD_API
915  GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation);
916 
917  // -----------------------------------------------------------------------//
918  /// \name Task Aspects
919  // -----------------------------------------------------------------------//
920  HD_API
921  virtual TfTokenVector GetTaskRenderTags(SdfPath const& taskId);
922 
923 private:
924  HdRenderIndex *_index;
925  SdfPath _delegateID;
926 
927  HdSceneDelegate() = delete;
928  HdSceneDelegate(HdSceneDelegate &) = delete;
929  HdSceneDelegate &operator=(HdSceneDelegate &) = delete;
930 };
931 
932 template <unsigned int CAPACITY>
933 void
935  TfToken const& key,
937  size_t authoredSamples =
939  id,
940  key,
941  CAPACITY,
942  sa->times.data(),
943  sa->values.data());
944  if (authoredSamples > CAPACITY) {
945  sa->Resize(authoredSamples);
946  size_t authoredSamplesSecondAttempt =
948  id,
949  key,
950  authoredSamples,
951  sa->times.data(),
952  sa->values.data());
953  // Number of samples should be consistent through multiple
954  // invocations of the sampling function.
955  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
956  }
957  sa->count = authoredSamples;
958 }
959 
960 template <unsigned int CAPACITY>
961 void
963  TfToken const& key,
965  size_t authoredSamples =
967  id,
968  key,
969  CAPACITY,
970  sa->times.data(),
971  sa->values.data(),
972  sa->indices.data());
973  if (authoredSamples > CAPACITY) {
974  sa->Resize(authoredSamples);
975  size_t authoredSamplesSecondAttempt =
977  id,
978  key,
979  authoredSamples,
980  sa->times.data(),
981  sa->values.data(),
982  sa->indices.data());
983  // Number of samples should be consistent through multiple
984  // invocations of the sampling function.
985  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
986  }
987  sa->count = authoredSamples;
988 }
989 
991 
992 #endif //PXR_IMAGING_HD_SCENE_DELEGATE_H
std::shared_ptr< SdfPathVector > HdIdVectorSharedPtr
A shared pointer to a vector of id's.
Definition: sceneDelegate.h:55
SdfAssetPath cardTextureXNeg
void SampleInstancerTransform(SdfPath const &instancerId, HdTimeSampleArray< GfMatrix4d, CAPACITY > *sa)
virtual HD_API VtValue GetExtComputationInput(SdfPath const &computationId, TfToken const &input)
virtual HD_API SdfPath GetScenePrimPath(SdfPath const &rprimId, int instanceIndex, HdInstancerContext *instancerContext=nullptr)
bool operator==(HdExtComputationOutputDescriptor const &rhs) const
virtual HD_API size_t SamplePrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues)
TfToken cardGeometry
HdCullStyle
Definition: enums.h:122
virtual HD_API void PostSyncCleanup()
bool operator!=(HdExtComputationInputDescriptor const &rhs) const
SdfAssetPath cardTextureZNeg
virtual HD_API VtValue GetIndexedPrimvar(SdfPath const &id, TfToken const &key, VtIntArray *outIndices)
virtual HD_API void InvokeExtComputation(SdfPath const &computationId, HdExtComputationContext *context)
virtual HD_API SdfPath GetDataSharingId(SdfPath const &primId)
TfSmallVector< float, CAPACITY > times
SdfAssetPath cardTextureXPos
virtual HD_API bool GetVisible(SdfPath const &id)
Returns the authored visible state of the prim.
virtual HD_API SdfPath GetInstancerId(SdfPath const &primId)
Returns the parent instancer of the given rprim or instancer.
bool operator!=(HdPrimvarDescriptor const &rhs) const
void SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, HdTimeSampleArray< VtValue, CAPACITY > *sa)
GLsizei const GLchar *const * string
Definition: glcorearb.h:814
~HdDisplayStyle()=default
bool operator!=(HdExtComputationPrimvarDescriptor const &rhs) const
std::vector< HdExtComputationInputDescriptor > HdExtComputationInputDescriptorVector
#define TF_CODING_ERROR
virtual HD_API HdVolumeFieldDescriptorVector GetVolumeFieldDescriptors(SdfPath const &volumeId)
virtual HD_API HdExtComputationInputDescriptorVector GetExtComputationInputDescriptors(SdfPath const &computationId)
bool operator!=(HdExtComputationOutputDescriptor const &rhs) const
Definition: vec3f.h:62
virtual HD_API std::string GetExtComputationKernel(SdfPath const &computationId)
#define HD_API
Definition: api.h:40
virtual HD_API bool IsEnabled(TfToken const &option) const
Returns true if the named option is enabled by the delegate.
GfVec3f drawModeColor
virtual HD_API SdfPathVector GetInstancerPrototypes(SdfPath const &instancerId)
HdVolumeFieldDescriptor(TfToken const &fieldName_, TfToken const &fieldPrimType_, SdfPath const &fieldId_)
int refineLevel
The prim refine level, in the range [0, 8].
Definition: sceneDelegate.h:83
std::vector< HdExtComputationOutputDescriptor > HdExtComputationOutputDescriptorVector
virtual HD_API size_t SampleIndexedPrimvar(SdfPath const &id, TfToken const &key, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues, VtIntArray *sampleIndices)
virtual HD_API GfMatrix4d GetInstancerTransform(SdfPath const &instancerId)
Returns the instancer transform.
bool operator!=(HdModelDrawMode const &rhs) const
HdExtComputationInputDescriptor(TfToken const &name_, SdfPath const &sourceComputationId_, TfToken const &sourceComputationOutputName_)
HdPrimvarDescriptor(TfToken const &name_, HdInterpolation interp_, TfToken const &role_=HdPrimvarRoleTokens->none, bool indexed_=false)
virtual HD_API HdBasisCurvesTopology GetBasisCurvesTopology(SdfPath const &id)
Gets the topological curve data for a given prim.
bool operator==(HdExtComputationInputDescriptor const &rhs) const
virtual HD_API PxOsdSubdivTags GetSubdivTags(SdfPath const &id)
Gets the subdivision surface tags (sharpness, holes, etc).
virtual HD_API HdIdVectorSharedPtr GetCoordSysBindings(SdfPath const &id)
Returns the coordinate system bindings, or a nullptr if none are bound.
HdExtComputationPrimvarDescriptor(TfToken const &name_, HdInterpolation interp_, TfToken const &role_, SdfPath const &sourceComputationId_, TfToken const &sourceComputationOutputName_, HdTupleType const &valueType_)
std::vector< std::pair< SdfPath, int > > HdInstancerContext
Instancer context: a pair of instancer paths and instance indices.
Definition: sceneDelegate.h:61
virtual HD_API VtValue GetMaterialResource(SdfPath const &materialId)
Returns the material ID bound to the rprim rprimId.
bool occludedSelectionShowsThrough
Definition: sceneDelegate.h:93
Definition: token.h:87
virtual HD_API HdDisplayStyle GetDisplayStyle(SdfPath const &id)
virtual HD_API VtArray< TfToken > GetCategories(SdfPath const &id)
Returns the prim categories.
HdInterpolation interpolation
Interpolation (data-sampling rate) of the primvar.
virtual HD_API VtValue GetLightParamValue(SdfPath const &id, TfToken const &paramName)
bool pointsShadingEnabled
Definition: sceneDelegate.h:97
TfToken name
Name of the primvar.
HdRenderIndex & GetRenderIndex()
Returns the RenderIndex owned by this delegate.
bool operator==(HdDisplayStyle const &rhs) const
SdfAssetPath cardTextureZPos
virtual HD_API HdPrimvarDescriptorVector GetPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolation)
Returns descriptors for all primvars of the given interpolation type.
virtual HD_API GfMatrix4d GetTransform(SdfPath const &id)
Returns the object space transform, including all parent transforms.
std::vector< TfToken > TfTokenVector
Convenience types.
Definition: token.h:457
bool displacementEnabled
Is the prim displacement shaded.
Definition: sceneDelegate.h:89
virtual HD_API GfRange3d GetExtent(SdfPath const &id)
std::vector< HdDirtyBits > dirtyBits
Definition: sceneDelegate.h:74
virtual HD_API TfToken GetRenderTag(SdfPath const &id)
GLuint const GLchar * name
Definition: glcorearb.h:786
bool operator==(HdExtComputationPrimvarDescriptor const &rhs) const
Definition: path.h:290
virtual HD_API size_t SampleTransform(SdfPath const &id, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues)
bool operator==(HdModelDrawMode const &rhs) const
std::vector< HdVolumeFieldDescriptor > HdVolumeFieldDescriptorVector
std::vector< class SdfPath > SdfPathVector
A vector of SdfPaths.
Definition: path.h:211
TfSmallVector< TYPE, CAPACITY > values
virtual HD_API SdfPath GetMaterialId(SdfPath const &rprimId)
Returns the material ID bound to the rprim rprimId.
SdfPath const & GetDelegateID() const
virtual HD_API HdModelDrawMode GetModelDrawMode(SdfPath const &id)
Returns the model draw mode object for the given prim.
virtual HD_API void Sync(HdSyncRequestVector *request)
Synchronizes the delegate state for the given request vector.
virtual void Resize(unsigned int newSize)
Resize the internal buffers.
void Resize(unsigned int newSize) override
Resize the internal buffers.
virtual HD_API VtValue Get(SdfPath const &id, TfToken const &key)
Returns a named value.
virtual HD_API VtValue GetCameraParamValue(SdfPath const &cameraId, TfToken const &paramName)
virtual HD_API size_t SampleExtComputationInput(SdfPath const &computationId, TfToken const &input, size_t maxSampleCount, float *sampleTimes, VtValue *sampleValues)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
bool operator!=(HdDisplayStyle const &rhs) const
bool flatShadingEnabled
Is the prim flat shaded.
Definition: sceneDelegate.h:86
virtual HD_API HdMeshTopology GetMeshTopology(SdfPath const &id)
Gets the topological mesh data for a given prim.
virtual HD_API ~HdSceneDelegate()
HdModelDrawMode(TfToken const &drawMode_, bool applyDrawMode_=false, GfVec3f drawModeColor_=GfVec3f(0.18), TfToken const &cardGeometry_=HdModelDrawModeTokens->cross, SdfAssetPath cardTextureXPos_=SdfAssetPath(), SdfAssetPath cardTextureYPos_=SdfAssetPath(), SdfAssetPath cardTextureZPos_=SdfAssetPath(), SdfAssetPath cardTextureXNeg_=SdfAssetPath(), SdfAssetPath cardTextureYNeg_=SdfAssetPath(), SdfAssetPath cardTextureZNeg_=SdfAssetPath())
HdExtComputationOutputDescriptor(TfToken const &name_, HdTupleType const &valueType_)
virtual HD_API TfTokenVector GetExtComputationSceneInputNames(SdfPath const &computationId)
HdInterpolation
Definition: enums.h:194
virtual HD_API TfTokenVector GetTaskRenderTags(SdfPath const &taskId)
virtual HD_API HdReprSelector GetReprSelector(SdfPath const &id)
Returns the authored repr (if any) for the given prim.
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
virtual HD_API size_t SampleInstancerTransform(SdfPath const &instancerId, size_t maxSampleCount, float *sampleTimes, GfMatrix4d *sampleValues)
virtual HD_API std::vector< VtArray< TfToken > > GetInstanceCategories(SdfPath const &instancerId)
Returns the categories for all instances in the instancer.
virtual HD_API HdCullStyle GetCullStyle(SdfPath const &id)
Returns the cullstyle for the given prim.
SdfPathVector IDs
Definition: sceneDelegate.h:71
void SampleTransform(SdfPath const &id, HdTimeSampleArray< GfMatrix4d, CAPACITY > *sa)
virtual HD_API HdRenderBufferDescriptor GetRenderBufferDescriptor(SdfPath const &id)
Returns the allocation descriptor for a given render buffer prim.
virtual HD_API HdExtComputationPrimvarDescriptorVector GetExtComputationPrimvarDescriptors(SdfPath const &id, HdInterpolation interpolationMode)
virtual HD_API VtValue GetShadingStyle(SdfPath const &id)
Returns the shading style for the given prim.
HdDisplayStyle(int refineLevel_, bool flatShading=false, bool displacement=true, bool occludedSelectionShowsThrough_=false, bool pointsShadingEnabled_=false, bool materialIsFinal_=false)
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
SdfAssetPath cardTextureYPos
bool operator==(HdPrimvarDescriptor const &rhs) const
virtual HD_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId)
SdfAssetPath cardTextureYNeg
virtual HD_API SdfPathVector GetScenePrimPaths(SdfPath const &rprimId, std::vector< int > instanceIndices, std::vector< HdInstancerContext > *instancerContexts=nullptr)
TfSmallVector< VtIntArray, CAPACITY > indices
SIM_DerVector3 cross(const SIM_DerVector3 &lhs, const SIM_DerVector3 &rhs)
Definition: value.h:164
virtual HD_API VtIntArray GetInstanceIndices(SdfPath const &instancerId, SdfPath const &prototypeId)
virtual HD_API bool GetDoubleSided(SdfPath const &id)
Returns the doubleSided state for the given prim.
std::vector< HdExtComputationPrimvarDescriptor > HdExtComputationPrimvarDescriptorVector
value_type * data()
Definition: smallVector.h:768