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  /// Creates a default DisplayStyle.
95  /// - refineLevel is 0.
96  /// - flatShading is disabled.
97  /// - displacement is enabled.
99  : refineLevel(0)
100  , flatShadingEnabled(false)
101  , displacementEnabled(true)
103  { }
104 
105  /// Creates a DisplayStyle.
106  /// \param refineLevel_ the refine level to display.
107  /// Valid range is [0, 8].
108  /// \param flatShading enables flat shading, defaults to false.
109  /// \param displacement enables displacement shading, defaults to false.
110  /// \param occludedSelectionShowsThrough controls whether the prim lets
111  /// occluded selection show through it, defaults to false.
112  HdDisplayStyle(int refineLevel_,
113  bool flatShading = false,
114  bool displacement = true,
115  bool occludedSelectionShowsThrough_ = false)
116  : refineLevel(std::max(0, refineLevel_))
117  , flatShadingEnabled(flatShading)
118  , displacementEnabled(displacement)
119  , occludedSelectionShowsThrough(occludedSelectionShowsThrough_)
120  {
121  if (refineLevel_ < 0) {
122  TF_CODING_ERROR("negative refine level is not supported");
123  } else if (refineLevel_ > 8) {
124  TF_CODING_ERROR("refine level > 8 is not supported");
125  }
126  }
127 
128  HdDisplayStyle(HdDisplayStyle const& rhs) = default;
129  ~HdDisplayStyle() = default;
130 
131  bool operator==(HdDisplayStyle const& rhs) const {
132  return refineLevel == rhs.refineLevel
137  }
138  bool operator!=(HdDisplayStyle const& rhs) const {
139  return !(*this == rhs);
140  }
141 };
142 
143 /// \struct HdPrimvarDescriptor
144 ///
145 /// Describes a primvar.
147  /// Name of the primvar.
149  /// Interpolation (data-sampling rate) of the primvar.
151  /// Optional "role" indicating a desired interpretation --
152  /// for example, to distinguish color/vector/point/normal.
153  /// See HdPrimvarRoleTokens; default is HdPrimvarRoleTokens->none.
155  /// Optional bool, true if primvar is indexed. This value should be checked
156  /// before calling "GetIndexedPrimvar"
157  bool indexed;
158 
161  HdInterpolation interp_,
162  TfToken const& role_=HdPrimvarRoleTokens->none,
163  bool indexed_=false)
164  : name(name_), interpolation(interp_), role(role_), indexed(indexed_)
165  { }
166  bool operator==(HdPrimvarDescriptor const& rhs) const {
167  return name == rhs.name && role == rhs.role
168  && interpolation == rhs.interpolation;
169  }
170  bool operator!=(HdPrimvarDescriptor const& rhs) const {
171  return !(*this == rhs);
172  }
173 };
174 
175 typedef std::vector<HdPrimvarDescriptor> HdPrimvarDescriptorVector;
176 
177 /// \struct HdExtComputationPrimvarDescriptor
178 ///
179 /// Extends HdPrimvarDescriptor to describe a primvar that takes
180 /// data from the output of an ExtComputation.
181 ///
182 /// The structure contains the id of the source ExtComputation in the
183 /// render index, the name of an output from that computation from which
184 /// the primvar will take data along with a valueType which describes
185 /// the type of the expected data.
190 
193  TfToken const& name_,
194  HdInterpolation interp_,
195  TfToken const & role_,
196  SdfPath const & sourceComputationId_,
197  TfToken const & sourceComputationOutputName_,
198  HdTupleType const & valueType_)
199  : HdPrimvarDescriptor(name_, interp_, role_, false)
200  , sourceComputationId(sourceComputationId_)
201  , sourceComputationOutputName(sourceComputationOutputName_)
202  , valueType(valueType_)
203  { }
205  return HdPrimvarDescriptor::operator==(rhs) &&
208  valueType == rhs.valueType;
209  }
211  return !(*this == rhs);
212  }
213 };
214 
215 typedef std::vector<HdExtComputationPrimvarDescriptor>
217 
218 /// \struct HdExtComputationInputDescriptor
219 ///
220 /// Describes an input to an ExtComputation that takes data from
221 /// the output of another ExtComputation.
222 ///
223 /// The structure contains the name of the input and the id of the
224 /// source ExtComputation in the render index, and which output of
225 /// that computation to bind the input to.
230 
233  TfToken const & name_,
234  SdfPath const & sourceComputationId_,
235  TfToken const & sourceComputationOutputName_)
236  : name(name_), sourceComputationId(sourceComputationId_)
237  , sourceComputationOutputName(sourceComputationOutputName_)
238  { }
239 
241  return name == rhs.name &&
244  }
246  return !(*this == rhs);
247  }
248 };
249 
250 typedef std::vector<HdExtComputationInputDescriptor>
252 
253 /// \struct HdExtComputationOutputDescriptor
254 ///
255 /// Describes an output of an ExtComputation.
256 ///
257 /// The structure contains the name of the output along with a valueType
258 /// which describes the type of the computation output data.
262 
265  TfToken const & name_,
266  HdTupleType const & valueType_)
267  : name(name_), valueType(valueType_)
268  { }
269 
271  return name == rhs.name &&
272  valueType == rhs.valueType;
273  }
275  return !(*this == rhs);
276  }
277 };
278 
279 typedef std::vector<HdExtComputationOutputDescriptor>
281 
282 /// \struct HdVolumeFieldDescriptor
283 ///
284 /// Description of a single field related to a volume primitive.
285 ///
290 
293  TfToken const & fieldName_,
294  TfToken const & fieldPrimType_,
295  SdfPath const & fieldId_)
296  : fieldName(fieldName_), fieldPrimType(fieldPrimType_), fieldId(fieldId_)
297  { }
298 };
299 
300 typedef std::vector<HdVolumeFieldDescriptor>
302 
303 /// \class HdSceneDelegate
304 ///
305 /// Adapter class providing data exchange with the client scene graph.
306 ///
308 public:
309  /// Constructor used for nested delegate objects which share a RenderIndex.
310  HD_API
311  HdSceneDelegate(HdRenderIndex *parentIndex,
312  SdfPath const& delegateID);
313 
314  HD_API
315  virtual ~HdSceneDelegate();
316 
317  /// Returns the RenderIndex owned by this delegate.
318  HdRenderIndex& GetRenderIndex() { return *_index; }
319 
320  /// Returns the ID of this delegate, which is used as a prefix for all
321  /// objects it creates in the RenderIndex.
322  ///
323  /// The default value is SdfPath::AbsoluteRootPath().
324  SdfPath const& GetDelegateID() const { return _delegateID; }
325 
326  /// Synchronizes the delegate state for the given request vector.
327  HD_API
328  virtual void Sync(HdSyncRequestVector* request);
329 
330  /// Opportunity for the delegate to clean itself up after
331  /// performing parallel work during sync phase
332  HD_API
333  virtual void PostSyncCleanup();
334 
335  // -----------------------------------------------------------------------//
336  /// \name Options
337  // -----------------------------------------------------------------------//
338 
339  /// Returns true if the named option is enabled by the delegate.
340  HD_API
341  virtual bool IsEnabled(TfToken const& option) const;
342 
343 
344  // -----------------------------------------------------------------------//
345  /// \name Rprim Aspects
346  // -----------------------------------------------------------------------//
347 
348  /// Gets the topological mesh data for a given prim.
349  HD_API
350  virtual HdMeshTopology GetMeshTopology(SdfPath const& id);
351 
352  /// Gets the topological curve data for a given prim.
353  HD_API
355 
356  /// Gets the subdivision surface tags (sharpness, holes, etc).
357  HD_API
358  virtual PxOsdSubdivTags GetSubdivTags(SdfPath const& id);
359 
360 
361  /// Gets the axis aligned bounds of a prim.
362  /// The returned bounds are in the local space of the prim
363  /// (transform is yet to be applied) and should contain the
364  /// bounds of any child prims.
365  ///
366  /// The returned bounds does not include any displacement that
367  /// might occur as the result of running shaders on the prim.
368  HD_API
369  virtual GfRange3d GetExtent(SdfPath const & id);
370 
371  /// Returns the object space transform, including all parent transforms.
372  HD_API
373  virtual GfMatrix4d GetTransform(SdfPath const & id);
374 
375  /// Returns the authored visible state of the prim.
376  HD_API
377  virtual bool GetVisible(SdfPath const & id);
378 
379  /// Returns the doubleSided state for the given prim.
380  HD_API
381  virtual bool GetDoubleSided(SdfPath const & id);
382 
383  /// Returns the cullstyle for the given prim.
384  HD_API
385  virtual HdCullStyle GetCullStyle(SdfPath const &id);
386 
387  /// Returns the shading style for the given prim.
388  HD_API
389  virtual VtValue GetShadingStyle(SdfPath const &id);
390 
391  /// Returns the refinement level for the given prim in the range [0,8].
392  ///
393  /// The refinement level indicates how many iterations to apply when
394  /// subdividing subdivision surfaces or other refinable primitives.
395  HD_API
396  virtual HdDisplayStyle GetDisplayStyle(SdfPath const& id);
397 
398  /// Returns a named value.
399  HD_API
400  virtual VtValue Get(SdfPath const& id, TfToken const& key);
401 
402  /// Returns a named primvar value. If \a *outIndices is not nullptr and the
403  /// primvar has indices, it will return the unflattened primvar and set
404  /// \a *outIndices to the primvar's associated indices, clearing the array
405  /// if the primvar is not indexed.
406  HD_API
407  virtual VtValue GetIndexedPrimvar(SdfPath const& id,
408  TfToken const& key,
409  VtIntArray *outIndices);
410 
411  /// Returns the authored repr (if any) for the given prim.
412  HD_API
413  virtual HdReprSelector GetReprSelector(SdfPath const &id);
414 
415  /// Returns the render tag that will be used to bucket prims during
416  /// render pass bucketing.
417  HD_API
418  virtual TfToken GetRenderTag(SdfPath const& id);
419 
420  /// Returns the prim categories.
421  HD_API
422  virtual VtArray<TfToken> GetCategories(SdfPath const& id);
423 
424  /// Returns the categories for all instances in the instancer.
425  HD_API
426  virtual std::vector<VtArray<TfToken>>
427  GetInstanceCategories(SdfPath const &instancerId);
428 
429  /// Returns the coordinate system bindings, or a nullptr if none are bound.
430  HD_API
432 
433  // -----------------------------------------------------------------------//
434  /// \name Motion samples
435  // -----------------------------------------------------------------------//
436 
437  /// Store up to \a maxSampleCount transform samples in \a *sampleValues.
438  /// Returns the union of the authored samples and the boundaries
439  /// of the current camera shutter interval. If this number is greater
440  /// than maxSampleCount, you might want to call this function again
441  /// to get all the authored data.
442  /// Sample times are relative to the scene delegate's current time.
443  /// \see GetTransform()
444  HD_API
445  virtual size_t
446  SampleTransform(SdfPath const & id,
447  size_t maxSampleCount,
448  float *sampleTimes,
449  GfMatrix4d *sampleValues);
450 
451  /// Convenience form of SampleTransform() that takes an HdTimeSampleArray.
452  /// This function returns the union of the authored transform samples
453  /// and the boundaries of the current camera shutter interval.
454  template <unsigned int CAPACITY>
455  void
458  size_t authoredSamples =
459  SampleTransform(id, CAPACITY, sa->times.data(), sa->values.data());
460  if (authoredSamples > CAPACITY) {
461  sa->Resize(authoredSamples);
462  size_t authoredSamplesSecondAttempt =
464  id,
465  authoredSamples,
466  sa->times.data(),
467  sa->values.data());
468  // Number of samples should be consisntent through multiple
469  // invokations of the sampling function.
470  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
471  }
472  sa->count = authoredSamples;
473  }
474 
475  /// Store up to \a maxSampleCount transform samples in \a *sampleValues.
476  /// Returns the union of the authored samples and the boundaries
477  /// of the current camera shutter interval. If this number is greater
478  /// than maxSampleCount, you might want to call this function again
479  /// to get all the authored data.
480  /// Sample times are relative to the scene delegate's current time.
481  /// \see GetInstancerTransform()
482  HD_API
483  virtual size_t
484  SampleInstancerTransform(SdfPath const &instancerId,
485  size_t maxSampleCount,
486  float *sampleTimes,
487  GfMatrix4d *sampleValues);
488 
489  /// Convenience form of SampleInstancerTransform()
490  /// that takes an HdTimeSampleArray.
491  /// This function returns the union of the authored samples
492  /// and the boundaries of the current camera shutter interval.
493  template <unsigned int CAPACITY>
494  void
495  SampleInstancerTransform(SdfPath const &instancerId,
497  size_t authoredSamples =
499  instancerId,
500  CAPACITY,
501  sa->times.data(),
502  sa->values.data());
503  if (authoredSamples > CAPACITY) {
504  sa->Resize(authoredSamples);
505  size_t authoredSamplesSecondAttempt =
507  instancerId,
508  authoredSamples,
509  sa->times.data(),
510  sa->values.data());
511  // Number of samples should be consisntent through multiple
512  // invokations of the sampling function.
513  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
514  }
515  sa->count = authoredSamples;
516  }
517 
518  /// Store up to \a maxSampleCount primvar samples in \a *samplesValues.
519  /// Returns the union of the authored samples and the boundaries
520  /// of the current camera shutter interval. If this number is greater
521  /// than maxSampleCount, you might want to call this function again
522  /// to get all the authored data.
523  ///
524  /// Sample values that are array-valued will have a size described
525  /// by the HdPrimvarDescriptor as applied to the toplogy.
526  ///
527  /// For example, this means that a mesh that is fracturing over time
528  /// will return samples with the same number of points; the number
529  /// of points will change as the scene delegate is resynchronized
530  /// to represent the scene at a time with different topology.
531  ///
532  /// Sample times are relative to the scene delegate's current time.
533  ///
534  /// \see Get()
535  HD_API
536  virtual size_t
537  SamplePrimvar(SdfPath const& id,
538  TfToken const& key,
539  size_t maxSampleCount,
540  float *sampleTimes,
541  VtValue *sampleValues);
542 
543  /// Convenience form of SamplePrimvar() that takes an HdTimeSampleArray.
544  /// This function returns the union of the authored samples
545  /// and the boundaries of the current camera shutter interval.
546  template <unsigned int CAPACITY>
547  void
548  SamplePrimvar(SdfPath const &id,
549  TfToken const& key,
551 
552  /// SamplePrimvar() for getting an unflattened primvar and its indices. If
553  /// \a *sampleIndices is not nullptr and the primvar has indices, it will
554  /// return unflattened primvar samples in \a *sampleValues and the primvar's
555  /// sampled indices in \a *sampleIndices, clearing the \a *sampleIndices
556  /// array if the primvar is not indexed.
557  HD_API
558  virtual size_t
559  SampleIndexedPrimvar(SdfPath const& id,
560  TfToken const& key,
561  size_t maxSampleCount,
562  float *sampleTimes,
563  VtValue *sampleValues,
564  VtIntArray *sampleIndices);
565 
566  /// Convenience form of SampleIndexedPrimvar() that takes
567  /// HdTimeSampleArrays. This function returns the union of the authored
568  /// samples and the boundaries of the current camera shutter interval.
569  template <unsigned int CAPACITY>
570  void
571  SampleIndexedPrimvar(SdfPath const &id,
572  TfToken const& key,
574 
575  // -----------------------------------------------------------------------//
576  /// \name Instancer prototypes
577  // -----------------------------------------------------------------------//
578 
579  /// Gets the extracted indices array of the prototype id used in the
580  /// instancer.
581  ///
582  /// example
583  /// instances: 0, 1, 2, 3, 4, 5
584  /// protoypes: A, B, A, A, B, C
585  ///
586  /// GetInstanceIndices(A) : [0, 2, 3]
587  /// GetInstanceIndices(B) : [1, 4]
588  /// GetInstanceIndices(C) : [5]
589  /// GetInstanceIndices(D) : []
590  ///
591  HD_API
592  virtual VtIntArray GetInstanceIndices(SdfPath const &instancerId,
593  SdfPath const &prototypeId);
594 
595  /// Returns the instancer transform.
596  HD_API
597  virtual GfMatrix4d GetInstancerTransform(SdfPath const &instancerId);
598 
599  /// Returns the parent instancer of the given rprim or instancer.
600  HD_API
601  virtual SdfPath GetInstancerId(SdfPath const& primId);
602 
603  /// Returns a list of prototypes of this instancer. The intent is to let
604  /// renderers cache instance indices by giving them a complete set of prims
605  /// to call GetInstanceIndices(instancer, prototype) on.
606  /// XXX: This is currently unused, but may be used in the future.
607  HD_API
608  virtual SdfPathVector GetInstancerPrototypes(SdfPath const& instancerId);
609 
610  // -----------------------------------------------------------------------//
611  /// \name Path Translation
612  // -----------------------------------------------------------------------//
613 
614  /// Returns the scene address of the prim corresponding to the given
615  /// rprim/instance index. This is designed to give paths in scene namespace,
616  /// rather than hydra namespace, so it always strips the delegate ID.
617  HD_API
618  virtual SdfPath GetScenePrimPath(SdfPath const& rprimId,
619  int instanceIndex,
620  HdInstancerContext *instancerContext = nullptr);
621 
622  // -----------------------------------------------------------------------//
623  /// \name Material Aspects
624  // -----------------------------------------------------------------------//
625 
626  /// Returns the material ID bound to the rprim \p rprimId.
627  HD_API
628  virtual SdfPath GetMaterialId(SdfPath const &rprimId);
629 
630  // Returns a material resource which contains the information
631  // needed to create a material.
632  HD_API
633  virtual VtValue GetMaterialResource(SdfPath const &materialId);
634 
635  // -----------------------------------------------------------------------//
636  /// \name Renderbuffer Aspects
637  // -----------------------------------------------------------------------//
638 
639  /// Returns the allocation descriptor for a given render buffer prim.
640  HD_API
642 
643  // -----------------------------------------------------------------------//
644  /// \name Light Aspects
645  // -----------------------------------------------------------------------//
646 
647  // Returns a single value for a given light and parameter.
648  HD_API
649  virtual VtValue GetLightParamValue(SdfPath const &id,
650  TfToken const &paramName);
651 
652  // -----------------------------------------------------------------------//
653  /// \name Camera Aspects
654  // -----------------------------------------------------------------------//
655 
656  /// Returns a single value for a given camera and parameter.
657  /// See HdCameraTokens for the list of paramters.
658  HD_API
659  virtual VtValue GetCameraParamValue(SdfPath const& cameraId,
660  TfToken const& paramName);
661 
662  // -----------------------------------------------------------------------//
663  /// \name Volume Aspects
664  // -----------------------------------------------------------------------//
665 
666  HD_API
668  GetVolumeFieldDescriptors(SdfPath const &volumeId);
669 
670  // -----------------------------------------------------------------------//
671  /// \name ExtComputation Aspects
672  // -----------------------------------------------------------------------//
673 
674  ///
675  /// For the given computation id, returns a list of inputs which
676  /// will be requested from the scene delegate using the Get() method.
677  ///
678  /// See GetExtComputationInputDescriptors and
679  /// GetExtComputationOutpuDescriptors for descriptions of other
680  /// computation inputs and outputs.
681  HD_API
682  virtual TfTokenVector
683  GetExtComputationSceneInputNames(SdfPath const& computationId);
684 
685  ///
686  /// For the given computation id, returns a list of computation
687  /// input descriptors.
688  ///
689  /// See HdExtComputationInputDecriptor
690  HD_API
692  GetExtComputationInputDescriptors(SdfPath const& computationId);
693 
694  /// For the given computation id, returns a list of computation
695  /// output descriptors.
696  ///
697  /// See HdExtComputationOutputDescriptor
698  HD_API
700  GetExtComputationOutputDescriptors(SdfPath const& computationId);
701 
702 
703  /// Returns a list of primvar names that should be bound to
704  /// a generated output from an ExtComputation for the given prim id and
705  /// interpolation mode. Binding information is obtained through
706  /// GetExtComputationPrimvarDesc()
707  /// Returns a structure describing source information for a primvar
708  /// that is bound to an ExtComputation. See HdExtComputationPrimvarDesc
709  /// for the expected information to be returned.
710  HD_API
713  HdInterpolation interpolationMode);
714 
715  /// Returns a single value for a given computation id and input token.
716  /// The token may be a computation input or a computation config parameter.
717  HD_API
718  virtual VtValue GetExtComputationInput(SdfPath const& computationId,
719  TfToken const& input);
720 
721  /// Return up to \a maxSampleCount samples for a given computation id and
722  /// input token.
723  /// The token may be a computation input or a computation config parameter.
724  /// Returns the union of the authored samples and the boundaries
725  /// of the current camera shutter interval. If this number is greater
726  /// than maxSampleCount, you might want to call this function again
727  /// to get all the authored data.
728  HD_API
729  virtual size_t SampleExtComputationInput(SdfPath const& computationId,
730  TfToken const& input,
731  size_t maxSampleCount,
732  float *sampleTimes,
733  VtValue *sampleValues);
734 
735  /// Convenience form of SampleExtComputationInput() that takes an
736  /// HdTimeSampleArray.
737  /// Returns the union of the authored samples and the boundaries
738  /// of the current camera shutter interval.
739  template <unsigned int CAPACITY>
740  void SampleExtComputationInput(SdfPath const& computationId,
741  TfToken const& input,
743  size_t authoredSamples = SampleExtComputationInput(
744  computationId, input, CAPACITY,
745  sa->times.data(), sa->values.data());
746 
747  if (authoredSamples > CAPACITY) {
748  sa->Resize(authoredSamples);
749  size_t authoredSamplesSecondAttempt = SampleExtComputationInput(
750  computationId, input, authoredSamples,
751  sa->times.data(), sa->values.data());
752  // Number of samples should be consisntent through multiple
753  // invokations of the sampling function.
754  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
755  }
756  sa->count = authoredSamples;
757  }
758 
759  /// Returns the kernel source assigned to the computation at the path id.
760  /// If the string is empty the computation has no GPU kernel and the
761  /// CPU callback should be used.
762  HD_API
763  virtual std::string GetExtComputationKernel(SdfPath const& computationId);
764 
765  /// Requests the scene delegate run the ExtComputation with the given id.
766  /// The context contains the input values that delegate requested through
767  /// GetExtComputationInputNames().
768  ///
769  /// The scene delegate is expected to set each output identified by
770  /// GetExtComputationOutputNames() on the context.
771  ///
772  /// Hydra may invoke the computation on a different thread from
773  /// what HdEngine::Execute() was called on. It may also invoke
774  /// many computations in parallel.
775  HD_API
776  virtual void InvokeExtComputation(SdfPath const& computationId,
777  HdExtComputationContext *context);
778 
779  // -----------------------------------------------------------------------//
780  /// \name Primitive Variables
781  // -----------------------------------------------------------------------//
782 
783  /// Returns descriptors for all primvars of the given interpolation type.
784  HD_API
786  GetPrimvarDescriptors(SdfPath const& id, HdInterpolation interpolation);
787 
788  // -----------------------------------------------------------------------//
789  /// \name Task Aspects
790  // -----------------------------------------------------------------------//
791  HD_API
792  virtual TfTokenVector GetTaskRenderTags(SdfPath const& taskId);
793 
794 private:
795  HdRenderIndex *_index;
796  SdfPath _delegateID;
797 
798  HdSceneDelegate() = delete;
799  HdSceneDelegate(HdSceneDelegate &) = delete;
800  HdSceneDelegate &operator=(HdSceneDelegate &) = delete;
801 };
802 
803 template <unsigned int CAPACITY>
804 void
806  TfToken const& key,
808  size_t authoredSamples =
810  id,
811  key,
812  CAPACITY,
813  sa->times.data(),
814  sa->values.data());
815  if (authoredSamples > CAPACITY) {
816  sa->Resize(authoredSamples);
817  size_t authoredSamplesSecondAttempt =
819  id,
820  key,
821  authoredSamples,
822  sa->times.data(),
823  sa->values.data());
824  // Number of samples should be consistent through multiple
825  // invocations of the sampling function.
826  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
827  }
828  sa->count = authoredSamples;
829 }
830 
831 template <unsigned int CAPACITY>
832 void
834  TfToken const& key,
836  size_t authoredSamples =
838  id,
839  key,
840  CAPACITY,
841  sa->times.data(),
842  sa->values.data(),
843  sa->indices.data());
844  if (authoredSamples > CAPACITY) {
845  sa->Resize(authoredSamples);
846  size_t authoredSamplesSecondAttempt =
848  id,
849  key,
850  authoredSamples,
851  sa->times.data(),
852  sa->values.data(),
853  sa->indices.data());
854  // Number of samples should be consistent through multiple
855  // invocations of the sampling function.
856  TF_VERIFY(authoredSamples == authoredSamplesSecondAttempt);
857  }
858  sa->count = authoredSamples;
859 }
860 
862 
863 #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)
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:785
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
HdDisplayStyle(int refineLevel_, bool flatShading=false, bool displacement=true, bool occludedSelectionShowsThrough_=false)
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)
TfToken name
Name of the primvar.
GLsizei const GLchar *const * string
Definition: glcorearb.h:813
HdRenderIndex & GetRenderIndex()
Returns the RenderIndex owned by this delegate.
bool operator==(HdDisplayStyle const &rhs) const
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
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:288
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:209
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:1375
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.
#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.
std::vector< HdPrimvarDescriptor > HdPrimvarDescriptorVector
bool operator==(HdPrimvarDescriptor const &rhs) const
virtual HD_API HdExtComputationOutputDescriptorVector GetExtComputationOutputDescriptors(SdfPath const &computationId)
TfSmallVector< VtIntArray, CAPACITY > indices
Definition: value.h:168
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