/// <summary> /// Function to perform clean up operations. /// </summary> private static void CleanUp() { GorgonExample.UnloadResources(); _window?.Dispose(); _fontFactory?.Dispose(); _graphics?.Dispose(); }
private static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Initialize(); GorgonApplication.Run(_mainForm, Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); // Always clean up when you're done. // Since Gorgon uses Direct 3D 11.4, we must be careful to dispose of any objects that implement IDisposable. // Failure to do so can lead to warnings from the Direct 3D runtime when running in DEBUG mode. _depthStencil?.Dispose(); _texture?.Dispose(); _geometryShader?.Dispose(); _pixelShader?.Dispose(); _vertexShader?.Dispose(); _bufferless?.Dispose(); _swap?.Dispose(); _graphics?.Dispose(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GorgonApplication.Run(Initialize(), Idle); if (_mp3Player != null) { _mp3Player.Stop(); } } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _mp3Player.Dispose(); _renderer?.Dispose(); _trooper?.Dispose(); _metal?.Dispose(); _targetView?.Dispose(); _target?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); } }
static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _helpFont?.Dispose(); _shadowTexture?.Dispose(); _gaussBlur?.Dispose(); _spriteTexture?.Dispose(); _backgroundTexture?.Dispose(); _renderer?.Dispose(); _blurTexture?.Dispose(); _blurTarget?.Dispose(); _layer1Texture?.Dispose(); _layer1Target?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _gaussBlur?.Dispose(); _oldFilm?.Dispose(); _displacement?.Dispose(); _finalView?.Dispose(); _finalTarget?.Dispose(); _postView2?.Dispose(); _postTarget2?.Dispose(); _postView1?.Dispose(); _postTarget1?.Dispose(); _background?.Dispose(); _renderer?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); foreach (GorgonTexture2D texture in _textures) { texture?.Dispose(); } _renderer?.Dispose(); _depthBuffer?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); _assemblyCache?.Dispose(); } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { // Now begin running the application idle loop. GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { // Always clean up when you're done. // Since Gorgon uses Direct 3D 11.x, which allocate objects that use native memory and COM objects, we must be careful to dispose of any objects that implement // IDisposable. Failure to do so can lead to warnings from the Direct 3D runtime when running in DEBUG mode. GorgonExample.UnloadResources(); _constantBuffer?.Dispose(); _vertexBuffer.VertexBuffer?.Dispose(); _inputLayout?.Dispose(); _vertexShader?.Dispose(); _pixelShader?.Dispose(); _swap?.Dispose(); _graphics?.Dispose(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); // Initialize our example. Initialize(); // Start it running. Gorgon.Run(_formMain, Idle); } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(null, ex)); } finally { // Perform clean up. if (_renderer != null) { _renderer.Dispose(); } if (_graphics != null) { _graphics.Dispose(); } } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _lightEffect?.Dispose(); _renderer?.Dispose(); _finalTexture?.Dispose(); _finalTarget?.Dispose(); _backgroundLogoTexture?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); } }
/// <summary> /// Function to create the primary graphics interface. /// </summary> /// <returns>A new graphics interface, or <b>null</b> if a suitable video device was not found on the system.</returns> /// <remarks> /// <para> /// This method will create a new graphics interface for our application to use. It will select the video device with the most suitable depth buffer available, and if it cannot find a suitable /// device, it will indicate that by returning <b>null</b>. /// </para> /// </remarks> private static GorgonGraphics CreateGraphicsInterface() { GorgonGraphics graphics = null; BufferFormat[] depthFormats = { BufferFormat.D32_Float, BufferFormat.D32_Float_S8X24_UInt, BufferFormat.D24_UNorm_S8_UInt, BufferFormat.D16_UNorm }; // Find out which devices we have installed in the system. IReadOnlyList <IGorgonVideoAdapterInfo> deviceList = GorgonGraphics.EnumerateAdapters(); if (deviceList.Count == 0) { GorgonDialogs.ErrorBox(_mainForm, "There are no suitable video adapters available in the system. This example is unable to continue and will now exit."); return(null); } int depthFormatIndex = 0; int selectedDeviceIndex = 0; IGorgonVideoAdapterInfo selectedDevice = null; _selectedVideoMode = new GorgonVideoMode(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height, BufferFormat.R8G8B8A8_UNorm); while (selectedDeviceIndex < deviceList.Count) { // Reset back to a 32 bit floating point depth. _depthFormat = depthFormats[depthFormatIndex++]; // Destroy the previous interface. graphics?.Dispose(); // Create the main graphics interface. graphics = new GorgonGraphics(deviceList[selectedDeviceIndex++]); // Validate depth buffer for this device. // Odds are good that if this fails, you should probably invest in a better video card. Preferably something created after 2005. if (!graphics.FormatSupport[_depthFormat].IsDepthBufferFormat) { continue; } selectedDevice = graphics.VideoAdapter; break; } // If, somehow, we are on a device from the dark ages, then we can't continue. if (selectedDevice != null) { return(graphics); } GorgonDialogs.ErrorBox(_mainForm, $"The selected video device ('{deviceList[0].Name}') does not support a 32, 24 or 16 bit depth buffer."); return(null); }
/// <summary>Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.</summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data. </param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); GorgonExample.UnloadResources(); _renderer?.Dispose(); _leftPanel?.Dispose(); _rightPanel?.Dispose(); _graphics?.Dispose(); }
/// <summary> /// Function to perform clean up operations. /// </summary> private static void CleanUp() { if (_form != null) { _form.Dispose(); } if (_graphics != null) { _graphics.Dispose(); } }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); GorgonExample.UnloadResources(); _pluginCache?.Dispose(); _texture?.Dispose(); _swap?.Dispose(); _graphics?.Dispose(); _image?.Dispose(); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data.</param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); GorgonApplication.IdleMethod = null; _sobel?.Dispose(); _sobelShader?.Dispose(); _outputTexture?.Dispose(); _sourceTexture?.Texture?.Dispose(); _renderer?.Dispose(); _graphics?.Dispose(); }
public static async Task Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.DoEvents(); // This is necessary to get winforms to play nice with our background thread prior to running the application. WindowsFormsSynchronizationContext.AutoInstall = false; SynchronizationContext.SetSynchronizationContext(new WindowsFormsSynchronizationContext()); FormMain window = GorgonExample.Initialize(new DX.Size2(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height), "Space Scene", async(sender, _) => await InitializeAsync(sender as FormMain)); GorgonApplication.Run(window); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { // Always perform your clean up. if (_keyboard != null) { _keyboard.KeyUp -= Keyboard_KeyUp; } _helpFont?.Dispose(); _fontFactory?.Dispose(); GorgonExample.UnloadResources(); if (_keyboard != null) { _input?.UnregisterDevice(_keyboard); } _input?.Dispose(); _sceneRenderer?.Dispose(); _resources?.Dispose(); _renderer?.Dispose(); _mainRtv?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); _assemblyCache?.Dispose(); } }
/// <summary>Raises the <see cref="E:System.Windows.Forms.Form.FormClosing" /> event.</summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs" /> that contains the event data. </param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); _blurredImage[1]?.Dispose(); _blurredTarget[1]?.Dispose(); _blurredImage[0]?.Dispose(); _blurredTarget[0]?.Dispose(); _blurEffect?.Dispose(); _helpFont?.Dispose(); _textFont?.Dispose(); _renderer?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.FormClosing"></see> event. /// </summary> /// <param name="e">A <see cref="T:System.Windows.Forms.FormClosingEventArgs"></see> that contains the event data.</param> protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); GorgonExample.UnloadResources(); // Perform clean up. Gorgon2D renderer = Interlocked.Exchange(ref _renderer, null); GorgonSwapChain screen = Interlocked.Exchange(ref _screen, null); GorgonGraphics graphics = Interlocked.Exchange(ref _graphics, null); renderer?.Dispose(); screen?.Dispose(); graphics?.Dispose(); }
public void CleanUp() { if (_graphics != null) { _graphics.Dispose(); } _graphics = null; if (_form != null) { _form.Dispose(); } _form = null; }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Initialize(); GorgonApplication.Run(_window, Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _2DRenderer.Dispose(); _fontFactory.Dispose(); _input?.Dispose(); if (_renderer != null) { foreach (Mesh mesh in _renderer.Meshes) { mesh.Dispose(); } _renderer.Dispose(); } _icoSphere?.Dispose(); _clouds?.Dispose(); _sphere?.Dispose(); _cube?.Dispose(); _plane?.Dispose(); _triangle?.Dispose(); _swapChain?.Dispose(); _graphics?.Dispose(); } }
private static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); try { Initialize(); GorgonApplication.Run(_mainForm, Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); _2D.Dispose(); // Always call dispose so we can free the native memory allocated for the backing graphics API. _sphere?.Dispose(); if (_planes != null) { foreach (Plane plane in _planes) { plane?.Dispose(); } } _texture?.Dispose(); _wvpBuffer?.Dispose(); _materialBuffer?.Dispose(); _vertexShader?.Dispose(); _pixelShader?.Dispose(); _inputLayout?.Dispose(); _swap?.Dispose(); _graphics?.Dispose(); } }
static void Main() { try { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); GorgonApplication.Run(Initialize(), Idle); } catch (Exception ex) { GorgonExample.HandleException(ex); } finally { GorgonExample.UnloadResources(); if (_images != null) { for (int i = 0; i < _images.Length; ++i) { _images[i]?.Dispose(); } } if (_compositor != null) { foreach (Gorgon2DCompositionPass pass in _compositor.Passes) { pass.Effect?.Dispose(); } _compositor.Dispose(); } _renderer?.Dispose(); _screen?.Dispose(); _graphics?.Dispose(); } }
public void CleanUp() { if (_renderer != null) { _renderer.Dispose(); _renderer = null; } if (_screen != null) { _screen.Dispose(); _screen = null; } if (_graphics != null) { _graphics.Dispose(); _graphics = null; } if (_form != null) { _form.Dispose(); _form = null; } }
protected override void OnFormClosing(FormClosingEventArgs e) { base.OnFormClosing(e); if (_font != null) { _font.Dispose(); } if (_2d != null) { _2d.Dispose(); } if (_swap != null) { _swap.Dispose(); } if (_graphics != null) { _graphics.Dispose(); } }
/// <summary> /// Defines the entry point of the application. /// </summary> private static void Main() { try { Console.ForegroundColor = ConsoleColor.White; Console.WriteLine("For this example, we'll upload two sets of values to the GPU and the compute engine will perform a simple mathematical"); Console.WriteLine("operation on each sets of values to produce another set of values stored as a structured buffer.\n"); Console.WriteLine("To do this, we first create a graphics interface so we can access the GPU from the compute engine, then we create the"); Console.WriteLine("compute engine itself and bind the buffers containing the input values and the output buffer. Then, finally, we execute"); Console.WriteLine("the compute shader and retrieve the result values from the output buffer into a buffer that the CPU can read and test"); Console.WriteLine("them for accuracy.\n"); Console.ResetColor(); // Initialize the required objects. Console.WriteLine("Initializing..."); Initialize(); // Initialize our input and output data structures. Console.WriteLine("Creating data..."); BuildInputOutputBuffers(); // Now create the engine and execute the shader. Console.WriteLine("Executing..."); OutputData[] results = Execute(); // Now test the results to ensure we the engine did what we wanted. IReadOnlyList <(int Index, OutputData Expected, OutputData Actual)> errors = TestResults(results); if (errors.Count != 0) { foreach ((int Index, OutputData Expected, OutputData Actual) in errors) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"Failure at element {Index}."); if (Expected.Sum != Actual.Sum) { Console.WriteLine($"Sum should be: {Expected.Sum}, Got: {Actual.Sum}"); } if (!Expected.Product.EqualsEpsilon(Actual.Product)) { Console.WriteLine($"Product should be: {Expected.Product}, Got: {Actual.Product}"); } Console.ResetColor(); } } else { Console.ForegroundColor = ConsoleColor.Green; Console.WriteLine("Success. All compute engine output values match expected values."); Console.ResetColor(); } } catch (Exception ex) { // And, of course, if we have errors, then we should obviously handle them. Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"There was an error running the application:\n{ex.Message}\n\nStack trace:\n{ex.StackTrace}"); Console.ResetColor(); } finally { _floatBuffer?.Dispose(); _intBuffer?.Dispose(); _outputBuffer?.Dispose(); _computeShader?.Dispose(); _graphics?.Dispose(); } // Wait for the user to exit. Console.WriteLine("Press any key to exit."); Console.ReadKey(); }
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(); } } }
public void CleanUp() { _graphics.Dispose(); }