public Texture(TextureNative native) { Native = native; }
private static LoadedTexture Convert(TextureNative src) { TextureFormat format; var loadMips = (src.Format & RasterFormat.ExtMipMap) == RasterFormat.ExtMipMap; var autoMips = (src.Format & RasterFormat.ExtAutoMipMap) == RasterFormat.ExtAutoMipMap; switch (src.Format & RasterFormat.NoExt) { case RasterFormat.BGRA8: case RasterFormat.BGR8: format = TextureFormat.RGBA32; break; case RasterFormat.LUM8: format = TextureFormat.Alpha8; break; case RasterFormat.R4G4B4A4: format = TextureFormat.RGBA4444; break; case RasterFormat.A1R5G5B5: format = TextureFormat.ARGB32; break; case RasterFormat.R5G6B5: format = TextureFormat.RGB565; break; default: throw new NotImplementedException(string.Format("RasterFormat.{0}", src.Format & RasterFormat.NoExt)); } switch (src.Compression) { case CompressionMode.None: break; case CompressionMode.DXT1: format = TextureFormat.DXT1; break; case CompressionMode.DXT3: format = TextureFormat.DXT5; break; default: throw new NotImplementedException(string.Format("CompressionMode.{0}", src.Compression)); } var tex = new Texture2D(src.Width, src.Height, format, false /*loadMips*/); switch (src.FilterFlags) { case Filter.None: case Filter.Nearest: case Filter.MipNearest: tex.filterMode = FilterMode.Point; break; case Filter.Linear: case Filter.MipLinear: case Filter.LinearMipNearest: tex.filterMode = FilterMode.Bilinear; break; case Filter.LinearMipLinear: case Filter.Unknown: tex.filterMode = FilterMode.Trilinear; break; } var data = src.ImageData; switch (src.Format & RasterFormat.NoExt) { case RasterFormat.BGR8: case RasterFormat.BGRA8: data = ConvertBGRToRGB(data); break; } switch (src.Compression) { case CompressionMode.DXT3: data = ConvertDXT3ToDXT5(data); break; } tex.LoadRawTextureData(data); tex.Apply(loadMips || autoMips, false /* true */); // makeNoLongerReadable: needed to flip GUI textures. doubles memory used for textures! return(new LoadedTexture(tex, src.Alpha)); }