Exemplo n.º 1
0
        /// <summary>
        /// Maps the data contained in a subresource to a memory pointer, and denies the GPU access to that subresource.
        /// </summary>
        /// <param name="resource">The resource.</param>
        /// <param name="subresource">The subresource.</param>
        /// <param name="mode">The mode.</param>
        /// <param name="flags">The flags.</param>
        /// <param name="stream">The output stream containing the pointer.</param>
        /// <returns>The locked <see cref="SharpDX.DataBox"/></returns>
        /// <unmanaged>HRESULT ID3D11DeviceContext::Map([In] ID3D11Resource* pResource,[In] unsigned int Subresource,[In] D3D11_MAP MapType,[In] D3D11_MAP_FLAG MapFlags,[Out] D3D11_MAPPED_SUBRESOURCE* pMappedResource)</unmanaged>
        public SharpDX.DataBox MapSubresource(SharpDX.Direct3D11.Resource resource, int subresource, SharpDX.Direct3D11.MapMode mode, SharpDX.Direct3D11.MapFlags flags, out DataStream stream)
        {
            int mipLevels;

            switch (resource.Dimension)
            {
            case ResourceDimension.Buffer:
                return(MapSubresource((Buffer)resource, mode, flags, out stream));

            case ResourceDimension.Texture1D:
                var texture1D = (Texture1D)resource;
                mipLevels = texture1D.Description.MipLevels;
                return(MapSubresource(texture1D, subresource % mipLevels, subresource / mipLevels, mode, flags, out stream));

            case ResourceDimension.Texture2D:
                var texture2D = (Texture2D)resource;
                mipLevels = texture2D.Description.MipLevels;
                return(MapSubresource(texture2D, subresource % mipLevels, subresource / mipLevels, mode, flags, out stream));

            case ResourceDimension.Texture3D:
                var texture3D = (Texture3D)resource;
                mipLevels = texture3D.Description.MipLevels;
                return(MapSubresource(texture3D, subresource % mipLevels, subresource / mipLevels, mode, flags, out stream));

            default:
                throw new InvalidOperationException(string.Format(CultureInfo.InvariantCulture, "MapSubresource is not supported for Resource [{0}]", resource.Dimension));
            }
        }
Exemplo n.º 2
0
        /// <summary>
        /// <p>Gets a reference to the data contained in a subresource, and denies the GPU access to that subresource.</p>
        /// </summary>
        /// <param name="resourceRef"><dd>  <p>A reference to a <strong><see cref="SharpDX.Direct3D11.Resource"/></strong> interface.</p> </dd></param>
        /// <param name="subresource"><dd>  <p>Index number of the subresource.</p> </dd></param>
        /// <param name="mapType"><dd>  <p>Specifies the CPU's read and write permissions for a resource. For possible values, see <strong><see cref="SharpDX.Direct3D11.MapMode"/></strong>.</p> </dd></param>
        /// <param name="mapFlags"><dd>  <p> <strong>Flag</strong> that specifies what the CPU should do when the GPU is busy. This flag is optional.</p> </dd></param>
        /// <param name="mappedResourceRef"><dd>  <p>A reference to the mapped subresource (see <strong><see cref="SharpDX.DataBox"/></strong>).</p> </dd></param>
        /// <returns>The mapped subresource (see <strong><see cref="SharpDX.DataBox"/></strong>). If <see cref="MapFlags.DoNotWait"/> is used and the resource is still being used by the GPU, this method return an empty DataBox whose property <see cref="DataBox.IsEmpty"/> returns <c>true</c>.<p>This method also throws an exception with the code <strong><see cref="SharpDX.DXGI.ResultCode.DeviceRemoved"/></strong> if <em>MapType</em> allows any CPU read access and the video card has been removed.</p><p>For more information about these error codes, see DXGI_ERROR.</p></returns>
        /// <remarks>
        /// <p>If you call <strong>Map</strong> on a deferred context, you can only pass <strong><see cref="SharpDX.Direct3D11.MapMode.WriteDiscard"/></strong>, <strong><see cref="SharpDX.Direct3D11.MapMode.WriteNoOverwrite"/></strong>, or both to the <em>MapType</em> parameter. Other <strong><see cref="SharpDX.Direct3D11.MapMode"/></strong>-typed values are not supported for a deferred context.</p><p>The Direct3D 11.1 runtime, which is available starting with Windows Developer Preview, can  map shader resource views (SRVs) of dynamic buffers with <strong><see cref="SharpDX.Direct3D11.MapMode.WriteNoOverwrite"/></strong>.  The Direct3D 11 and earlier runtimes limited mapping to vertex or index buffers.</p>
        /// If <see cref="MapFlags.DoNotWait"/> is used and the resource is still being used by the GPU, this method return an empty DataBox whose property <see cref="DataBox.IsEmpty"/> returns <c>true</c>.
        /// </remarks>
        /// <msdn-id>ff476457</msdn-id>
        /// <unmanaged>HRESULT ID3D11DeviceContext::Map([In] ID3D11Resource* pResource,[In] unsigned int Subresource,[In] D3D11_MAP MapType,[In] D3D11_MAP_FLAG MapFlags,[Out] D3D11_MAPPED_SUBRESOURCE* pMappedResource)</unmanaged>
        /// <unmanaged-short>ID3D11DeviceContext::Map</unmanaged-short>
        public SharpDX.DataBox MapSubresource(SharpDX.Direct3D11.Resource resourceRef, int subresource, SharpDX.Direct3D11.MapMode mapType, SharpDX.Direct3D11.MapFlags mapFlags)
        {
            var box    = default(DataBox);
            var result = MapSubresource(resourceRef, subresource, mapType, mapFlags, out box);

            if ((mapFlags & MapFlags.DoNotWait) != 0 && result == DXGI.ResultCode.WasStillDrawing)
            {
                return(box);
            }
            result.CheckError();
            return(box);
        }