/*
 * This source file is part of KEOS (Free 3D Engine)
 * For the latest info, see http://www.keosengine.org/
 * E-mails : thierry.vouriot@keosengine.org, yeri@keosengine.org
 * 
 * This program is free software; you can redistribute it and/or modify it under
 * the terms of the GNU Lesser General Public License as published by the Free Software
 * Foundation; either version 2 of the License, or (at your option) any later
 * version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place - Suite 330, Boston, MA 02111-1307, USA, or go to
 * http://www.gnu.org/copyleft/lesser.txt.
 *
 */

#include "KeosD3D9Enum.h"

namespace Keos
{
    //=======================================================================
    // CD3D9Enum implementation
    //=======================================================================

    //-----------------------------------------------------------------------
    D3DTRANSFORMSTATETYPE CD3D9Enum::MatrixType[] =
    {
        D3DTS_WORLD,
        D3DTS_PROJECTION,
        D3DTS_TEXTURE0,
        D3DTS_TEXTURE1,
        D3DTS_TEXTURE2,
        D3DTS_TEXTURE3
    };

    //-----------------------------------------------------------------------
    D3DPRIMITIVETYPE CD3D9Enum::PrimitiveType[] =
    {
        D3DPT_TRIANGLELIST,
        D3DPT_TRIANGLESTRIP,
        D3DPT_TRIANGLEFAN,
        D3DPT_LINELIST,
        D3DPT_LINESTRIP,
        D3DPT_POINTLIST
    };

    //-----------------------------------------------------------------------
    D3DFORMAT CD3D9Enum::PixelFormat[] =
    {
	    D3DFMT_L8,
	    D3DFMT_A8L8,
	    D3DFMT_A1R5G5B5,
	    D3DFMT_A4R4G4B4,
	    D3DFMT_R8G8B8,
	    D3DFMT_A8R8G8B8,
        D3DFMT_DXT1,
        D3DFMT_DXT3,
        D3DFMT_DXT5
    };

    //-----------------------------------------------------------------------
    D3DBLEND CD3D9Enum::Blend[] =
    {
        D3DBLEND_SRCALPHA,
        D3DBLEND_INVSRCALPHA,
        D3DBLEND_DESTALPHA,
        D3DBLEND_INVDESTALPHA,
        D3DBLEND_SRCCOLOR,
        D3DBLEND_INVSRCCOLOR,
        D3DBLEND_DESTCOLOR,
        D3DBLEND_INVDESTCOLOR,
        D3DBLEND_ONE,
        D3DBLEND_ZERO
    };
    
    //-----------------------------------------------------------------------
    D3DTEXTUREOP CD3D9Enum::TextureOp[] =
    {
        D3DTOP_SELECTARG1,
        D3DTOP_ADD,
        D3DTOP_MODULATE,
        D3DTOP_SELECTARG1,
        D3DTOP_ADD,
        D3DTOP_MODULATE
    };

    //-----------------------------------------------------------------------
    ulong CD3D9Enum::TextureArg[] =
    {
        D3DTA_DIFFUSE,
        D3DTA_TEXTURE,
        D3DTA_CURRENT,
        D3DTA_TFACTOR
    };

    //-----------------------------------------------------------------------
    D3DRENDERSTATETYPE CD3D9Enum::RenderParameter[] =
    {
        D3DRS_ZWRITEENABLE,
        D3DRS_ALPHABLENDENABLE
    };

    //-----------------------------------------------------------------------
    ulong CD3D9Enum::BufferFlags(ulong nFlags)
    {
        return (nFlags & BUF_DYNAMIC ? D3DUSAGE_DYNAMIC : 0);
    }

    //-----------------------------------------------------------------------
    ulong CD3D9Enum::LockFlags(ulong nFlags)
    {
        ulong nLockFlags = 0;

        if (nFlags & LOCK_READONLY)
            nLockFlags = D3DLOCK_READONLY;

        if (nFlags & LOCK_WRITEONLY)
        {
            nLockFlags = D3DLOCK_DISCARD;
            //LockFlags = D3DLOCK_NOOVERWRITE;
        }

        return nLockFlags;
    }

    //-----------------------------------------------------------------------
    D3DTRANSFORMSTATETYPE CD3D9Enum::Get(TMatrixType Value)
    {
        return MatrixType[Value];
    }

    //-----------------------------------------------------------------------
    D3DPRIMITIVETYPE CD3D9Enum::Get(TPrimitiveType Value)
    {
        return PrimitiveType[Value];
    }

    //-----------------------------------------------------------------------    
    D3DFORMAT CD3D9Enum::Get(TPixelFormat Value)
    {
        return PixelFormat[Value];
    }

    //-----------------------------------------------------------------------
    D3DBLEND CD3D9Enum::Get(TBlend Value)
    {
        return Blend[Value];
    }

    //-----------------------------------------------------------------------
    D3DTEXTUREOP CD3D9Enum::Get(TTextureOp Value)
    {
        return TextureOp[Value];
    }

    //-----------------------------------------------------------------------
    ulong CD3D9Enum::Get(TTextureArg Value)
    {
        return TextureArg[Value];
    }

    //-----------------------------------------------------------------------
    D3DRENDERSTATETYPE CD3D9Enum::Get(TRenderParameter Value)
    {
        return RenderParameter[Value];
    }

} // namespace Keos
