// EMERGENT GAME TECHNOLOGIES PROPRIETARY INFORMATION
//
// This software is supplied under the terms of a license agreement or
// nondisclosure agreement with Emergent Game Technologies and may not 
// be copied or disclosed except in accordance with the terms of that 
// agreement.
//
//      Copyright (c) 1996-2007 Emergent Game Technologies.
//      All Rights Reserved.
//
// Emergent Game Technologies, Chapel Hill, North Carolina 27517
// http://www.emergent.net

#ifndef NIFXLPARAMETERDESC_H
#define NIFXLPARAMETERDESC_H

#include "NiFXLShaderLibType.h"
#include <NiShaderAttributeDesc.h>

class NiFXLParameterMatrixDesc;
class NiFXLParameterVectorDesc;
class NiFXLParameterFloatDesc;
class NiFXLParameterBooleanDesc;
class NiFXLParameterIntegerDesc;
class NiFXLParameterSamplerDesc;
class NiFXLParameterPredefinedDesc;
class NiFXLParameterObjectDesc;
class NiFXLParameterArrayDesc;

//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterDesc : public NiMemObject
{
public:
    static NiFXLParameterMatrixDesc* GetMatrixDesc();
    static NiFXLParameterVectorDesc* GetVectorDesc();
    static NiFXLParameterFloatDesc* GetFloatDesc();
    static NiFXLParameterBooleanDesc* GetBooleanDesc();
    static NiFXLParameterIntegerDesc* GetIntegerDesc();
    static NiFXLParameterSamplerDesc* GetSamplerDesc();
    static NiFXLParameterPredefinedDesc* GetPredefinedDesc();
    static NiFXLParameterObjectDesc* GetObjectDesc();
    static NiFXLParameterArrayDesc* GetArrayDesc();

    enum ParameterType
    {
        PT_NONE,
        PT_MATRIX,
        PT_VECTOR,
        PT_FLOAT,
        PT_BOOL,
        PT_UINT,
        PT_SAMPLER,
        PT_PREDEFINED,
        PT_OBJECT,
        PT_ARRAY
    };

    ParameterType m_eParamType;
    bool m_bGlobal;

    const char* m_pcName;
protected:
    static NiFXLParameterMatrixDesc ms_kMatrixDesc;
    static NiFXLParameterVectorDesc ms_kVectorDesc;
    static NiFXLParameterFloatDesc ms_kFloatDesc;
    static NiFXLParameterBooleanDesc ms_kBooleanDesc;
    static NiFXLParameterIntegerDesc ms_kIntegerDesc;
    static NiFXLParameterSamplerDesc ms_kSamplerDesc;
    static NiFXLParameterPredefinedDesc ms_kPredefinedDesc;
    static NiFXLParameterObjectDesc ms_kObjectDesc;
    static NiFXLParameterArrayDesc ms_kArrayDesc;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterMatrixDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    float m_afInitValue[16];
    unsigned int m_uiNumRows;
    unsigned int m_uiNumCols;

    bool m_bHidden;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterVectorDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    enum 
    {
        MAX_ROWS = 1,
        MAX_COLUMNS = 4,
        MAX_ENTRIES = MAX_ROWS * MAX_COLUMNS
    };

    enum VectorType
    {
        TYPE_POINT2 = 0,
        TYPE_POINT3,
        TYPE_POINT4,
        TYPE_MAX
    };

    VectorType GetVectorType();

    float m_afInitValue[MAX_ENTRIES];
    float m_afMaxValue[MAX_ENTRIES];
    float m_afMinValue[MAX_ENTRIES];

    unsigned int m_uiNumRows;
    unsigned int m_uiNumCols;
    unsigned int m_uiNumAtomicElements;

    bool m_bHidden;
    bool m_bColor;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterArrayDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    enum ArrayType
    {
        TYPE_FLOAT = 0,
        TYPE_POINT2,
        TYPE_POINT3,
        TYPE_POINT4,
        TYPE_COLORA,
        TYPE_MAX
    };

    enum 
    {
        MAX_ROWS = 256,
        MAX_COLUMNS = 4,
        MAX_ENTRIES = MAX_ROWS*MAX_COLUMNS
    };

    ArrayType GetArrayType();

    float m_afInitValue[MAX_ENTRIES];
    float m_afMaxValue[MAX_ENTRIES];
    float m_afMinValue[MAX_ENTRIES];
    float m_afTempValues[MAX_ENTRIES];

    unsigned int m_uiNumRows;
    unsigned int m_uiNumCols;
    unsigned int m_uiNumElements;
    unsigned int GetElementSize();

    bool m_bHidden;
    bool m_bColor;

    static bool ExpandToVector4Array(const float* pfSrcArray, 
        D3DXVECTOR4* pfDestArray,
        unsigned int uiRows, unsigned int uiColumns, 
        unsigned int uiNumElements);
    static bool CompactFromVector4Array( 
        const D3DXVECTOR4* pfSrcArray, float* pfDestArray,
        unsigned int uiRows, unsigned int uiColumns, 
        unsigned int uiNumElements);
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterFloatDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    float m_fInitValue;
    float m_fMaxValue;
    float m_fMinValue;

    bool m_bHidden;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterBooleanDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    bool m_bInitValue;

    bool m_bHidden;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterIntegerDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    unsigned int m_uiInitValue;
    unsigned int m_uiMaxValue;
    unsigned int m_uiMinValue;

    bool m_bHidden;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterSamplerDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcDesc;

    void* m_pvInitValue;

    bool m_bHidden;

    enum TextureType
    {
        TT_NONE,
        TT_2D,
        TT_3D,
        TT_CUBE
    };

    TextureType m_eTextureType;

    const char* m_pcTextureName;
    const char* m_pcTextureFunction;
    const char* m_pcTextureTarget;

    const char* m_pcTextureType;
    unsigned int m_uiTextureWidth;
    unsigned int m_uiTextureHeight;
    unsigned int m_uiTextureDepth;
    const char* m_pcTextureMap;
    unsigned int m_uiTextureIndex;

    unsigned int m_uiObjectType;
    unsigned int m_uiObjectIndex;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterPredefinedDesc : 
    public NiFXLParameterDesc
{
public:
    const char* m_pcPredefined;
    unsigned int m_uiMapping;
    unsigned int m_uiArrayCount;
    unsigned int m_uiExtraData;
};
//---------------------------------------------------------------------------
class NIFXLSHADER_ENTRY NiFXLParameterObjectDesc :
    public NiFXLParameterDesc
{
public:
    unsigned int m_uiMapping;
    NiShaderAttributeDesc::ObjectType m_eObjectType;
    unsigned int m_uiObjectIndex;
};
//---------------------------------------------------------------------------

#endif //NiFXLPARAMETERDESC_H
