XPlor/libs/xassets/xmaterialpass.cpp

92 lines
2.7 KiB
C++
Raw Normal View History

2025-09-03 13:15:13 -04:00
#include "xmaterialpass.h"
#include "xmaterialvertexdeclaration.h"
#include "xmaterialvertexshader.h"
#include "xmaterialpixelshader.h"
2025-09-07 12:36:08 -04:00
#include <QDebug>
#include <QIODevice>
2025-09-03 13:15:13 -04:00
XMaterialPass::XMaterialPass()
: XAsset()
2025-09-05 18:35:17 -04:00
, mVertexDecl()
2025-09-07 12:36:08 -04:00
, mVertexShaderArray(15)
2025-09-05 18:35:17 -04:00
, mVertexShader()
, mPixelShader()
2025-09-03 13:15:13 -04:00
, mPerPrimArgCount(0)
, mPerObjArgCount(0)
, mStableArgCount(0)
, mCustomSamplerFlags(0)
//, mPrecompiledIndex(0)
2025-09-05 18:35:17 -04:00
, mArgs()
2025-09-03 13:15:13 -04:00
{
2025-09-07 12:36:08 -04:00
SetName("Material Pass");
2025-09-03 13:15:13 -04:00
}
void XMaterialPass::Clear()
{
}
2025-09-10 21:58:26 -04:00
void XMaterialPass::ParseData(XDataStream *aStream)
2025-09-03 13:15:13 -04:00
{
2025-09-07 12:36:08 -04:00
if (IsDebug())
{
qDebug() << QString("[%1] Parsing data for %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(GetName());
}
2025-09-05 18:35:17 -04:00
mVertexDecl.ParsePtr(aStream, false);
if (GetCommonInfo()->GetGame() != GAME_COD4)
2025-09-05 18:35:17 -04:00
{
for (int i = 0; i < 15; i++)
{
mVertexShaderArray[i].ParsePtr(aStream, false);
}
2025-09-05 18:35:17 -04:00
}
mVertexShader.ParsePtr(aStream, false);
mPixelShader.ParsePtr(aStream, false);
if (GetCommonInfo()->GetGame() == GAME_COD4)
{
mPerPrimArgCount = aStream->ParseUInt8(QString("%1 per primary arg count").arg(GetName()));
mPerObjArgCount = aStream->ParseUInt8(QString("%1 per object arg count").arg(GetName()));
mStableArgCount = aStream->ParseUInt8(QString("%1 stable arg count").arg(GetName()));
mCustomSamplerFlags = aStream->ParseUInt8(QString("%1 custom sampler flags").arg(GetName()));
}
else
{
mPerPrimArgCount = aStream->ParseUInt32(QString("%1 per primary arg count").arg(GetName()));
mPerObjArgCount = aStream->ParseUInt32(QString("%1 per object arg count").arg(GetName()));
mStableArgCount = aStream->ParseUInt32(QString("%1 stable arg count").arg(GetName()));
mCustomSamplerFlags = aStream->ParseUInt32(QString("%1 custom sampler flags").arg(GetName()));
mPrecompiledIndex = aStream->ParseUInt32(QString("%1 precompiled index").arg(GetName()));
2025-09-07 12:36:08 -04:00
aStream->skipRawData(3);
}
2025-09-07 12:36:08 -04:00
qint32 argsPtr = aStream->ParseInt32(QString("%1 args ptr").arg(GetName()));
2025-09-05 18:35:17 -04:00
mVertexDecl.ParseDataSafe(aStream);
2025-09-07 12:36:08 -04:00
if (GetCommonInfo()->GetGame() != GAME_COD4)
2025-09-05 18:35:17 -04:00
{
for (int i = 0; i < mVertexShaderArray.size(); i++)
{
mVertexShaderArray[i].ParseData(aStream);
}
2025-09-05 18:35:17 -04:00
}
mVertexShader.ParseDataSafe(aStream);
mPixelShader.ParseDataSafe(aStream);
2025-09-07 12:36:08 -04:00
if (argsPtr)
{
int argCount = mStableArgCount + mPerObjArgCount + mPerPrimArgCount;
for (int i = 0; i < argCount; i++)
{
XMaterialShaderArgument arg;
arg.ParseData(aStream);
mArgs.append(arg);
}
}
2025-09-03 13:15:13 -04:00
}