예제 #1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="DeviceHandlerD3D11" /> class.
        /// </summary>
        internal DeviceHandlerD2D(GraphicsDeviceConfiguration deviceConfig, EngineFactory engineFactory, EngineDevice engineDevice)
        {
            try
            {
                // Simulate exception if requested
                if (deviceConfig.CoreConfiguration.ThrowD2DInitDeviceError)
                {
                    throw new SeeingSharpGraphicsException("Simulation Direct2D device init exception");
                }

                using (var dxgiDevice = engineDevice.DeviceD3D11_1.QueryInterface <IDXGIDevice>())
                {
                    _deviceD2D        = engineFactory.FactoryD2D_2.CreateDevice(dxgiDevice);
                    _deviceContextD2D = _deviceD2D
                                        .CreateDeviceContext(D2D.DeviceContextOptions.None);
                    _renderTarget = _deviceContextD2D;
                }
            }
            catch (Exception)
            {
                SeeingSharpUtil.SafeDispose(ref _deviceContextD2D);
                SeeingSharpUtil.SafeDispose(ref _deviceD2D);
                SeeingSharpUtil.SafeDispose(ref _renderTarget);
            }
        }
예제 #2
0
 public void EditDeviceConfiguration(EngineAdapterInfo adapterInfo, GraphicsDeviceConfiguration deviceConfig)
 {
 }
예제 #3
0
 public void EditDeviceConfiguration(EngineAdapterInfo adapterInfo, GraphicsDeviceConfiguration deviceConfig)
 {
     _manipulateDeviceConfig?.Invoke(adapterInfo, deviceConfig);
 }
예제 #4
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;
        }