/// <summary> /// コンストラクタ /// </summary> /// <param name="filename">ファイルパス</param> /// <param name="device">デバイス</param> public ImageResource(string filename, Device device) { try { ImageInformation ii = ImageInformation.FromFile(filename); this._width = ii.Width; this._height = ii.Height; this._texture = Texture.FromFile(device, filename, this._width, this._height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed, Filter.Linear, Filter.Linear, 0); } catch { MessageBox.Show(PPDExceptionContentProvider.Provider.GetContent(PPDExceptionType.ImageReadError) + System.Environment.NewLine + filename); } }
public Picture(string filename, Device device) { try { ImageInformation ii = ImageInformation.FromFile(filename); this._width = ii.Width; this._height = ii.Height; this.tex = Texture.FromFile(device, filename, this._width, this._height, 0, Usage.None, Format.A8R8G8B8, Pool.Managed, Filter.Linear, Filter.Linear, 0); initok = true; } catch (Exception e) { MessageBox.Show("画像ファイル\n" + filename + "の取得に失敗しました\n" + e.Message); } }
/// <summary> /// コンストラクタ /// </summary> /// <param name="device"></param> /// <param name="filename">ファイルパス</param> /// <param name="pa"></param> public ImageResource(PPDDevice device, string filename, bool pa) { try { this.filename = filename; var ii = ImageInformation.FromFile(filename); this.width = ii.Width; this.height = ii.Height; this.halfPixel = new Vector2(0.5f / this.width, 0.5f / this.height); this.texture = (Texture.DX11.Texture)TextureFactoryManager.Factory.FromFile(device, filename, this.width, this.height, pa); CreateVertexBuffer(device); } catch { MessageBox.Show(PPDExceptionContentProvider.Provider.GetContent(PPDExceptionType.ImageReadError) + System.Environment.NewLine + filename); } }
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); }
protected override void LoadInfo(int slice, string path) { try { ImageInformation?info = ImageInformation.FromFile(path); if (info.HasValue) { this.size[slice] = new Vector2(info.Value.Width, info.Value.Height); this.format[slice] = info.Value.Format; } else { MarkInvalid(slice); } } catch { MarkInvalid(slice); } }
static public Texture11 FromFile(Device device, string fileName, LoadOptions options = LoadOptions.AssumeSRgb) { try { ImageLoadInformation loadInfo = new ImageLoadInformation(); loadInfo.BindFlags = BindFlags.ShaderResource; loadInfo.CpuAccessFlags = CpuAccessFlags.None; loadInfo.Depth = -1; loadInfo.Filter = FilterFlags.Box; loadInfo.FirstMipLevel = 0; loadInfo.Format = SharpDX.DXGI.Format.R8G8B8A8_UNorm; loadInfo.Height = -1; loadInfo.MipLevels = -1; loadInfo.OptionFlags = ResourceOptionFlags.None; loadInfo.Usage = ResourceUsage.Default; loadInfo.Width = -1; bool shouldPromoteSRgb = RenderContext11.sRGB && (options & LoadOptions.AssumeSRgb) == LoadOptions.AssumeSRgb; if (fileName.EndsWith(".png", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".jpg", StringComparison.InvariantCultureIgnoreCase) || fileName.EndsWith(".jpeg", StringComparison.InvariantCultureIgnoreCase)) { loadInfo.Filter = FilterFlags.Box; if (shouldPromoteSRgb) { loadInfo.Format = promoteFormatToSRGB(loadInfo.Format); } if (isSRGBFormat(loadInfo.Format)) { loadInfo.Filter |= FilterFlags.SRgb; } } else { // Promote image format to sRGB ImageInformation?info = ImageInformation.FromFile(fileName); if (info.HasValue && shouldPromoteSRgb) { loadInfo.Format = promoteFormatToSRGB(info.Value.Format); } if (isSRGBFormat(loadInfo.Format)) { loadInfo.Filter |= FilterFlags.SRgb; } } Texture2D texture = Texture2D.FromFile <Texture2D>(device, fileName, loadInfo); return(new Texture11(texture)); } catch (Exception e) { try { ImageLoadInformation ili = new ImageLoadInformation() { BindFlags = BindFlags.ShaderResource, CpuAccessFlags = CpuAccessFlags.None, Depth = -1, Filter = FilterFlags.Box, FirstMipLevel = 0, Format = RenderContext11.DefaultTextureFormat, Height = -1, MipFilter = FilterFlags.None, MipLevels = 1, OptionFlags = ResourceOptionFlags.None, Usage = ResourceUsage.Default, Width = -1 }; if (ili.Format == SharpDX.DXGI.Format.R8G8B8A8_UNorm_SRgb) { ili.Filter |= FilterFlags.SRgb; } Texture2D texture = Texture2D.FromFile <Texture2D>(device, fileName, ili); return(new Texture11(texture)); } catch { return(null); } } }
public static ShaderResourceView LoadTextureArray(FileInfo[] szTextureNames) { Texture2DDescription textureDesc = new Texture2DDescription(); Texture2D textureArray = null; Texture2D pD3D10Resource = null; for (int a = 0; a < szTextureNames.Length; ++a) { FileInfo f = szTextureNames[a]; ImageInformation? SrcInfo = ImageInformation.FromFile(f.FullName); ImageLoadInformation loadInfo = new ImageLoadInformation(); loadInfo.Width = SrcInfo.Value.Width; loadInfo.Height = SrcInfo.Value.Height; loadInfo.Depth = SrcInfo.Value.Depth; loadInfo.FirstMipLevel = 0; loadInfo.MipLevels = SrcInfo.Value.MipLevels; loadInfo.Usage = ResourceUsage.Staging; loadInfo.BindFlags = 0; loadInfo.CpuAccessFlags = CpuAccessFlags.Write | CpuAccessFlags.Read; loadInfo.Format = SrcInfo.Value.Format; loadInfo.FilterFlags = FilterFlags.None; loadInfo.MipFilterFlags = FilterFlags.None; pD3D10Resource = Texture2D.FromFile(Game.Device, f.FullName, loadInfo); if (pD3D10Resource != null) { DataRectangle mappedTex2D; if (textureArray == null) { textureDesc = pD3D10Resource.Description; textureDesc.Usage = ResourceUsage.Default; textureDesc.BindFlags = BindFlags.ShaderResource; textureDesc.CpuAccessFlags = CpuAccessFlags.None; textureDesc.ArraySize = szTextureNames.Length; textureArray = new Texture2D(Game.Device, textureDesc); } for (int iMip = 0; iMip < textureDesc.MipLevels; ++iMip) { mappedTex2D = pD3D10Resource.Map(iMip, MapMode.Read, D3D10.MapFlags.None); DataBox db = new DataBox(mappedTex2D.Pitch, 0, mappedTex2D.Data); Game.Device.UpdateSubresource(db, textureArray, D3D10.Resource.CalculateSubresourceIndex(iMip, a, textureDesc.MipLevels)); pD3D10Resource.Unmap(iMip); } pD3D10Resource.Dispose(); } } ShaderResourceViewDescription SRVDesc = new ShaderResourceViewDescription(); SRVDesc.Format = textureDesc.Format; SRVDesc.Dimension = ShaderResourceViewDimension.Texture2DArray; SRVDesc.MipLevels = textureDesc.MipLevels; SRVDesc.ArraySize = szTextureNames.Length; SRVDesc.FirstArraySlice = 0; SRVDesc.MostDetailedMip = 0; ShaderResourceView ppSRV = new ShaderResourceView(Game.Device, textureArray, SRVDesc); textureArray.Dispose(); return(ppSRV); }