Dump IW4 vertexdecl

This commit is contained in:
Jan 2022-03-23 17:11:30 +01:00
parent 8e76f05d05
commit b0ed7e9544
2 changed files with 71 additions and 9 deletions

View File

@ -875,8 +875,8 @@ namespace IW4
struct MaterialStreamRouting
{
char source;
char dest;
unsigned char source;
unsigned char dest;
};
struct MaterialVertexStreamRouting
@ -888,7 +888,7 @@ namespace IW4
struct MaterialVertexDeclaration
{
const char* name;
char streamCount;
unsigned char streamCount;
bool hasOptionalSource;
MaterialVertexStreamRouting routing;
};

View File

@ -75,9 +75,71 @@ namespace IW4
m_stream << "}\n";
}
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];
return "";
}
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];
return "";
}
void DumpVertexDecl(const MaterialPass& pass)
{
// TODO
if (pass.vertexDecl == nullptr || pass.vertexDecl->streamCount <= 0)
return;
m_stream << "\n";
const auto streamCount = std::min(static_cast<size_t>(pass.vertexDecl->streamCount), std::extent_v<decltype(MaterialVertexStreamRouting::data)>);
for (auto streamIndex = 0u; streamIndex < streamCount; streamIndex++)
{
const auto& stream = pass.vertexDecl->routing.data[streamIndex];
Indent();
m_stream << "vertex." << GetStreamDestinationString(static_cast<MaterialStreamDestination_e>(stream.dest))
<< " = code." << GetStreamSourceString(static_cast<MaterialStreamStreamSource_e>(stream.source)) << ";\n";
}
}
void DumpPass(const MaterialPass& pass)