public DdsTexture( DxgiFormat dxgiFormat, int width, int height = 1, int depth = 1, int arraySize = 1, int mipCount = 0, ResourceDimension dimension = ResourceDimension.Unknown, ResourceMiscFlags miscFlags = 0) { if (dxgiFormat == DxgiFormat.UNKNOWN) { throw new ArgumentException("Formats can not be 'unknown'"); } if (width <= 0) { throw new ArgumentException("Width must be greater than zero"); } if (height <= 0) { throw new ArgumentException("Height must be greater than zero"); } if (depth <= 0) { throw new ArgumentException("Depth must be greater than zero"); } if (arraySize <= 0) { throw new ArgumentException("Array size must be greater than zero"); } if (mipCount < 0) { throw new ArgumentException("Mip count must can not be negative"); } if (dimension != ResourceDimension.Unknown && dimension != ResourceDimension.Texture3D && depth != 1) { throw new ArgumentException(string.Format("Dimension10 is {0}, but Depth is not 1", dimension)); } if ((dimension == ResourceDimension.Buffer || dimension == ResourceDimension.Texture1D) && height != 1) { throw new ArgumentException(string.Format("Dimension10 is {0}, but Height is not 1", dimension)); } if (dimension == ResourceDimension.Buffer && mipCount > 1) { throw new ArgumentException("Dimension10 is Buffer, but MipCount is not 0 or 1"); } this.Width = width; this.Height = height; this.Depth = depth; /* * if (depth != 1) * Dimension10 = ResourceDimension.Texture3D; * else if (height != 1) * Dimension10 = ResourceDimension.Texture2D; * else * Dimension10 = ResourceDimension.Texture1D;*/ this.MiscFlags10 = miscFlags; this.D3DFormat = Helper.D3DFormatFromDxgi(dxgiFormat); if (mipCount == 0) { int mipWidth = width; int mipHeight = height; int mipDepth = depth; mipCount = 1; while (mipWidth != 1 || mipHeight != 1 || mipDepth != 1) { if (mipWidth != 1) { mipWidth /= 2; } if (mipHeight != 1) { mipHeight /= 2; } if (mipDepth != 1) { mipDepth /= 2; } mipCount++; } } this.Data = new byte[arraySize][]; int chainSize; this.CalculateMipInfos(mipCount, -1, -1, out chainSize); for (int i = 0; i < this.Data.Length; i++) { this.Data[i] = new byte[chainSize]; } }
public DdsTexture(DxgiFormat dxgiFormat, int width, int height = 1, int depth = 1, int arraySize = 1, int mipCount = 0, ResourceDimension dimension = ResourceDimension.Unknown, ResourceMiscFlags miscFlags = 0 ) { if (dxgiFormat == DxgiFormat.UNKNOWN) throw new ArgumentException("Formats can not be 'unknown'"); if (width <= 0) throw new ArgumentException("Width must be greater than zero"); if (height <= 0) throw new ArgumentException("Height must be greater than zero"); if (depth <= 0) throw new ArgumentException("Depth must be greater than zero"); if (arraySize <= 0) throw new ArgumentException("Array size must be greater than zero"); if (mipCount < 0) throw new ArgumentException("Mip count must can not be negative"); if (dimension != ResourceDimension.Unknown && dimension != ResourceDimension.Texture3D && depth != 1) throw new ArgumentException(string.Format("Dimension10 is {0}, but Depth is not 1", dimension)); if ((dimension == ResourceDimension.Buffer || dimension == ResourceDimension.Texture1D) && height != 1) throw new ArgumentException(string.Format("Dimension10 is {0}, but Height is not 1", dimension)); if (dimension == ResourceDimension.Buffer && mipCount > 1) throw new ArgumentException("Dimension10 is Buffer, but MipCount is not 0 or 1"); Width = width; Height = height; Depth = depth; /* if (depth != 1) Dimension10 = ResourceDimension.Texture3D; else if (height != 1) Dimension10 = ResourceDimension.Texture2D; else Dimension10 = ResourceDimension.Texture1D;*/ MiscFlags10 = miscFlags; D3DFormat = Helper.D3DFormatFromDxgi(dxgiFormat); Data = new byte[arraySize][]; if (mipCount == 0) { int mipWidth = width; int mipHeight = height; int mipDepth = depth; mipCount = 1; while (mipWidth != 1 || mipHeight != 1 || mipDepth != 1) { if (mipWidth != 1) mipWidth /= 2; if (mipHeight != 1) mipHeight /= 2; if (mipDepth != 1) mipDepth /= 2; mipCount++; } } int chainSize; CalculateMipInfos(mipCount, -1, -1, out chainSize); for (int i = 0; i < Data.Length; i++) Data[i] = new byte[chainSize]; }