/// <summary> /// Handles the KeyUp event of the MainForm control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param> private static void MainForm_KeyUp(object sender, KeyEventArgs e) { if ((e.KeyCode != Keys.Enter) || (!e.Alt) || (_swap == null)) { return; } if (!_swap.IsWindowed) { _swap.ExitFullScreen(); return; } IGorgonVideoOutputInfo output = _graphics.VideoAdapter.Outputs[GorgonApplication.MainForm.Handle]; if (output == null) { return; } // Find an appropriate video mode. var searchMode = new GorgonVideoMode(GorgonApplication.MainForm.ClientSize.Width, GorgonApplication.MainForm.ClientSize.Height, BufferFormat.R8G8B8A8_UNorm); output.VideoModes.FindNearestVideoMode(output, in searchMode, out GorgonVideoMode nearestMode); // To enter full screen borderless window mode, call EnterFullScreen with no parameters. _swap.EnterFullScreen(in nearestMode, output); }
/// <summary> /// Handles the KeyDown event of the _mainForm control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="KeyEventArgs" /> instance containing the event data.</param> /// <exception cref="NotSupportedException"></exception> private static void _mainForm_KeyDown(object sender, KeyEventArgs e) { if ((!e.Alt) || (e.KeyCode != Keys.Enter)) { return; } if (!_swap.IsWindowed) { _swap.ExitFullScreen(); } else { // Get the output for the main window. var currentScreen = Screen.FromControl(_mainForm); IGorgonVideoOutputInfo output = _graphics.VideoAdapter.Outputs[currentScreen.DeviceName]; _swap.EnterFullScreen(in _selectedVideoMode, output); } }
/// <summary> /// Function to initialize the GPU resource objects. /// </summary> private static void InitializeGpuResources() { _graphics = CreateGraphicsInterface(); // If we couldn't create the graphics interface, then leave. if (_graphics == null) { return; } // Create a 1280x800 window with a depth buffer. // We can modify the resolution in the config file for the application, but like other Gorgon examples, the default is 1280x800. _swap = new GorgonSwapChain(_graphics, _mainForm, new GorgonSwapChainInfo("Main") { // Set up for 32 bit RGBA normalized display. Format = BufferFormat.R8G8B8A8_UNorm, Width = Settings.Default.Resolution.Width, Height = Settings.Default.Resolution.Height }); // Build the depth buffer for our swap chain. BuildDepthBuffer(_swap.Width, _swap.Height); if (!Settings.Default.IsWindowed) { // Get the output for the main window. var currentScreen = Screen.FromControl(_mainForm); IGorgonVideoOutputInfo output = _graphics.VideoAdapter.Outputs[currentScreen.DeviceName]; // If we've asked for full screen mode, then locate the correct video mode and set us up. _selectedVideoMode = new GorgonVideoMode(Settings.Default.Resolution.Width, Settings.Default.Resolution.Height, BufferFormat.R8G8B8A8_UNorm); _swap.EnterFullScreen(in _selectedVideoMode, output); } // Handle resizing because the projection matrix and depth buffer needs to be updated to reflect the new view size. _swap.BeforeSwapChainResized += Swap_BeforeResized; _swap.AfterSwapChainResized += Swap_AfterResized; // Set the current render target output so we can see something. _graphics.SetRenderTarget(_swap.RenderTargetView, _depthBuffer); // Create our shaders. // Our vertex shader. This is a simple shader, it just processes a vertex by multiplying it against // the world/view/projection matrix and spits it back out. _vertexShader = GorgonShaderFactory.Compile <GorgonVertexShader>(_graphics, Resources.Shader, "BoingerVS"); // Our main pixel shader. This is a very simple shader, it just reads a texture and spits it back out. Has no // diffuse capability. _pixelShader = GorgonShaderFactory.Compile <GorgonPixelShader>(_graphics, Resources.Shader, "BoingerPS"); // Create the vertex input layout. // We need to create a layout for our vertex type because the shader won't know how to interpret the data we're sending it otherwise. // This is why we need a vertex shader before we even create the layout. _inputLayout = GorgonInputLayout.CreateUsingType <BoingerVertex>(_graphics, _vertexShader); // Resources are stored as System.Drawing.Bitmap files, so we need to convert into an IGorgonImage so we can upload it to a texture. // We also will generate mip-map levels for this image so that scaling the texture will look better. using (IGorgonImage image = Resources.Texture.ToGorgonImage()) { _texture = image.ToTexture2D(_graphics, new GorgonTexture2DLoadOptions { Usage = ResourceUsage.Immutable, Name = "Texture" }) .GetShaderResourceView(); } // Create our constant buffer. // Our constant buffers are how we send data to our shaders. This one in particular will be responsible for sending our world/view/projection matrix // to the vertex shader. _wvpBuffer = GorgonConstantBufferView.CreateConstantBuffer(_graphics, new GorgonConstantBufferInfo("WVPBuffer") { Usage = ResourceUsage.Dynamic, SizeInBytes = DX.Matrix.SizeInBytes }); // This one will hold our material information. _materialBuffer = GorgonConstantBufferView.CreateConstantBuffer(_graphics, new GorgonConstantBufferInfo("MaterialBuffer") { Usage = ResourceUsage.Dynamic, SizeInBytes = Unsafe.SizeOf <GorgonColor>() }); GorgonColor defaultMaterialColor = GorgonColor.White; _materialBuffer.Buffer.SetData(ref defaultMaterialColor); GorgonExample.LoadResources(_graphics); }
/// <summary> /// Function to find a display mode supported by the Gorgon. /// </summary> /// <param name="videoModes">The list of video modes to evaluate.</param> /// <param name="output">The output to use when looking for a video mode.</param> /// <param name="videoMode">The <see cref="GorgonVideoMode"/> used to find the closest match.</param> /// <param name="suggestedMode">A <see cref="GorgonVideoMode"/> that is the nearest match for the provided video mode.</param> /// <exception cref="ArgumentNullException">Thrown when the <paramref name="output"/> parameter is <b>null</b>.</exception> /// <remarks> /// <para> /// Users may leave the <see cref="GorgonVideoMode"/> values at unspecified (either 0, or default enumeration values) to indicate that these values should not be used in the search. /// </para> /// <para> /// The following members in <see cref="GorgonVideoMode"/> may be skipped (if not listed, then this member must be specified): /// <list type="bullet"> /// <item> /// <description><see cref="GorgonVideoMode.Width"/> and <see cref="GorgonVideoMode.Height"/>. Both values must be set to 0 if not filtering by width or height.</description> /// </item> /// <item> /// <description><see cref="GorgonVideoMode.RefreshRate"/> should be set to empty in order to skip filtering by refresh rate.</description> /// </item> /// <item> /// <description><see cref="GorgonVideoMode.Scaling"/> should be set to <see cref="ModeScaling.Unspecified"/> in order to skip filtering by the scaling mode.</description> /// </item> /// <item> /// <description><see cref="GorgonVideoMode.ScanlineOrder"/> should be set to <see cref="ModeScanlineOrder.Unspecified"/> in order to skip filtering by the scanline order.</description> /// </item> /// </list> /// </para> /// <para> /// <note type="important"> /// <para> /// The <see cref="GorgonVideoMode.Format"/> member must be one of the UNorm format types and cannot be set to <see cref="BufferFormat.Unknown"/>. /// </para> /// </note> /// </para> /// </remarks> public static void FindNearestVideoMode(this IReadOnlyList <GorgonVideoMode> videoModes, IGorgonVideoOutputInfo output, in GorgonVideoMode videoMode, out GorgonVideoMode suggestedMode)
/// <summary> /// Handles the KeyDown event of the _form control. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="KeyEventArgs"/> instance containing the event data.</param> private static void Form_KeyDown(object sender, KeyEventArgs e) { int ballIncrement = 1; switch (e.KeyCode) { case Keys.Pause: _paused = !_paused; break; case Keys.F1: _showHelp = !_showHelp; break; case Keys.Up: if ((e.Control) && (e.Shift)) { ballIncrement = 1000; } else { if (e.Control) { ballIncrement = 100; } if (e.Shift) { ballIncrement = 10; } } GenerateBalls(ballIncrement); break; case Keys.Down: if ((e.Control) && (e.Shift)) { ballIncrement = 1000; } else { if (e.Control) { ballIncrement = 100; } if (e.Shift) { ballIncrement = 10; } } GenerateBalls(-ballIncrement); break; case Keys.Enter: if (e.Alt) { if (_mainScreen.IsWindowed) { IGorgonVideoOutputInfo output = _graphics.VideoAdapter.Outputs[_window.Handle]; if (output == null) { _mainScreen.EnterFullScreen(); } else { var mode = new GorgonVideoMode(_window.ClientSize.Width, _window.ClientSize.Height, BufferFormat.R8G8B8A8_UNorm); _mainScreen.EnterFullScreen(in mode, output); } } else { _mainScreen.ExitFullScreen(); } } break; case Keys.OemMinus: _blur.BlurRadius--; if (_blur.BlurRadius < 0) { _blur.BlurRadius = 0; } break; case Keys.Oemplus: _blur.BlurRadius++; if (_blur.BlurRadius > _blur.MaximumBlurRadius) { _blur.BlurRadius = _blur.MaximumBlurRadius; } break; } }