Loading...
Searching...
No Matches
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 PXR_IMAGING_HD_VT_BUFFER_SOURCE_H
25#define PXR_IMAGING_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"
35#include "pxr/base/vt/value.h"
36
37#include <vector>
38
39#include <iosfwd>
40
41PXR_NAMESPACE_OPEN_SCOPE
42
43
49class HdVtBufferSource final : public HdBufferSource
50{
51public:
57 HD_API
58 HdVtBufferSource(TfToken const &name, VtValue const& value,
59 int arraySize=1, bool allowDoubles=true);
60
69 HD_API
70 HdVtBufferSource(TfToken const &name, GfMatrix4d const &matrix,
71 bool allowDoubles=true);
72
82 HD_API
83 HdVtBufferSource(TfToken const &name, VtArray<GfMatrix4d> const &matrices,
84 int arraySize=1, bool allowDoubles=true);
85
89 HD_API
90 static HdType GetDefaultMatrixType();
91
93 HD_API
95
100 HD_API
101 void Truncate(size_t numElements);
102
104 TfToken const &GetName() const override {
105 return _name;
106 }
107
109 void const* GetData() const override {
110 return HdGetValueData(_value);
111 }
112
114 HdTupleType GetTupleType() const override {
115 return _tupleType;
116 }
117
120 HD_API
121 size_t GetNumElements() const override;
122
124 void GetBufferSpecs(HdBufferSpecVector *specs) const override {
125 specs->push_back(HdBufferSpec(_name, _tupleType));
126 }
127
129 bool Resolve() override {
130 if (!_TryLock()) return false;
131
132 // nothing. just marks as resolved, and returns _data in GetData()
133 _SetResolved();
134 return true;
135 }
136
137protected:
138 HD_API
139 bool _CheckValid() const override;
140
141private:
142 // Constructor helper.
143 void _SetValue(const VtValue &v, int arraySize, bool allowDoubles);
144
145 TfToken _name;
146
147 // We hold the source value to avoid making unnecessary copies of the data: if
148 // we immediately copy the source into a temporary buffer, we may need to
149 // copy it again into an aggregate buffer later.
150 //
151 // We can elide this member easily with only a few internal changes, it
152 // should never surface in the public API and for the same reason, this
153 // class should remain noncopyable.
154 VtValue _value;
155 HdTupleType _tupleType;
156 size_t _numElements;
157};
158
160HD_API
161std::ostream &operator <<(std::ostream &out, const HdVtBufferSource& self);
162
163PXR_NAMESPACE_CLOSE_SCOPE
164
165#endif //PXR_IMAGING_HD_VT_BUFFER_SOURCE_H
Stores a 4x4 matrix of double elements.
Definition: matrix4d.h:88
A transient buffer of data that has not yet been committed.
Definition: bufferSource.h:56
bool _TryLock()
Non-blocking lock acquisition.
Definition: bufferSource.h:173
void _SetResolved()
Marks this buffer source as resolved.
Definition: bufferSource.h:149
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:88
Represents an arbitrary dimensional rectangular container class.
Definition: array.h:228
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:165
Describes each named resource of buffer array.
Definition: bufferSpec.h:53
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:358
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...