private void CreateDevice()
 {
     try
     {
         // Create device
         device = D3DDevice1.CreateDevice1(
             null,
             DriverType.Hardware,
             null,
             CreateDeviceOptions.SupportBgra,
             FeatureLevel.Ten);
     }
     catch (Exception)
     {
         // if we can't create a hardware device,
         // try the warp one
     }
     if (device == null)
     {
         device = D3DDevice1.CreateDevice1(
             null,
             DriverType.Software,
             "d3d10warp.dll",
             CreateDeviceOptions.SupportBgra,
             FeatureLevel.Ten);
     }
 }
Exemple #2
0
        private static D3DDevice1 TryCreateDevice1(DriverType type)
        {
            // We'll try to create the device that supports any of these feature levels
            FeatureLevel[] levels =
            {
                FeatureLevel.Ten,
                FeatureLevel.NinePointThree,
                FeatureLevel.NinePointTwo,
                FeatureLevel.NinePointOne
            };

            foreach (FeatureLevel level in levels)
            {
                try
                {
                    return(D3DDevice1.CreateDevice1(null, type, null,
                                                    CreateDeviceOptions.SupportBgra, level));
                }
                catch (ArgumentException)                 // E_INVALIDARG
                {
                }
                catch (OutOfMemoryException)                 // E_OUTOFMEMORY
                {
                }
                catch (DirectXException)                 // D3DERR_INVALIDCALL or E_FAIL
                {
                }
            }
            return(null);            // We failed to create a device at any required feature level
        }