Ejemplo n.º 1
0
 protected override SharpDX.DXGI.SwapChain2 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc)
 {
     // Creates a SwapChain from a CoreWindow pointer
     using (var comWindow = new ComObject(window))
     using (var swapChain1 = new SwapChain1(factory, device, comWindow, ref desc))
         return swapChain1.QueryInterface<SwapChain2>();
 }
Ejemplo n.º 2
0
        private void CreateSwapChain(IntPtr window, bool vsync)
        {
            using (SharpDX.DXGI.Factory4 factory = new Factory4())
            {
                //SharpDX.DXGI.Adapter adapter = factory.GetAdapterByLuid(_dev.AdapterLuid);
                //System.Console.WriteLine($"  Adapter: {adapter.Description.Description}");
                System.Console.WriteLine($"  Adapter: {factory.Adapters[0].Description.Description}");

                if (!vsync)
                {
                    using (SharpDX.DXGI.Factory5 factory5 = factory.QueryInterface <Factory5>())
                    {
                        if (factory5 != null)
                        {
                            SharpDX.Mathematics.Interop.RawBool tearing = false;
                            GCHandle pinnedInt = GCHandle.Alloc(tearing, GCHandleType.Pinned);
                            IntPtr   pointer   = pinnedInt.AddrOfPinnedObject();

                            factory5.CheckFeatureSupport(SharpDX.DXGI.Feature.PresentAllowTearing, pointer, System.Runtime.InteropServices.Marshal.SizeOf(tearing));
                            if (tearing != false)
                            {
                                _swapChainFlags = SharpDX.DXGI.SwapChainFlags.AllowTearing;
                                _presentFlags   = SharpDX.DXGI.PresentFlags.AllowTearing;
                            }

                            pinnedInt.Free();
                        }
                    }

                    _syncInterval = 0;
                }
                else
                {
                    _syncInterval = 1;
                }

                SharpDX.DXGI.SwapChainDescription1 desc = new SharpDX.DXGI.SwapChainDescription1();
                desc.Width             = 0;
                desc.Height            = 0;
                desc.Format            = SharpDX.DXGI.Format.R8G8B8A8_UNorm;
                desc.Stereo            = false;
                desc.SampleDescription = new SampleDescription {
                    Count = 1, Quality = 0
                };
                desc.Usage       = SharpDX.DXGI.Usage.RenderTargetOutput;
                desc.BufferCount = FrameCount;
                desc.Scaling     = SharpDX.DXGI.Scaling.Stretch;
                desc.SwapEffect  = SharpDX.DXGI.SwapEffect.FlipDiscard;
                desc.AlphaMode   = SharpDX.DXGI.AlphaMode.Unspecified;
                desc.Flags       = _swapChainFlags;

                using (SharpDX.DXGI.SwapChain1 swapChain = new SharpDX.DXGI.SwapChain1(factory, _queue, window, ref desc))
                {
                    factory.MakeWindowAssociation(window, WindowAssociationFlags.IgnoreAltEnter);
                    _swapChain = swapChain.QueryInterface <SharpDX.DXGI.SwapChain3>();
                }
            }
        }
Ejemplo n.º 3
0
        private void InitializeD3D()
        {
            using (D3D11.Device defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.Debug))
                this.device = defaultDevice.QueryInterface <D3D11.Device2>();
            this.deviceContext = this.device.ImmediateContext2;

            DXGI.SwapChainDescription1 swapChainDescription = new DXGI.SwapChainDescription1()
            {
                AlphaMode         = DXGI.AlphaMode.Ignore,
                BufferCount       = 2,
                Format            = DXGI.Format.R8G8B8A8_UNorm,
                Height            = (int)(this.swapChainPanel.RenderSize.Height),
                Width             = (int)(this.swapChainPanel.RenderSize.Width),
                SampleDescription = new DXGI.SampleDescription(1, 0),
                Scaling           = SharpDX.DXGI.Scaling.Stretch,
                Stereo            = false,
                SwapEffect        = DXGI.SwapEffect.FlipSequential,
                Usage             = DXGI.Usage.RenderTargetOutput
            };

            using (DXGI.Device3 dxgiDevice3 = this.device.QueryInterface <DXGI.Device3>())
                using (DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent <DXGI.Factory3>())
                {
                    DXGI.SwapChain1 swapChain1 = new DXGI.SwapChain1(dxgiFactory3, this.device, ref swapChainDescription);
                    this.swapChain = swapChain1.QueryInterface <DXGI.SwapChain2>();
                }

            using (DXGI.ISwapChainPanelNative nativeObject = ComObject.As <DXGI.ISwapChainPanelNative>(this.swapChainPanel))
                nativeObject.SwapChain = this.swapChain;

            this.backBufferTexture = this.swapChain.GetBackBuffer <D3D11.Texture2D>(0);
            this.backBufferView    = new D3D11.RenderTargetView(this.device, this.backBufferTexture);

            deviceContext.Rasterizer.SetViewport(0, 0, (int)swapChainPanel.ActualWidth, (int)swapChainPanel.ActualHeight);

            CompositionTarget.Rendering    += CompositionTarget_Rendering;
            Application.Current.Suspending += Current_Suspending;

            isDXInitialized = true;
        }
