Loading...
Searching...
No Matches
shaderNodeMetadata.h
1//
2// Copyright 2025 Pixar
3//
4// Licensed under the terms set forth in the LICENSE.txt file available at
5// https://openusd.org/license.
6//
7
8#ifndef PXR_USD_SDR_SHADER_NODE_METADATA_H
9#define PXR_USD_SDR_SHADER_NODE_METADATA_H
10
11#include "pxr/pxr.h"
14#include "pxr/usd/sdr/api.h"
15#include "pxr/usd/sdr/declare.h"
16
17PXR_NAMESPACE_OPEN_SCOPE
18
19// Note: Metadata keys that are generated by parsers should start with
20// "__SDR__" to reduce the risk of collision with metadata actually in the
21// shader.
22//
23// Enum names should correlate directly to named API e.g. "GetLabel" or
24// "GetSdrUsdEncodingVersion"
25#define SDR_NODE_METADATA_TOKENS \
26 ((Category, "category")) /* deprecated */ \
27 ((Domain, "domain")) \
28 ((Subdomain, "subdomain")) \
29 ((Context, "context")) \
30 ((Role, "role")) \
31 ((TargetRenderer, "targetRenderer")) \
32 ((Collections, "collections")) \
33 ((Departments, "departments")) /* deprecated */ \
34 ((Help, "help")) \
35 ((Label, "label")) \
36 ((Pages, "pages")) /* deprecated */ \
37 ((OpenPages, "openPages")) \
38 ((PagesShownIf, "pagesShownIf")) \
39 ((Primvars, "primvars")) \
40 ((ImplementationName, "__SDR__implementationName")) \
41 ((Target, "__SDR__target")) /* deprecated */ \
42 ((SdrUsdEncodingVersion, "sdrUsdEncodingVersion")) \
43 ((SdrDefinitionNameFallbackPrefix, "sdrDefinitionNameFallbackPrefix"))
44
45#define SDR_NODE_DOMAIN_TOKENS \
46 ((Rendering, "rendering")) \
47 ((General, "general"))
48
49#define SDR_NODE_SUBDOMAIN_TOKENS \
50 /* rendering domain */ \
51 ((Shading, "shading")) \
52 ((Filtering, "filtering")) \
53 ((Lighting, "lighting")) \
54 ((Rendering, "rendering"))
55
56#define SDR_NODE_CONTEXT_TOKENS \
57 /* shading subdomain */ \
58 ((Pattern, "pattern")) \
59 ((Surface, "surface")) \
60 ((Volume, "volume")) \
61 ((Displacement, "displacement")) \
62 /* lighting subdomain */ \
63 ((Light, "light")) \
64 ((LightFilter, "lightFilter")) \
65 /* filtering subdomain*/ \
66 ((DisplayFilter, "displayFilter")) \
67 ((PixelFilter, "pixelFilter")) \
68 ((SampleFilter, "sampleFilter")) \
69 ((VolumeFilter, "volumeFilter")) \
70 /* rendering subdomain */ \
71 ((Integrator, "integrator")) \
72 ((Projection, "projection"))
73
74#define SDR_NODE_ROLE_TOKENS \
75 ((Primvar, "primvar")) \
76 ((Texture, "texture")) \
77 ((Field, "field")) \
78 ((Math, "math"))
79
80
88TF_DECLARE_PUBLIC_TOKENS(SdrNodeMetadata, SDR_API, SDR_NODE_METADATA_TOKENS);
89TF_DECLARE_PUBLIC_TOKENS(SdrNodeDomain, SDR_API, SDR_NODE_DOMAIN_TOKENS);
90TF_DECLARE_PUBLIC_TOKENS(SdrNodeSubdomain, SDR_API, SDR_NODE_SUBDOMAIN_TOKENS);
91TF_DECLARE_PUBLIC_TOKENS(SdrNodeContext, SDR_API, SDR_NODE_CONTEXT_TOKENS);
92TF_DECLARE_PUBLIC_TOKENS(SdrNodeRole, SDR_API, SDR_NODE_ROLE_TOKENS);
93
94
107{
108public:
109 SDR_API
111
116 SDR_API
117 SdrShaderNodeMetadata(const SdrTokenMap& legacyMetadata);
118
125 const std::initializer_list<std::pair<TfToken, std::string>>& init
126 ): SdrShaderNodeMetadata(_LegacyCtorFromInitializer(init)) {}
127
128 SDR_API
129 explicit SdrShaderNodeMetadata(const VtDictionary& items);
130
132 SDR_API
133 bool HasItem(const TfToken& key) const;
134
146 SDR_API
147 void SetItem(const TfToken& key, const VtValue& value);
148
150 template <typename T>
151 void SetItem(const TfToken& key, const T& value) {
152 SetItem(key, VtValue(value));
153 }
154
162 SDR_API
163 VtValue GetItemValue(const TfToken& key) const;
164
169 template <typename T>
170 T GetItemValueAs(const TfToken& key) const {
171 const VtValue v = GetItemValue(key);
172 if (!v.IsEmpty()) {
173 const VtValue converted = VtValue::Cast<T>(v);
174 if (!converted.IsEmpty()) {
175 return converted.UncheckedGet<T>();
176 }
177 }
178
179 return {};
180 }
181
183 SDR_API
184 void ClearItem(const TfToken& key);
185
187 const VtDictionary& GetItems() const & { return _items; }
188
190 VtDictionary GetItems() && { return std::move(_items); }
191
202
205 SDR_API
206 static VtValue GetDefaultValue(const TfToken& key);
207
212 SDR_API
215
219
220 SDR_API
221 bool HasLabel() const;
222 SDR_API
223 TfToken GetLabel() const;
224 SDR_API
225 void SetLabel(const TfToken& v);
226 SDR_API
227 void ClearLabel();
228
235
237 SDR_API
238 bool HasCategory() const;
240 SDR_API
243 SDR_API
244 void SetCategory(const TfToken& v);
246 SDR_API
249
260 SDR_API
261 bool HasDomain() const;
262 SDR_API
263 TfToken GetDomain() const;
264 SDR_API
265 void SetDomain(const TfToken& v);
266 SDR_API
267 void ClearDomain();
269
276 SDR_API
277 bool HasSubdomain() const;
278 SDR_API
279 TfToken GetSubdomain() const;
280 SDR_API
281 void SetSubdomain(const TfToken& v);
282 SDR_API
283 void ClearSubdomain();
285
292 SDR_API
293 bool HasContext() const;
294 SDR_API
295 TfToken GetContext() const;
296 SDR_API
297 void SetContext(const TfToken& v);
298 SDR_API
299 void ClearContext();
301
306 SDR_API
307 bool HasRole() const;
308 SDR_API
309 TfToken GetRole() const;
310 SDR_API
311 void SetRole(const TfToken& v);
312 SDR_API
313 void ClearRole();
315
330 SDR_API
331 bool HasTargetRenderer() const;
332 SDR_API
333 TfToken GetTargetRenderer() const;
334 SDR_API
335 void SetTargetRenderer(const TfToken& v);
336 SDR_API
337 void ClearTargetRenderer();
339
350 SDR_API
351 bool HasCollections() const;
352 SDR_API
353 SdrTokenVec GetCollections() const;
354 SDR_API
355 void SetCollections(const SdrTokenVec& v);
356 SDR_API
357 void ClearCollections();
359
360 SDR_API
361 bool HasHelp() const;
362 SDR_API
363 std::string GetHelp() const;
364 SDR_API
365 void SetHelp(const std::string& v);
366 SDR_API
367 void ClearHelp();
368
375
377 SDR_API
378 bool HasDepartments() const;
380 SDR_API
381 SdrTokenVec GetDepartments() const;
383 SDR_API
384 void SetDepartments(const SdrTokenVec& v);
386 SDR_API
389
398 SDR_API
399 bool HasPages() const;
401 SDR_API
402 SdrTokenVec GetPages() const;
404 SDR_API
405 void SetPages(const SdrTokenVec& v);
407 SDR_API
410
411 SDR_API
412 bool HasOpenPages() const;
413 SDR_API
414 SdrTokenVec GetOpenPages() const;
415 SDR_API
416 void SetOpenPages(const SdrTokenVec& v);
417 SDR_API
418 void ClearOpenPages();
419
430 SDR_API
431 bool HasPagesShownIf() const;
432 SDR_API
433 SdrTokenMap GetPagesShownIf() const;
434 SDR_API
435 void SetPagesShownIf(const SdrTokenMap& v);
436 SDR_API
437 void ClearPagesShownIf();
439
440 SDR_API
441 bool HasPrimvars() const;
442 SDR_API
443 SdrStringVec GetPrimvars() const;
444 SDR_API
445 void SetPrimvars(const SdrStringVec& v);
446 SDR_API
447 void ClearPrimvars();
448
449 SDR_API
450 bool HasImplementationName() const;
451 SDR_API
452 std::string GetImplementationName() const;
453 SDR_API
454 void SetImplementationName(const std::string& v);
455 SDR_API
456 void ClearImplementationName();
457
458 SDR_API
459 bool HasSdrUsdEncodingVersion() const;
460 SDR_API
461 int GetSdrUsdEncodingVersion() const;
462 SDR_API
463 void SetSdrUsdEncodingVersion(const int& v);
464 SDR_API
465 void ClearSdrUsdEncodingVersion();
466
467 SDR_API
468 bool HasSdrDefinitionNameFallbackPrefix() const;
469 SDR_API
470 std::string GetSdrDefinitionNameFallbackPrefix() const;
471 SDR_API
472 void SetSdrDefinitionNameFallbackPrefix(const std::string& v);
473 SDR_API
474 void ClearSdrDefinitionNameFallbackPrefix();
475
477
478private:
479 friend class SdrShaderNode;
480
481 // Deprecated function for legacy metadata support.
482 //
483 // Unnamed metadata with non-string values are not returned in
484 // the legacy map.
485 SdrTokenMap _EncodeLegacyMetadata() const;
486
487 static
488 SdrTokenMap _LegacyCtorFromInitializer(
489 std::initializer_list<std::pair<TfToken, std::string>> f)
490 {
491 return SdrTokenMap(f.begin(), f.end());
492 }
493
494 // This method sets metadata items that have default values
495 // as indicated by GetDefaultValues.
496 //
497 // Note: This method is invoked at the ends of this class's
498 // constructors.
499 void _SetDefaultInitializations();
500
501 VtDictionary _items;
502};
503
504PXR_NAMESPACE_CLOSE_SCOPE
505
506#endif // PXR_USD_SDR_SHADER_NODE_METADATA_H
Represents a node that holds shading information.
Definition: shaderNode.h:45
SdrShaderNodeMetadata contains generic and named metadata for SdrShaderNode.
SDR_API void ClearPages()
SDR_API bool HasLabel() const
Named metadata.
SDR_API bool HasItem(const TfToken &key) const
Returns whether this metadata contains an item with the given key.
SDR_API void SetDepartments(const SdrTokenVec &v)
T GetItemValueAs(const TfToken &key) const
Convenience to get an item value as T.
void SetItem(const TfToken &key, const T &value)
This is an overloaded member function, provided for convenience. It differs from the above function o...
SDR_API SdrShaderNodeMetadata(const SdrTokenMap &legacyMetadata)
Ingest metadata from the legacy SdrTokenMap structure.
SDR_API SdrTokenVec GetPages() const
static SDR_API const VtDictionary & GetDefaultValues()
Returns all metadata items that have default values.
SDR_API void ClearItem(const TfToken &key)
Clear the metadata item for the given key if it exists.
SDR_API bool HasDepartments() const
SDR_API void SetPages(const SdrTokenVec &v)
SDR_API void SetCategory(const TfToken &v)
const VtDictionary & GetItems() const &
Get all key-value items.
SDR_API bool HasPages() const
SDR_API void ClearCategory()
SDR_API VtValue GetItemValue(const TfToken &key) const
Get the VtValue for the given key.
SDR_API void SetItem(const TfToken &key, const VtValue &value)
Set a key-value item for this metadata.
VtDictionary GetItems() &&
Get all key-value items by-value.
SdrShaderNodeMetadata(const std::initializer_list< std::pair< TfToken, std::string > > &init)
Ingest metadata from an initializer list for the legacy SdrTokenMap.
SDR_API void ClearDepartments()
SDR_API bool HasCategory() const
SDR_API TfToken GetCategory() const
SDR_API SdrTokenVec GetDepartments() const
static SDR_API VtValue GetDefaultValue(const TfToken &key)
This method returns a non-empty VtValue if and only if the key represents a metadata item with a defa...
Token for efficient comparison, assignment, and hashing of known strings.
Definition: token.h:71
A map with string keys and VtValue values.
Definition: dictionary.h:52
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition: value.h:90
bool IsEmpty() const
Returns true iff this value is empty.
Definition: value.h:1227
T const & UncheckedGet() const &
Returns a const reference to the held object if the held object is of type T.
Definition: value.h:1046
This file defines some macros that are useful for declaring and using static TfTokens.
#define TF_DECLARE_PUBLIC_TOKENS(...)
Macro to define public tokens.
Definition: staticTokens.h:92