예제 #1
0
 internal FactoryHandlerDXGI(GraphicsCoreConfiguration coreConfiguration)
 {
     _dxgiFactory = SeeingSharpUtil.TryExecute(() => CreateDXGIFactory2 <IDXGIFactory4>(coreConfiguration.DebugEnabled));
     if (_dxgiFactory == null)
     {
         _dxgiFactory = SeeingSharpUtil.TryExecute(() => CreateDXGIFactory2 <IDXGIFactory2>(coreConfiguration.DebugEnabled));
     }
     if (_dxgiFactory == null)
     {
         _dxgiFactory = SeeingSharpUtil.TryExecute(() => CreateDXGIFactory1 <IDXGIFactory1>());
     }
     if (_dxgiFactory == null)
     {
         throw new SeeingSharpGraphicsException("Unable to create the DXGI Factory object!");
     }
 }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceHandlerD3D11"/> class.
        /// </summary>
        internal DeviceHandlerD3D11(GraphicsDeviceConfiguration deviceConfig, IDXGIAdapter1 dxgiAdapter)
        {
            _dxgiAdapter = dxgiAdapter;

            // Define possible create flags
            var createFlags = D3D11.DeviceCreationFlags.BgraSupport;

            if (deviceConfig.CoreConfiguration.DebugEnabled)
            {
                createFlags |= D3D11.DeviceCreationFlags.Debug;
            }

            // Define all steps on which we try to initialize Direct3D
            var initParameterQueue =
                new List <Tuple <D3D.FeatureLevel, D3D11.DeviceCreationFlags, HardwareDriverLevel> >();

            // Define all tries for hardware initialization
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_1, createFlags, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_11_0, createFlags, HardwareDriverLevel.Direct3D11));
            initParameterQueue.Add(Tuple.Create(
                                       D3D.FeatureLevel.Level_10_0, createFlags, HardwareDriverLevel.Direct3D10));

            // Try to create the device, each defined configuration step by step
            foreach (var(actFeatureLevel, actCreateFlags, actDriverLevel) in initParameterQueue)
            {
                try
                {
                    // Try to create the device using current parameters
                    var result = D3D11CreateDevice(
                        dxgiAdapter, D3D.DriverType.Unknown, createFlags,
                        new D3D.FeatureLevel[] { actFeatureLevel }, out var device);
                    if (!result.Success)
                    {
                        continue;
                    }
                    if (device == null)
                    {
                        continue;
                    }

                    try
                    {
                        _device1 = device.QueryInterface <D3D11.ID3D11Device1>();
                        _device3 = SeeingSharpUtil.TryExecute(() => _device1.QueryInterface <D3D11.ID3D11Device3>());

                        if (_device3 != null)
                        {
                            _immediateContext3 = _device3.ImmediateContext3;
                        }
                    }
                    finally
                    {
                        SeeingSharpUtil.SafeDispose(ref device);
                    }

                    // Device successfully created, save all parameters and break this loop
                    _featureLevel    = actFeatureLevel;
                    _creationFlags   = actCreateFlags;
                    this.DriverLevel = actDriverLevel;
                    break;
                }
                catch (Exception)
                {
                    // ignored
                }
            }

            // Throw exception on failure
            if (_device1 == null)
            {
                throw new SeeingSharpGraphicsException("Unable to initialize d3d11 device!");
            }

            // Get immediate context from the device
            _immediateContext = _device1.ImmediateContext;
        }