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 PXR_USD_SDR_REGISTRY_H
26 #define PXR_USD_SDR_REGISTRY_H
27 
28 /// \file sdr/registry.h
29 
30 #include "pxr/pxr.h"
31 #include "pxr/base/tf/singleton.h"
32 #include "pxr/usd/sdr/api.h"
33 #include "pxr/usd/ndr/registry.h"
34 #include "pxr/usd/sdr/declare.h"
35 #include "pxr/usd/sdr/shaderNode.h"
36 
37 PXR_NAMESPACE_OPEN_SCOPE
38 
39 /// \class SdrRegistry
40 ///
41 /// The shading-specialized version of `NdrRegistry`.
42 ///
43 class SdrRegistry : public NdrRegistry
44 {
45 public:
46     /// Get the single `SdrRegistry` instance.
47     SDR_API
48     static SdrRegistry& GetInstance();
49 
50     /// Exactly like `NdrRegistry::GetNodeByIdentifier()`, but returns a
51     /// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
52     SDR_API
53     SdrShaderNodeConstPtr GetShaderNodeByIdentifier(
54         const NdrIdentifier& identifier,
55         const NdrTokenVec& typePriority = NdrTokenVec());
56 
57     /// Exactly like `NdrRegistry::GetNodeByIdentifierAndType()`, but returns
58     /// a `SdrShaderNode` pointer instead of a `NdrNode` pointer.
59     SDR_API
60     SdrShaderNodeConstPtr GetShaderNodeByIdentifierAndType(
61         const NdrIdentifier& identifier,
62         const TfToken& nodeType);
63 
64     /// Exactly like `NdrRegistry::GetNodeByName()`, but returns a
65     /// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
66     SDR_API
67     SdrShaderNodeConstPtr GetShaderNodeByName(
68         const std::string& name,
69         const NdrTokenVec& typePriority = NdrTokenVec(),
70         NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
71 
72     /// Exactly like `NdrRegistry::GetNodeByNameAndType()`, but returns a
73     /// `SdrShaderNode` pointer instead of a `NdrNode` pointer.
74     SDR_API
75     SdrShaderNodeConstPtr GetShaderNodeByNameAndType(
76         const std::string& name,
77         const TfToken& nodeType,
78         NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
79 
80     /// Wrapper method for NdrRegistry::GetNodeFromAsset().
81     /// Returns a valid SdrShaderNode pointer upon success.
82     SDR_API
83     SdrShaderNodeConstPtr GetShaderNodeFromAsset(
84         const SdfAssetPath &shaderAsset,
85         const NdrTokenMap &metadata=NdrTokenMap(),
86         const TfToken &subIdentifier=TfToken(),
87         const TfToken &sourceType=TfToken());
88 
89     /// Wrapper method for NdrRegistry::GetNodeFromSourceCode().
90     /// Returns a valid SdrShaderNode pointer upon success.
91     SDR_API
92     SdrShaderNodeConstPtr GetShaderNodeFromSourceCode(
93         const std::string &sourceCode,
94         const TfToken &sourceType,
95         const NdrTokenMap &metadata=NdrTokenMap());
96 
97     /// Exactly like `NdrRegistry::GetNodesByIdentifier()`, but returns a vector
98     /// of `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
99     SDR_API
100     SdrShaderNodePtrVec GetShaderNodesByIdentifier(const NdrIdentifier& identifier);
101 
102     /// Exactly like `NdrRegistry::GetNodesByName()`, but returns a vector of
103     /// `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
104     SDR_API
105     SdrShaderNodePtrVec GetShaderNodesByName(
106         const std::string& name,
107         NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
108 
109     /// Exactly like `NdrRegistry::GetNodesByFamily()`, but returns a vector of
110     /// `SdrShaderNode` pointers instead of a vector of `NdrNode` pointers.
111     SDR_API
112     SdrShaderNodePtrVec GetShaderNodesByFamily(
113         const TfToken& family = TfToken(),
114         NdrVersionFilter filter = NdrVersionFilterDefaultOnly);
115 
116 protected:
117     // Allow TF to construct the class
118     friend class TfSingleton<SdrRegistry>;
119 
120     SdrRegistry();
121     ~SdrRegistry();
122 };
123 
124 PXR_NAMESPACE_CLOSE_SCOPE
125 
126 #endif // PXR_USD_SDR_REGISTRY_H
127