Loading...
Searching...
No Matches
oslParser.h
Go to the documentation of this file.
1//
2// Copyright 2018 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_PLUGIN_SDR_OSL_OSL_PARSER_H
9#define PXR_USD_PLUGIN_SDR_OSL_OSL_PARSER_H
10
12
13#include "pxr/pxr.h"
14#include "pxr/usd/plugin/sdrOsl/api.h"
15#include "pxr/base/vt/value.h"
17#include "pxr/usd/sdr/declare.h"
18#include <OSL/oslquery.h>
19
20PXR_NAMESPACE_OPEN_SCOPE
21
22// Forward declarations
23class SdrShaderNode;
25
95{
96public:
97 typedef OSL::OSLQuery::Parameter OslParameter;
98
99 SDROSL_API
101 SDROSL_API
103
104 SDROSL_API
105 SdrShaderNodeUniquePtr ParseShaderNode(
106 const SdrShaderNodeDiscoveryResult& discoveryResult) override;
107
108 SDROSL_API
109 const SdrTokenVec& GetDiscoveryTypes() const override;
110
111 SDROSL_API
112 const TfToken& GetShadingSystem() const override;
113
114private:
115 // Sets the shader's sdr metadata context.
116 // - If the metadata already has a "context" item, this does nothing.
117 // - If the metadata has a "schemaBase" item, sets "context" mapped
118 // from the "schemaBase" item value.
119 // - Otherwise, does nothing
120 void _setSdrContext(SdrTokenMap& metadata) const;
121
122 // Gets a vector of properties that are present on the specified OSL
123 // query object
124 SdrShaderPropertyUniquePtrVec _getNodeProperties(
125 const OSL::OSLQuery &query,
126 const SdrShaderNodeDiscoveryResult& discoveryResult,
127 const std::string& fallbackprefix) const;
128
129 // Gets all metadata for the node that's present on the specified OSL
130 // query object
131 SdrTokenMap _getNodeMetadata(const OSL::OSLQuery &query,
132 const SdrTokenMap &baseMetadata) const;
133
134 // Gets all metadata for the specified OSL parameter
135 SdrTokenMap _getPropertyMetadata(const OslParameter* param,
136 const SdrShaderNodeDiscoveryResult& discoveryResult) const;
137
138 // Injects any metadata that is generated by the parser. This type of
139 // metadata provides additional hints to the property.
140 void _injectParserMetadata(SdrTokenMap& metadata,
141 const TfToken& typeName) const;
142
143 // Gets the specified parameter's value as a string. Can handle string,
144 // float, and integer values (if not one of these types, an empty string
145 // is returned).
146 std::string _getParamAsString(const OslParameter& param) const;
147
148 // Gets a common type + array size (if array) from the OSL parameter
149 std::tuple<TfToken, size_t> _getTypeName(
150 const OslParameter* param,
151 const SdrTokenMap& metadata) const;
152
153 // Gets the default value of the specified param.
154 VtValue _getDefaultValue(
155 const SdrOslParserPlugin::OslParameter& param,
156 const std::string& oslType,
157 size_t arraySize,
158 const SdrTokenMap& metadata
159 ) const;
160};
161
162PXR_NAMESPACE_CLOSE_SCOPE
163
164#endif // PXR_USD_PLUGIN_SDR_OSL_OSL_PARSER_H
Parses OSL nodes.
Definition oslParser.h:95
SDROSL_API const SdrTokenVec & GetDiscoveryTypes() const override
Returns the types of nodes that this plugin can parse.
SDROSL_API SdrShaderNodeUniquePtr ParseShaderNode(const SdrShaderNodeDiscoveryResult &discoveryResult) override
Takes the specified SdrShaderNodeDiscoveryResult instance, which was a result of the discovery proces...
SDROSL_API const TfToken & GetShadingSystem() const override
Returns the shading system that this parser operates in.
Interface for parser plugins.
Represents a node that holds shading information.
Definition shaderNode.h:45
Token for efficient comparison, assignment, and hashing of known strings.
Definition token.h:81
Provides a container which may hold any type, and provides introspection and iteration over array typ...
Definition value.h:90
Represents the raw data of a node, and some other bits of metadata, that were determined via a SdrDis...