HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bufferArrayRange.h
Go to the documentation of this file.
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"
16 
17 #include <memory>
18 
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 
26 /// \class HdBufferArrayRange
27 ///
28 /// Interface class for representing range (subset) locator of HdBufferArray.
29 ///
30 /// Each memory management strategy defines a specialized range class which is
31 /// inherited of this interface so that client (drawItem) can be agnostic about
32 /// the implementation detail of aggregation.
33 ///
35 {
36 public:
37 
38  HD_API
40 
41  /// Destructor (do nothing).
42  /// The specialized range class may want to do something for garbage
43  /// collection in its destructor. However, be careful not do any
44  /// substantial work here (obviously including any kind of GL calls),
45  /// since the destructor gets called frequently on various contexts.
46  HD_API
47  virtual ~HdBufferArrayRange();
48 
49  /// Returns true if this range is valid
50  virtual bool IsValid() const = 0;
51 
52  /// Returns true is the range has been assigned to a buffer
53  virtual bool IsAssigned() const = 0;
54 
55  /// Returns true if this range is marked as immutable.
56  virtual bool IsImmutable() const = 0;
57 
58  /// Returns true if this needs a staging buffer for CPU to GPU copies.
59  virtual bool RequiresStaging() const = 0;
60 
61  /// Resize memory area for this range. Returns true if it causes container
62  /// buffer reallocation.
63  virtual bool Resize(int numElements) = 0;
64 
65  /// Copy source data into buffer
66  virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource) = 0;
67 
68  /// Read back the buffer content
69  virtual VtValue ReadData(TfToken const &name) const = 0;
70 
71  /// Returns the offset at which this range begins in the underlying buffer
72  /// array in terms of elements.
73  virtual int GetElementOffset() const = 0;
74 
75  /// Returns the byte offset at which this range begins in the underlying
76  /// buffer array for the given resource.
77  virtual int GetByteOffset(TfToken const& resourceName) const = 0;
78 
79  /// Returns the number of elements
80  virtual size_t GetNumElements() const = 0;
81 
82  /// Returns the version of the buffer array.
83  virtual size_t GetVersion() const = 0;
84 
85  /// Increment the version of the buffer array. mostly used for notifying
86  /// drawbatches to be rebuilt to remove expired BufferArrayRange.
87  virtual void IncrementVersion() = 0;
88 
89  /// Returns the max number of elements
90  virtual size_t GetMaxNumElements() const = 0;
91 
92  /// Gets the usage hint on the underlying buffer array
93  virtual HdBufferArrayUsageHint GetUsageHint() const = 0;
94 
95  /// Sets the buffer array associated with this buffer;
96  virtual void SetBufferArray(HdBufferArray *bufferArray) = 0;
97 
98  /// Debug output
99  virtual void DebugDump(std::ostream &out) const = 0;
100 
101  /// Returns true if the underlying buffer array is aggregated to other's
103  return (other && (_GetAggregation() == other->_GetAggregation()));
104  }
105 
106  /// Gets the bufferSpecs for all resources.
107  virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const = 0;
108 
109 protected:
110  /// Returns the aggregation container to be used in IsAggregatedWith()
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 
123 /// \class HdBufferArrayRangeContainer
124 ///
125 /// A resizable container of HdBufferArrayRanges.
126 ///
128 {
129 public:
130  /// Constructor
131  HdBufferArrayRangeContainer(int size) : _ranges(size) { }
132 
133  /// Set \p range into the container at \p index.
134  /// If the size of container is smaller than index, resize it.
135  HD_API
136  void Set(int index, HdBufferArrayRangeSharedPtr const &range);
137 
138  /// Returns the bar at \p index. returns null if either the index
139  /// is out of range or not yet set.
140  HD_API
141  HdBufferArrayRangeSharedPtr const &Get(int index) const;
142 
143  /// Resize the buffer array range container to size \p size.
144  /// Used to explicitly resize or shrink the container.
145  HD_API
146  void Resize(int size);
147 
148 private:
149  std::vector<HdBufferArrayRangeSharedPtr> _ranges;
150 };
151 
152 
154 
155 #endif // PXR_IMAGING_HD_BUFFER_ARRAY_RANGE_H
virtual int GetByteOffset(TfToken const &resourceName) const =0
GLenum GLint * range
Definition: glcorearb.h:1925
virtual bool IsValid() const =0
Returns true if this range is valid.
HdBufferArrayRangeContainer(int size)
Constructor.
virtual bool IsImmutable() const =0
Returns true if this range is marked as immutable.
HD_API HdBufferArrayRangeSharedPtr const & Get(int index) const
#define HD_API
Definition: api.h:23
virtual bool RequiresStaging() const =0
Returns true if this needs a staging buffer for CPU to GPU copies.
virtual VtValue ReadData(TfToken const &name) const =0
Read back the buffer content.
virtual size_t GetVersion() const =0
Returns the version of the buffer array.
virtual void DebugDump(std::ostream &out) const =0
Debug output.
virtual size_t GetNumElements() const =0
Returns the number of elements.
virtual void GetBufferSpecs(HdBufferSpecVector *bufferSpecs) const =0
Gets the bufferSpecs for all resources.
virtual bool IsAssigned() const =0
Returns true is the range has been assigned to a buffer.
Definition: token.h:70
virtual void CopyData(HdBufferSourceSharedPtr const &bufferSource)=0
Copy source data into buffer.
HD_API void Set(int index, HdBufferArrayRangeSharedPtr const &range)
GLuint const GLchar * name
Definition: glcorearb.h:786
std::vector< struct HdBufferSpec > HdBufferSpecVector
virtual size_t GetMaxNumElements() const =0
Returns the max number of elements.
bool IsAggregatedWith(HdBufferArrayRangeSharedPtr const &other) const
Returns true if the underlying buffer array is aggregated to other's.
HdBufferArrayRange & operator=(const HdBufferArrayRange &)=delete
virtual HD_API ~HdBufferArrayRange()
HD_API HdBufferArrayRange()
virtual void IncrementVersion()=0
GLsizeiptr size
Definition: glcorearb.h:664
virtual bool Resize(int numElements)=0
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
virtual const void * _GetAggregation() const =0
Returns the aggregation container to be used in IsAggregatedWith()
GLuint index
Definition: glcorearb.h:786
HD_API void Resize(int size)
uint32_t HdBufferArrayUsageHint
Definition: bufferArray.h:60
virtual void SetBufferArray(HdBufferArray *bufferArray)=0
Sets the buffer array associated with this buffer;.
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
std::shared_ptr< HdBufferArrayRange > HdBufferArrayRangeSharedPtr
Definition: bufferArray.h:27
HD_API std::ostream & operator<<(std::ostream &out, const HdBufferArrayRange &self)
std::shared_ptr< class HdBufferSource > HdBufferSourceSharedPtr
virtual int GetElementOffset() const =0
Definition: value.h:146
virtual HdBufferArrayUsageHint GetUsageHint() const =0
Gets the usage hint on the underlying buffer array.