HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
bufferSpec.h
Go to the documentation of this file.
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 
36 
37 
38 typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
39 
40 /// \class HdBufferSpec
41 ///
42 /// Describes each named resource of buffer array.
43 /// This specifies the buffer's value type as HdTupleType,
44 /// which specifies the value type, number of components, and
45 /// number of array entries (which may be 1).
46 ///
47 /// for example:
48 /// HdBufferSpecVector
49 /// 0: name = points, tupleType = {HdTypeFloatVec3, 1}
50 /// 1: name = normals, tupleType = {HdTypeFloatVec3, 1}
51 /// 2: name = colors, tupleType = {HdTypeFloatVec3, 1}
52 ///
53 struct HdBufferSpec final {
54  /// Constructor.
56  name(name), tupleType(tupleType) {}
57 
58  /// Util function for adding buffer specs of sources into bufferspecs.
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 
69  /// Returns true if \p subset is a subset of \p superset.
70  /// An empty set is considered a valid subset of the superset.
71  HD_API
72  static bool IsSubset(HdBufferSpecVector const &subset,
73  HdBufferSpecVector const &superset);
74 
75  /// Returns union set of \p spec1 and \p spec2. Duplicated entries are
76  /// uniquified. The order of items in spec1 and spec2 are preserved relative
77  /// to themselves respectively in the result, with items in spec1 appearing
78  /// first.
79  HD_API
81  HdBufferSpecVector const &spec2);
82 
83  /// Returns difference set of \p spec1 and \p spec2, i.e., entries in spec1
84  /// that are not in spec2. Duplicated entries are uniquified. The order of
85  /// items in spec1 is preserved.
86  HD_API
88  HdBufferSpecVector const &spec2);
89 
90  /// Debug output.
91  HD_API
92  static void Dump(HdBufferSpecVector const &specs);
93 
94  /// Return a size_t hash for this spec.
95  HD_API
96  size_t Hash() const;
97 
98  /// Functor to use for unordered sets, maps.
99  struct HashFunctor {
100  size_t operator()(HdBufferSpec const& spec) const {
101  return spec.Hash();
102  }
103  };
104 
105  /// Equality checks.
106  bool operator == (HdBufferSpec const &other) const {
107  return name == other.name && tupleType == other.tupleType;
108  }
109  bool operator != (HdBufferSpec const &other) const {
110  return !(*this == other);
111  }
112 
113  /// Ordering.
114  bool operator < (HdBufferSpec const &other) const {
115  return name < other.name || (name == other.name &&
116  tupleType < other.tupleType);
117  }
118 
121 };
122 
123 // Support TfHash.
124 template <class HashState>
125 void
126 TfHashAppend(HashState &h, HdBufferSpec const &bs)
127 {
128  h.Append(bs.name, bs.tupleType);
129 }
130 
132 
133 #endif // PXR_IMAGING_HD_BUFFER_SPEC_H
HdTupleType tupleType
Definition: bufferSpec.h:120
static void GetBufferSpecs(T const &sources, HdBufferSpecVector *bufferSpecs)
Util function for adding buffer specs of sources into bufferspecs.
Definition: bufferSpec.h:60
static HD_API void Dump(HdBufferSpecVector const &specs)
Debug output.
static HD_API HdBufferSpecVector ComputeUnion(HdBufferSpecVector const &spec1, HdBufferSpecVector const &spec2)
HD_API size_t Hash() const
Return a size_t hash for this spec.
static HD_API HdBufferSpecVector ComputeDifference(HdBufferSpecVector const &spec1, HdBufferSpecVector const &spec2)
#define HD_API
Definition: api.h:40
Functor to use for unordered sets, maps.
Definition: bufferSpec.h:99
TfToken name
Definition: bufferSpec.h:119
PXR_NAMESPACE_OPEN_SCOPE typedef std::vector< struct HdBufferSpec > HdBufferSpecVector
Definition: bufferSpec.h:38
static HD_API bool IsSubset(HdBufferSpecVector const &subset, HdBufferSpecVector const &superset)
bool operator!=(HdBufferSpec const &other) const
Definition: bufferSpec.h:109
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:87
bool operator==(HdBufferSpec const &other) const
Equality checks.
Definition: bufferSpec.h:106
GLuint const GLchar * name
Definition: glcorearb.h:786
std::vector< struct HdBufferSpec > HdBufferSpecVector
GLfloat GLfloat GLfloat GLfloat h
Definition: glcorearb.h:2002
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1432
size_t operator()(HdBufferSpec const &spec) const
Definition: bufferSpec.h:100
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
bool operator<(HdBufferSpec const &other) const
Ordering.
Definition: bufferSpec.h:114
HdBufferSpec(TfToken const &name, HdTupleType tupleType)
Constructor.
Definition: bufferSpec.h:55
void TfHashAppend(HashState &h, HdBufferSpec const &bs)
Definition: bufferSpec.h:126
GLenum src
Definition: glcorearb.h:1793