Ejemplo n.º 4
0
        private void SwapChainPanel_OnLoaded(object sender, RoutedEventArgs e)
        {
            using (var defDevice = new D3D.Device(DriverType.Hardware, D3D.DeviceCreationFlags.Debug))
            {
                _device = defDevice.QueryInterface <D3D.Device3>();
            }
            _context = _device.ImmediateContext3;

            var pixelScale    = DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;
            var swapChainDesc = new DXGI.SwapChainDescription1()
            {
                AlphaMode         = DXGI.AlphaMode.Premultiplied,
                BufferCount       = 2,
                Flags             = DXGI.SwapChainFlags.None,
                Format            = DXGI.Format.B8G8R8A8_UNorm,
                Width             = (int)(panel.RenderSize.Width * pixelScale),
                Height            = (int)(panel.RenderSize.Height * pixelScale),
                SampleDescription = new DXGI.SampleDescription(1, 0),
                Scaling           = DXGI.Scaling.Stretch,
                Stereo            = false,
                SwapEffect        = DXGI.SwapEffect.FlipSequential,
                Usage             = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput
            };

            using (var dxgiDevice = _device.QueryInterface <DXGI.Device3>())
            {
                var factory = dxgiDevice.Adapter.GetParent <DXGI.Factory4>();
                using (var tmpSwapChain = new DXGI.SwapChain1(factory, _device, ref swapChainDesc))
                {
                    _swapChain = tmpSwapChain.QueryInterface <DXGI.SwapChain3>();
                }
            }

            using (var nativeObject = ComObject.As <DXGI.ISwapChainPanelNative>(panel))
            {
                nativeObject.SwapChain = _swapChain;
            }

            using (var depthBuffer = new D3D.Texture2D(_device, new D3D.Texture2DDescription()
            {
                Format = DXGI.Format.D24_UNorm_S8_UInt,
                ArraySize = 1,
                MipLevels = 1,
                Width = swapChainDesc.Width,
                Height = swapChainDesc.Height,
                SampleDescription = new DXGI.SampleDescription(1, 0),
                BindFlags = D3D.BindFlags.DepthStencil,
            }))
            {
                _depthStencilView = new D3D.DepthStencilView(_device, depthBuffer, new D3D.DepthStencilViewDescription()
                {
                    Dimension = D3D.DepthStencilViewDimension.Texture2D
                });
            }

            _backBuffer = D3D.Resource.FromSwapChain <D3D.Texture2D>(_swapChain, 0);
            _renderView = new D3D.RenderTargetView1(_device, _backBuffer);

            var viewport = new ViewportF(0, 0, (float)panel.RenderSize.Width, (float)panel.RenderSize.Height, 0.0f, 1.0f);

            _context.Rasterizer.SetViewport(viewport);

            ShaderBytecode shaderBytecode;

            using (shaderBytecode = ShaderBytecode.CompileFromFile("shaders.hlsl", "vs", "vs_5_0", ShaderFlags.Debug))
            {
                _vertexShader = new D3D.VertexShader(_device, shaderBytecode);
            }

            using (var byteCode = ShaderBytecode.CompileFromFile(@"shaders.hlsl", "ps", "ps_5_0", ShaderFlags.Debug))
            {
                _pixelShader = new D3D.PixelShader(_device, byteCode);
            }

            D3D.InputElement[] inputElements =
            {
                new D3D.InputElement("POSITION", 0, DXGI.Format.R32G32B32A32_Float, 0, 0),
            };
            _inputLayout = new D3D.InputLayout(_device, shaderBytecode, inputElements);

            _vertices = new[]
            {
                new Vector4(-0.5f, 0.0f, 0.5f, 1.0f),
                new Vector4(0.0f, 0.5f, 0.5f, 1.0f),
                new Vector4(0.5f, 0.0f, 0.5f, 1.0f),
            };
            _vertexBuffer  = D3D.Buffer.Create(_device, D3D.BindFlags.VertexBuffer, _vertices);
            _vertexBinding = new D3D.VertexBufferBinding(_vertexBuffer, Utilities.SizeOf <Vector4>(), 0);

            _constantBuffer = new SharpDX.Direct3D11.Buffer(
                _device,
                Utilities.SizeOf <SharpDX.Matrix>(),
                D3D.ResourceUsage.Default,
                D3D.BindFlags.ConstantBuffer,
                D3D.CpuAccessFlags.None,
                D3D.ResourceOptionFlags.None,
                0);

            _timer = new Stopwatch();
            _timer.Start();

            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }
