Load Vertex Stream Routing

This commit is contained in:
Jan 2022-04-10 17:48:12 +02:00
parent bd291a75a9
commit e0bcf7aff0
3 changed files with 71 additions and 39 deletions

View File

@ -59,9 +59,40 @@ namespace IW4
"debug bumpmap",
"debug bumpmap instanced",
};
static_assert(std::extent_v<decltype(techniqueTypeNames)> == 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<decltype(materialStreamDestinationNames)> == 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<decltype(materialStreamSourceNames)> == STREAM_SRC_COUNT);
inline CodeSamplerSource s_lightmapSamplers[]
{
{"primary", TEXTURE_SRC_CODE_LIGHTMAP_PRIMARY, nullptr, 0, 0},

View File

@ -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<size_t>(pass.m_vertex_decl.streamCount);
if(pass.m_vertex_decl.streamCount >= std::extent_v<decltype(MaterialVertexStreamRouting::data)>)
{
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<MaterialStreamDestination_e>(foundDestination - std::begin(materialStreamDestinationNames));
const auto sourceIndex = static_cast<MaterialStreamStreamSource_e>(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;
}
};

View File

@ -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<decltype(destinationNames)> == STREAM_DST_COUNT);
const auto dstIndex = static_cast<size_t>(dst);
assert(dstIndex < std::extent_v<decltype(destinationNames)>);
if (dstIndex < std::extent_v<decltype(destinationNames)>)
return destinationNames[dstIndex];
assert(dstIndex < std::extent_v<decltype(materialStreamDestinationNames)>);
if (dstIndex < std::extent_v<decltype(materialStreamDestinationNames)>)
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<decltype(sourceNames)> == STREAM_SRC_COUNT);
const auto srcIndex = static_cast<size_t>(src);
assert(srcIndex < std::extent_v<decltype(sourceNames)>);
if (srcIndex < std::extent_v<decltype(sourceNames)>)
return sourceNames[srcIndex];
assert(srcIndex < std::extent_v<decltype(materialStreamSourceNames)>);
if (srcIndex < std::extent_v<decltype(materialStreamSourceNames)>)
return materialStreamSourceNames[srcIndex];
return "";
}