All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
bufferSpec.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_BUFFER_SPEC_H
8#define PXR_IMAGING_HD_BUFFER_SPEC_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/types.h"
14#include "pxr/base/tf/stl.h"
15#include "pxr/base/tf/token.h"
16#include <vector>
17
18PXR_NAMESPACE_OPEN_SCOPE
19
20
21typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
22
36struct HdBufferSpec final {
38 HdBufferSpec(TfToken const &name, HdTupleType tupleType) :
39 name(name), tupleType(tupleType) {}
40
42 template<typename T>
43 static void GetBufferSpecs(T const &sources,
44 HdBufferSpecVector *bufferSpecs) {
45 for (auto const &src : sources) {
46 if (src->IsValid()) {
47 src->GetBufferSpecs(bufferSpecs);
48 }
49 }
50 }
51
54 HD_API
55 static bool IsSubset(HdBufferSpecVector const &subset,
56 HdBufferSpecVector const &superset);
57
62 HD_API
63 static HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1,
64 HdBufferSpecVector const &spec2);
65
69 HD_API
70 static HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1,
71 HdBufferSpecVector const &spec2);
72
74 HD_API
75 static void Dump(HdBufferSpecVector const &specs);
76
78 HD_API
79 size_t Hash() const;
80
82 struct HashFunctor {
83 size_t operator()(HdBufferSpec const& spec) const {
84 return spec.Hash();
85 }
86 };
87
89 bool operator == (HdBufferSpec const &other) const {
90 return name == other.name && tupleType == other.tupleType;
91 }
92 bool operator != (HdBufferSpec const &other) const {
93 return !(*this == other);
94 }
95
97 bool operator < (HdBufferSpec const &other) const {
98 return name < other.name || (name == other.name &&
99 tupleType < other.tupleType);
100 }
101
102 TfToken name;
103 HdTupleType tupleType;
104};
105
106// Support TfHash.
107template <class HashState>
108void
109TfHashAppend(HashState &h, HdBufferSpec const &bs)
110{
111 h.Append(bs.name, bs.tupleType);
112}
113
114PXR_NAMESPACE_CLOSE_SCOPE
115
116#endif // PXR_IMAGING_HD_BUFFER_SPEC_H
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
Functor to use for unordered sets, maps.
Definition: bufferSpec.h:82
Describes each named resource of buffer array.
Definition: bufferSpec.h:36
static HD_API bool IsSubset(HdBufferSpecVector const &subset, HdBufferSpecVector const &superset)
Returns true if subset is a subset of superset.
static HD_API HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1, HdBufferSpecVector const &spec2)
Returns difference set of spec1 and spec2, i.e., entries in spec1 that are not in spec2.
bool operator==(HdBufferSpec const &other) const
Equality checks.
Definition: bufferSpec.h:89
static HD_API void Dump(HdBufferSpecVector const &specs)
Debug output.
static HD_API HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1, HdBufferSpecVector const &spec2)
Returns union set of spec1 and spec2.
bool operator<(HdBufferSpec const &other) const
Ordering.
Definition: bufferSpec.h:97
HdBufferSpec(TfToken const &name, HdTupleType tupleType)
Constructor.
Definition: bufferSpec.h:38
HD_API size_t Hash() const
Return a size_t hash for this spec.
static void GetBufferSpecs(T const &sources, HdBufferSpecVector *bufferSpecs)
Util function for adding buffer specs of sources into bufferspecs.
Definition: bufferSpec.h:43
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...