using System;
using D3D = Microsoft.DirectX.Direct3D;

namespace Icarus.Utilities.Graphics
{
	/// <summary>
	/// Summary description for DirectXUtilities.
	/// </summary>
	public class DirectXUtilities
	{
		#region Singleton Implementation
		/// <summary>
		/// Singleton Implementation.
		/// </summary>
		private static DirectXUtilities mg_Instance = new DirectXUtilities();

		/// <summary>
		/// Singleton Implementation.
		/// </summary>
		private DirectXUtilities() 
		{
		}

		/// <summary>
		/// Singleton Implementation.
		/// </summary>
		public static DirectXUtilities Instance 
		{
			get { return mg_Instance; }
		}
		#endregion

		/// <summary>
		/// Find16BitMode - Tests for 16-bit buffer formats for compatibility with
		/// the current display adapter in full-screen.
		/// </summary>
		/// <returns>The chosen format, or D3D.Format.Unknown if one isn't found</returns>
		public D3D.Format Find16BitMode()
		{
			D3D.Format[] poss_formats={D3D.Format.R5G6B5, D3D.Format.X1R5G5B5};
			D3D.DeviceType dev=D3D.DeviceType.Hardware;

			foreach(D3D.Format format in poss_formats)
			{

				if (D3D.Manager.CheckDeviceType(0,dev,format,format,false))
				{
					return format;
				}
			}

			return D3D.Format.Unknown;
         
		}

		/// <summary>
		/// Returns the current display mode.
		/// </summary>
		public D3D.DisplayMode FindCurrentDisplayMode() 
		{
			return D3D.Manager.Adapters[0].CurrentDisplayMode;
		}
	}
}
