/// <summary> /// Handles the Click event of the ButtonImagePath control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void ButtonImagePath_Click(object sender, EventArgs e) { Cursor.Current = Cursors.WaitCursor; IGorgonImage image = null; var png = new GorgonCodecPng(); try { if (DialogOpenPng.ShowDialog(this) != DialogResult.OK) { return; } TextImagePath.Text = DialogOpenPng.FileName; _sourceTexture?.Texture?.Dispose(); _outputTexture?.Dispose(); _sourceTexture = null; _outputTexture = null; image = png.LoadFromFile(DialogOpenPng.FileName); _sourceTexture = image.ConvertToFormat(BufferFormat.R8G8B8A8_UNorm) .ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Name = Path.GetFileNameWithoutExtension(DialogOpenPng.FileName) }).GetShaderResourceView(); _outputTexture = new GorgonTexture2D(_graphics, new GorgonTexture2DInfo(_sourceTexture, "Output") { Format = BufferFormat.R8G8B8A8_Typeless, Binding = TextureBinding.ShaderResource | TextureBinding.ReadWriteView }); // Get an SRV for the output texture so we can render it later. _outputView = _outputTexture.GetShaderResourceView(BufferFormat.R8G8B8A8_UNorm); // Get a UAV for the output. _outputUav = _outputTexture.GetReadWriteView(BufferFormat.R32_UInt); // Process the newly loaded texture. _sobel.Process(_sourceTexture, _outputUav, TrackThickness.Value, TrackThreshold.Value / 100.0f); TrackThreshold.Enabled = TrackThickness.Enabled = true; } catch (Exception ex) { GorgonDialogs.ErrorBox(this, ex); TrackThreshold.Enabled = TrackThickness.Enabled = false; } finally { image?.Dispose(); Cursor.Current = Cursors.Default; } }
public void Test2DStagingFail() { GorgonTexture2D texture = null; try { texture = _framework.Graphics.Textures.CreateTexture("Test2D", new GorgonTexture2DSettings { Width = 256, Height = 256, ArrayCount = 1, Format = BufferFormat.R8G8B8A8, MipCount = 1, AllowUnorderedAccessViews = false, Usage = BufferUsage.Staging }); texture.GetShaderView(BufferFormat.R8G8B8A8_Int); } finally { if (texture != null) { texture.Dispose(); } } }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!_disposed) { if (disposing) { if (_logo != null) { _logo.Dispose(); } if (_2D != null) { _2D.Dispose(); } } } _container = null; _2D = null; _logo = null; _disposed = true; base.Dispose(disposing); }
/// <summary> /// Function to clean up the renderer objects. /// </summary> private void CleanUpRenderer() { if (_renderer == null) { return; } if (_lastState != null) { _renderer.End2D(_lastState); _lastState = null; } if (_texture != null) { _texture.Dispose(); _texture = null; } if (_defaultTexture != null) { _defaultTexture.Dispose(); _defaultTexture = null; } if (_swapChain != null) { _swapChain.Dispose(); _swapChain = null; } _clipper = null; _graphics = null; }
/// <summary> /// Function to clean up resources used by the effect. /// </summary> public void FreeResources() { if (_randomTexture == null) { return; } _randomTexture.Dispose(); _randomTexture = null; }
/// <summary> /// Releases unmanaged and - optionally - managed resources. /// </summary> /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param> protected override void Dispose(bool disposing) { if (!_disposed) { if (disposing) { // Save our settings. GorgonFontEditorPlugIn.Settings.Save(); if (_badGlyphTexture != null) { _badGlyphTexture.Dispose(); } // Remove any externally linked dependencies. EditorFile = null; if (Font != null) { Font.Dispose(); } if (Renderer != null) { Renderer.Dispose(); } if (_textDisplay != null) { _textDisplay.Dispose(); } if (_swap != null) { _swap.Dispose(); } } _swap = null; Renderer = null; Font = null; _panel = null; _textDisplay = null; _disposed = true; } base.Dispose(disposing); }
public void Test2ViewsSameShaderStage() { GorgonTexture2D texture = null; _framework.CreateTestScene(Shaders, Shaders, true); try { using (var data = new GorgonImageData(new GorgonTexture2DSettings { Width = 256, Height = 256, ArrayCount = 1, Format = BufferFormat.R8G8B8A8, MipCount = 1, ShaderViewFormat = BufferFormat.R8G8B8A8_Int, AllowUnorderedAccessViews = false, Usage = BufferUsage.Default })) { for (int i = 0; i < 5000; i++) { data.Buffers[0].Data.Position = ((GorgonRandom.RandomInt32(0, 256) * data.Buffers[0].PitchInformation.RowPitch) + GorgonRandom.RandomInt32(0, 256) * 4); data.Buffers[0].Data.Write((int)((GorgonRandom.RandomSingle() * 2.0f - 1.0f) * (Int32.MaxValue - 2))); } texture = _framework.Graphics.Textures.CreateTexture <GorgonTexture2D>("Test2D", data); } GorgonTextureShaderView view = texture.GetShaderView(BufferFormat.R8G8B8A8_UIntNormal); _framework.Graphics.Shaders.PixelShader.Resources[0] = texture; _framework.Graphics.Shaders.PixelShader.Resources[1] = view; Assert.IsTrue(_framework.Run() == DialogResult.Yes); } finally { if (texture != null) { texture.Dispose(); } } }
/// <summary> /// Function to convert the image to use our custom codec. /// </summary> private void ConvertImage() { // The path to our image file for our custom codec. string tempPath = Path.ChangeExtension(Path.GetTempPath().FormatDirectory(Path.DirectorySeparatorChar) + Path.GetRandomFileName(), "Useless"); // The new texture holding image data read by the custom codec. GorgonTexture2D newTexture = null; try { // Save the current texture using our useless new custom codec. _image.Save(tempPath, _customCodec); newTexture = _graphics.Textures.FromFile <GorgonTexture2D>("UselessTexture", tempPath, _customCodec); // Free the old texture and assign to the new one. _image.Dispose(); _image = newTexture; } catch { // Clean up the new texture should we have an exception (this shouldn't happen, better safe than sorry). if (newTexture != null) { newTexture.Dispose(); } throw; } finally { try { File.Delete(tempPath); } // ReSharper disable once EmptyGeneralCatchClause catch { // Intentionally left blank. // If we can't clean up the temp file, then it's no big deal right now. } } }
/// <summary>Function to dispose any texture resources.</summary> protected override void OnDestroyTexture() { _texture?.Dispose(); _texture = null; _textureView = null; }
public void TestAutoSRV() { GorgonTexture1D _1D = null; GorgonTexture2D _2D = null; GorgonTexture3D _3D = null; try { _1D = _framework.Graphics.Textures.CreateTexture("Test1D", new GorgonTexture1DSettings { Width = 256, ArrayCount = 1, Format = BufferFormat.R8_UIntNormal, MipCount = 1, ShaderViewFormat = BufferFormat.Unknown, AllowUnorderedAccessViews = false, Usage = BufferUsage.Default }); Assert.IsNotNull((GorgonShaderView)_1D); Assert.AreEqual(_1D.Settings.Format, ((GorgonShaderView)_1D).Format); _2D = _framework.Graphics.Textures.CreateTexture("Test2D", new GorgonTexture2DSettings { Width = 256, Height = 256, ArrayCount = 1, Format = BufferFormat.R8G8B8A8_UIntNormal, MipCount = 1, ShaderViewFormat = BufferFormat.Unknown, AllowUnorderedAccessViews = false, Usage = BufferUsage.Default }); Assert.IsNotNull((GorgonShaderView)_2D); Assert.AreEqual(_2D.Settings.Format, ((GorgonShaderView)_2D).Format); _3D = _framework.Graphics.Textures.CreateTexture("Test3D", new GorgonTexture3DSettings { Width = 256, Height = 256, Depth = 64, Format = BufferFormat.R8G8B8A8_UIntNormal, MipCount = 1, ShaderViewFormat = BufferFormat.Unknown, AllowUnorderedAccessViews = false, Usage = BufferUsage.Default }); Assert.IsNotNull((GorgonShaderView)_3D); Assert.AreEqual(_3D.Settings.Format, ((GorgonShaderView)_3D).Format); } finally { if (_1D != null) { _1D.Dispose(); } if (_2D != null) { _2D.Dispose(); } if (_3D != null) { _3D.Dispose(); } } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Initialize(); Gorgon.Run(_form, Idle); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex)); } finally { if (_materialBuffer != null) { _materialBuffer.Dispose(); } if (_normalEarfMap != null) { _normalEarfMap.Dispose(); } if (_normalMap != null) { _normalMap.Dispose(); } if (_specEarfMap != null) { _specEarfMap.Dispose(); } if (_specMap != null) { _specMap.Dispose(); } if (_cloudMap != null) { _cloudMap.Dispose(); } if (_clouds != null) { _clouds.Dispose(); } if (_sphere != null) { _sphere.Dispose(); } if (_light != null) { _light.Dispose(); } if (_cube != null) { _cube.Dispose(); } if (_plane != null) { _plane.Dispose(); } if (_triangle != null) { _triangle.Dispose(); } if (_wvp != null) { _wvp.Dispose(); } if (_renderer2D != null) { _renderer2D.Dispose(); } if (_swapChain != null) { _swapChain.Dispose(); } if (_graphics != null) { _graphics.Dispose(); } } }
/// <summary> /// Handles the Click event of the buttonOpen control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="EventArgs"/> instance containing the event data.</param> private void buttonOpen_Click(object sender, EventArgs e) { DisableNumericLimits(); numericWidth.ValueChanged -= numericX_ValueChanged; numericHeight.ValueChanged -= numericX_ValueChanged; numericX.ValueChanged -= numericX_ValueChanged; numericY.ValueChanged -= numericX_ValueChanged; try { if (!string.IsNullOrWhiteSpace(GorgonFontEditorPlugIn.Settings.LastTextureImportPath)) { imageFileBrowser.StartDirectory = GorgonFontEditorPlugIn.Settings.LastTextureImportPath; } imageFileBrowser.FileTypes.Clear(); imageFileBrowser.FileTypes.Add(ImageEditor.ContentType); imageFileBrowser.FileView = GorgonFontEditorPlugIn.Settings.LastTextureImportDialogView; if (imageFileBrowser.ShowDialog(ParentForm) == DialogResult.OK) { // Don't load the same image. if ((TextureBrushFile != null) && (string.Equals(TextureBrushFile.FilePath, imageFileBrowser.Files[0].FilePath))) { return; } Cursor.Current = Cursors.WaitCursor; // Load the image. using (Stream stream = imageFileBrowser.OpenFile()) { using (IImageEditorContent imageContent = ImageEditor.ImportContent(imageFileBrowser.Files[0], stream)) { if (imageContent.Image.Settings.ImageType != ImageType.Image2D) { GorgonDialogs.ErrorBox(ParentForm, string.Format(Resources.GORFNT_ERR_IMAGE_NOT_2D, imageContent.Name)); return; } if ((imageContent.Image.Settings.Format != BufferFormat.R8G8B8A8_UIntNormal_sRGB) && (imageContent.Image.Settings.Format != BufferFormat.R8G8B8A8_UIntNormal) && (imageContent.Image.Settings.Format != BufferFormat.B8G8R8A8_UIntNormal) && (imageContent.Image.Settings.Format != BufferFormat.B8G8R8A8_UIntNormal_sRGB)) { GorgonDialogs.ErrorBox(ParentForm, string.Format(Resources.GORFNT_BRUSH_IMAGE_WRONG_FORMAT, imageFileBrowser.Files[0].Filename, imageContent.Image.Settings.Format)); return; } // If we've loaded a texture previously and haven't committed it yet, then get rid of it. if (_texture != null) { _texture.Dispose(); } var settings = (GorgonTexture2DSettings)imageContent.Image.Settings.Clone(); _texture = _graphics.Textures.CreateTexture <GorgonTexture2D>(imageContent.Name, imageContent.Image, settings); // Reset the texture brush settings. numericWidth.Value = settings.Width; numericHeight.Value = settings.Height; numericX.Value = 0; numericY.Value = 0; comboWrapMode.Text = Resources.GORFNT_TEXT_TILE; // Function to retrieve the transformation and node point values from the image. InitializeClipper(_texture, new RectangleF(0, 0, settings.Width, settings.Height)); TextureBrushFile = imageFileBrowser.Files[0]; OnBrushChanged(); } } GorgonFontEditorPlugIn.Settings.LastTextureImportPath = Path.GetDirectoryName(imageFileBrowser.Files[0].FilePath).FormatDirectory('/'); } GorgonFontEditorPlugIn.Settings.LastTextureImportDialogView = imageFileBrowser.FileView; } catch (Exception ex) { GorgonDialogs.ErrorBox(ParentForm, ex); } finally { EnableNumericLimits(); numericWidth.ValueChanged += numericX_ValueChanged; numericHeight.ValueChanged += numericX_ValueChanged; numericX.ValueChanged += numericX_ValueChanged; numericY.ValueChanged += numericX_ValueChanged; Cursor.Current = Cursors.Default; UpdateLabelInfo(); ValidateCommands(); } }