Пример #1
0
        /// <summary>
        /// Initialization, invoke in change directx device or surface size
        /// </summary>
        /// <param name="target"></param>
        public void SetRenderTargetDX11(Texture2D target)
        {
            if (this.renderTarget != null)
            {
                renderTarget.Dispose();
                renderTarget = null;
                base.Lock();
                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
                base.Unlock();
            }
            IsInitilized = target != null;
            if (target == null)
            {
                return;
            }

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

            var format = TranslateFormat(target);

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

            var handle = GetSharedHandle(target);

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

            try {
                this.renderTarget = new SharpDX.Direct3D9.Texture(device,
                                                                  target.Description.Width, target.Description.Height, 1,
                                                                  SharpDX.Direct3D9.Usage.RenderTarget, format,
                                                                  SharpDX.Direct3D9.Pool.Default, ref handle);

                using (var surface = this.renderTarget.GetSurfaceLevel(0)) {
                    base.Lock();
#if NET40
                    base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
#else
                    // "enableSoftwareFallback = true" makes Remote Desktop possible.
                    // See: http://msdn.microsoft.com/en-us/library/hh140978%28v=vs.110%29.aspx
                    base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer, true);
#endif
                    base.Unlock();
                }
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
            }
        }
Пример #2
0
        /// <summary>
        /// If we didn't do this, D3DImage would keep an reference to the backbuffer that causes the device reset below to fail.
        /// </summary>
        private void RemoveBackBufferReference()
        {
            if (_renderTarget != null)
            {
                _renderTarget.Dispose();
                _renderTarget = null;
            }

            if (_renderTargetD3D9 != null)
            {
                _renderTargetD3D9.Dispose();
                _renderTargetD3D9 = null;
            }

            _d3dImage.Lock();
            _d3dImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
            _d3dImage.Unlock();
        }
Пример #3
0
 /// <summary>
 /// dispose the texture.
 /// </summary>
 public void Dispose()
 {
     if (sprite != null)
     {
         sprite.Dispose();
     }
     if (texture != null)
     {
         texture.Dispose();
     }
 }
Пример #4
0
        /// <summary>
        /// Dispose the layer.
        /// </summary>
        public void Dispose()
        {
            if (surface != null)
            {
                surface.Dispose();
                surface = null;
            }

            if (texture != null)
            {
                texture.Dispose();
                texture = null;
            }
        }
 private void Dispose(bool disposing)
 {
     if (IsDisposed)
     {
         return;
     }
     _viewModel?.Dispose();
     _renderTarget?.Dispose();
     _renderTargetD3D9?.Dispose();
     _instanceCount--;
     if (_instanceCount <= 0)
     {
         _graphicsDeviceService?.Dispose();
     }
     IsDisposed = true;
 }
 private void ResetBackBufferReference()
 {
     if (DesignerProperties.GetIsInDesignMode(this))
     {
         return;
     }
     if (_renderTarget != null)
     {
         _renderTarget.Dispose();
         _renderTarget = null;
     }
     if (_renderTargetD3D9 != null)
     {
         _renderTargetD3D9.Dispose();
         _renderTargetD3D9 = null;
     }
     _direct3DImage.Lock();
     _direct3DImage.SetBackBuffer(D3DResourceType.IDirect3DSurface9, IntPtr.Zero);
     _direct3DImage.Unlock();
 }
Пример #7
0
 /// <summary>
 /// Dispose the polygon
 /// </summary>
 public void Dispose()
 {
     if (line != null)
     {
         line.Dispose();
         line = null;
     }
     if (fillerLine != null)
     {
         fillerLine.Dispose();
         fillerLine = null;
     }
     if (sprite != null)
     {
         sprite.Dispose();
         sprite = null;
     }
     if (tex != null)
     {
         tex.Dispose();
         tex = null;
     }
 }