All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bufferSpec.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_BUFFER_SPEC_H
25 #define PXR_IMAGING_HD_BUFFER_SPEC_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/types.h"
31 #include "pxr/base/tf/stl.h"
32 #include "pxr/base/tf/token.h"
33 #include <vector>
34 
35 PXR_NAMESPACE_OPEN_SCOPE
36 
37 
38 typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
39 
53 struct HdBufferSpec final {
55  HdBufferSpec(TfToken const &name, HdTupleType tupleType) :
56  name(name), tupleType(tupleType) {}
57 
59  template<typename T>
60  static void GetBufferSpecs(T const &sources,
61  HdBufferSpecVector *bufferSpecs) {
62  for (auto const &src : sources) {
63  if (src->IsValid()) {
64  src->GetBufferSpecs(bufferSpecs);
65  }
66  }
67  }
68 
71  HD_API
72  static bool IsSubset(HdBufferSpecVector const &subset,
73  HdBufferSpecVector const &superset);
74 
77  HD_API
78  static HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1,
79  HdBufferSpecVector const &spec2);
80 
83  HD_API
84  static HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1,
85  HdBufferSpecVector const &spec2);
86 
88  HD_API
89  static void Dump(HdBufferSpecVector const &specs);
90 
92  HD_API
93  size_t Hash() const;
94 
96  struct HashFunctor {
97  size_t operator()(HdBufferSpec const& spec) const {
98  return spec.Hash();
99  }
100  };
101 
103  bool operator == (HdBufferSpec const &other) const {
104  return name == other.name && tupleType == other.tupleType;
105  }
106  bool operator != (HdBufferSpec const &other) const {
107  return !(*this == other);
108  }
109 
111  bool operator < (HdBufferSpec const &other) const {
112  return name < other.name || (name == other.name &&
113  tupleType < other.tupleType);
114  }
115 
116  TfToken name;
117  HdTupleType tupleType;
118 };
119 
120 // Support TfHash.
121 template <class HashState>
122 void
123 TfHashAppend(HashState &h, HdBufferSpec const &bs)
124 {
125  h.Append(bs.name, bs.tupleType);
126 }
127 
128 PXR_NAMESPACE_CLOSE_SCOPE
129 
130 #endif // PXR_IMAGING_HD_BUFFER_SPEC_H
HD_API size_t Hash() const
Return a size_t hash for this spec.
HdTupleType represents zero, one, or more values of the same HdType.
Definition: types.h:325
static HD_API void Dump(HdBufferSpecVector const &specs)
Debug output.
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...
Functor to use for unorderd sets, maps.
Definition: bufferSpec.h:96
bool operator==(HdBufferSpec const &other) const
Equality checks.
Definition: bufferSpec.h:103
Describes each named resource of buffer array.
Definition: bufferSpec.h:53
static HD_API bool IsSubset(HdBufferSpecVector const &subset, HdBufferSpecVector const &superset)
Returns true if subset is a subset of superset.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:87
static HD_API HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1, HdBufferSpecVector const &spec2)
Returns union set of spec1 and spec2.
static void GetBufferSpecs(T const &sources, HdBufferSpecVector *bufferSpecs)
Util function for adding buffer specs of sources into bufferspecs.
Definition: bufferSpec.h:60
bool operator<(HdBufferSpec const &other) const
Ordering.
Definition: bufferSpec.h:111
HdBufferSpec(TfToken const &name, HdTupleType tupleType)
Constructor.
Definition: bufferSpec.h:55
TfToken class for efficient string referencing and hashing, plus conversions to and from stl string c...