// Static functions static public TextureObject CreateTexture3DFromFile(Device device, int width, int height, int depth, Format format, string fileName) { TextureObject newTexture = new TextureObject(); // Variables newTexture.m_Width = width; newTexture.m_Height = height; newTexture.m_Depth = depth; newTexture.m_TexFormat = format; newTexture.m_Mips = 1; BindFlags bindFlags = BindFlags.ShaderResource | BindFlags.RenderTarget | BindFlags.UnorderedAccess; ImageLoadInformation imageLoadInfo = new ImageLoadInformation() { BindFlags = bindFlags, CpuAccessFlags = CpuAccessFlags.None, Format = format, Height = height, Width = width, Depth = depth, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default }; newTexture.m_TextureObject3D = Texture3D.FromFile(device, fileName, imageLoadInfo); ShaderResourceViewDescription srvViewDesc = new ShaderResourceViewDescription { ArraySize = 0, Format = format, Dimension = ShaderResourceViewDimension.Texture3D, Flags = 0, FirstArraySlice = 0, MostDetailedMip = 0, MipLevels = 1, }; newTexture.m_ShaderResourceView = new ShaderResourceView(device, newTexture.m_TextureObject3D, srvViewDesc); newTexture.m_RenderTargetView = new RenderTargetView(device, newTexture.m_TextureObject3D); newTexture.m_UnorderedAccessView = new UnorderedAccessView(device, newTexture.m_TextureObject3D); return(newTexture); }
public static ShaderResourceView Load3DTextureFromFile(string fileName) { if (_textures3D == null) { _textures3D = new Dictionary <string, Texture3D>(); } Texture3D texture = null; string path = Utils.GetRootPath() + "\\Content\\Textures\\" + fileName; ImageInformation? SrcInfo = ImageInformation.FromFile(path); ImageLoadInformation texLoadInfo = new ImageLoadInformation(); texLoadInfo.Width = SrcInfo.Value.Width; texLoadInfo.Height = SrcInfo.Value.Height; texLoadInfo.Depth = SrcInfo.Value.Depth; texLoadInfo.FirstMipLevel = 0; texLoadInfo.MipLevels = SrcInfo.Value.MipLevels; texLoadInfo.Usage = ResourceUsage.Default; texLoadInfo.BindFlags = BindFlags.ShaderResource; texLoadInfo.CpuAccessFlags = 0; texLoadInfo.OptionFlags = SrcInfo.Value.OptionFlags; texLoadInfo.Format = SrcInfo.Value.Format; texLoadInfo.FilterFlags = FilterFlags.Triangle; texLoadInfo.MipFilterFlags = FilterFlags.Triangle; //if (_textures3D.ContainsKey(fileName)) // texture = _textures3D[fileName]; //else { texture = Texture3D.FromFile(Game.Device, path, texLoadInfo); _textures3D[fileName] = texture; } ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription(); SRVDesc.Format = texLoadInfo.Format; SRVDesc.Dimension = ShaderResourceViewDimension.Texture3D; SRVDesc.MostDetailedMip = 0; SRVDesc.MipLevels = texLoadInfo.MipLevels; ShaderResourceView srv = new ShaderResourceView(Game.Device, texture, SRVDesc); texture.Dispose(); return(srv); }
public static GPUTexture3D FromFile(DX11Game game, string path) { var tex = Texture3D.FromFile(game.Device, path); return(new GPUTexture3D(tex)); }