#include "xmaterialtechnique.h"

XMaterialTechnique::XMaterialTechnique()
    : XAsset()
    , mName()
    , mFlags(0)
    , mPassCount(0)
    , mPassArray()
{
    SetName("Material Technique");
}

XMaterialTechnique::~XMaterialTechnique()
{

}

void XMaterialTechnique::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        if (IsDebug())
        {
            qDebug() << QString("[%1] Parsing data for %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(GetName());
        }
        mName.ParsePtr(aStream, false);

        *aStream
            >> mFlags
            >> mPassCount;

        if (IsDebug())
        {
            qDebug() << QString("[%1] mFlags = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(mFlags);
            qDebug() << QString("[%1] mPassCount = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(mPassCount);
        }

        mPassArray = QVector<XMaterialPass>(mPassCount);

        for (int i = 0; i < mPassCount; i++)
        {
            mPassArray[i].ParseData(aStream);
        }

        mName.ParseData(aStream);
    }
}

void XMaterialTechnique::Clear()
{
    mName.Clear();
    mFlags = 0;
    mPassCount = 0;
    mPassArray.clear();
}
