bufferArrayRange.h
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 #ifndef PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
8 #define PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
9 
10 #include "pxr/pxr.h"
11 #include "pxr/imaging/hd/api.h"
12 #include "pxr/imaging/hd/version.h"
13 #include "pxr/base/tf/token.h"
14 #include "pxr/base/vt/value.h"
15 #include "pxr/imaging/hd/bufferArray.h"
16 
17 #include <memory>
18 
19 PXR_NAMESPACE_OPEN_SCOPE
20 
21 
22 using HdBufferSpecVector = std::vector<struct HdBufferSpec>;
23 using HdBufferArrayRangeSharedPtr = std::shared_ptr<class HdBufferArrayRange>;
24 using HdBufferSourceSharedPtr = std::shared_ptr<class HdBufferSource>;
25 
35 {
36 public:
37 
38  HD_API
40 
46  HD_API
47  virtual ~HdBufferArrayRange();
48 
50  virtual bool IsValid() const = 0;
51 
53  virtual bool IsAssigned() const = 0;
54 
56  virtual bool IsImmutable() const = 0;
57 
59  virtual bool RequiresStaging() const = 0;
60 
63  virtual bool Resize(int numElements) = 0;
64 
66  virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource) = 0;
67 
69  virtual VtValue ReadData(TfToken const &name) const = 0;
70 
73  virtual int GetElementOffset() const = 0;
74 
77  virtual int GetByteOffset(TfToken const& resourceName) const = 0;
78 
80  virtual size_t GetNumElements() const = 0;
81 
83  virtual size_t GetVersion() const = 0;
84 
87  virtual void IncrementVersion() = 0;
88 
90  virtual size_t GetMaxNumElements() const = 0;
91 
93  virtual HdBufferArrayUsageHint GetUsageHint() const = 0;
94 
96  virtual void SetBufferArray(HdBufferArray *bufferArray) = 0;
97 
99  virtual void DebugDump(std::ostream &out) const = 0;
100 
102  bool IsAggregatedWith(HdBufferArrayRangeSharedPtr const &other) const {
103  return (other && (_GetAggregation() == other->_GetAggregation()));
104  }
105 
107  virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const = 0;
108 
109 protected:
111  virtual const void *_GetAggregation() const = 0;
112 
113  // Don't allow copies
114  HdBufferArrayRange(const HdBufferArrayRange &) = delete;
115  HdBufferArrayRange &operator=(const HdBufferArrayRange &) = delete;
116 
117 };
118 
119 HD_API
120 std::ostream &operator <<(std::ostream &out,
121  const HdBufferArrayRange &self);
122 
128 {
129 public:
131  HdBufferArrayRangeContainer(int size) : _ranges(size) { }
132 
135  HD_API
136  void Set(int index, HdBufferArrayRangeSharedPtr const &range);
137 
140  HD_API
141  HdBufferArrayRangeSharedPtr const &Get(int index) const;
142 
145  HD_API
146  void Resize(int size);
147 
148 private:
149  std::vector<HdBufferArrayRangeSharedPtr> _ranges;
150 };
151 
152 
153 PXR_NAMESPACE_CLOSE_SCOPE
154 
155 #endif // PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
virtual bool IsValid() const =0
Returns true if this range is valid.
bool IsAggregatedWith(HdBufferArrayRangeSharedPtr const &other) const
Returns true if the underlying buffer array is aggregated to other's.
Similar to a VAO, this object is a bundle of coherent buffers.
Definition: bufferArray.h:68
virtual VtValue ReadData(TfToken const &name) const =0
Read back the buffer content.
virtual int GetByteOffset(TfToken const &resourceName) const =0
Returns the byte offset at which this range begins in the underlying buffer array for the given resou...
virtual bool IsImmutable() const =0
Returns true if this range is marked as immutable.
virtual size_t GetVersion() const =0
Returns the version of the buffer array.
Interface class for representing range (subset) locator of HdBufferArray.
virtual size_t GetMaxNumElements() const =0
Returns the max number of elements.
A resizable container of HdBufferArrayRanges.
virtual int GetElementOffset() const =0
Returns the offset at which this range begins in the underlying buffer array in terms of elements.
virtual bool IsAssigned() const =0
Returns true is the range has been assigned to a buffer.
HD_API void Set(int index, HdBufferArrayRangeSharedPtr const &range)
Set range into the container at index.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:80
HdBufferArrayRangeContainer(int size)
Constructor.
virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource)=0
Copy source data into buffer.
virtual void DebugDump(std::ostream &out) const =0
Debug output.
virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const =0
Gets the bufferSpecs for all resources.
virtual bool Resize(int numElements)=0
Resize memory area for this range.
virtual const void * _GetAggregation() const =0
Returns the aggregation container to be used in IsAggregatedWith()
HD_API HdBufferArrayRangeSharedPtr const & Get(int index) const
Returns the bar at index.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
virtual HD_API ~HdBufferArrayRange()
Destructor (do nothing).
virtual HdBufferArrayUsageHint GetUsageHint() const =0
Gets the usage hint on the underlying buffer array.
virtual void IncrementVersion()=0
Increment the version of the buffer array.
virtual size_t GetNumElements() const =0
Returns the number of elements.
virtual void SetBufferArray(HdBufferArray *bufferArray)=0
Sets the buffer array associated with this buffer;.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:89
virtual bool RequiresStaging() const =0
Returns true if this needs a staging buffer for CPU to GPU copies.
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...
HD_API void Resize(int size)
Resize the buffer array range container to size size.