#include "xgfxvertexshaderloaddef.h"

XGfxVertexShaderLoadDef::XGfxVertexShaderLoadDef()
    : XAsset()
    , mCachedPart()
    , mPhysicalPart()
    , mCachedPartSize(0)
    , mPhysicalPartSize(0)
{
    SetName("Vertex Shader Definition");
}

XGfxVertexShaderLoadDef::~XGfxVertexShaderLoadDef()
{

}

void XGfxVertexShaderLoadDef::Clear()
{
    mCachedPart = QByteArray();
    mPhysicalPart = QByteArray();
    mCachedPartSize = 0;
    mPhysicalPartSize = 0;
}

void XGfxVertexShaderLoadDef::ParseData(QDataStream *aStream)
{
    if (IsDebug())
    {
        qDebug() << QString("[%1] Parsing data for %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(GetName());
    }
    qint32 cachedPartPtr, physicalPartPtr;
    *aStream
        >> cachedPartPtr
        >> physicalPartPtr
        >> mCachedPartSize
        >> mPhysicalPartSize;

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

    if (physicalPartPtr)
    {
        aStream->readRawData(mPhysicalPart.data(), mPhysicalPartSize);
        if (IsDebug())
        {
            qDebug() << QString("[%1] mPhysicalPart = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(mPhysicalPart);
        }
    }
    if (cachedPartPtr)
    {
        aStream->readRawData(mCachedPart.data(), mCachedPartSize);
        if (IsDebug())
        {
            qDebug() << QString("[%1] mCachedPart = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(mCachedPart);
        }
    }
}
