#include "xgfxdrawsurffields.h"

XGfxDrawSurfFields::XGfxDrawSurfFields()
    : XAsset()
    , mObjectId(0)
    , mReflectionProbeIndex(0)
    , mCustomIndex(0)
    , mMaterialSortedIndex(0)
    , mPrepass(0)
    , mPrimaryLightIndex(0)
    , mSurfType(0)
    , mPrimarySortKey(0)
    , mUnused(0)
{
    SetName("GFX Draw Surface Fields");
}

void XGfxDrawSurfFields::ParseData(XDataStream *aStream)
{
    // Read the raw 64-bit value from the stream
    quint64 raw;
    *aStream >> raw;
    if (IsDebug())
    {
        qDebug() << QString("[%1] raw = %2").arg(aStream->device()->pos(), 10, 10, QChar('0')).arg(raw);
    }

    // Decode bitfields from the 64-bit packed value
    // mObjectId  =-  raw        & 0xFFFF;        // bits 0-15
    // mReflectionProbeIndex = (raw >> 16) & 0xFF;          // bits 16-23
    // mCustomIndex = (raw >> 24) & 0x1F;          // bits 24-28
    // mMaterialSortedIndex = (raw >> 29) & 0x7FF;         // bits 29-39
    // mPrepass   =- (raw >> 40) & 0x3;           // bits 40-41
    // mPrimaryLightIndex = (raw >> 42) & 0xFF;          // bits 42-49
    // mSurfType  =- (raw >> 50) & 0xF;           // bits 50-53
    // mPrimarySortKey = (raw >> 54) & 0x3F;          // bits 54-59
    // mUnused    =- (raw >> 60) & 0xF;           // bits 60-63
}

void XGfxDrawSurfFields::Clear()
{
    mObjectId = 0;
    mReflectionProbeIndex = 0;
    mCustomIndex = 0;
    mMaterialSortedIndex = 0;
    mPrepass = 0;
    mPrimaryLightIndex = 0;
    mSurfType = 0;
    mPrimarySortKey = 0;
    mUnused = 0;
}
