From 19eb0237a07ac30afcdbbfd5fca54ad3c8213f7a Mon Sep 17 00:00:00 2001
From: Ashwin Bhat <1727158+ashwinbhat@users.noreply.github.com>
Date: Thu, 17 Aug 2023 15:07:04 -0700
Subject: [PATCH 1/6] Version information for MaterialX dlls (#1447)
---
cmake/modules/MaterialXVersion.rc.in | 34 +++++++++++++++++++++++
source/MaterialXCore/CMakeLists.txt | 24 ++++++++++------
source/MaterialXFormat/CMakeLists.txt | 24 ++++++++++------
source/MaterialXGenGlsl/CMakeLists.txt | 24 ++++++++++------
source/MaterialXGenMdl/CMakeLists.txt | 24 ++++++++++------
source/MaterialXGenMsl/CMakeLists.txt | 24 ++++++++++------
source/MaterialXGenOsl/CMakeLists.txt | 24 ++++++++++------
source/MaterialXGenShader/CMakeLists.txt | 24 ++++++++++------
source/MaterialXRender/CMakeLists.txt | 24 ++++++++++------
source/MaterialXRenderGlsl/CMakeLists.txt | 32 +++++++++++++--------
source/MaterialXRenderHw/CMakeLists.txt | 28 ++++++++++++-------
source/MaterialXRenderMsl/CMakeLists.txt | 22 ++++++++-------
source/MaterialXRenderOsl/CMakeLists.txt | 24 ++++++++++------
13 files changed, 228 insertions(+), 104 deletions(-)
create mode 100644 cmake/modules/MaterialXVersion.rc.in
diff --git a/cmake/modules/MaterialXVersion.rc.in b/cmake/modules/MaterialXVersion.rc.in
new file mode 100644
index 0000000000..989fbb8e55
--- /dev/null
+++ b/cmake/modules/MaterialXVersion.rc.in
@@ -0,0 +1,34 @@
+
+#define MATERIALX_FILEVERSION @MATERIALX_MAJOR_VERSION@,@MATERIALX_MINOR_VERSION@,@MATERIALX_BUILD_VERSION@,0
+#define MATERIALX_FILEVERSION_STR "@MATERIALX_MAJOR_VERSION@.@MATERIALX_MINOR_VERSION@.@MATERIALX_BUILD_VERSION@.0\0"
+#define MATERIALX_FILENAME_STR "@MATERIALX_MODULE_NAME@.dll\0"
+
+1 VERSIONINFO
+ FILEVERSION MATERIALX_FILEVERSION
+ PRODUCTVERSION MATERIALX_FILEVERSION
+ FILEFLAGSMASK 0x3fL
+#ifdef _DEBUG
+ FILEFLAGS 0x1L
+#else
+ FILEFLAGS 0x0L
+#endif
+ FILEOS 0x4L
+ FILETYPE 0x1L
+ FILESUBTYPE 0x0L
+BEGIN
+ BLOCK "StringFileInfo"
+ BEGIN
+ BLOCK "040904E4"
+ BEGIN
+ VALUE "FileVersion", MATERIALX_FILEVERSION_STR
+ VALUE "LegalCopyright", "Apache License 2.0\0"
+ VALUE "OriginalFilename", MATERIALX_FILENAME_STR
+ VALUE "ProductName", "MaterialX\0"
+ VALUE "ProductVersion", MATERIALX_FILEVERSION_STR
+ END
+ END
+ BLOCK "VarFileInfo"
+ BEGIN
+ VALUE "Translation", 0x409, 1252
+ END
+END
diff --git a/source/MaterialXCore/CMakeLists.txt b/source/MaterialXCore/CMakeLists.txt
index 37edf7929a..675c42c5de 100644
--- a/source/MaterialXCore/CMakeLists.txt
+++ b/source/MaterialXCore/CMakeLists.txt
@@ -1,25 +1,33 @@
+set(MATERIALX_MODULE_NAME MaterialXCore)
+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/Generated.h.in ${CMAKE_CURRENT_BINARY_DIR}/Generated.h)
file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h" "${CMAKE_CURRENT_BINARY_DIR}/*.h")
-add_library(MaterialXCore ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_CORE_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXCore PROPERTIES
- OUTPUT_NAME MaterialXCore${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXCore
+ ${MATERIALX_MODULE_NAME}
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXCore
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
@@ -27,14 +35,14 @@ target_include_directories(MaterialXCore
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXCore
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(FILES ${materialx_headers}
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXCore/)
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/)
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXCore.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXFormat/CMakeLists.txt b/source/MaterialXFormat/CMakeLists.txt
index 940ef9662c..6b6d3ae9c3 100644
--- a/source/MaterialXFormat/CMakeLists.txt
+++ b/source/MaterialXFormat/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXFormat)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXFormat ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_FORMAT_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXFormat PROPERTIES
- OUTPUT_NAME MaterialXFormat${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,26 +26,26 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXFormat
+ ${MATERIALX_MODULE_NAME}
MaterialXCore
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXFormat
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXFormat
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXFormat/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXFormat.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXGenGlsl/CMakeLists.txt b/source/MaterialXGenGlsl/CMakeLists.txt
index 2ddcb5475c..58ff8a45ba 100644
--- a/source/MaterialXGenGlsl/CMakeLists.txt
+++ b/source/MaterialXGenGlsl/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXGenGlsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXGenGlsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_GENGLSL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXGenGlsl PROPERTIES
- OUTPUT_NAME MaterialXGenGlsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,27 +26,27 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXGenGlsl
+ ${MATERIALX_MODULE_NAME}
MaterialXGenShader
MaterialXCore
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXGenGlsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXGenGlsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenGlsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenGlsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXGenMdl/CMakeLists.txt b/source/MaterialXGenMdl/CMakeLists.txt
index b73e674b7f..04dc2e76b4 100644
--- a/source/MaterialXGenMdl/CMakeLists.txt
+++ b/source/MaterialXGenMdl/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXGenMdl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXGenMdl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_GENMDL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXGenMdl PROPERTIES
- OUTPUT_NAME MaterialXGenMdl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,30 +26,30 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXGenMdl
+ ${MATERIALX_MODULE_NAME}
MaterialXGenShader
MaterialXCore
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXGenMdl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXGenMdl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMdl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/mdl
DESTINATION "${MATERIALX_INSTALL_MDL_MODULE_PATH}")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMdl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXGenMsl/CMakeLists.txt b/source/MaterialXGenMsl/CMakeLists.txt
index 31d2599531..d8ba092ee8 100644
--- a/source/MaterialXGenMsl/CMakeLists.txt
+++ b/source/MaterialXGenMsl/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXGenMsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXGenMsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_GENMSL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXGenMsl PROPERTIES
- OUTPUT_NAME MaterialXGenMsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,27 +26,27 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXGenMsl
+ ${MATERIALX_MODULE_NAME}
MaterialXGenShader
MaterialXCore
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXGenMsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXGenMsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenMsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenMsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXGenOsl/CMakeLists.txt b/source/MaterialXGenOsl/CMakeLists.txt
index 03e30de0c1..24bd0043d9 100644
--- a/source/MaterialXGenOsl/CMakeLists.txt
+++ b/source/MaterialXGenOsl/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXGenOsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXGenOsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_GENOSL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXGenOsl PROPERTIES
- OUTPUT_NAME MaterialXGenOsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,28 +26,28 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXGenOsl
+ ${MATERIALX_MODULE_NAME}
MaterialXGenShader
MaterialXCore
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXGenOsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXGenOsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenOsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenOsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXGenShader/CMakeLists.txt b/source/MaterialXGenShader/CMakeLists.txt
index 231dda6e5c..0a16049f25 100644
--- a/source/MaterialXGenShader/CMakeLists.txt
+++ b/source/MaterialXGenShader/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXGenShader)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXGenShader ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_GENSHADER_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXGenShader PROPERTIES
- OUTPUT_NAME MaterialXGenShader${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,29 +26,29 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXGenShader
+ ${MATERIALX_MODULE_NAME}
MaterialXCore
MaterialXFormat
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXGenShader
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXGenShader
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXGenShader/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXGenShader.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../../resources"
diff --git a/source/MaterialXRender/CMakeLists.txt b/source/MaterialXRender/CMakeLists.txt
index d0a50232cd..eb054303c5 100644
--- a/source/MaterialXRender/CMakeLists.txt
+++ b/source/MaterialXRender/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(MATERIALX_MODULE_NAME MaterialXRender)
+
include_directories(
${EXTERNAL_INCLUDE_DIRS}
${CMAKE_CURRENT_SOURCE_DIR}/../)
@@ -18,12 +20,18 @@ if(UNIX)
add_compile_options(-Wno-unused-function)
endif()
-add_library(MaterialXRender ${materialx_source} ${materialx_headers} ${materialx_inlined})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers} ${materialx_inlined})
add_definitions(-DMATERIALX_RENDER_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
target_link_libraries(
- MaterialXRender
+ ${MATERIALX_MODULE_NAME}
MaterialXGenShader
${CMAKE_DL_LIBS})
@@ -33,7 +41,7 @@ if(MATERIALX_BUILD_OIIO)
find_package(OpenImageIO REQUIRED)
if(OPENIMAGEIO_FOUND)
include_directories(${OPENIMAGEIO_INCLUDE_DIR})
- target_link_libraries(MaterialXRender ${OPENIMAGEIO_LIBRARIES})
+ target_link_libraries(${MATERIALX_MODULE_NAME} ${OPENIMAGEIO_LIBRARIES})
# Also needed by MaterialXTest:
set(OPENIMAGEIO_FOUND "${OPENIMAGEIO_FOUND}" PARENT_SCOPE)
set(OPENIMAGEIO_INCLUDE_DIR "${OPENIMAGEIO_INCLUDE_DIR}" PARENT_SCOPE)
@@ -44,25 +52,25 @@ if(MATERIALX_BUILD_OIIO)
endif()
set_target_properties(
- MaterialXRender PROPERTIES
- OUTPUT_NAME MaterialXRender${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
-install(TARGETS MaterialXRender
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXRender/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING
PATTERN "*.h*"
PATTERN "*.inl")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXRender.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXRenderGlsl/CMakeLists.txt b/source/MaterialXRenderGlsl/CMakeLists.txt
index ddab96c318..971c356bd0 100644
--- a/source/MaterialXRenderGlsl/CMakeLists.txt
+++ b/source/MaterialXRenderGlsl/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(MATERIALX_MODULE_NAME MaterialXRenderGlsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.c*")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
@@ -34,12 +36,18 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-declarations)
endif()
-add_library(MaterialXRenderGlsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_RENDERGLSL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
if(MATERIALX_BUILD_SHARED_LIBS)
- target_compile_definitions(MaterialXRenderGlsl PUBLIC GLAD_GLAPI_EXPORT PRIVATE GLAD_GLAPI_EXPORT_BUILD)
+ target_compile_definitions(${MATERIALX_MODULE_NAME} PUBLIC GLAD_GLAPI_EXPORT PRIVATE GLAD_GLAPI_EXPORT_BUILD)
endif()
set(COMMON_LIBRARIES
@@ -50,19 +58,19 @@ set(COMMON_LIBRARIES
if(WIN32)
if(MSVC)
target_link_libraries(
- MaterialXRenderGlsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
Opengl32)
elseif(MINGW)
target_link_libraries(
- MaterialXRenderGlsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
Opengl32
gdi32)
endif()
elseif(APPLE)
target_link_libraries(
- MaterialXRenderGlsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
${OPENGL_LIBRARIES}
"-framework Foundation"
@@ -70,7 +78,7 @@ elseif(APPLE)
"-framework Metal")
elseif(UNIX)
target_link_libraries(
- MaterialXRenderGlsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
${OPENGL_LIBRARIES}
${X11_LIBRARIES}
@@ -78,30 +86,30 @@ elseif(UNIX)
endif()
set_target_properties(
- MaterialXRenderGlsl PROPERTIES
- OUTPUT_NAME MaterialXRenderGlsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
-target_include_directories(MaterialXRenderGlsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXRenderGlsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXRenderGlsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXRenderGlsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXRenderHw/CMakeLists.txt b/source/MaterialXRenderHw/CMakeLists.txt
index 85ef13c55c..07210b12fa 100644
--- a/source/MaterialXRenderHw/CMakeLists.txt
+++ b/source/MaterialXRenderHw/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(MATERIALX_MODULE_NAME MaterialXRenderHw)
+
file(GLOB materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
@@ -20,18 +22,24 @@ endif()
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXRenderHw ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_RENDERHW_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
if(MSVC)
target_link_libraries(
- MaterialXRenderHw
+ ${MATERIALX_MODULE_NAME}
MaterialXRender
${CMAKE_DL_LIBS})
elseif(APPLE)
target_link_libraries(
- MaterialXRenderHw
+ ${MATERIALX_MODULE_NAME}
MaterialXRender
${CMAKE_DL_LIBS}
"-framework Foundation"
@@ -39,7 +47,7 @@ elseif(APPLE)
"-framework Metal")
elseif(UNIX)
target_link_libraries(
- MaterialXRenderHw
+ ${MATERIALX_MODULE_NAME}
MaterialXRender
${CMAKE_DL_LIBS}
${X11_LIBRARIES}
@@ -47,30 +55,30 @@ elseif(UNIX)
endif()
set_target_properties(
- MaterialXRenderHw PROPERTIES
- OUTPUT_NAME MaterialXRenderHw${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
-target_include_directories(MaterialXRenderHw
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXRenderHw
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXRenderHw/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXRenderHw.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXRenderMsl/CMakeLists.txt b/source/MaterialXRenderMsl/CMakeLists.txt
index 5ad50ea2cc..173a9e9bae 100644
--- a/source/MaterialXRenderMsl/CMakeLists.txt
+++ b/source/MaterialXRenderMsl/CMakeLists.txt
@@ -1,3 +1,5 @@
+set(MATERIALX_MODULE_NAME MaterialXRenderMsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.m*")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
@@ -34,7 +36,7 @@ if(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
add_compile_options(-Wno-deprecated-declarations)
endif()
-add_library(MaterialXRenderMsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_RENDERMSL_EXPORTS)
@@ -45,12 +47,12 @@ set(COMMON_LIBRARIES
if(MSVC)
target_link_libraries(
- MaterialXRenderMsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
Opengl32)
elseif(APPLE)
target_link_libraries(
- MaterialXRenderMsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
${OPENGL_LIBRARIES}
"-framework Foundation"
@@ -58,7 +60,7 @@ elseif(APPLE)
"-framework Metal")
elseif(UNIX)
target_link_libraries(
- MaterialXRenderMsl
+ ${MATERIALX_MODULE_NAME}
${COMMON_LIBRARIES}
${OPENGL_LIBRARIES}
${X11_LIBRARIES}
@@ -66,29 +68,29 @@ elseif(UNIX)
endif()
set_target_properties(
- MaterialXRenderMsl PROPERTIES
- OUTPUT_NAME MaterialXRenderMsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
VERSION "${MATERIALX_LIBRARY_VERSION}"
SOVERSION "${MATERIALX_MAJOR_VERSION}")
-target_include_directories(MaterialXRenderMsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXRenderMsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXRenderMsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXRenderMsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
diff --git a/source/MaterialXRenderOsl/CMakeLists.txt b/source/MaterialXRenderOsl/CMakeLists.txt
index a4ffa81235..d4e5dbf151 100644
--- a/source/MaterialXRenderOsl/CMakeLists.txt
+++ b/source/MaterialXRenderOsl/CMakeLists.txt
@@ -1,16 +1,24 @@
+set(MATERIALX_MODULE_NAME MaterialXRenderOsl)
+
file(GLOB_RECURSE materialx_source "${CMAKE_CURRENT_SOURCE_DIR}/*.cpp")
file(GLOB_RECURSE materialx_headers "${CMAKE_CURRENT_SOURCE_DIR}/*.h*")
assign_source_group("Source Files" ${materialx_source})
assign_source_group("Header Files" ${materialx_headers})
-add_library(MaterialXRenderOsl ${materialx_source} ${materialx_headers})
+add_library(${MATERIALX_MODULE_NAME} ${materialx_source} ${materialx_headers})
add_definitions(-DMATERIALX_RENDEROSL_EXPORTS)
+# Create version resource
+if(MATERIALX_BUILD_SHARED_LIBS AND MSVC)
+ configure_file(${CMAKE_SOURCE_DIR}/cmake/modules/MaterialXVersion.rc.in ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+ target_sources(${MATERIALX_MODULE_NAME} PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/version.rc)
+endif()
+
set_target_properties(
- MaterialXRenderOsl PROPERTIES
- OUTPUT_NAME MaterialXRenderOsl${MATERIALX_LIBNAME_SUFFIX}
+ ${MATERIALX_MODULE_NAME} PROPERTIES
+ OUTPUT_NAME ${MATERIALX_MODULE_NAME}${MATERIALX_LIBNAME_SUFFIX}
COMPILE_FLAGS "${EXTERNAL_COMPILE_FLAGS}"
LINK_FLAGS "${EXTERNAL_LINK_FLAGS}"
INSTALL_RPATH "${MATERIALX_SAME_DIR_RPATH}"
@@ -18,26 +26,26 @@ set_target_properties(
SOVERSION "${MATERIALX_MAJOR_VERSION}")
target_link_libraries(
- MaterialXRenderOsl
+ ${MATERIALX_MODULE_NAME}
MaterialXRender
${CMAKE_DL_LIBS})
-target_include_directories(MaterialXRenderOsl
+target_include_directories(${MATERIALX_MODULE_NAME}
PUBLIC
$
$
PRIVATE
${EXTERNAL_INCLUDE_DIRS})
-install(TARGETS MaterialXRenderOsl
+install(TARGETS ${MATERIALX_MODULE_NAME}
EXPORT MaterialX
ARCHIVE DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
LIBRARY DESTINATION ${MATERIALX_INSTALL_LIB_PATH}
RUNTIME DESTINATION bin)
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/"
- DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/MaterialXRenderOsl/ MESSAGE_NEVER
+ DESTINATION ${MATERIALX_INSTALL_INCLUDE_PATH}/${MATERIALX_MODULE_NAME}/ MESSAGE_NEVER
FILES_MATCHING PATTERN "*.h*")
-install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/MaterialXRenderOsl.pdb"
+install(FILES "${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_BUILD_TYPE}/${MATERIALX_MODULE_NAME}.pdb"
DESTINATION "${MATERIALX_INSTALL_LIB_PATH}/" OPTIONAL)
From b23de80a5e8e3cdf4b2ed5a5e12ced765c8b0125 Mon Sep 17 00:00:00 2001
From: Bernard Kwok
Date: Thu, 17 Aug 2023 22:29:08 -0400
Subject: [PATCH 2/6] Add support for top level inputs (#1453)
Fix so that top level inputs are parsed properly and values and path reflection data is correct (for uniform updates).
---
.../stdlib/nodegraph_inputs/top_level_input.mtlx | 10 ++++++++++
source/MaterialXCore/Interface.cpp | 2 +-
source/MaterialXGenShader/ShaderNode.cpp | 12 +++++++++++-
3 files changed, 22 insertions(+), 2 deletions(-)
create mode 100644 resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx
diff --git a/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx
new file mode 100644
index 0000000000..d92eae7f19
--- /dev/null
+++ b/resources/Materials/TestSuite/stdlib/nodegraph_inputs/top_level_input.mtlx
@@ -0,0 +1,10 @@
+
+
+
+
+
+
+
+
+
+
diff --git a/source/MaterialXCore/Interface.cpp b/source/MaterialXCore/Interface.cpp
index 3a93a384c2..b733d3a4c7 100644
--- a/source/MaterialXCore/Interface.cpp
+++ b/source/MaterialXCore/Interface.cpp
@@ -305,7 +305,7 @@ InputPtr Input::getInterfaceInput() const
{
if (hasInterfaceName())
{
- ConstNodeGraphPtr graph = getAncestorOfType();
+ ConstGraphElementPtr graph = getAncestorOfType();
if (graph)
{
return graph->getInput(getInterfaceName());
diff --git a/source/MaterialXGenShader/ShaderNode.cpp b/source/MaterialXGenShader/ShaderNode.cpp
index c923e4be57..3eb750f1ff 100644
--- a/source/MaterialXGenShader/ShaderNode.cpp
+++ b/source/MaterialXGenShader/ShaderNode.cpp
@@ -381,7 +381,17 @@ void ShaderNode::initialize(const Node& node, const NodeDef& nodeDef, GenContext
ShaderInput* input = getInput(nodeValue->getName());
if (input)
{
- input->setPath(nodeValue->getNamePath());
+ string path = nodeValue->getNamePath();
+ InputPtr nodeInput = nodeValue->asA();
+ if (nodeInput)
+ {
+ InputPtr interfaceInput = nodeInput->getInterfaceInput();
+ if (interfaceInput)
+ {
+ path = interfaceInput->getNamePath();
+ }
+ }
+ input->setPath(path);
}
}
From 79433cca61a2b3c23fc20c41a3c5ed7c19286da7 Mon Sep 17 00:00:00 2001
From: Jonathan Stone
Date: Fri, 18 Aug 2023 15:55:59 -0700
Subject: [PATCH 3/6] Simplify default color handling in GLSL (#1452)
This changelist simplifies default color handling in GLSL, making the renderer responsible for generating fallback textures when images are not found on disk, and removing associated dynamic branches in GLSL shader code.
Two advantages of this simplification are:
- Hydra Storm and other MaterialXGenGlsl integrations can now render materials that reference 1x1 images without needing special-case logic.
- The render performance of MaterialXGenGlsl shaders that reference images is slightly improved, as dynamic branches exact a performance cost in some situations.
This new logic doesn't yet handle color space differences between missing images and default colors, and we should address this across languages in a future improvement.
---
libraries/stdlib/genglsl/mx_image_color3.glsl | 11 +----
libraries/stdlib/genglsl/mx_image_color4.glsl | 11 +----
libraries/stdlib/genglsl/mx_image_float.glsl | 11 +----
.../stdlib/genglsl/mx_image_vector2.glsl | 11 +----
.../stdlib/genglsl/mx_image_vector3.glsl | 11 +----
.../stdlib/genglsl/mx_image_vector4.glsl | 11 +----
.../stdlib/texture/image_default.mtlx | 36 +++++++++++++++++
source/MaterialXGraphEditor/RenderView.cpp | 2 +-
source/MaterialXRender/ImageHandler.cpp | 40 ++++++++-----------
source/MaterialXRender/ImageHandler.h | 10 +----
source/MaterialXRenderGlsl/GlslMaterial.cpp | 2 +-
source/MaterialXRenderGlsl/GlslProgram.cpp | 2 +-
source/MaterialXRenderMsl/MslMaterial.mm | 2 +-
.../MslPipelineStateObject.mm | 2 +-
source/MaterialXView/Viewer.cpp | 4 +-
.../PyMaterialXRender/PyImageHandler.cpp | 4 +-
16 files changed, 74 insertions(+), 96 deletions(-)
create mode 100644 resources/Materials/TestSuite/stdlib/texture/image_default.mtlx
diff --git a/libraries/stdlib/genglsl/mx_image_color3.glsl b/libraries/stdlib/genglsl/mx_image_color3.glsl
index 802318f475..8c4c039554 100644
--- a/libraries/stdlib/genglsl/mx_image_color3.glsl
+++ b/libraries/stdlib/genglsl/mx_image_color3.glsl
@@ -2,13 +2,6 @@
void mx_image_color3(sampler2D tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv).rgb;
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv).rgb;
}
diff --git a/libraries/stdlib/genglsl/mx_image_color4.glsl b/libraries/stdlib/genglsl/mx_image_color4.glsl
index e74ad9445f..7541b9da04 100644
--- a/libraries/stdlib/genglsl/mx_image_color4.glsl
+++ b/libraries/stdlib/genglsl/mx_image_color4.glsl
@@ -2,13 +2,6 @@
void mx_image_color4(sampler2D tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv);
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv);
}
diff --git a/libraries/stdlib/genglsl/mx_image_float.glsl b/libraries/stdlib/genglsl/mx_image_float.glsl
index 9b831035d2..0a402a101c 100644
--- a/libraries/stdlib/genglsl/mx_image_float.glsl
+++ b/libraries/stdlib/genglsl/mx_image_float.glsl
@@ -2,13 +2,6 @@
void mx_image_float(sampler2D tex_sampler, int layer, float defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out float result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv).r;
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv).r;
}
diff --git a/libraries/stdlib/genglsl/mx_image_vector2.glsl b/libraries/stdlib/genglsl/mx_image_vector2.glsl
index 124cb09287..42a7235297 100644
--- a/libraries/stdlib/genglsl/mx_image_vector2.glsl
+++ b/libraries/stdlib/genglsl/mx_image_vector2.glsl
@@ -2,13 +2,6 @@
void mx_image_vector2(sampler2D tex_sampler, int layer, vec2 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec2 result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv).rg;
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv).rg;
}
diff --git a/libraries/stdlib/genglsl/mx_image_vector3.glsl b/libraries/stdlib/genglsl/mx_image_vector3.glsl
index 840e60fe6f..d49eab735e 100644
--- a/libraries/stdlib/genglsl/mx_image_vector3.glsl
+++ b/libraries/stdlib/genglsl/mx_image_vector3.glsl
@@ -2,13 +2,6 @@
void mx_image_vector3(sampler2D tex_sampler, int layer, vec3 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec3 result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv).rgb;
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv).rgb;
}
diff --git a/libraries/stdlib/genglsl/mx_image_vector4.glsl b/libraries/stdlib/genglsl/mx_image_vector4.glsl
index f4b61d83f0..c8bdc66fc4 100644
--- a/libraries/stdlib/genglsl/mx_image_vector4.glsl
+++ b/libraries/stdlib/genglsl/mx_image_vector4.glsl
@@ -2,13 +2,6 @@
void mx_image_vector4(sampler2D tex_sampler, int layer, vec4 defaultval, vec2 texcoord, int uaddressmode, int vaddressmode, int filtertype, int framerange, int frameoffset, int frameendaction, vec2 uv_scale, vec2 uv_offset, out vec4 result)
{
- if (textureSize(tex_sampler, 0).x > 1)
- {
- vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
- result = texture(tex_sampler, uv);
- }
- else
- {
- result = defaultval;
- }
+ vec2 uv = mx_transform_uv(texcoord, uv_scale, uv_offset);
+ result = texture(tex_sampler, uv);
}
diff --git a/resources/Materials/TestSuite/stdlib/texture/image_default.mtlx b/resources/Materials/TestSuite/stdlib/texture/image_default.mtlx
new file mode 100644
index 0000000000..89b99c3c39
--- /dev/null
+++ b/resources/Materials/TestSuite/stdlib/texture/image_default.mtlx
@@ -0,0 +1,36 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/source/MaterialXGraphEditor/RenderView.cpp b/source/MaterialXGraphEditor/RenderView.cpp
index faf48f543a..f36a492502 100644
--- a/source/MaterialXGraphEditor/RenderView.cpp
+++ b/source/MaterialXGraphEditor/RenderView.cpp
@@ -720,7 +720,7 @@ void RenderView::loadEnvironmentLight()
envIrradianceMap = _imageHandler->acquireImage(envIrradiancePath);
// If not found, then generate an irradiance map via spherical harmonics.
- if (envIrradianceMap == _imageHandler->getInvalidImage())
+ if (envIrradianceMap == _imageHandler->getZeroImage())
{
mx::Sh3ColorCoeffs shIrradiance = mx::projectEnvironment(envRadianceMap, true);
envIrradianceMap = mx::renderEnvironment(shIrradiance, IRRADIANCE_MAP_WIDTH, IRRADIANCE_MAP_HEIGHT);
diff --git a/source/MaterialXRender/ImageHandler.cpp b/source/MaterialXRender/ImageHandler.cpp
index bc43b617ff..d54a18fedd 100644
--- a/source/MaterialXRender/ImageHandler.cpp
+++ b/source/MaterialXRender/ImageHandler.cpp
@@ -56,9 +56,6 @@ ImageHandler::ImageHandler(ImageLoaderPtr imageLoader)
{
addLoader(imageLoader);
_zeroImage = createUniformImage(2, 2, 4, Image::BaseType::UINT8, Color4(0.0f));
-
- // Generated shaders interpret 1x1 textures as invalid images.
- _invalidImage = createUniformImage(1, 1, 4, Image::BaseType::UINT8, Color4(0.0f));
}
void ImageHandler::addLoader(ImageLoaderPtr loader)
@@ -118,7 +115,7 @@ bool ImageHandler::saveImage(const FilePath& filePath,
return false;
}
-ImagePtr ImageHandler::acquireImage(const FilePath& filePath)
+ImagePtr ImageHandler::acquireImage(const FilePath& filePath, const Color4& defaultColor)
{
// Resolve the input filepath.
FilePath resolvedFilePath = filePath;
@@ -142,9 +139,12 @@ ImagePtr ImageHandler::acquireImage(const FilePath& filePath)
return image;
}
- // No valid image was found, so cache the sentinel invalid image.
- cacheImage(resolvedFilePath, _invalidImage);
- return _invalidImage;
+ // No valid image was found, so generate a uniform texture with the given default color.
+ // TODO: This step assumes that the missing image and its default color are in the same
+ // color space, which is not always the case.
+ ImagePtr defaultImage = createUniformImage(1, 1, 4, Image::BaseType::UINT8, defaultColor);
+ cacheImage(resolvedFilePath, defaultImage);
+ return defaultImage;
}
bool ImageHandler::bindImage(ImagePtr, const ImageSamplingProperties&)
@@ -189,7 +189,7 @@ ImageVec ImageHandler::getReferencedImages(ConstDocumentPtr doc)
if (file)
{
ImagePtr image = acquireImage(file->getResolvedValueString());
- if (image && image != _invalidImage)
+ if (image)
{
imageVec.push_back(image);
}
@@ -214,14 +214,6 @@ ImagePtr ImageHandler::loadImage(const FilePath& filePath)
}
if (image)
{
- // Generated shaders interpret 1x1 textures as invalid images, so valid 1x1
- // images must be resized.
- if (image->getWidth() == 1 && image->getHeight() == 1)
- {
- image = createUniformImage(2, 2, image->getChannelCount(),
- image->getBaseType(), image->getTexelColor(0, 0));
- }
-
return image;
}
}
@@ -288,23 +280,23 @@ void ImageSamplingProperties::setProperties(const string& fileNameUniform,
root = root.substr(0, pos);
}
- const string uaddressmodeStr = root + UADDRESS_MODE_SUFFIX;
- const ShaderPort* port = uniformBlock.find(uaddressmodeStr);
+ const ShaderPort* port = uniformBlock.find(root + UADDRESS_MODE_SUFFIX);
ValuePtr intValue = port ? port->getValue() : nullptr;
uaddressMode = ImageSamplingProperties::AddressMode(intValue && intValue->isA() ? intValue->asA() : INVALID_MAPPED_INT_VALUE);
- const string vaddressmodeStr = root + VADDRESS_MODE_SUFFIX;
- port = uniformBlock.find(vaddressmodeStr);
+ port = uniformBlock.find(root + VADDRESS_MODE_SUFFIX);
intValue = port ? port->getValue() : nullptr;
vaddressMode = ImageSamplingProperties::AddressMode(intValue && intValue->isA() ? intValue->asA() : INVALID_MAPPED_INT_VALUE);
- const string filtertypeStr = root + FILTER_TYPE_SUFFIX;
- port = uniformBlock.find(filtertypeStr);
+ port = uniformBlock.find(root + FILTER_TYPE_SUFFIX);
intValue = port ? port->getValue() : nullptr;
filterType = ImageSamplingProperties::FilterType(intValue && intValue->isA() ? intValue->asA() : INVALID_MAPPED_INT_VALUE);
- const string defaultColorStr = root + DEFAULT_COLOR_SUFFIX;
- port = uniformBlock.find(defaultColorStr);
+ port = uniformBlock.find(root + DEFAULT_COLOR_SUFFIX);
+ if (!port)
+ {
+ port = uniformBlock.find(root + DEFAULT_COLOR_SUFFIX + "_cm_in");
+ }
ValuePtr colorValue = port ? port->getValue() : nullptr;
if (colorValue)
{
diff --git a/source/MaterialXRender/ImageHandler.h b/source/MaterialXRender/ImageHandler.h
index ee1fe127c4..c744eb2f6a 100644
--- a/source/MaterialXRender/ImageHandler.h
+++ b/source/MaterialXRender/ImageHandler.h
@@ -188,7 +188,7 @@ class MX_RENDER_API ImageHandler
/// found in the cache, then each image loader will be applied in turn.
/// @param filePath File path of the image.
/// @return On success, a shared pointer to the acquired image.
- ImagePtr acquireImage(const FilePath& filePath);
+ ImagePtr acquireImage(const FilePath& filePath, const Color4& defaultColor = Color4(0.0f));
/// Bind an image for rendering.
/// @param image The image to bind.
@@ -247,13 +247,6 @@ class MX_RENDER_API ImageHandler
return _zeroImage;
}
- /// Return the sentinel invalid image, representing images that cannot be loaded
- /// and should be replaced with their declared default value.
- ImagePtr getInvalidImage() const
- {
- return _invalidImage;
- }
-
/// Acquire all images referenced by the given document, and return the
/// images in a vector.
ImageVec getReferencedImages(ConstDocumentPtr doc);
@@ -278,7 +271,6 @@ class MX_RENDER_API ImageHandler
FileSearchPath _searchPath;
StringResolverPtr _resolver;
ImagePtr _zeroImage;
- ImagePtr _invalidImage;
};
MATERIALX_NAMESPACE_END
diff --git a/source/MaterialXRenderGlsl/GlslMaterial.cpp b/source/MaterialXRenderGlsl/GlslMaterial.cpp
index ef7a0ed0c2..ce4582d44f 100644
--- a/source/MaterialXRenderGlsl/GlslMaterial.cpp
+++ b/source/MaterialXRenderGlsl/GlslMaterial.cpp
@@ -209,7 +209,7 @@ ImagePtr GlslMaterial::bindImage(const FilePath& filePath, const std::string& un
imageHandler->setFilenameResolver(resolver);
// Acquire the given image.
- ImagePtr image = imageHandler->acquireImage(filePath);
+ ImagePtr image = imageHandler->acquireImage(filePath, samplingProperties.defaultColor);
if (!image)
{
return nullptr;
diff --git a/source/MaterialXRenderGlsl/GlslProgram.cpp b/source/MaterialXRenderGlsl/GlslProgram.cpp
index a60997716a..900cac0ef1 100644
--- a/source/MaterialXRenderGlsl/GlslProgram.cpp
+++ b/source/MaterialXRenderGlsl/GlslProgram.cpp
@@ -491,7 +491,7 @@ ImagePtr GlslProgram::bindTexture(unsigned int uniformType, int uniformLocation,
uniformType >= GL_SAMPLER_1D && uniformType <= GL_SAMPLER_CUBE)
{
// Acquire the image.
- ImagePtr image = imageHandler->acquireImage(filePath);
+ ImagePtr image = imageHandler->acquireImage(filePath, samplingProperties.defaultColor);
if (imageHandler->bindImage(image, samplingProperties))
{
GLTextureHandlerPtr textureHandler = std::static_pointer_cast(imageHandler);
diff --git a/source/MaterialXRenderMsl/MslMaterial.mm b/source/MaterialXRenderMsl/MslMaterial.mm
index 7e9cd38adc..66fc0462f2 100644
--- a/source/MaterialXRenderMsl/MslMaterial.mm
+++ b/source/MaterialXRenderMsl/MslMaterial.mm
@@ -199,7 +199,7 @@
imageHandler->setFilenameResolver(resolver);
// Acquire the given image.
- return imageHandler->acquireImage(filePath);
+ return imageHandler->acquireImage(filePath, samplingProperties.defaultColor);
}
void MslMaterial::bindLighting(LightHandlerPtr lightHandler,
diff --git a/source/MaterialXRenderMsl/MslPipelineStateObject.mm b/source/MaterialXRenderMsl/MslPipelineStateObject.mm
index 84a615fd61..4f8378ae46 100644
--- a/source/MaterialXRenderMsl/MslPipelineStateObject.mm
+++ b/source/MaterialXRenderMsl/MslPipelineStateObject.mm
@@ -542,7 +542,7 @@ int GetStrideOfMetalType(MTLDataType type)
{
// Acquire the image.
string error;
- ImagePtr image = imageHandler->acquireImage(filePath);
+ ImagePtr image = imageHandler->acquireImage(filePath, samplingProperties.defaultColor);
imageHandler->bindImage(image, samplingProperties);
return bindTexture(renderCmdEncoder, uniformLocation, image, imageHandler);
}
diff --git a/source/MaterialXView/Viewer.cpp b/source/MaterialXView/Viewer.cpp
index ecbb4352fc..6346658d07 100644
--- a/source/MaterialXView/Viewer.cpp
+++ b/source/MaterialXView/Viewer.cpp
@@ -474,7 +474,7 @@ void Viewer::loadEnvironmentLight()
}
// Look for an irradiance map using an expected filename convention.
- mx::ImagePtr envIrradianceMap = _imageHandler->getInvalidImage();
+ mx::ImagePtr envIrradianceMap = _imageHandler->getZeroImage();
if (!_normalizeEnvironment && !_splitDirectLight)
{
mx::FilePath envIrradiancePath = _envRadianceFilename.getParentPath() / IRRADIANCE_MAP_FOLDER / _envRadianceFilename.getBaseName();
@@ -482,7 +482,7 @@ void Viewer::loadEnvironmentLight()
}
// If not found, then generate an irradiance map via spherical harmonics.
- if (envIrradianceMap == _imageHandler->getInvalidImage())
+ if (envIrradianceMap == _imageHandler->getZeroImage())
{
if (_generateReferenceIrradiance)
{
diff --git a/source/PyMaterialX/PyMaterialXRender/PyImageHandler.cpp b/source/PyMaterialX/PyMaterialXRender/PyImageHandler.cpp
index 7ece49d60b..d261bc7306 100644
--- a/source/PyMaterialX/PyMaterialXRender/PyImageHandler.cpp
+++ b/source/PyMaterialX/PyMaterialXRender/PyImageHandler.cpp
@@ -41,7 +41,8 @@ void bindPyImageHandler(py::module& mod)
.def("addLoader", &mx::ImageHandler::addLoader)
.def("saveImage", &mx::ImageHandler::saveImage,
py::arg("filePath"), py::arg("image"), py::arg("verticalFlip") = false)
- .def("acquireImage", &mx::ImageHandler::acquireImage)
+ .def("acquireImage", &mx::ImageHandler::acquireImage,
+ py::arg("filePath"), py::arg("defaultColor") = mx::Color4(0.0f))
.def("bindImage", &mx::ImageHandler::bindImage)
.def("unbindImage", &mx::ImageHandler::unbindImage)
.def("unbindImages", &mx::ImageHandler::unbindImages)
@@ -54,6 +55,5 @@ void bindPyImageHandler(py::module& mod)
py::arg("image") = nullptr)
.def("clearImageCache", &mx::ImageHandler::clearImageCache)
.def("getZeroImage", &mx::ImageHandler::getZeroImage)
- .def("getInvalidImage", &mx::ImageHandler::getInvalidImage)
.def("getReferencedImages", &mx::ImageHandler::getReferencedImages);
}
From 7fd2b4f5069e54f86688e19159393741e43511b2 Mon Sep 17 00:00:00 2001
From: Jonathan Stone
Date: Sat, 19 Aug 2023 10:12:47 -0700
Subject: [PATCH 4/6] Remove exceptions from topologicalSort
This changelist removes cycle exceptions from the topologicalSort methods in MaterialX, as these functions are already protected from recursion, and clients have more robust ways of checking for cycles in graphs (e.g. hasUpstreamCycle).
This addresses edge cases in MaterialXGraphEditor where certain graph configurations could trigger a crash.
---
source/MaterialXCore/Node.cpp | 10 ----------
source/MaterialXCore/Node.h | 1 -
source/MaterialXGenShader/ShaderGraph.cpp | 6 ------
source/MaterialXGenShader/ShaderGraph.h | 1 -
4 files changed, 18 deletions(-)
diff --git a/source/MaterialXCore/Node.cpp b/source/MaterialXCore/Node.cpp
index 45524b116d..28be7e432c 100644
--- a/source/MaterialXCore/Node.cpp
+++ b/source/MaterialXCore/Node.cpp
@@ -439,9 +439,7 @@ vector GraphElement::topologicalSort() const
}
}
- size_t visitCount = 0;
vector result;
-
while (!childQueue.empty())
{
// Pop the queue and add to topological order.
@@ -467,14 +465,6 @@ vector GraphElement::topologicalSort() const
}
}
}
-
- visitCount++;
- }
-
- // Check if there was a cycle.
- if (visitCount != children.size())
- {
- throw ExceptionFoundCycle("Encountered a cycle in graph: " + getName());
}
return result;
diff --git a/source/MaterialXCore/Node.h b/source/MaterialXCore/Node.h
index a316b0eb6c..1b1115fde7 100644
--- a/source/MaterialXCore/Node.h
+++ b/source/MaterialXCore/Node.h
@@ -308,7 +308,6 @@ class MX_CORE_API GraphElement : public InterfaceElement
/// Return a vector of all children (nodes and outputs) sorted in
/// topological order.
- /// @throws ExceptionFoundCycle if a cycle is encountered.
vector topologicalSort() const;
/// If not yet present, add a geometry node to this graph matching the given property
diff --git a/source/MaterialXGenShader/ShaderGraph.cpp b/source/MaterialXGenShader/ShaderGraph.cpp
index e6ad6eca29..8a424f8bf5 100644
--- a/source/MaterialXGenShader/ShaderGraph.cpp
+++ b/source/MaterialXGenShader/ShaderGraph.cpp
@@ -1225,12 +1225,6 @@ void ShaderGraph::topologicalSort()
}
}
}
-
- // Check if there was a cycle.
- if (count != _nodeMap.size())
- {
- throw ExceptionFoundCycle("Encountered a cycle in graph: " + getName());
- }
}
void ShaderGraph::setVariableNames(GenContext& context)
diff --git a/source/MaterialXGenShader/ShaderGraph.h b/source/MaterialXGenShader/ShaderGraph.h
index 4e30c4ae66..4117599c27 100644
--- a/source/MaterialXGenShader/ShaderGraph.h
+++ b/source/MaterialXGenShader/ShaderGraph.h
@@ -103,7 +103,6 @@ class MX_GENSHADER_API ShaderGraph : public ShaderNode
void addDefaultGeomNode(ShaderInput* input, const GeomPropDef& geomprop, GenContext& context);
/// Sort the nodes in topological order.
- /// @throws ExceptionFoundCycle if a cycle is encountered.
void topologicalSort();
/// Return an iterator for traversal upstream from the given output
From 42bb654d5d0b1cd9206045fcebaa36bdc7c0ac9f Mon Sep 17 00:00:00 2001
From: Jonathan Stone
Date: Sat, 19 Aug 2023 12:45:40 -0700
Subject: [PATCH 5/6] Add empty vector check to node paste
This changelist adds an empty vector check to node paste operations in the graph editor, addressing a case where copying nodes from a deleted material would trigger a crash.
---
source/MaterialXGraphEditor/Graph.cpp | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/source/MaterialXGraphEditor/Graph.cpp b/source/MaterialXGraphEditor/Graph.cpp
index 9e3fbccc40..c773ef4457 100644
--- a/source/MaterialXGraphEditor/Graph.cpp
+++ b/source/MaterialXGraphEditor/Graph.cpp
@@ -3796,11 +3796,11 @@ void Graph::drawGraph(ImVec2 mousePos)
linkGraph();
ImVec2 canvasPos = ed::ScreenToCanvas(mousePos);
// place the copied nodes or the individual new nodes
- if ((int) _copiedNodes.size() > 0)
+ if (!_copiedNodes.empty())
{
positionPasteBin(canvasPos);
}
- else
+ else if (!_graphNodes.empty())
{
ed::SetNodePosition(_graphNodes.back()->getId(), canvasPos);
}
From 2d12c1687887f793609133cadf192bf4b29e9502 Mon Sep 17 00:00:00 2001
From: Jonathan Stone
Date: Sat, 19 Aug 2023 19:02:52 -0700
Subject: [PATCH 6/6] Improve validation in graph editor
This changelist improves the document validation step in the graph editor, importing the standard libraries to allow validation of node interfaces as well as document syntax.
---
source/MaterialXGraphEditor/Graph.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/source/MaterialXGraphEditor/Graph.cpp b/source/MaterialXGraphEditor/Graph.cpp
index c773ef4457..9bf3afcd1b 100644
--- a/source/MaterialXGraphEditor/Graph.cpp
+++ b/source/MaterialXGraphEditor/Graph.cpp
@@ -84,7 +84,6 @@ Graph::Graph(const std::string& materialFilename,
_geomFilter.push_back(".gltf");
_graphDoc = loadDocument(materialFilename);
- _graphDoc->importLibrary(_stdLib);
_initial = true;
createNodeUIList(_stdLib);
@@ -177,6 +176,7 @@ mx::DocumentPtr Graph::loadDocument(mx::FilePath filename)
if (!filename.isEmpty())
{
mx::readFromXmlFile(doc, filename, _searchPath, &readOptions);
+ doc->importLibrary(_stdLib);
std::string message;
if (!doc->validate(&message))
{
@@ -4057,7 +4057,6 @@ void Graph::drawGraph(ImVec2 mousePos)
std::string graphName = fileName.getBaseName();
_currGraphName.push_back(graphName.substr(0, graphName.length() - 5));
_graphDoc = loadDocument(fileName);
- _graphDoc->importLibrary(_stdLib);
_initial = true;
buildUiBaseGraph(_graphDoc);