HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
vectorSchema.h
Go to the documentation of this file.
1 //
2 // Copyright 2022 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 
25 #ifndef PXR_IMAGING_HD_VECTOR_SCHEMA_H
26 #define PXR_IMAGING_HD_VECTOR_SCHEMA_H
27 
28 #include "pxr/imaging/hd/api.h"
29 
31 
33 
34 // ----------------------------------------------------------------------------
35 
36 /// Vector schema classes represent a view of a vector data source
37 /// which is returning untyped data sources.
38 ///
40 {
41 public:
42  HdVectorSchema(HdVectorDataSourceHandle const &vector)
43  : _vector(vector) {}
44 
45  HD_API
46  static HdVectorDataSourceHandle
48  size_t count,
49  const HdDataSourceBaseHandle *values);
50 
51  /// Returns the vector data source that this schema is interpreting.
52  HD_API
53  HdVectorDataSourceHandle GetVector();
54  HD_API
55  bool IsDefined() const;
56 
57  /// Returns \c true if this schema is applied on top of a non-null
58  /// vector.
59  explicit operator bool() const { return IsDefined(); }
60 
61  /// Number of elements in the vector.
62  HD_API
63  size_t GetNumElements() const;
64 
65 protected:
66  HdVectorDataSourceHandle _vector;
67 };
68 
69 /// Base class for vector schema classes that represent a view of
70 /// a vector data source containing data source of a given type.
71 ///
72 template<typename T>
74 {
75 public:
78 
79  HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
80  : HdVectorSchema(vector) {}
81 
82  DataSourceHandle GetElement(const size_t element) const {
83  return
84  _vector
85  ? DataSource::Cast(_vector->GetElement(element))
86  : nullptr;
87  }
88 };
89 
90 /// Base class for vector schema classes that represent a view of
91 /// a vector data source containing container data sources conforming
92 /// to a given HdSchema.
93 ///
94 template<typename Schema>
96 {
97 public:
98  HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
99  : HdVectorSchema(vector) {}
100 
101  Schema GetElement(const size_t element) const {
102  return Schema(
103  _vector
104  ? HdContainerDataSource::Cast(_vector->GetElement(element))
105  : nullptr);
106  }
107 };
108 
110 
111 #endif
HD_API size_t GetNumElements() const
Number of elements in the vector.
Schema GetElement(const size_t element) const
Definition: vectorSchema.h:101
HdVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:42
#define HD_API
Definition: api.h:40
DataSourceHandle GetElement(const size_t element) const
Definition: vectorSchema.h:82
HD_API bool IsDefined() const
HD_API HdVectorDataSourceHandle GetVector()
Returns the vector data source that this schema is interpreting.
HdVectorDataSourceHandle _vector
Definition: vectorSchema.h:66
HdSchemaBasedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:98
static HD_API HdVectorDataSourceHandle BuildRetained(size_t count, const HdDataSourceBaseHandle *values)
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1441
HdTypedVectorSchema(HdVectorDataSourceHandle const &vector)
Definition: vectorSchema.h:79
GLenum GLsizei GLsizei GLint * values
Definition: glcorearb.h:1602
typename DataSource::Handle DataSourceHandle
Definition: vectorSchema.h:77
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:91
GLint GLsizei count
Definition: glcorearb.h:405
void * Handle
Definition: plugin.h:27