Exemplo n.º 1
0
        public void SetRenderTargetDX11(SharpDX.Direct3D11.Texture2D renderTarget)
        {
            if (this.RenderTarget != null)
            {
                this.RenderTarget = null;

                base.Lock();
                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                base.Unlock();
            }

            if (renderTarget == null)
            {
                return;
            }

            if (!IsShareable(renderTarget))
            {
                throw new ArgumentException("Texture must be created with ResourceOptionFlags.Shared");
            }

            Format format = DX11ImageSource.TranslateFormat(renderTarget);

            if (format == Format.Unknown)
            {
                throw new ArgumentException("Texture format is not compatible with OpenSharedResource");
            }

            IntPtr handle = GetSharedHandle(renderTarget);

            if (handle == IntPtr.Zero)
            {
                throw new ArgumentNullException("Handle");
            }

            this.RenderTarget = new Texture(DX11ImageSource.D3DDevice, renderTarget.Description.Width, renderTarget.Description.Height, 1, Usage.RenderTarget, format, Pool.Default, ref handle);
            using (Surface surface = this.RenderTarget.GetSurfaceLevel(0))
            {
                base.Lock();

                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
                base.Unlock();
            }
        }
Exemplo n.º 2
0
        private void StartD3D()
        {
            //this.Device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.VideoSupport | DeviceCreationFlags.Debug, FeatureLevel.Level_11_0);
            this.Device = new Device(DriverType.Hardware, DeviceCreationFlags.BgraSupport | DeviceCreationFlags.VideoSupport, FeatureLevel.Level_10_0);

            this.dxdevice = Device.QueryInterface <SharpDX.DXGI.Device1>();
            //MessageBox.Show(dxdevice.Adapter.Description.Description);

            dxdevice.Disposing += (e, s) =>
            {
                Console.WriteLine("DISPOSING WPF D3D");
            };

            this.D3DSurface = new DX11ImageSource();
            this.D3DSurface.IsFrontBufferAvailableChanged += OnIsFrontBufferAvailableChanged;

            this.CreateAndBindTargets();

            this.Source = this.D3DSurface;
        }