#include "xgfxlight.h"

#include "qcolor.h"
#include "xgfxlightdef.h"

XGfxLight::XGfxLight()
    : XAsset()
    , mType(0)
    , mCanUseShadowMap(0)
    , mColor()
    , mDir()
    , mOrigin()
    , mRadius(0.0f)
    , mCosHalfFovOuter(0.0f)
    , mCosHalfFovInner(0.0f)
    , mExponent(0)
    , mSpotShadowIndex(0)
    , mDefPtr(0)
    , mDef(new XGfxLightDef())
{
}

XGfxLight::~XGfxLight()
{
    delete mDef;
}

void XGfxLight::ParseData(QDataStream *aStream) {
    if (GetPtr() == -1) {
        *aStream
            >> mType
            >> mCanUseShadowMap;

        aStream->skipRawData(2);

        float r, g, b;

        *aStream
            >> r
            >> g
            >> b
            >> mDir[0]
            >> mDir[1]
            >> mDir[2]
            >> mOrigin[0]
            >> mOrigin[1]
            >> mOrigin[2]
            >> mRadius
            >> mCosHalfFovOuter
            >> mCosHalfFovInner
            >> mExponent
            >> mSpotShadowIndex
            >> mDefPtr;

        mColor = QColor(r, g, b);

        if (mDefPtr == -1)
        {
            mDef->ParseData(aStream);
        }
    }
}

void XGfxLight::Clear()
{

}
