All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
vtBufferSource.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_VT_BUFFER_SOURCE_H
8#define PXR_IMAGING_HD_VT_BUFFER_SOURCE_H
9
10#include "pxr/pxr.h"
11#include "pxr/imaging/hd/api.h"
12#include "pxr/imaging/hd/version.h"
13#include "pxr/imaging/hd/bufferSource.h"
14#include "pxr/imaging/hd/types.h"
15
16#include "pxr/base/tf/token.h"
18#include "pxr/base/vt/value.h"
19
20#include <vector>
21
22#include <iosfwd>
23
24PXR_NAMESPACE_OPEN_SCOPE
25
26
32class HdVtBufferSource final : public HdBufferSource
33{
34public:
40 HD_API
41 HdVtBufferSource(TfToken const &name, VtValue const& value,
42 int arraySize=1, bool allowDoubles=true);
43
52 HD_API
53 HdVtBufferSource(TfToken const &name, GfMatrix4d const &matrix,
54 bool allowDoubles=true);
55
65 HD_API
66 HdVtBufferSource(TfToken const &name, VtArray<GfMatrix4d> const &matrices,
67 int arraySize=1, bool allowDoubles=true);
68
72 HD_API
73 static HdType GetDefaultMatrixType();
74
76 HD_API
78
83 HD_API
84 void Truncate(size_t numElements);
85
87 TfToken const &GetName() const override {
88 return _name;
89 }
90
92 void const* GetData() const override {
93 return HdGetValueData(_value);
94 }
95
97 HdTupleType GetTupleType() const override {
98 return _tupleType;
99 }
100
103 HD_API
104 size_t GetNumElements() const override;
105
107 void GetBufferSpecs(HdBufferSpecVector *specs) const override {
108 specs->push_back(HdBufferSpec(_name, _tupleType));
109 }
110
112 bool Resolve() override {
113 if (!_TryLock()) return false;
114
115 // nothing. just marks as resolved, and returns _data in GetData()
116 _SetResolved();
117 return true;
118 }
119
120protected:
121 HD_API
122 bool _CheckValid() const override;
123
124private:
125 // Constructor helper.
126 void _SetValue(const VtValue &v, int arraySize, bool allowDoubles);
127
128 TfToken _name;
129
130 // We hold the source value to avoid making unnecessary copies of the data: if
131 // we immediately copy the source into a temporary buffer, we may need to
132 // copy it again into an aggregate buffer later.
133 //
134 // We can elide this member easily with only a few internal changes, it
135 // should never surface in the public API and for the same reason, this
136 // class should remain noncopyable.
137 VtValue _value;
138 HdTupleType _tupleType;
139 size_t _numElements;
140};
141
143HD_API
144std::ostream &operator <<(std::ostream &out, const HdVtBufferSource& self);
145
146PXR_NAMESPACE_CLOSE_SCOPE
147
148#endif //PXR_IMAGING_HD_VT_BUFFER_SOURCE_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:71
A transient buffer of data that has not yet been committed.
Definition: bufferSource.h:39
bool _TryLock()
Non-blocking lock acquisition.
Definition: bufferSource.h:156
void _SetResolved()
Marks this buffer source as resolved.
Definition: bufferSource.h:132
An implementation of HdBufferSource where the source data value is a VtValue.
HD_API HdVtBufferSource(TfToken const &name, GfMatrix4d const &matrix, bool allowDoubles=true)
Constructs a new buffer from a matrix.
void const * GetData() const override
Returns the raw pointer to the underlying data.
HD_API HdVtBufferSource(TfToken const &name, VtArray< GfMatrix4d > const &matrices, int arraySize=1, bool allowDoubles=true)
Constructs a new buffer from a matrix.
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.
HD_API bool _CheckValid() const override
Checks the validity of the source buffer.
TfToken const & GetName() const override
Return the name of this buffer source.
bool Resolve() override
Prepare the access of GetData().
void GetBufferSpecs(HdBufferSpecVector *specs) const override
Add the buffer spec for this buffer source into given bufferspec vector.
static HD_API HdType GetDefaultMatrixType()
Returns the default matrix type.
HD_API ~HdVtBufferSource() override
Destructor deletes the internal storage.
HD_API size_t GetNumElements() const override
Returns the number of elements (e.g.
HD_API HdVtBufferSource(TfToken const &name, VtValue const &value, int arraySize=1, bool allowDoubles=true)
Constructs a new buffer from a VtValue.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:211
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:147
Describes each named resource of buffer array.
Definition: bufferSpec.h:36
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:343
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...