Ejemplo n.º 5
0
        protected override SharpDX.DXGI.SwapChain2 CreateSwapChain(SharpDX.DXGI.Factory2 factory, SharpDX.Direct3D11.Device1 device, SharpDX.DXGI.SwapChainDescription1 desc)
        {
            // Creates the swap chain for XAML composition
            using (var swapChain1 = new SwapChain1(factory, device, ref desc))
            {
                var swapChain2 = swapChain1.QueryInterface<SwapChain2>();

                // Associate the SwapChainPanel with the swap chain
                nativePanel.SwapChain = swapChain2;

                // Returns the new swap chain
                return swapChain2;
            }
        }
Ejemplo n.º 6
0
        public VideoRenderer(VideoTrack videoTrack, RendererOptions options)
        {
            VideoTrack = videoTrack;

            VideoFrameWidth     = options.VideoFrameWidth;
            VideoFrameHeight    = options.VideoFrameHeight;
            VideoFrameQueueSize = options.VideoFrameQueueSize;

            videoTrack.LocalVideoFrameProcessed += OnLocalVideoFrameProcessed;

            // _onMissedFrame = options.OnMissedFrame ?? OnMissedFrame;

            bool debug = options.CreationFlags.HasFlag(D3D11.DeviceCreationFlags.Debug);

            FactoryDXGI = new DXGI.Factory2(debug);

            // Find the requested adapter.
            using (var adapters = FactoryDXGI.Adapters.ToDisposableList())
            {
                var adapter = adapters.First(a => a.Description.VendorId == options.AdapterVendorId);

                Device3D = new D3D11.Device(adapter, options.CreationFlags, options.FeatureLevels);

                DeviceDXGI = Device3D.QueryInterface <DXGI.Device>();

                // We need to access D3D11 on multiple threads, so enable multi-threading
                ThreadLock3D = Device3D.ImmediateContext.QueryInterface <D3D11.Multithread>();
                ThreadLock3D.SetMultithreadProtected(true);

                if (options.PreviewWindowOptions != null)
                {
                    var width  = options.PreviewWindowOptions.Width ?? VideoFrameWidth;
                    var height = options.PreviewWindowOptions.Height ?? width * VideoFrameHeight / VideoFrameWidth;

                    _sdlWindow = new SdlWindow("WebRTC server preview", width, height);


                    // SwapChain description
                    var desc = new DXGI.SwapChainDescription1()
                    {
                        BufferCount       = 2,
                        AlphaMode         = DXGI.AlphaMode.Unspecified,
                        Format            = DXGI.Format.B8G8R8A8_UNorm,
                        Width             = VideoFrameWidth,
                        Height            = VideoFrameHeight,
                        Scaling           = DXGI.Scaling.Stretch,
                        Stereo            = false,
                        Flags             = DXGI.SwapChainFlags.AllowTearing | DXGI.SwapChainFlags.FrameLatencyWaitAbleObject,
                        Usage             = DXGI.Usage.RenderTargetOutput,
                        SampleDescription = new DXGI.SampleDescription(1, 0),
                        SwapEffect        = DXGI.SwapEffect.FlipDiscard,
                    };

                    SwapChain = new DXGI.SwapChain1(FactoryDXGI, Device3D, _sdlWindow.NativeHandle, ref desc);

                    using (var swapChain2 = SwapChain.QueryInterface <DXGI.SwapChain2>())
                    {
                        var value = swapChain2.MaximumFrameLatency;
                        swapChain2.MaximumFrameLatency = 1;
                    }
                }
            }
        }
