/// <summary>
        /// Sets the render target of this D3DImage object.
        /// </summary>
        /// <param name="renderTarget">The render target to set.</param>
        public void SetRenderTarget(D3D11.Texture2D renderTarget)
        {
            if (this.m_d3dRenderTarget != null)
            {
                this.m_d3dRenderTarget = 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");
            }

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

            IntPtr handle = GetSharedHandle(renderTarget);

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

            //Map the texture to the D3DImage base class
            bool  tDisposed = renderTarget.IsDisposed;
            float tWidth    = renderTarget.Description.Width;
            float tHeight   = renderTarget.Description.Height;

            this.m_d3dRenderTarget = new D3D9.Texture(
                m_d3dDevice,
                renderTarget.Description.Width,
                renderTarget.Description.Height,
                1, D3D9.Usage.RenderTarget, format, D3D9.Pool.Default, ref handle);
            using (D3D9.Surface surface = this.m_d3dRenderTarget.GetSurfaceLevel(0))
            {
                base.Lock();
                base.SetBackBuffer(D3DResourceType.IDirect3DSurface9, surface.NativePointer);
                base.Unlock();
            }
        }