#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("Image");
}

XGfxImage::~XGfxImage()
{

}

void XGfxImage::ParseData(QDataStream *aStream)
{
    if (GetPtr() == -1)
    {
        *aStream >> mMapType;

        mTexture.ParseData(aStream);

        *aStream >> mSemantic;

        aStream->skipRawData(3);

        mCardMemory.ParseData(aStream);

        qint32 pixelsPtr;
        *aStream
            >> mWidth
            >> mHeight
            >> mDepth
            >> mCategory
            >> mDelayLoadPixels
            >> pixelsPtr
            >> mBaseSize
            >> mStreamSlot
            >> mStreaming;

        aStream->skipRawData(1);

        mName.ParsePtr(aStream);

        int variableSkip = 5;
        if (mDelayLoadPixels)
        {
            variableSkip = 2;
        }
        aStream->skipRawData(variableSkip);
        if (pixelsPtr)
        {
            aStream->readRawData(mPixels.data(), mCardMemory.GetPlatform());
        }
        // TODO: This is wrong
        mTexture.ParseData(aStream);
    }
}

void XGfxImage::Clear()
{

}
