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 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 
19 
20 
21 typedef std::vector<struct HdBufferSpec> HdBufferSpecVector;
22 
23 /// \class HdBufferSpec
24 ///
25 /// Describes each named resource of buffer array.
26 /// This specifies the buffer's value type as HdTupleType,
27 /// which specifies the value type, number of components, and
28 /// number of array entries (which may be 1).
29 ///
30 /// for example:
31 /// HdBufferSpecVector
32 /// 0: name = points, tupleType = {HdTypeFloatVec3, 1}
33 /// 1: name = normals, tupleType = {HdTypeFloatVec3, 1}
34 /// 2: name = colors, tupleType = {HdTypeFloatVec3, 1}
35 ///
36 struct HdBufferSpec final {
37  /// Constructor.
39  name(name), tupleType(tupleType) {}
40 
41  /// Util function for adding buffer specs of sources into bufferspecs.
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 
52  /// Returns true if \p subset is a subset of \p superset.
53  /// An empty set is considered a valid subset of the superset.
54  HD_API
55  static bool IsSubset(HdBufferSpecVector const &subset,
56  HdBufferSpecVector const &superset);
57 
58  /// Returns union set of \p spec1 and \p spec2. Duplicated entries are
59  /// uniquified. The order of items in spec1 and spec2 are preserved relative
60  /// to themselves respectively in the result, with items in spec1 appearing
61  /// first.
62  HD_API
64  HdBufferSpecVector const &spec2);
65 
66  /// Returns difference set of \p spec1 and \p spec2, i.e., entries in spec1
67  /// that are not in spec2. Duplicated entries are uniquified. The order of
68  /// items in spec1 is preserved.
69  HD_API
71  HdBufferSpecVector const &spec2);
72 
73  /// Debug output.
74  HD_API
75  static void Dump(HdBufferSpecVector const &specs);
76 
77  /// Return a size_t hash for this spec.
78  HD_API
79  size_t Hash() const;
80 
81  /// Functor to use for unordered sets, maps.
82  struct HashFunctor {
83  size_t operator()(HdBufferSpec const& spec) const {
84  return spec.Hash();
85  }
86  };
87 
88  /// Equality checks.
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 
96  /// Ordering.
97  bool operator < (HdBufferSpec const &other) const {
98  return name < other.name || (name == other.name &&
99  tupleType < other.tupleType);
100  }
101 
104 };
105 
106 // Support TfHash.
107 template <class HashState>
108 void
109 TfHashAppend(HashState &h, HdBufferSpec const &bs)
110 {
111  h.Append(bs.name, bs.tupleType);
112 }
113 
115 
116 #endif // PXR_IMAGING_HD_BUFFER_SPEC_H
HdTupleType tupleType
Definition: bufferSpec.h:103
static void GetBufferSpecs(T const &sources, HdBufferSpecVector *bufferSpecs)
Util function for adding buffer specs of sources into bufferspecs.
Definition: bufferSpec.h:43
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:23
Functor to use for unordered sets, maps.
Definition: bufferSpec.h:82
TfToken name
Definition: bufferSpec.h:102
PXR_NAMESPACE_OPEN_SCOPE typedef std::vector< struct HdBufferSpec > HdBufferSpecVector
Definition: bufferSpec.h:21
static HD_API bool IsSubset(HdBufferSpecVector const &subset, HdBufferSpecVector const &superset)
bool operator!=(HdBufferSpec const &other) const
Definition: bufferSpec.h:92
GLsizei GLenum * sources
Definition: glcorearb.h:2542
Definition: token.h:70
bool operator==(HdBufferSpec const &other) const
Equality checks.
Definition: bufferSpec.h:89
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:1425
size_t operator()(HdBufferSpec const &spec) const
Definition: bufferSpec.h:83
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
bool operator<(HdBufferSpec const &other) const
Ordering.
Definition: bufferSpec.h:97
HdBufferSpec(TfToken const &name, HdTupleType tupleType)
Constructor.
Definition: bufferSpec.h:38
void TfHashAppend(HashState &h, HdBufferSpec const &bs)
Definition: bufferSpec.h:109
GLenum src
Definition: glcorearb.h:1793