/// <summary> /// Read DX10-DXGI header from full DDS header block. /// </summary> /// <param name="fullHeaderBlock">Entire DDS header block.</param> /// <param name="offset">Offset at which this header starts in full block.</param> public DDS_DXGI_DX10_Additional(byte[] fullHeaderBlock, int offset = 128) { dxgiFormat = (DXGI_FORMAT)BitConverter.ToInt32(fullHeaderBlock, offset); resourceDimension = (D3D10_RESOURCE_DIMENSION)BitConverter.ToInt32(fullHeaderBlock, offset + 4); miscFlag = (D3D10_RESOURCE_MISC_FLAGS)BitConverter.ToUInt32(fullHeaderBlock, offset + 8); arraySize = BitConverter.ToUInt32(fullHeaderBlock, offset + 12); miscFlags2 = (DXGI_MiscFlags)BitConverter.ToUInt32(fullHeaderBlock, offset + 16); }
public void Read(BinaryReaderExt reader) { dxgiFormat = (DXGI_FORMAT)reader.ReadInt32(); resourceDimension = (D3D10_RESOURCE_DIMENSION)reader.ReadInt32(); miscFlag = reader.ReadUInt32(); arraySize = reader.ReadUInt32(); miscFlags2 = reader.ReadUInt32(); }
public void GetType(ref D3D10_RESOURCE_DIMENSION rType) { if (m_GetTypeFunc == null) { var fp = GetFunctionPointer(7); m_GetTypeFunc = (GetTypeFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetTypeFunc)); } m_GetTypeFunc(m_ptr, ref rType); }
public virtual void GetComType( out D3D10_RESOURCE_DIMENSION rType ) { var fp = GetFunctionPointer(7); if (m_GetTypeFunc == null) { m_GetTypeFunc = (GetTypeFunc)Marshal.GetDelegateForFunctionPointer(fp, typeof(GetTypeFunc)); } m_GetTypeFunc(m_ptr, out rType); }
public static Format TextureInfo(byte[] data) { // bool isCubeMap; // Validate DDS file in memory DDS_HEADER header = new DDS_HEADER(); int ddsHeaderSize = Marshal.SizeOf(header); int ddspfSize = Marshal.SizeOf(new DDS_PIXELFORMAT()); int ddsHeader10Size = Marshal.SizeOf(new DDS_HEADER_DXT10()); if (data.Length < (sizeof(uint) + ddsHeaderSize)) { throw new Exception(); } //first is magic number int dwMagicNumber = BitConverter.ToInt32(data, 0); if (dwMagicNumber != DDS_MAGIC) { throw new Exception(); } header = ByteArrayToStructure <DDS_HEADER>(data, 4, ddsHeaderSize); // Verify header to validate DDS file if (header.size != ddsHeaderSize || header.ddspf.size != ddspfSize) { throw new Exception(); } // Check for DX10 extension bool bDXT10Header = false; if (((header.ddspf.flags & DDS_FOURCC) > 0) && (MAKEFOURCC('D', 'X', '1', '0') == header.ddspf.fourCC)) { // Must be long enough for both headers and magic value if (data.Length < (ddsHeaderSize + 4 + ddsHeader10Size)) { throw new Exception(); } bDXT10Header = true; } int offset = 4 + ddsHeaderSize + (bDXT10Header ? ddsHeader10Size : 0); // return InitTextureFromData(device, context, header, null, data, offset, 0, out isCubeMap); // return InitTextureFromData(device, context, header, null, data, offset, 0, out isCubeMap); // return InitTextureFromData(device, context, header, null, data, offset, 0, out isCubeMap); DDS_HEADER_DXT10?header10 = null; if (bDXT10Header) { header10 = ByteArrayToStructure <DDS_HEADER_DXT10>(data, 4 + ddsHeaderSize, ddsHeader10Size); } int width = header.width; int height = header.height; int depth = header.depth; D3D10_RESOURCE_DIMENSION resDim = D3D10_RESOURCE_DIMENSION.UNKNOWN; int arraySize = 1; Format format = Format.UNKNOWN; // isCubeMap = false; int mipCount = header.mipMapCount; if (0 == mipCount) { mipCount = 1; } if (((header.ddspf.flags & DDS_FOURCC) > 0) && (MAKEFOURCC('D', 'X', '1', '0') == header.ddspf.fourCC)) { DDS_HEADER_DXT10 d3d10ext = header10.Value; arraySize = d3d10ext.arraySize; if (arraySize == 0) { throw new Exception(); } if (BitsPerPixel(d3d10ext.dxgiFormat) == 0) { throw new Exception(); } format = d3d10ext.dxgiFormat; switch ((D3D10_RESOURCE_DIMENSION)d3d10ext.resourceDimension) { case D3D10_RESOURCE_DIMENSION.TEXTURE1D: // D3DX writes 1D textures with a fixed Height of 1 if ((header.flags & DDS_HEIGHT) > 0 && height != 1) { throw new Exception(); } height = depth = 1; break; case D3D10_RESOURCE_DIMENSION.TEXTURE2D: //D3D11_RESOURCE_MISC_TEXTURECUBE if ((d3d10ext.miscFlag & 0x4) > 0) { arraySize *= 6; // isCubeMap = true; } depth = 1; break; case D3D10_RESOURCE_DIMENSION.TEXTURE3D: if (!((header.flags & DDS_HEADER_FLAGS_VOLUME) > 0)) { throw new Exception(); } if (arraySize > 1) { throw new Exception(); } break; default: throw new Exception(); } resDim = (D3D10_RESOURCE_DIMENSION)d3d10ext.resourceDimension; } else { format = GetDXGIFormat(header.ddspf); if (format == Format.UNKNOWN) { throw new Exception(); } if ((header.flags & DDS_HEADER_FLAGS_VOLUME) > 0) { resDim = D3D10_RESOURCE_DIMENSION.TEXTURE3D; } else { if ((header.caps2 & DDS_CUBEMAP) > 0) { // We require all six faces to be defined if ((header.caps2 & DDS_CUBEMAP_ALLFACES) != DDS_CUBEMAP_ALLFACES) { throw new Exception(); } arraySize = 6; // isCubeMap = true; } depth = 1; resDim = D3D10_RESOURCE_DIMENSION.TEXTURE2D; } } return(format); }
/// <summary> /// Read DX10-DXGI header from full DDS header block. /// </summary> /// <param name="fullHeaderBlock">Entire DDS header block.</param> /// <param name="offset">Offset at which this header starts in full block.</param> public DDS_DXGI_DX10_Additional(byte[] fullHeaderBlock, int offset = 128) { dxgiFormat = (DXGI_FORMAT)BitConverter.ToInt32(fullHeaderBlock, offset); resourceDimension = (D3D10_RESOURCE_DIMENSION)BitConverter.ToInt64(fullHeaderBlock, offset + 4); miscFlag = (D3D10_RESOURCE_MISC_FLAGS)BitConverter.ToUInt32(fullHeaderBlock, offset + 12); arraySize = BitConverter.ToUInt32(fullHeaderBlock, offset + 16); miscFlags2 = (DXGI_MiscFlags)BitConverter.ToUInt32(fullHeaderBlock, offset + 20); }