Ejemplo n.º 7
0
        private void SwapChainPanel_Loaded(object sender, RoutedEventArgs e)
        {
            var v = ApplicationView.GetForCurrentView();

            v.FullScreenSystemOverlayMode = FullScreenSystemOverlayMode.Minimal;
            v.TryEnterFullScreenMode();
#if DEBUG
            var debugLevel = D3D11.DeviceCreationFlags.Debug | D3D11.DeviceCreationFlags.BgraSupport;
#else
            var debugLevel = D3D11.DeviceCreationFlags.None | D3D11.DeviceCreationFlags.BgraSupport;
#endif
            using (D3D11.Device defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, debugLevel))
            {
                this.device = defaultDevice.QueryInterface <D3D11.Device2>();
            }
            this.deviceContext = this.device.ImmediateContext2;
            float pixelScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;

            DXGI.SwapChainDescription1 swapChainDescription = new DXGI.SwapChainDescription1()
            {
                AlphaMode         = DXGI.AlphaMode.Premultiplied,
                BufferCount       = 2,
                Format            = DXGI.Format.B8G8R8A8_UNorm,
                Height            = (int)(this.SwapChainPanel.RenderSize.Height * pixelScale),
                Width             = (int)(this.SwapChainPanel.RenderSize.Width * pixelScale),
                SampleDescription = new DXGI.SampleDescription(1, 0),
                Scaling           = DXGI.Scaling.Stretch,
                Stereo            = false,
                SwapEffect        = DXGI.SwapEffect.FlipSequential,
                Usage             = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput,
            };
            using (DXGI.Device3 dxgiDevice3 = this.device.QueryInterface <DXGI.Device3>())
            {
                using (DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent <DXGI.Factory3>())
                {
                    using (DXGI.SwapChain1 swapChain1 = new DXGI.SwapChain1(dxgiFactory3, this.device, ref swapChainDescription))
                    {
                        this.swapChain = swapChain1.QueryInterface <DXGI.SwapChain2>();
                    }
                }
            }
            using (DXGI.ISwapChainPanelNative nativeObject = ComObject.As <DXGI.ISwapChainPanelNative>(this.SwapChainPanel))
            {
                nativeObject.SwapChain = this.swapChain;
            }
            this.backBufferTexture = D3D11.Texture2D.FromSwapChain <D3D11.Texture2D>(this.swapChain, 0);
            this.backBufferView    = new D3D11.RenderTargetView(this.device, this.backBufferTexture);
            isDXInitialized        = true;
            tw = new TextWirter(device, swapChain, Color.Black, DisplayInformation.GetForCurrentView().LogicalDpi);
//            #region D2D

//#if DEBUG
//            var debug = SharpDX.Direct2D1.DebugLevel.Error;
//#else
//            var debug = SharpDX.Direct2D1.DebugLevel.None;
//#endif

//            d2dFactory = new SharpDX.Direct2D1.Factory1(SharpDX.Direct2D1.FactoryType.SingleThreaded, debug);
//            using (var dxgiDevice = device.QueryInterface<SharpDX.DXGI.Device>())
//            {
//                d2dDevice = new SharpDX.Direct2D1.Device(d2dFactory, dxgiDevice);
//            }
//            d2dContext = new SharpDX.Direct2D1.DeviceContext(d2dDevice, SharpDX.Direct2D1.DeviceContextOptions.None);

