7#ifndef PXR_IMAGING_HD_DATASOURCE_H
8#define PXR_IMAGING_HD_DATASOURCE_H
12#include "pxr/imaging/hd/api.h"
13#include "pxr/imaging/hd/dataSourceLocator.h"
16#include "pxr/base/vt/value.h"
17#include "pxr/base/vt/visitValue.h"
24PXR_NAMESPACE_OPEN_SCOPE
29#define HD_DECLARE_DATASOURCE_ABSTRACT(type) \
30 using Handle = std::shared_ptr<type>; \
31 using AtomicHandle = Handle; \
32 static Handle AtomicLoad(AtomicHandle &ptr) { \
33 return std::atomic_load(&ptr); \
35 static void AtomicStore(AtomicHandle &ptr, const Handle &v) { \
36 std::atomic_store(&ptr, v); \
38 static bool AtomicCompareExchange(AtomicHandle &ptr, \
39 AtomicHandle &expected, \
40 const Handle &desired) { \
41 return std::atomic_compare_exchange_strong(&ptr, &expected, desired); \
43 static Handle Cast(const HdDataSourceBase::Handle &v) { \
44 return std::dynamic_pointer_cast<type>(v); \
53#define HD_DECLARE_DATASOURCE(type) \
54 HD_DECLARE_DATASOURCE_ABSTRACT(type) \
55 template <typename ... Args> \
56 static Handle New(Args&& ... args) { \
57 return Handle(new type(std::forward<Args>(args) ... )); \
63#define HD_DECLARE_DATASOURCE_INITIALIZER_LIST_NEW(type, T) \
64 static Handle New(std::initializer_list<T> initList) { \
65 return Handle(new type(initList)); \
68#define HD_DECLARE_DATASOURCE_HANDLES(type) \
69 using type##Handle = type::Handle; \
70 using type##AtomicHandle = type::AtomicHandle;
117 static HdDataSourceBaseHandle
Get(
118 const Handle &container,
143 virtual HdDataSourceBaseHandle
GetElement(
size_t element) = 0;
183 std::vector<Time> * outSampleTimes) = 0;
186 friend class Hd_SampledDataSourceDefaultValueAccessor;
189 virtual VtValue _GetDefaultValue();
210 virtual VtValue _GetDefaultValue()
override {
211 if constexpr (VtIsKnownValueType<T>()) {
239class Hd_SampledDataSourceDefaultValueAccessor
243 GetDefaultValue(
const HdSampledDataSourceHandle &dataSource) {
244 return dataSource ? dataSource->_GetDefaultValue() :
VtValue {};
260 template <
class T,
class ...>
class Visitor,
261 typename ...TypeArgs,
265HdVisitSampledDataSourceType(
266 const HdSampledDataSourceHandle& dataSource, FnArgs&&... args)
268 return VtVisitValueType<Visitor, TypeArgs...>(
269 Hd_SampledDataSourceDefaultValueAccessor::GetDefaultValue(dataSource),
270 std::forward<FnArgs>(args)...);
280 template <
class T,
template <
class...>
class,
class ...>
class Visitor,
281 template <
class...>
class Tmpl,
282 typename ...TypeArgs,
286HdVisitSampledDataSourceType(
287 const HdSampledDataSourceHandle& dataSource, FnArgs&&... args)
289 return VtVisitValueType<Visitor, Tmpl, TypeArgs...>(
290 Hd_SampledDataSourceDefaultValueAccessor::GetDefaultValue(dataSource),
291 std::forward<FnArgs>(args)...);
300 template <
typename...>
class DataSource,
301 class UntypedDataSource>
302struct Hd_CopySampledDataSourceTypeVisitor
304 template <
class ...Args>
305 static HdDataSourceBaseHandle Visit(Args&&... args)
307 if constexpr (std::is_same_v<T, VtValue>) {
308 if constexpr (std::is_void_v<UntypedDataSource>) {
312 return UntypedDataSource::New(std::forward<Args>(args)...);
316 return DataSource<T>::New(std::forward<Args>(args)...);
326 template <
typename...>
class DataSource,
327 class UntypedDataSource = void,
329HdDataSourceBaseHandle
330HdCopySampledDataSourceType(
331 const HdSampledDataSourceHandle& dataSource, Args&&... args)
333 return HdVisitSampledDataSourceType<
334 Hd_CopySampledDataSourceTypeVisitor, DataSource, UntypedDataSource>(
335 dataSource, std::forward<Args>(args)...);
341HdGetMergedContributingSampleTimesForInterval(
343 const HdSampledDataSourceHandle *inputDataSources,
344 HdSampledDataSource::Time startTime,
345 HdSampledDataSource::Time endTime,
346 std::vector<HdSampledDataSource::Time> * outSampleTimes);
351HdDebugPrintDataSource(
353 HdDataSourceBaseHandle,
354 int indentLevel = 0);
359HdDebugPrintDataSource(HdDataSourceBaseHandle,
int indentLevel = 0);
361PXR_NAMESPACE_CLOSE_SCOPE
A datasource representing the absence of a datasource.
A datasource representing structured (named, hierarchical) data, for example a geometric primitive or...
virtual TfTokenVector GetNames()=0
Returns the list of names for which Get(...) is expected to return a non-null value.
virtual HdDataSourceBaseHandle Get(const TfToken &name)=0
Returns the child datasource of the given name.
static HD_API HdDataSourceBaseHandle Get(const Handle &container, const HdDataSourceLocator &locator)
A convenience function: given container, return the descendant identified by locator,...
Represents an object which can produce scene data.
Represents an object that can identify the location of a data source.
A datasource representing time-sampled values.
virtual bool GetContributingSampleTimesForInterval(Time startTime, Time endTime, std::vector< Time > *outSampleTimes)=0
Given a shutter window of interest (startTime and endTime relative to the current frame),...
virtual VtValue GetValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset.
A datasource representing a concretely-typed sampled value.
virtual T GetTypedValue(Time shutterOffset)=0
Returns the value of this data source at frame-relative time shutterOffset, as type T.
A datasource representing indexed data.
virtual size_t GetNumElements()=0
Return the number of elements in this datasource.
virtual HdDataSourceBaseHandle GetElement(size_t element)=0
Return the element at position element in this datasource.
Token for efficient comparison, assignment, and hashing of known strings.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
std::vector< TfToken > TfTokenVector
Convenience types.