/// <summary>
        /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
        /// </summary>
        /// <param name="buffer">A buffer.</param>
        /// <param name="view">The render-target view.</param>
        /// <param name="topLeftX">The X position of the left hand side of the viewport.</param>
        /// <param name="minDepth">The minimum depth of the viewport.</param>
        /// <param name="maxDepth">The maximum depth of the viewport.</param>
        public D3D11Viewport(D3D11Buffer buffer, D3D11RenderTargetView view, float topLeftX, float minDepth, float maxDepth)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException("buffer");
            }

            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            var description = view.Description;

            uint numElements;

            switch (description.ViewDimension)
            {
            case D3D11RtvDimension.Buffer:
                numElements = description.Buffer.NumElements;
                break;

            default:
                throw new ArgumentOutOfRangeException("view");
            }

            this.topLeftX = topLeftX;
            this.topLeftY = 0.0f;
            this.width    = numElements - topLeftX;
            this.height   = 1.0f;
            this.minDepth = minDepth;
            this.maxDepth = maxDepth;
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
        /// </summary>
        /// <param name="texture">A 2D texture.</param>
        /// <param name="view">The render-target view.</param>
        /// <param name="topLeftX">The X position of the left hand side of the viewport.</param>
        /// <param name="topLeftY">The Y position of the top of the viewport.</param>
        /// <param name="minDepth">The minimum depth of the viewport.</param>
        /// <param name="maxDepth">The maximum depth of the viewport.</param>
        public D3D11Viewport(D3D11Texture2D texture, D3D11RenderTargetView view, float topLeftX, float topLeftY, float minDepth, float maxDepth)
        {
            if (texture == null)
            {
                throw new ArgumentNullException("texture");
            }

            if (view == null)
            {
                throw new ArgumentNullException("view");
            }

            var textureDescription = texture.Description;
            var viewDescription    = view.Description;

            uint mipSlice;

            switch (viewDescription.ViewDimension)
            {
            case D3D11RtvDimension.Texture2D:
                mipSlice = viewDescription.Texture2D.MipSlice;
                break;

            case D3D11RtvDimension.Texture2DArray:
                mipSlice = viewDescription.Texture2DArray.MipSlice;
                break;

            case D3D11RtvDimension.Texture2DMs:
            case D3D11RtvDimension.Texture2DMsArray:
                mipSlice = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("view");
            }

            uint subResourceWidth  = textureDescription.Width / (uint)(1 << (int)mipSlice);
            uint subResourceHeight = textureDescription.Height / (uint)(1 << (int)mipSlice);

            this.topLeftX = topLeftX;
            this.topLeftY = topLeftY;
            this.width    = (subResourceWidth != 0 ? subResourceWidth : 1) - topLeftX;
            this.height   = (subResourceHeight != 0 ? subResourceHeight : 1) - topLeftY;
            this.minDepth = minDepth;
            this.maxDepth = maxDepth;
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
 /// </summary>
 /// <param name="buffer">A buffer.</param>
 /// <param name="view">The render-target view.</param>
 /// <param name="topLeftX">The X position of the left hand side of the viewport.</param>
 public D3D11Viewport(D3D11Buffer buffer, D3D11RenderTargetView view, float topLeftX)
     : this(buffer, view, topLeftX, 0.0f, 1.0f)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
 /// </summary>
 /// <param name="buffer">A buffer.</param>
 /// <param name="view">The render-target view.</param>
 public D3D11Viewport(D3D11Buffer buffer, D3D11RenderTargetView view)
     : this(buffer, view, 0.0f, 0.0f, 1.0f)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
 /// </summary>
 /// <param name="texture">A 3D texture.</param>
 /// <param name="view">The render-target view.</param>
 /// <param name="topLeftX">The X position of the left hand side of the viewport.</param>
 /// <param name="topLeftY">The Y position of the top of the viewport.</param>
 public D3D11Viewport(D3D11Texture3D texture, D3D11RenderTargetView view, float topLeftX, float topLeftY)
     : this(texture, view, topLeftX, topLeftY, 0.0f, 1.0f)
 {
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="D3D11Viewport"/> struct.
 /// </summary>
 /// <param name="texture">A 3D texture.</param>
 /// <param name="view">The render-target view.</param>
 public D3D11Viewport(D3D11Texture3D texture, D3D11RenderTargetView view)
     : this(texture, view, 0.0f, 0.0f, 0.0f, 1.0f)
 {
 }