@@ -161,12 +161,7 @@ HdStMaterialXShaderGen<Base>::_EmitGlslfxHeader(mx::ShaderStage& mxStage) const
161161 TF_WARN (" MaterialX geomprop '%s' has unknown type '%s'" ,
162162 primvarPair.first .c_str (), primvarPair.second .c_str ());
163163 }
164-
165- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
166- const std::string type = (!mxTypeIsNone (mxType)) ? Base::_syntax->getTypeName (&mxType) : " vec2" ;
167- #else
168- const std::string type = (!mxTypeIsNone (mxType)) ? Base::_syntax->getTypeName (mxType) : " vec2" ;
169- #endif
164+ const std::string type = mxGetTypeString (mxType, Base::_syntax);
170165
171166 line += " \" " + primvarPair.first + " \" : {\n " ;
172167 line += " \" type\" : \" " + type + " \"\n " ;
@@ -289,7 +284,7 @@ HdStMaterialXShaderGen<Base>::_EmitMxSurfaceShader(
289284 if (outputConnection) {
290285
291286 std::string finalOutput = outputConnection->getVariable ();
292- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
287+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
293288 // channels feature removed in MaterialX 1.39
294289 const std::string& channels = outputSocket->getChannels ();
295290 if (!channels.empty ()) {
@@ -1358,49 +1353,58 @@ HdStMaterialXShaderGenMsl::_EmitMxFunctions(
13581353
13591354bool mxTypeIsNone (mx::TypeDesc typeDesc)
13601355{
1361- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1362- return typeDesc == *mx::Type::NONE;
1356+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1357+ return typeDesc == *mx::Type::NONE;
13631358#else
1364- return typeDesc == mx::Type::NONE;
1359+ return typeDesc == mx::Type::NONE;
13651360#endif
13661361}
13671362
13681363bool mxTypeIsSurfaceShader (mx::TypeDesc typeDesc)
13691364{
1370- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1371- return typeDesc == *mx::Type::SURFACESHADER;
1365+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1366+ return typeDesc == *mx::Type::SURFACESHADER;
13721367#else
1373- return typeDesc == mx::Type::SURFACESHADER;
1368+ return typeDesc == mx::Type::SURFACESHADER;
13741369#endif
13751370}
13761371
13771372bool mxTypeDescIsFilename (const mx::TypeDesc typeDesc)
13781373{
1379- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1380- return typeDesc == *mx::Type::FILENAME;
1374+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1375+ return typeDesc == *mx::Type::FILENAME;
13811376#else
1382- return typeDesc == mx::Type::FILENAME;
1377+ return typeDesc == mx::Type::FILENAME;
13831378#endif
13841379}
13851380
13861381mx::TypeDesc getMxTypeDesc (const std::string& typeName)
13871382{
1388- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1389- const mx::TypeDesc* mxType = mx::TypeDesc::get (typeName);
1390- if (mxType)
1391- return *mxType;
1392- return *mx::Type::NONE;
1383+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1384+ const mx::TypeDesc* mxType = mx::TypeDesc::get (typeName);
1385+ if (mxType)
1386+ return *mxType;
1387+ return *mx::Type::NONE;
13931388#else
1394- return mx::TypeDesc::get (typeName);
1389+ return mx::TypeDesc::get (typeName);
13951390#endif
13961391}
13971392
13981393const MaterialX::TypeDesc getMxTypeDesc (const mx::ShaderPort* port)
13991394{
1400- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1401- return port->getType () ? *(port->getType ()) : *mx::Type::NONE;
1395+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1396+ return port->getType () ? *(port->getType ()) : *mx::Type::NONE;
1397+ #else
1398+ return port->getType ();
1399+ #endif
1400+ }
1401+
1402+ const std::string mxGetTypeString (const mx::TypeDesc mxType, mx::SyntaxPtr syntax)
1403+ {
1404+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1405+ return (!mxTypeIsNone (mxType)) ? syntax->getTypeName (&mxType) : " vec2" ;
14021406#else
1403- return port-> getType () ;
1407+ return (! mxTypeIsNone (mxType)) ? syntax-> getTypeName (mxType) : " vec2 " ;
14041408#endif
14051409}
14061410
0 commit comments