private static Texture LoadDds(string path) { var bytes = File.ReadAllBytes(path); var width = DdsLoader.DdsGetWidth(bytes); var height = DdsLoader.DdsGetHeight(bytes); var nMipmap = DdsLoader.DdsGetMipmap(bytes); var hasMipmap = nMipmap > 1; var ret = new Texture2D(width, height, TextureFormat.ARGB32, hasMipmap); if (hasMipmap) { for (var i = 0; i < nMipmap; i++) { var intColors = DdsLoader.DdsRead(bytes, DdsLoader.DdsReaderArgb, i); ret.SetPixels(IntsArgbToColorUpsideDown(intColors, width / (1 << i), height / (1 << i)), i); } } else { var intColors = DdsLoader.DdsRead(bytes, DdsLoader.DdsReaderArgb, 0); ret.SetPixels(IntsArgbToColorUpsideDown(intColors, width, height)); } ret.Apply(); return(ret); }
/// <summary> /// Create texture inplace with new parameters. /// Old texture will be completely discarded /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> /// <param name="mips"></param> void CreateFromFile(byte[] fileInMemory, string name, bool forceSRgb) { IntPtr resource = new IntPtr(0); IntPtr resourceView = new IntPtr(0); bool result; lock (device.DeviceContext) { if ((char)fileInMemory[0] == 'D' && (char)fileInMemory[1] == 'D' && (char)fileInMemory[2] == 'S' && (char)fileInMemory[3] == ' ') { result = DdsLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView); } else { result = WicLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView); } if (!result) { throw new GraphicsException("Failed to load texture: " + name); } tex2D = new D3D.Texture2D(resource); SRV = new D3D.ShaderResourceView(resourceView); } Width = tex2D.Description.Width; Height = tex2D.Description.Height; Depth = 1; mipCount = tex2D.Description.MipLevels; format = Converter.Convert(tex2D.Description.Format); }
private static ShaderResourceView LoadTexture(Device device, IArchiveFile file) { using (var dataView = file.OpenDataView()) { DdsLoader.CreateDDSTextureFromMemory(device, dataView.DataPointer, out Resource texture, out ShaderResourceView view); texture.Dispose(); return(view); } }
private ShaderResourceView Load(IArchiveFile file) { using (var dataView = file.OpenDataView()) { DdsLoader.CreateDDSTextureFromMemory(device, dataView.DataPointer, out var texture, out var textureView); texture.Dispose(); return(textureView); } }
public static Overlay Load(Device device, ShaderCache shaderCache, IArchiveFile textureFile) { Size2 overlaySize; ShaderResourceView overlayResourceView; using (var dataView = textureFile.OpenDataView()) { DdsLoader.CreateDDSTextureFromMemory(device, dataView.DataPointer, out var texture, out overlayResourceView); var desc = (texture as Texture2D).Description; overlaySize = new Size2(desc.Width, desc.Height); texture.Dispose(); } return(new Overlay(device, shaderCache, overlaySize, overlayResourceView)); }
/// <summary> /// Create texture inplace with new parameters. /// Old texture will be completely discarded /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <param name="format"></param> /// <param name="mips"></param> void CreateFromFile(byte[] fileInMemory, string name, bool forceSRgb) { IntPtr resource = new IntPtr(0); IntPtr resourceView = new IntPtr(0); var r = DdsLoader.CreateTextureFromMemory(device.Device.NativePointer, fileInMemory, forceSRgb, ref resource, ref resourceView); if (!r) { throw new GraphicsException("Failed to load texture: " + name); } texCube = new D3D.Texture2D(resource); SRV = new D3D.ShaderResourceView(resourceView); Width = texCube.Description.Width; Height = texCube.Description.Height; Depth = 1; mipCount = texCube.Description.MipLevels; format = Converter.Convert(texCube.Description.Format); }