@@ -163,12 +163,7 @@ HdStMaterialXShaderGen<Base>::_EmitGlslfxHeader(mx::ShaderStage& mxStage) const
163163 TF_WARN (" MaterialX geomprop '%s' has unknown type '%s'" ,
164164 primvarPair.first .c_str (), primvarPair.second .c_str ());
165165 }
166-
167- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
168- const std::string type = (!mxTypeIsNone (mxType)) ? Base::_syntax->getTypeName (&mxType) : " vec2" ;
169- #else
170- const std::string type = (!mxTypeIsNone (mxType)) ? Base::_syntax->getTypeName (mxType) : " vec2" ;
171- #endif
166+ const std::string type = mxGetTypeString (mxType, Base::_syntax);
172167
173168 line += " \" " + primvarPair.first + " \" : {\n " ;
174169 line += " \" type\" : \" " + type + " \"\n " ;
@@ -291,7 +286,7 @@ HdStMaterialXShaderGen<Base>::_EmitMxSurfaceShader(
291286 if (outputConnection) {
292287
293288 std::string finalOutput = outputConnection->getVariable ();
294- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
289+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
295290 // channels feature removed in MaterialX 1.39
296291 const std::string& channels = outputSocket->getChannels ();
297292 if (!channels.empty ()) {
@@ -1360,49 +1355,58 @@ HdStMaterialXShaderGenMsl::_EmitMxFunctions(
13601355
13611356bool mxTypeIsNone (mx::TypeDesc typeDesc)
13621357{
1363- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1364- return typeDesc == *mx::Type::NONE;
1358+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1359+ return typeDesc == *mx::Type::NONE;
13651360#else
1366- return typeDesc == mx::Type::NONE;
1361+ return typeDesc == mx::Type::NONE;
13671362#endif
13681363}
13691364
13701365bool mxTypeIsSurfaceShader (mx::TypeDesc typeDesc)
13711366{
1372- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1373- return typeDesc == *mx::Type::SURFACESHADER;
1367+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1368+ return typeDesc == *mx::Type::SURFACESHADER;
13741369#else
1375- return typeDesc == mx::Type::SURFACESHADER;
1370+ return typeDesc == mx::Type::SURFACESHADER;
13761371#endif
13771372}
13781373
13791374bool mxTypeDescIsFilename (const mx::TypeDesc typeDesc)
13801375{
1381- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1382- return typeDesc == *mx::Type::FILENAME;
1376+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1377+ return typeDesc == *mx::Type::FILENAME;
13831378#else
1384- return typeDesc == mx::Type::FILENAME;
1379+ return typeDesc == mx::Type::FILENAME;
13851380#endif
13861381}
13871382
13881383mx::TypeDesc getMxTypeDesc (const std::string& typeName)
13891384{
1390- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION== 38
1391- const mx::TypeDesc* mxType = mx::TypeDesc::get (typeName);
1392- if (mxType)
1393- return *mxType;
1394- return *mx::Type::NONE;
1385+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1386+ const mx::TypeDesc* mxType = mx::TypeDesc::get (typeName);
1387+ if (mxType)
1388+ return *mxType;
1389+ return *mx::Type::NONE;
13951390#else
1396- return mx::TypeDesc::get (typeName);
1391+ return mx::TypeDesc::get (typeName);
13971392#endif
13981393}
13991394
14001395const MaterialX::TypeDesc getMxTypeDesc (const mx::ShaderPort* port)
14011396{
1402- #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION==38
1403- return port->getType () ? *(port->getType ()) : *mx::Type::NONE;
1397+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1398+ return port->getType () ? *(port->getType ()) : *mx::Type::NONE;
1399+ #else
1400+ return port->getType ();
1401+ #endif
1402+ }
1403+
1404+ const std::string mxGetTypeString (const mx::TypeDesc mxType, mx::SyntaxPtr syntax)
1405+ {
1406+ #if MATERIALX_MAJOR_VERSION == 1 && MATERIALX_MINOR_VERSION <= 38
1407+ return (!mxTypeIsNone (mxType)) ? syntax->getTypeName (&mxType) : " vec2" ;
14041408#else
1405- return port-> getType () ;
1409+ return (! mxTypeIsNone (mxType)) ? syntax-> getTypeName (mxType) : " vec2 " ;
14061410#endif
14071411}
14081412
0 commit comments