예제 #1
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize(int adapterIndex)
        {
            Log(LogLevel.Information, $"Adapter Index = {adapterIndex}");
            var adapter = GetAdapter(ref adapterIndex);

            AdapterIndex = adapterIndex;
#if DX11
            if (adapter != null)
            {
                if (adapter.Description.VendorId == 0x1414 && adapter.Description.DeviceId == 0x8c)
                {
                    DriverType = DriverType.Warp;
                    device     = new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_0);
                }
                else
                {
                    DriverType = DriverType.Hardware;
#if DEBUGMEMORY
                    device = new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
#else
                    device = new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport);
#if DX11_1
                    device1 = device.QueryInterface <global::SharpDX.Direct3D11.Device1>();
#endif
#endif
                    // DeviceCreationFlags.Debug should not be used in productive mode!
                    // See: http://sharpdx.org/forum/4-general/1774-how-to-debug-a-sharpdxexception
                    // See: http://stackoverflow.com/questions/19810462/launching-sharpdx-directx-app-with-devicecreationflags-debug
                }
            }
#else
            device = new global::SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_1);
#endif
            Log(LogLevel.Information, $"Direct3D device initilized. DriverType: {DriverType}; FeatureLevel: {device.FeatureLevel}");

            #region Initial Internal Pools
            Log(LogLevel.Information, "Initializing resource pools");
            RemoveAndDispose(ref constantBufferPool);
            constantBufferPool = Collect(new ConstantBufferPool(Device, Logger));

            RemoveAndDispose(ref shaderPoolManager);
            shaderPoolManager = Collect(new ShaderPoolManager(Device, constantBufferPool, Logger));

            RemoveAndDispose(ref statePoolManager);
            statePoolManager = Collect(new StatePoolManager(Device));

            RemoveAndDispose(ref geometryBufferManager);
            geometryBufferManager = Collect(new GeometryBufferManager(this));

            RemoveAndDispose(ref materialTextureManager);
            materialTextureManager = Collect(new TextureResourceManager(Device));

            RemoveAndDispose(ref materialVariableManager);
            materialVariableManager = Collect(new MaterialVariablePool(this));

            RemoveAndDispose(ref deviceContextPool);
            deviceContextPool = Collect(new DeviceContextPool(Device));
            #endregion
            Log(LogLevel.Information, "Initializing Direct2D resources");
            factory2D          = Collect(new global::SharpDX.Direct2D1.Factory1(global::SharpDX.Direct2D1.FactoryType.MultiThreaded));
            wicImgFactory      = Collect(new global::SharpDX.WIC.ImagingFactory());
            directWriteFactory = Collect(new global::SharpDX.DirectWrite.Factory(global::SharpDX.DirectWrite.FactoryType.Shared));
            using (var dxgiDevice2 = device.QueryInterface <global::SharpDX.DXGI.Device>())
            {
                device2D        = Collect(new global::SharpDX.Direct2D1.Device(factory2D, dxgiDevice2));
                deviceContext2D = Collect(new global::SharpDX.Direct2D1.DeviceContext(device2D, global::SharpDX.Direct2D1.DeviceContextOptions.EnableMultithreadedOptimizations));
            }
            Initialized = true;
        }
예제 #2
0
        /// <summary>
        /// Initializes this instance.
        /// </summary>
        private void Initialize(int adapterIndex)
        {
            logger.LogInformation("Adapter Index = {}", adapterIndex);
            var adapter = GetAdapter(ref adapterIndex);

            AdapterIndex = adapterIndex;
            if (AdapterIndex < 0 || adapter == null)
            {
                throw new PlatformNotSupportedException("Graphic adapter does not meet minimum requirement, must support DirectX 10 or above.");
            }
#if DX11
            if (adapter != null)
            {
                DriverType = EnableSoftwareRendering ? DriverType.Warp : DriverType.Hardware;
                if (adapter.Description.VendorId == 0x1414 && adapter.Description.DeviceId == 0x8c)
                {
                    DriverType = DriverType.Warp;
                    device     = EnableSoftwareRendering ?
                                 new global::SharpDX.Direct3D11.Device(DriverType, DeviceCreationFlags.BgraSupport)
                        : new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport);
                }
                else
                {
                    if (DriverType == DriverType.Warp)
                    {
#if DEBUGMEMORY
                        device = new global::SharpDX.Direct3D11.Device(DriverType, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
#else
                        device = new global::SharpDX.Direct3D11.Device(DriverType, DeviceCreationFlags.BgraSupport);
#endif
                    }
                    else
                    {
#if DEBUGMEMORY
                        device = new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.Debug);
#else
                        device = new global::SharpDX.Direct3D11.Device(adapter, DeviceCreationFlags.BgraSupport);
#endif
                        // DeviceCreationFlags.Debug should not be used in productive mode!
                        // See: http://sharpdx.org/forum/4-general/1774-how-to-debug-a-sharpdxexception
                        // See: http://stackoverflow.com/questions/19810462/launching-sharpdx-directx-app-with-devicecreationflags-debug
                    }
                }

#if DX11_1
                device1 = device.QueryInterface <global::SharpDX.Direct3D11.Device1>();
#endif
            }
#else
            device = new global::SharpDX.Direct3D11.Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport, FeatureLevel.Level_10_1);
#endif
            logger.LogInformation("Direct3D device initilized. DriverType: {}; FeatureLevel: {}", DriverType, device.FeatureLevel);

            #region Initial Internal Pools
            logger.LogInformation("Initializing resource pools");
            RemoveAndDispose(ref constantBufferPool);
            constantBufferPool = new ConstantBufferPool(Device);

            RemoveAndDispose(ref shaderPoolManager);
            shaderPoolManager = new ShaderPoolManager(Device, constantBufferPool);

            RemoveAndDispose(ref statePoolManager);
            statePoolManager = new StatePoolManager(Device);

            RemoveAndDispose(ref geometryBufferManager);
            geometryBufferManager = new GeometryBufferManager(this);

            RemoveAndDispose(ref materialTextureManager);
            materialTextureManager = new TextureResourceManager(Device);

            RemoveAndDispose(ref materialVariableManager);
            materialVariableManager = new MaterialVariablePool(this);

            RemoveAndDispose(ref deviceContextPool);
            deviceContextPool = new DeviceContextPool(Device);

            RemoveAndDispose(ref structArrayPool);
            structArrayPool = new StructArrayPool();
            #endregion
            logger.LogInformation("Initializing Direct2D resources");
            factory2D          = new global::SharpDX.Direct2D1.Factory1(global::SharpDX.Direct2D1.FactoryType.MultiThreaded);
            wicImgFactory      = new global::SharpDX.WIC.ImagingFactory();
            directWriteFactory = new global::SharpDX.DirectWrite.Factory(global::SharpDX.DirectWrite.FactoryType.Shared);
            using (var dxgiDevice2 = device.QueryInterface <global::SharpDX.DXGI.Device>())
            {
                device2D        = new global::SharpDX.Direct2D1.Device(factory2D, dxgiDevice2);
                deviceContext2D = new global::SharpDX.Direct2D1.DeviceContext(device2D,
                                                                              global::SharpDX.Direct2D1.DeviceContextOptions.EnableMultithreadedOptimizations);
            }
            Initialized = true;
        }