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