private static DxTexture ReadTextureCubeFromStream(GtexData gtex, Stream input) { Texture2DDescription descriptor = GetTextureCubeDescription(gtex); using (SafeUnmanagedArray array = new SafeUnmanagedArray(gtex.MipMapData.Sum(d => d.Length))) { DataRectangle[] rects = new DataRectangle[gtex.MipMapData.Length]; using (UnmanagedMemoryStream io = array.OpenStream(FileAccess.Write)) { byte[] buff = new byte[32 * 1024]; for (int index = 0; index < gtex.MipMapData.Length; index++) { GtexMipMapLocation mimMap = gtex.MipMapData[index]; Int32 pitch = GetPitch(descriptor, index); rects[index] = CreateDataRectangle(array, io, pitch); input.SetPosition(mimMap.Offset); input.CopyToStream(io, mimMap.Length, buff); } } Texture2D texture = new Texture2D(_device.Device, descriptor, rects); // Workaround _textureCreatingWorkaround(_device.Device.ImmediateContext, texture, ImageFileFormat.Dds); return(new DxTexture(texture, descriptor)); } }
private static DxTexture ReadTexture(Stream imgbStream, GtexData gtex) { if (gtex.Header.LayerCount == 0) { return(null); } return(DxTextureReader.LoadFromStream(gtex, imgbStream)); }
public static DxTexture LoadFromStream(GtexData gtex, Stream input) { if (gtex.Header.LayerCount == 0) { return(null); } return(gtex.Header.IsCubeMap ? ReadTextureCubeFromStream(gtex, input) : Read2DTextureFromStream(gtex, input)); }
public void Inject(WpdEntry entry, Stream input, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff) { int sourceSize = (int)input.Length; headers.Value.Position = entry.Offset; SectionHeader sectionHeader = headers.Value.ReadContent <SectionHeader>(); VtexHeader textureHeader = headers.Value.ReadContent <VtexHeader>(); byte[] unknownData = new byte[textureHeader.GtexOffset - VtexHeader.Size]; headers.Value.Read(unknownData, 0, unknownData.Length); GtexData data = headers.Value.ReadContent <GtexData>(); if (data.MipMapData.Length != 1) { throw new NotImplementedException(); } DdsHeader ddsHeader = DdsHeaderDecoder.FromFileStream(input); DdsHeaderEncoder.ToGtexHeader(ddsHeader, data.Header); GtexMipMapLocation mipMapLocation = data.MipMapData[0]; int dataSize = sourceSize - 128; if (dataSize <= mipMapLocation.Length) { content.Value.Seek(mipMapLocation.Offset, SeekOrigin.Begin); } else { content.Value.Seek(0, SeekOrigin.End); mipMapLocation.Offset = (int)content.Value.Position; } input.CopyToStream(content.Value, dataSize, buff); mipMapLocation.Length = dataSize; using (MemoryStream ms = new MemoryStream(180)) { sectionHeader.WriteToStream(ms); textureHeader.WriteToStream(ms); ms.Write(unknownData, 0, unknownData.Length); data.WriteToStream(ms); ms.SetPosition(0); DefaultWpdEntryInjector defaultInjector = new DefaultWpdEntryInjector(); defaultInjector.Inject(entry, ms, headers, content, buff); } }
private static DxTexture[] ReadTextures(ImgbArchiveAccessor accessor, TextureSection[] gtexDatas) { DxTexture[] textures = new DxTexture[gtexDatas.Length]; using (Stream imgbStream = accessor.ExtractContent()) using (DisposableStack insurance = new DisposableStack()) { for (int i = 0; i < gtexDatas.Length; i++) { GtexData data = gtexDatas[i].Gtex; textures[i] = insurance.Add(ReadTexture(imgbStream, data)); } insurance.Clear(); } return(textures); }
public void Extract(WpdEntry entry, Stream output, Lazy <Stream> headers, Lazy <Stream> content, Byte[] buff) { headers.Value.Position = entry.Offset; SectionHeader sectionHeader = headers.Value.ReadContent <SectionHeader>(); TextureHeader textureHeader = headers.Value.ReadContent <TextureHeader>(); GtexData gtex = headers.Value.ReadContent <GtexData>(); DdsHeader header = DdsHeaderDecoder.FromGtexHeader(gtex.Header); DdsHeaderEncoder.ToFileStream(header, output); foreach (GtexMipMapLocation mipMap in gtex.MipMapData) { content.Value.Position = mipMap.Offset; content.Value.CopyToStream(output, mipMap.Length, buff); } }
private static Texture2DDescription Get2DTextureDescription(GtexData gtex) { if (gtex.Header.IsCubeMap) { throw new Exception("IsCubeMap: true"); } return(new Texture2DDescription { ArraySize = 1, Width = gtex.Header.Width, Height = gtex.Header.Height, Format = GetDxFormat(gtex.Header.Format), MipLevels = gtex.Header.MipMapCount, BindFlags = BindFlags.ShaderResource, OptionFlags = ResourceOptionFlags.Shared, Usage = ResourceUsage.Default, CpuAccessFlags = CpuAccessFlags.None, SampleDescription = new SampleDescription(1, 0) }); }
public SequencedStreamFactory(Stream resourceStream, GtexData data) { _resourceStream = resourceStream; _data = data; }
public PreviewTexture(GtexData gtex) : base() { this.tex = new TextureSection("__previewTexture", gtex); this.EnableCamera = false; }