//	Darkstar Engine  (c) UnderWorld Interactive Studio (all coding by Svarog    2007-2008)
//
//      Данный файл является частью Darkstar Engine. Любое использование кода файла
//      без согласия компании, является нарушением закона об авторском праве (в слу-
//      чае если не оговорено обратное).
//
//      Имя файла: render_target_common.inl
//      Краткое описание: common render target objects and structures
//

namespace gs
{
	__forceinline bool isDepthStencilFormat(const DRTFORMAT& format)
	{
		if(format == DRTFMT_D16_UNORM || format == DRTFMT_D24_UNORM_S8_UINT || format == DRTFMT_D32_FLOAT)
			return true;
		return false;
	};

	#ifdef GD_D3D10

	__forceinline RTFORMAT getSpecRTFormat(const DRTFORMAT& darkstar_format)
	{
		switch(darkstar_format)
		{
		case DRTFMT_R8G8B8A8_UNORM:
			return DXGI_FORMAT_R8G8B8A8_UNORM;
		case DRTFMT_R32G32B32A32_FLOAT:
			return DXGI_FORMAT_R32G32B32A32_FLOAT;
		case DRTFMT_R32G32B32_FLOAT:
			return DXGI_FORMAT_R32G32B32_FLOAT;
		case DRTFMT_R16G16B16A16_FLOAT:
			return DXGI_FORMAT_R16G16B16A16_FLOAT;
		case DRTFMT_R32G32_FLOAT:
			return DXGI_FORMAT_R32G32_FLOAT;
		case DRTFMT_R10G10B10A2_UNORM:
			return DXGI_FORMAT_R10G10B10A2_UNORM;
		case DRTFMT_R11G11B10_FLOAT:
			return DXGI_FORMAT_R11G11B10_FLOAT;
		case DRTFMT_R16G16_FLOAT:
			return DXGI_FORMAT_R16G16_FLOAT;
		case DRTFMT_R32_FLOAT:
			return DXGI_FORMAT_R32_FLOAT;
		case DRTFMT_R16_FLOAT:
			return DXGI_FORMAT_R16_FLOAT;
		case DRTFMT_B5G5R5A1_UNORM:
			return DXGI_FORMAT_B5G5R5A1_UNORM;
		case DRTFMT_B5G6R5_UNORM:
			return DXGI_FORMAT_B5G6R5_UNORM;
		case DRTFMT_D16_UNORM:
			return DXGI_FORMAT_D16_UNORM;
		case DRTFMT_D24_UNORM_S8_UINT:
			return DXGI_FORMAT_D24_UNORM_S8_UINT;
		case DRTFMT_D32_FLOAT:
			return DXGI_FORMAT_D32_FLOAT;
		case DRTFMT_B8G8R8A8_UNORM:
			return DXGI_FORMAT_B8G8R8A8_UNORM;
		default:
			return DXGI_FORMAT_UNKNOWN;
		};
	};

	__forceinline DRTFORMAT getDarkRTFormat(const RTFORMAT& spec_format)
	{
		switch(spec_format)
		{
		case DXGI_FORMAT_R8G8B8A8_UNORM:
			return DRTFMT_R8G8B8A8_UNORM;
		case DXGI_FORMAT_R32G32B32A32_FLOAT:
			return DRTFMT_R32G32B32A32_FLOAT;
		case DXGI_FORMAT_R32G32B32_FLOAT:
			return DRTFMT_R32G32B32_FLOAT;
		case DXGI_FORMAT_R16G16B16A16_FLOAT:
			return DRTFMT_R16G16B16A16_FLOAT;
		case DXGI_FORMAT_R32G32_FLOAT:
			return DRTFMT_R32G32_FLOAT;
		case DXGI_FORMAT_R10G10B10A2_UNORM:
			return DRTFMT_R10G10B10A2_UNORM;
		case DXGI_FORMAT_R11G11B10_FLOAT:
			return DRTFMT_R11G11B10_FLOAT;
		case DXGI_FORMAT_R16G16_FLOAT:
			return DRTFMT_R16G16_FLOAT;
		case DXGI_FORMAT_R32_FLOAT:
			return DRTFMT_R32_FLOAT;
		case DXGI_FORMAT_R16_FLOAT:
			return DRTFMT_R16_FLOAT;
		case DXGI_FORMAT_B5G5R5A1_UNORM:
			return DRTFMT_B5G5R5A1_UNORM;
		case DXGI_FORMAT_B5G6R5_UNORM:
			return DRTFMT_B5G6R5_UNORM;
		case DXGI_FORMAT_D16_UNORM:
			return DRTFMT_D16_UNORM;
		case DXGI_FORMAT_D24_UNORM_S8_UINT:
			return DRTFMT_D24_UNORM_S8_UINT;
		case DXGI_FORMAT_D32_FLOAT:
			return DRTFMT_D32_FLOAT;
		case DXGI_FORMAT_B8G8R8A8_UNORM:
			return DRTFMT_B8G8R8A8_UNORM;
		default:
			return DRTFMT_UNKNOWN;
		};
	};