//            BitmapProperties1 properties = new BitmapProperties1(
//                new PixelFormat(
//                    SharpDX.DXGI.Format.B8G8R8A8_UNorm,
//                    SharpDX.Direct2D1.AlphaMode.Premultiplied),
//                DisplayInformation.GetForCurrentView().LogicalDpi,
//                DisplayInformation.GetForCurrentView().LogicalDpi,
//                BitmapOptions.Target | BitmapOptions.CannotDraw);
//            DXGI.Surface backBuffer = swapChain.GetBackBuffer<DXGI.Surface>(0);
//            d2dTarget = new Bitmap1(d2dContext, backBuffer, properties);
//            SharpDX.DirectWrite.Factory fontFactory = new SharpDX.DirectWrite.Factory();
//            textFormat = new TextFormat(fontFactory, "Segoe UI", 24.0f);
//            textLayout1 = new TextLayout(fontFactory, "This is an example of a moving TextLayout object with snapped pixel boundaries.", textFormat, 400.0f, 200.0f);
//            textLayout2 = new TextLayout(fontFactory, "This is an example of a moving TextLayout object with no snapped pixel boundaries.", textFormat, 400.0f, 200.0f);
//            layoutY = 0.0f;
//            backgroundBrush = new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.White);
//            textBrush = new SharpDX.Direct2D1.SolidColorBrush(d2dContext, Color.Black);
//            #endregion

            CompositionTarget.Rendering    += CompositionTarget_Rendering;
            Application.Current.Suspending += Application_Suspending;
        }
Ejemplo n.º 8
0
        private void SwapChainPanel_Loaded(object sender, RoutedEventArgs e)
        {
            // Create a new Direct3D hardware device and ask for Direct3D 11.2 support
            using (D3D11.Device defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.Debug))
            {
                this.device = defaultDevice.QueryInterface <D3D11.Device2>();
            }

            // Save the context instance
            this.deviceContext = this.device.ImmediateContext2;

            Size2 sizeInPixels = RenderSizeToPixelSize(this.SwapChainPanel.RenderSize);

            // Properties of the swap chain
            DXGI.SwapChainDescription1 swapChainDescription = new DXGI.SwapChainDescription1()
            {
                // No transparency.
                AlphaMode = DXGI.AlphaMode.Ignore,
                // Double buffer.
                BufferCount = 2,
                // BGRA 32bit pixel format.
                Format = DXGI.Format.B8G8R8A8_UNorm,
                // Unlike in CoreWindow swap chains, the dimensions must be set.
                Height = sizeInPixels.Height,
                Width  = sizeInPixels.Width,
                // Default multisampling.
                SampleDescription = new DXGI.SampleDescription(1, 0),
                // In case the control is resized, stretch the swap chain accordingly.
                Scaling = DXGI.Scaling.Stretch,
                // No support for stereo display.
                Stereo = false,
                // Sequential displaying for double buffering.
                SwapEffect = DXGI.SwapEffect.FlipSequential,
                // This swapchain is going to be used as the back buffer.
                Usage = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput,
            };

            // Retrive the DXGI device associated to the Direct3D device.
            using (DXGI.Device3 dxgiDevice3 = this.device.QueryInterface <DXGI.Device3>())
            {
                // Get the DXGI factory automatically created when initializing the Direct3D device.
                using (DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent <DXGI.Factory3>())
                {
                    // Create the swap chain and get the highest version available.
                    using (DXGI.SwapChain1 swapChain1 = new DXGI.SwapChain1(dxgiFactory3, this.device, ref swapChainDescription))
                    {
                        this.swapChain = swapChain1.QueryInterface <DXGI.SwapChain2>();
                    }
                }
            }

            // Obtain a reference to the native COM object of the SwapChainPanel.
            using (DXGI.ISwapChainPanelNative nativeObject = ComObject.As <DXGI.ISwapChainPanelNative>(this.SwapChainPanel))
            {
                // Set its swap chain.
                nativeObject.SwapChain = this.swapChain;
            }

            // Create a Texture2D from the existing swap chain to use as
            this.backBufferTexture = D3D11.Texture2D.FromSwapChain <D3D11.Texture2D>(this.swapChain, 0);
            this.backBufferView    = new D3D11.RenderTargetView(this.device, this.backBufferTexture);

            // This event is fired when the application requests a new frame from the DirectX interop controls.
            CompositionTarget.Rendering += CompositionTarget_Rendering;

            // Subscribe to the suspending event
            Application.Current.Suspending += Application_Suspending;

            // Mark our resources as initialized
            isDXInitialized = true;
        }
