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