/// <summary> /// Function to load the image to be used a thumbnail. /// </summary> /// <param name="thumbnailCodec">The codec for the thumbnail images.</param> /// <param name="thumbnailFile">The path to the thumbnail file.</param> /// <param name="content">The content being thumbnailed.</param> /// <param name="cancelToken">The token used to cancel the operation.</param> /// <returns>The thumbnail image, and a flag to indicate whether the thumbnail needs conversion.</returns> private (IGorgonImage thumbnailImage, bool needsConversion) LoadThumbNailImage(IGorgonImageCodec thumbnailCodec, FileInfo thumbnailFile, IContentFile content, CancellationToken cancelToken) { IGorgonImage result; Stream inStream = null; try { // If we've already got the file, then leave. if (thumbnailFile.Exists) { inStream = thumbnailFile.Open(FileMode.Open, FileAccess.Read, FileShare.Read); result = thumbnailCodec.LoadFromStream(inStream); return(cancelToken.IsCancellationRequested ? (null, false) : (result, false)); } inStream = content.OpenRead(); result = _ddsCodec.LoadFromStream(inStream); return(result, true); } catch (Exception ex) { CommonServices.Log.Print($"[ERROR] Cannot create thumbnail for '{content.Path}'", LoggingLevel.Intermediate); CommonServices.Log.LogException(ex); return(null, false); } finally { inStream?.Dispose(); } }
/// <summary> /// Function to load the common resources at application start up. /// </summary> public static void LoadResources() { IGorgonImageCodec dds = new GorgonCodecDds(); using (var stream = new MemoryStream(Resources.Bg_Pattern_256x256, false)) { CheckerBoardPatternImage = dds.LoadFromStream(stream); } using (var stream = new MemoryStream(Resources.manual_input_24x24, false)) { KeyboardIcon = dds.LoadFromStream(stream); } using (var stream = new MemoryStream(Resources.manual_vertex_edit_64x64, false)) { KeyboardIconLarge = dds.LoadFromStream(stream); } }
/// <summary> /// Function to load textures from application resources. /// </summary> private static void LoadTextures() { // Load standard images from the resource section. _renderer.TextureCache["UV"] = Resources.UV.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "UV" }).GetShaderResourceView(); _renderer.TextureCache["Earth"] = Resources.earthmap1k.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Earth" }).GetShaderResourceView(); _renderer.TextureCache["Earth_Specular"] = Resources.earthspec1k.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Earth_Specular" }).GetShaderResourceView(); _renderer.TextureCache["Clouds"] = Resources.earthcloudmap.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Clouds" }).GetShaderResourceView(); _renderer.TextureCache["GorgonNormalMap"] = Resources.normalmap.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "GorgonNormalMap" }).GetShaderResourceView(); // The following images are DDS encoded and require an encoder to read them from the resources. var dds = new GorgonCodecDds(); using (var stream = new MemoryStream(Resources.Rain_Height_NRM)) using (IGorgonImage image = dds.LoadFromStream(stream)) { _renderer.TextureCache["Water_Normal"] = image.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Water_Normal" }).GetShaderResourceView(); } using (var stream = new MemoryStream(Resources.Rain_Height_SPEC)) using (IGorgonImage image = dds.LoadFromStream(stream)) { _renderer.TextureCache["Water_Specular"] = image.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Water_Specular" }).GetShaderResourceView(); } using (var stream = new MemoryStream(Resources.earthbump1k_NRM)) using (IGorgonImage image = dds.LoadFromStream(stream)) { _renderer.TextureCache["Earth_Normal"] = image.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = "Earth_Normal" }).GetShaderResourceView(); } }