Ejemplo n.º 9
0
 private void CreateSwapChain(ref SwapChainDescription1 swapChainDescription1, Factory4 factory)
 {
     using (var sc1 = new SwapChain1(factory, commandQueue, form.Handle, ref swapChainDescription1))
         swapChain = Collect(sc1.QueryInterface<SwapChain3>());
 }
Ejemplo n.º 10
0
 private void CreateSwapChain(ref SwapChainDescription1 swapChainDescription1, Factory4 factory)
 {
     using (var sc1 = new SwapChain1(factory, commandQueue, ref swapChainDescription1))
     {
         swapChain = Collect(sc1.QueryInterface<SwapChain3>());
         using (var comPtr = new ComObject(panel))
         {
             using (var native = comPtr.QueryInterface<ISwapChainPanelNative>())
             {
                 native.SwapChain = swapChain;
             }
         }
     }
 }
Ejemplo n.º 11
0
        private void SwapChainPanel_Loaded(object sender, RoutedEventArgs e)
        {
            // Create a new Direct3D hardware device and ask for Direct3D 11.2 support
            using (D3D11.Device defaultDevice = new D3D11.Device(D3D.DriverType.Hardware, D3D11.DeviceCreationFlags.Debug))
            {
                this.device = defaultDevice.QueryInterface<D3D11.Device2>();
            }

            // Save the context instance
            this.deviceContext = this.device.ImmediateContext2;

            // We have to take into account pixel scaling; Windows Phone 8.1 uses virtual resolutions smaller than the physical screen size.
            float pixelScale = Windows.Graphics.Display.DisplayInformation.GetForCurrentView().LogicalDpi / 96.0f;

            // Properties of the swap chain
            DXGI.SwapChainDescription1 swapChainDescription = new DXGI.SwapChainDescription1()
            {
                // No transparency.
                AlphaMode = DXGI.AlphaMode.Ignore,
                // Double buffer.
                BufferCount = 2,
                // BGRA 32bit pixel format.
                Format = DXGI.Format.B8G8R8A8_UNorm,
                // Unlike in CoreWindow swap chains, the dimensions must be set.
                Height = (int)(this.SwapChainPanel.RenderSize.Height * pixelScale),
                Width = (int)(this.SwapChainPanel.RenderSize.Width * pixelScale),
                // Default multisampling.
                SampleDescription = new DXGI.SampleDescription(1, 0),
                // In case the control is resized, stretch the swap chain accordingly.
                Scaling = DXGI.Scaling.Stretch,
                // No support for stereo display.
                Stereo = false,
                // Sequential displaying for double buffering.
                SwapEffect = DXGI.SwapEffect.FlipSequential,
                // This swapchain is going to be used as the back buffer.
                Usage = DXGI.Usage.BackBuffer | DXGI.Usage.RenderTargetOutput,
            };

            // Retrive the DXGI device associated to the Direct3D device.
            using (DXGI.Device3 dxgiDevice3 = this.device.QueryInterface<DXGI.Device3>())
            {
                // Get the DXGI factory automatically created when initializing the Direct3D device.
                using (DXGI.Factory3 dxgiFactory3 = dxgiDevice3.Adapter.GetParent<DXGI.Factory3>())
                {
                    // Create the swap chain and get the highest version available.
                    using (DXGI.SwapChain1 swapChain1 = new DXGI.SwapChain1(dxgiFactory3, this.device, ref swapChainDescription))
                    {
                        this.swapChain = swapChain1.QueryInterface<DXGI.SwapChain2>();
                    }
                }
            }

            // Obtain a reference to the native COM object of the SwapChainPanel.
            using (DXGI.ISwapChainPanelNative nativeObject = ComObject.As<DXGI.ISwapChainPanelNative>(this.SwapChainPanel))
            {
                // Set its swap chain.
                nativeObject.SwapChain = this.swapChain;
            }

            // Create a Texture2D from the existing swap chain to use as 
            this.backBufferTexture = D3D11.Texture2D.FromSwapChain<D3D11.Texture2D>(this.swapChain, 0);
            this.backBufferView = new D3D11.RenderTargetView(this.device, this.backBufferTexture);

            // This event is fired when the application requests a new frame from the DirectX interop controls.
            CompositionTarget.Rendering += CompositionTarget_Rendering;
        }