#include "xgfximage.h"

XGfxImage::XGfxImage()
    : XAsset()
    , mMapType()
    , mTexture()
    , mSemantic(0)
    , mCardMemory()
    , mWidth(0)
    , mHeight(0)
    , mDepth(0)
    , mCategory(0)
    , mDelayLoadPixels(false)
    , mPixels()
    , mBaseSize(0)
    , mStreamSlot(0)
    , mStreaming(false)
    , mName()
{
    SetType(ASSET_TYPE_IMAGE);
    SetName("GFX Image");
}

XGfxImage::~XGfxImage()
{

}

void XGfxImage::ParseData(XDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        mMapType = (XMapType)aStream->ParseUInt32(QString("%1 map type").arg(GetName()));

        mTexture.ParsePtr(aStream, false);

        mSemantic = aStream->ParseUInt8(QString("%1 semantic").arg(GetName()));

        aStream->skipRawData(3);

        mCardMemory.ParseData(aStream);

        qint32 pixelsPtr;

        mWidth = aStream->ParseUInt16(QString("%1 width").arg(GetName()));
        mHeight = aStream->ParseUInt16(QString("%1 height").arg(GetName()));
        mDepth = aStream->ParseUInt16(QString("%1 depth").arg(GetName()));
        mCategory = aStream->ParseUInt8(QString("%1 category").arg(GetName()));
        mDelayLoadPixels = aStream->ParseUInt8(QString("%1 delay load pixels").arg(GetName()));
        pixelsPtr = aStream->ParseInt32(QString("%1 pixels ptr").arg(GetName()));
        mBaseSize = aStream->ParseUInt32(QString("%1 base size").arg(GetName()));
        mStreamSlot = aStream->ParseUInt16(QString("%1 stream slot").arg(GetName()));
        mStreaming = aStream->ParseUInt8(QString("%1 streaming").arg(GetName()));

        aStream->skipRawData(1);

        mName.ParsePtr(aStream);

        //int variableSkip = mDelayLoadPixels ? 2 : 5;
        //aStream->skipRawData(variableSkip);

        if (pixelsPtr == -1)
        {
            mPixels.resize(mCardMemory.GetPlatform());
            aStream->readRawData(mPixels.data(), mCardMemory.GetPlatform());
        }

        mTexture.ParseData(aStream);
    }
}

void XGfxImage::Clear()
{

}
