// Copyright (c) 2010-2014 SharpDX - Alexandre Mutel // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. using System; using System.Diagnostics; using System.IO; using System.Runtime.InteropServices; using SharpDX.Direct3D; using SharpDX.DXGI; namespace SharpDX.Direct3D11 { public partial class Resource { /// /// Gets a swap chain back buffer. /// /// The type of the buffer. /// The swap chain to get the buffer from. /// The index of the desired buffer. /// The buffer interface, or null on failure. public static T FromSwapChain(SwapChain swapChain, int index) where T : Resource { return swapChain.GetBackBuffer(index); } /// /// Calculates the sub resource index from a miplevel. /// /// A zero-based index for the mipmap level to address; 0 indicates the first, most detailed mipmap level. /// The zero-based index for the array level to address; always use 0 for volume (3D) textures. /// Number of mipmap levels in the resource. /// /// The index which equals MipSlice + (ArraySlice * MipLevels). /// /// D3D11CalcSubresource public static int CalculateSubResourceIndex(int mipSlice, int arraySlice, int mipLevel) { return (mipLevel * arraySlice) + mipSlice; } /// /// Calculates the resulting size at a single level for an original size. /// /// The mip level to get the size. /// Size of the base. /// /// Size of the mipLevel /// public static int CalculateMipSize(int mipLevel, int baseSize) { baseSize = baseSize >> mipLevel; return baseSize > 0 ? baseSize : 1; } /// /// Calculates the sub resource index for a particular mipSlice and arraySlice. /// /// The mip slice. /// The array slice. /// The size of slice. This values is resource dependent. Texture1D -> mipSize of the Width. Texture2D -> mipSize of the Height. Texture3D -> mipsize of the Depth /// The resulting miplevel calulated for this instance with this mipSlice and arraySlice. public virtual int CalculateSubResourceIndex(int mipSlice, int arraySlice, out int mipSize) { throw new NotImplementedException("This method is not implemented for this kind of resource"); } } }