diff --git a/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h b/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h index e4e8424f..37fb745b 100644 --- a/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h +++ b/src/ObjCommon/Game/IW4/TechsetConstantsIW4.h @@ -59,9 +59,40 @@ namespace IW4 "debug bumpmap", "debug bumpmap instanced", }; - static_assert(std::extent_v == TECHNIQUE_COUNT); + static const char* materialStreamDestinationNames[] + { + "position", + "normal", + "color[0]", + "color[1]", + "depth", + "texcoord[0]", + "texcoord[1]", + "texcoord[2]", + "texcoord[3]", + "texcoord[4]", + "texcoord[5]", + "texcoord[6]", + "texcoord[7]", + }; + static_assert(std::extent_v == STREAM_DST_COUNT); + + static const char* materialStreamSourceNames[] + { + "position", + "color", + "texcoord[0]", + "normal", + "tangent", + "texcoord[1]", + "texcoord[2]", + "normalTransform[0]", + "normalTransform[1]" + }; + static_assert(std::extent_v == STREAM_SRC_COUNT); + inline CodeSamplerSource s_lightmapSamplers[] { {"primary", TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, nullptr, 0, 0}, diff --git a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp index 25a26e9c..4b5b0c72 100644 --- a/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp +++ b/src/ObjLoading/Game/IW4/AssetLoaders/AssetLoaderTechniqueSet.cpp @@ -536,6 +536,39 @@ namespace IW4 bool AcceptVertexStreamRouting(const std::string& destination, const std::string& source, std::string& errorMessage) override { + assert(!m_passes.empty()); + auto& pass = m_passes.at(m_passes.size() - 1); + + const auto streamIndex = static_cast(pass.m_vertex_decl.streamCount); + if(pass.m_vertex_decl.streamCount >= std::extent_v) + { + errorMessage = "Too many stream routings"; + return false; + } + + const auto foundDestination = std::find(std::begin(materialStreamDestinationNames), std::end(materialStreamDestinationNames), destination); + if(foundDestination == std::end(materialStreamDestinationNames)) + { + errorMessage = "Unknown stream destination"; + return false; + } + + const auto foundSource = std::find(std::begin(materialStreamSourceNames), std::end(materialStreamSourceNames), source); + if (foundSource == std::end(materialStreamSourceNames)) + { + errorMessage = "Unknown stream source"; + return false; + } + + const auto destinationIndex = static_cast(foundDestination - std::begin(materialStreamDestinationNames)); + const auto sourceIndex = static_cast(foundSource - std::begin(materialStreamSourceNames)); + + pass.m_vertex_decl.routing.data[streamIndex].dest = destinationIndex; + pass.m_vertex_decl.routing.data[streamIndex].source = sourceIndex; + + pass.m_vertex_decl.hasOptionalSource = pass.m_vertex_decl.hasOptionalSource || sourceIndex >= STREAM_SRC_OPTIONAL_BEGIN; + + pass.m_vertex_decl.streamCount++; return true; } }; diff --git a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp index bc083a8b..349b0d07 100644 --- a/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp +++ b/src/ObjWriting/Game/IW4/AssetDumpers/AssetDumperTechniqueSet.cpp @@ -350,51 +350,19 @@ namespace IW4 static const char* GetStreamDestinationString(const MaterialStreamDestination_e dst) { - static const char* destinationNames[] - { - "position", - "normal", - "color[0]", - "color[1]", - "depth", - "texcoord[0]", - "texcoord[1]", - "texcoord[2]", - "texcoord[3]", - "texcoord[4]", - "texcoord[5]", - "texcoord[6]", - "texcoord[7]", - }; - static_assert(std::extent_v == STREAM_DST_COUNT); - const auto dstIndex = static_cast(dst); - assert(dstIndex < std::extent_v); - if (dstIndex < std::extent_v) - return destinationNames[dstIndex]; + assert(dstIndex < std::extent_v); + if (dstIndex < std::extent_v) + return materialStreamDestinationNames[dstIndex]; return ""; } static const char* GetStreamSourceString(const MaterialStreamStreamSource_e src) { - static const char* sourceNames[] - { - "position", - "color", - "texcoord[0]", - "normal", - "tangent", - "texcoord[1]", - "texcoord[2]", - "normalTransform[0]", - "normalTransform[1]" - }; - static_assert(std::extent_v == STREAM_SRC_COUNT); - const auto srcIndex = static_cast(src); - assert(srcIndex < std::extent_v); - if (srcIndex < std::extent_v) - return sourceNames[srcIndex]; + assert(srcIndex < std::extent_v); + if (srcIndex < std::extent_v) + return materialStreamSourceNames[srcIndex]; return ""; }