#include "xmaterial.h"

XMaterial::XMaterial()
    : XAsset()
    , mInfo()
    , mStateBitsEntry(26)
    , mTextureCount(0)
    , mConstantCount(0)
    , mStateBitsCount(0)
    , mStateFlags(0)
    , mCameraRegion(0)
    , mTechniqueSet()
    , mTextureTable()
    , mConstantTable()
    , mStateBitsTable()
{
    SetType(ASSET_TYPE_MATERIAL);
    SetName("Material");
}

XMaterial::~XMaterial()
{

}

void XMaterial::ParseData(QDataStream *aStream)
{
    mInfo.ParseData(aStream);

    for (int i = 0; i < 26; i++)
    {
        *aStream >> mStateBitsEntry[i];
    }

    *aStream
        >> mTextureCount
        >> mConstantCount
        >> mStateBitsCount
        >> mStateFlags
        >> mCameraRegion;

    aStream->skipRawData(1);

    mTechniqueSet.ParsePtr(aStream, false);
    mTextureTable.ParsePtr(aStream, false);
    mConstantTable.ParsePtr(aStream, false);
    mStateBitsTable.ParsePtr(aStream, false);

    mTechniqueSet.ParseData(aStream);
    mTextureTable.ParseData(aStream);
    mConstantTable.ParseData(aStream);
    mStateBitsTable.ParseData(aStream);
}

void XMaterial::Clear()
{
    mInfo.Clear();
    mStateBitsEntry.clear();
    mTextureCount = 0;
    mConstantCount = 0;
    mStateBitsCount = 0;
    mStateFlags = 0;
    mCameraRegion = 0;
    mTechniqueSet =  XMaterialTechniqueSet();
    mTextureTable =  XMaterialTextureDef();
    mConstantTable =  XMaterialConstantDef();
    mStateBitsTable =  XGfxStateBits();
}
