All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vtBufferSource.h
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 HD_VT_BUFFER_SOURCE_H
25 #define HD_VT_BUFFER_SOURCE_H
26 
27 #include "pxr/pxr.h"
28 #include "pxr/imaging/hd/api.h"
29 #include "pxr/imaging/hd/version.h"
30 #include "pxr/imaging/hd/bufferSource.h"
31 #include "pxr/imaging/hd/types.h"
32 
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/gf/matrix4d.h"
35 #include "pxr/base/vt/value.h"
36 
37 #include <vector>
38 #include <boost/shared_ptr.hpp>
39 
40 #include <iosfwd>
41 
42 PXR_NAMESPACE_OPEN_SCOPE
43 
44 
51 public:
55  HD_API
56  HdVtBufferSource(TfToken const &name, VtValue const& value,
57  int arraySize=1);
58 
64  HD_API
65  HdVtBufferSource(TfToken const &name, GfMatrix4d const &matrix);
66 
74  HD_API
75  HdVtBufferSource(TfToken const &name, VtArray<GfMatrix4d> const &matrices,
76  int arraySize=1);
77 
81  HD_API
82  static HdType GetDefaultMatrixType();
83 
85  HD_API
87 
92  HD_API
93  void Truncate(size_t numElements);
94 
96  virtual TfToken const &GetName() const override {
97  return _name;
98  }
99 
101  virtual void const* GetData() const override {
102  return HdGetValueData(_value);
103  }
104 
106  virtual HdTupleType GetTupleType() const override {
107  return _tupleType;
108  }
109 
112  HD_API
113  virtual size_t GetNumElements() const override;
114 
116  virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override {
117  specs->push_back(HdBufferSpec(_name, _tupleType));
118  }
119 
121  virtual bool Resolve() override {
122  if (!_TryLock()) return false;
123 
124  // nothing. just marks as resolved, and returns _data in GetData()
125  _SetResolved();
126  return true;
127  }
128 
129 protected:
130  HD_API
131  virtual bool _CheckValid() const override;
132 
133 private:
134  // Constructor helper.
135  void _SetValue(const VtValue &v, int arraySize);
136 
137  TfToken _name;
138 
139  // We hold the source value to avoid making unnecessary copies of the data: if
140  // we immediately copy the source into a temporary buffer, we may need to
141  // copy it again into an aggregate buffer later.
142  //
143  // We can elide this member easily with only a few internal changes, it
144  // should never surface in the public API and for the same reason, this
145  // class should remain noncopyable.
146  VtValue _value;
147  HdTupleType _tupleType;
148  size_t _numElements;
149 };
150 
152 HD_API
153 std::ostream &operator <<(std::ostream &out, const HdVtBufferSource& self);
154 
155 PXR_NAMESPACE_CLOSE_SCOPE
156 
157 #endif //HD_VT_BUFFER_SOURCE_H
void _SetResolved()
Marks this buffer source as resolved.
Definition: bufferSource.h:150
virtual HD_API bool _CheckValid() const override
Checks the validity of the source buffer.
HD_API HdVtBufferSource(TfToken const &name, VtValue const &value, int arraySize=1)
Constructs a new buffer from a VtValue.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:239
virtual bool Resolve() override
Prepare the access of GetData().
Describes each named resource of buffer array.
Definition: bufferSpec.h:53
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
virtual void GetBufferSpecs(HdBufferSpecVector *specs) const override
Add the buffer spec for this buffer source into given bufferspec vector.
HD_API ~HdVtBufferSource()
Destructor deletes the internal storage.
A transient buffer of data that has not yet been committed.
Definition: bufferSource.h:57
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:193
bool _TryLock()
Non-blocking lock acquisition.
Definition: bufferSource.h:174
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
virtual HD_API size_t GetNumElements() const override
Returns the number of elements (e.g.
virtual TfToken const & GetName() const override
Return the name of this buffer source.
virtual void const * GetData() const override
Returns the raw pointer to the underlying data.
virtual HdTupleType GetTupleType() const override
Returns the data type and count of this buffer source.
HD_API void Truncate(size_t numElements)
Truncate the buffer to the given number of elements.
static HD_API HdType GetDefaultMatrixType()
Returns the default matrix type.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182
An implementation of HdBufferSource where the source data value is a VtValue.