All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
shaderProperty.h
Go to the documentation of this file.
1 //
2 // Copyright 2018 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 SDR_SHADERPROPERTY_H
26 #define SDR_SHADERPROPERTY_H
27 
29 
30 #include "pxr/pxr.h"
31 #include "pxr/usd/sdr/api.h"
32 #include "pxr/base/tf/staticTokens.h"
33 #include "pxr/base/tf/token.h"
34 #include "pxr/base/tf/weakBase.h"
35 #include "pxr/base/vt/value.h"
36 #include "pxr/usd/ndr/property.h"
37 #include "pxr/usd/sdr/shaderNode.h"
38 
39 PXR_NAMESPACE_OPEN_SCOPE
40 
41 // If additional types are added here, it's also worth trying to add a mapping
42 // to the equivalent Sdf type in the implementation file.
43 #define SDR_PROPERTY_TYPE_TOKENS \
44  ((Int, "int")) \
45  ((String, "string")) \
46  ((Float, "float")) \
47  ((Color, "color")) \
48  ((Point, "point")) \
49  ((Normal, "normal")) \
50  ((Vector, "vector")) \
51  ((Matrix, "matrix")) \
52  ((Struct, "struct")) \
53  ((Terminal, "terminal")) \
54  ((Vstruct, "vstruct")) \
55  ((Unknown, "unknown"))
56 
57 // Note: Metadata keys that are generated by parsers should start with
58 // "__SDR__" to reduce the risk of collision with metadata actually in the
59 // shader.
60 #define SDR_PROPERTY_METADATA_TOKENS \
61  ((Label, "label")) \
62  ((Help, "help")) \
63  ((Page, "page")) \
64  ((RenderType, "renderType")) \
65  ((Role, "role")) \
66  ((Widget, "widget")) \
67  ((Hints, "hints")) \
68  ((Options, "options")) \
69  ((IsDynamicArray, "isDynamicArray")) \
70  ((Connectable, "connectable")) \
71  ((ValidConnectionTypes, "validConnectionTypes")) \
72  ((VstructMemberOf, "vstructMemberOf")) \
73  ((VstructMemberName, "vstructMemberName")) \
74  ((VstructConditionalExpr, "vstructConditionalExpr"))\
75  ((IsAssetIdentifier, "__SDR__isAssetIdentifier"))\
76  ((ImplementationName, "__SDR__implementationName"))\
77  ((DefaultInput, "__SDR__defaultinput")) \
78  ((Target, "__SDR__target")) \
79  ((Colorspace, "__SDR__colorspace"))
80 
81 
82 // The following tokens are valid values for the metadata "role"
83 #define SDR_PROPERTY_ROLE_TOKENS \
84  ((None, "none"))
85 
86 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyTypes, SDR_API, SDR_PROPERTY_TYPE_TOKENS);
87 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyMetadata, SDR_API,
88  SDR_PROPERTY_METADATA_TOKENS);
89 TF_DECLARE_PUBLIC_TOKENS(SdrPropertyRole, SDR_API,
90  SDR_PROPERTY_ROLE_TOKENS);
91 
97 {
98 public:
99  // Constructor.
100  SDR_API
102  const TfToken& name,
103  const TfToken& type,
104  const VtValue& defaultValue,
105  bool isOutput,
106  size_t arraySize,
107  const NdrTokenMap& metadata,
108  const NdrTokenMap& hints,
109  const NdrOptionVec& options
110  );
111 
118 
122  SDR_API
123  const TfToken& GetLabel() const { return _label; }
124 
126  SDR_API
127  const std::string& GetHelp() const;
128 
130  SDR_API
131  const TfToken& GetPage() const { return _page; }
132 
136  SDR_API
137  const TfToken& GetWidget() const { return _widget; }
138 
141  SDR_API
142  const NdrTokenMap& GetHints() const { return _hints; }
143 
147  SDR_API
148  const NdrOptionVec& GetOptions() const { return _options; }
149 
157  SDR_API
158  const std::string& GetImplementationName() const;
159 
161 
162 
165 
167  SDR_API
168  const TfToken& GetVStructMemberOf() const {
169  return _vstructMemberOf;
170  }
171 
173  SDR_API
174  const TfToken& GetVStructMemberName() const {
175  return _vstructMemberName;
176  }
177 
179  SDR_API
180  bool IsVStructMember() const;
181 
183  SDR_API
184  bool IsVStruct() const;
185 
186 
188  SDR_API
190  return _vstructConditionalExpr;
191  }
192 
194 
195 
198 
202  SDR_API
203  bool IsConnectable() const override { return _isConnectable; }
204 
209  SDR_API
210  const NdrTokenVec& GetValidConnectionTypes() const {
211  return _validConnectionTypes;
212  }
213 
215  SDR_API
216  bool CanConnectTo(const NdrProperty& other) const override;
217 
219 
220 
223 
232  SDR_API
233  const SdfTypeIndicator GetTypeAsSdfType() const override;
234 
241  SDR_API
242  bool IsAssetIdentifier() const;
243 
246  SDR_API
247  bool IsDefaultInput() const;
248 
250 
251 protected:
252  SdrShaderProperty& operator=(const SdrShaderProperty&) = delete;
253 
254  // Allow the shader's post process function to access the property's
255  // internals. Some property information can only be determined after parse
256  // time.
257  friend void SdrShaderNode::_PostProcessProperties();
258 
259  // Some metadata values cannot be returned by reference from the main
260  // metadata dictionary because they need additional parsing.
261  const NdrTokenMap _hints;
262  const NdrOptionVec _options;
263 
264  // Tokenized metadata
265  NdrTokenVec _validConnectionTypes;
266  TfToken _label;
267  TfToken _page;
268  TfToken _widget;
269  TfToken _vstructMemberOf;
270  TfToken _vstructMemberName;
271  TfToken _vstructConditionalExpr;
272 };
273 
274 PXR_NAMESPACE_CLOSE_SCOPE
275 
276 #endif // SDR_SHADERPROPERTY_H
SDR_API const NdrOptionVec & GetOptions() const
If the property has a set of valid values that are pre-determined, this will return the valid option ...
SDR_API bool IsVStruct() const
Returns true if the field is the head of a vstruct.
SDR_API bool IsDefaultInput() const
Determines if the value held by this property is the default input for this node. ...
SDR_API const TfToken & GetVStructConditionalExpr() const
If this field is part of a vstruct, this is the conditional expression.
A specialized version of NdrProperty which holds shading information.
SDR_API const std::string & GetHelp() const
The help message assigned to this property, if any.
SDR_API const std::string & GetImplementationName() const
Returns the implementation name of this property.
SDR_API bool CanConnectTo(const NdrProperty &other) const override
Determines if this property can be connected to the specified property.
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:89
Represents a property (input or output) that is part of a NdrNode instance.
Definition: property.h:50
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:118
SDR_API const NdrTokenVec & GetValidConnectionTypes() const
Gets the list of valid connection types for this property.
SDR_API const SdfTypeIndicator GetTypeAsSdfType() const override
Converts the property's type from GetType() into a SdfValueTypeName.
SDR_API const TfToken & GetPage() const
The page (group), eg "Advanced", this property appears on, if any.
SDR_API bool IsVStructMember() const
Returns true if this field is part of a vstruct.
SDR_API bool IsAssetIdentifier() const
Determines if the value held by this property is an asset identifier (eg, a file path); the logic for...
SDR_API const TfToken & GetLabel() const
The label assigned to this property, if any.
SDR_API const NdrTokenMap & GetHints() const
Any UI "hints" that are associated with this property.
SDR_API const TfToken & GetVStructMemberName() const
If this field is part of a vstruct, this is its name in the struct.
SDR_API const TfToken & GetVStructMemberOf() const
If this field is part of a vstruct, this is the name of the struct.
SDR_API const TfToken & GetWidget() const
The widget "hint" that indicates the widget that can best display the type of data contained in this ...
SDR_API bool IsConnectable() const override
Whether this property can be connected to other properties.
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:182