	#endif

	#ifdef GD_D3D9

	__forceinline RTFORMAT getSpecRTFormat(const DRTFORMAT& darkstar_format)
	{
		switch(darkstar_format)
		{
		case DRTFMT_R8G8B8A8_UNORM:
			return D3DFMT_A8B8G8R8;
		case DRTFMT_R32G32B32A32_FLOAT:
			return D3DFMT_A32B32G32R32F;
		case DRTFMT_R32G32B32_FLOAT:
			return D3DFMT_A32B32G32R32F; // unfortunately there is no such format in directx 9, so we will be use closest format
		case DRTFMT_R16G16B16A16_FLOAT:
			return D3DFMT_A16B16G16R16F;
		case DRTFMT_R32G32_FLOAT:
			return D3DFMT_G32R32F;
		case DRTFMT_R10G10B10A2_UNORM:
			return D3DFMT_A2B10G10R10;
		case DRTFMT_R11G11B10_FLOAT:
			return D3DFMT_A2B10G10R10; // unfortunately there is no such format in directx 9, so we will be use closest format
		case DRTFMT_R16G16_FLOAT:
			return D3DFMT_G16R16F;
		case DRTFMT_R32_FLOAT:
			return D3DFMT_R32F;
		case DRTFMT_R16_FLOAT:
			return D3DFMT_R16F;
		case DRTFMT_B5G5R5A1_UNORM:
			return D3DFMT_A1R5G5B5;
		case DRTFMT_B5G6R5_UNORM:
			return D3DFMT_R5G6B5;
		case DRTFMT_D16_UNORM:
			return D3DFMT_D16;
		case DRTFMT_D24_UNORM_S8_UINT:
			return D3DFMT_D24S8;
		case DRTFMT_D32_FLOAT:
			return D3DFMT_D32;
		case DRTFMT_B8G8R8A8_UNORM:
			return D3DFMT_A8R8G8B8;
		default:
			return D3DFMT_UNKNOWN;
		};
	};

	__forceinline DRTFORMAT getDarkRTFormat(const RTFORMAT& spec_format)
	{
		switch(spec_format)
		{
		case D3DFMT_A8B8G8R8:
			return DRTFMT_R8G8B8A8_UNORM;
		case D3DFMT_A32B32G32R32F:
			return DRTFMT_R32G32B32A32_FLOAT;
		case D3DDECLTYPE_FLOAT3:
			return DRTFMT_R32G32B32_FLOAT;
		case D3DFMT_A16B16G16R16F:
			return DRTFMT_R16G16B16A16_FLOAT;
		case DRTFMT_R32G32_FLOAT:
			return DRTFMT_R32G32_FLOAT;
		case D3DFMT_A2B10G10R10:
			return DRTFMT_R10G10B10A2_UNORM;
		case D3DFMT_G16R16F:
			return DRTFMT_R16G16_FLOAT;
		case D3DFMT_R32F:
			return DRTFMT_R32_FLOAT;
		case D3DFMT_R16F:
			return DRTFMT_R16_FLOAT;
		case D3DFMT_A1R5G5B5:
			return DRTFMT_B5G5R5A1_UNORM;
		case D3DFMT_R5G6B5:
			return DRTFMT_B5G6R5_UNORM;
		case D3DFMT_D16:
			return DRTFMT_D16_UNORM;
		case D3DFMT_D24S8:
			return DRTFMT_D24_UNORM_S8_UINT;
		case D3DFMT_D32:
			return DRTFMT_D32_FLOAT;
		case D3DFMT_X8R8G8B8:
			return DRTFMT_R8G8B8A8_UNORM;
		case D3DFMT_A8R8G8B8:
			return DRTFMT_B8G8R8A8_UNORM;
		default:
			return DRTFMT_UNKNOWN;
		};
	};
	#endif
};