/// <summary> /// Function called before a pass is rendered. /// </summary> /// <param name="pass">Pass to render.</param> /// <returns> /// TRUE to continue rendering, FALSE to stop. /// </returns> protected override bool OnBeforePassRender(GorgonEffectPass pass) { if ((_displacementTarget == null) || (_backgroundTarget == null)) { return(false); } if (pass.PassIndex == 0) { base.OnBeforePassRender(pass); Gorgon2D.PixelShader.Current = null; Gorgon2D.VertexShader.Current = null; Gorgon2D.PixelShader.Resources[1] = null; _displacementTarget.Clear(GorgonColor.Transparent); Gorgon2D.Target = _displacementTarget; return(true); } Gorgon2D.PixelShader.Current = pass.PixelShader; Gorgon2D.VertexShader.Current = pass.VertexShader; Gorgon2D.PixelShader.Resources[1] = _displacementTarget; return(true); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.ResizeEnd" /> event. /// </summary> /// <param name="e">A <see cref="T:System.EventArgs" /> that contains the event data.</param> protected override void OnResizeEnd(EventArgs e) { base.OnResizeEnd(e); var currentImageSize = new Size(_backBuffer.Settings.Width, _backBuffer.Settings.Height); // Copy the render target texture to a temporary buffer and resize the main buffer. // The copy the temporary buffer back to the main buffer. _backupImage.CopySubResource(_backBuffer, new Rectangle(Point.Empty, currentImageSize)); _backBuffer.Dispose(); _backBuffer = _graphics.Output.CreateRenderTarget("BackBuffer", new GorgonRenderTarget2DSettings { Width = ClientSize.Width, Height = ClientSize.Height, Format = BufferFormat.R8G8B8A8_UIntNormal }); _backBuffer.Clear(Color.White); _backBuffer.CopySubResource(_backupImage, new Rectangle(0, 0, _backBuffer.Settings.Width, _backBuffer.Settings.Height)); // Set the mouse range to the new size. _mouse.SetPositionRange(0, 0, ClientSize.Width, ClientSize.Height); }
/// <summary> /// Function to render a pass. /// </summary> /// <param name="pass">Pass that is to be rendered.</param> protected override void OnRenderPass(GorgonEffectPass pass) { Gorgon2D.Target = _hTarget; // Render horizontal pass. _hTarget.Clear(GorgonColor.Transparent); _blurBuffer.Update(_xOffsets); // Render the scene. pass.RenderAction(pass); // Render vertical pass. Gorgon2D.Target = _vTarget; _blurBuffer.Update(_yOffsets); _blurSprite.Draw(); }
/// <summary> /// Raises the <see cref="E:System.Windows.Forms.Form.Load"></see> event. /// </summary> /// <param name="e">An <see cref="T:System.EventArgs"></see> that contains the event data.</param> protected override void OnLoad(EventArgs e) { base.OnLoad(e); try { // Load the plug-in assembly. Gorgon.PlugIns.LoadPlugInAssembly(Program.PlugInPath + "Gorgon.Input.Raw.DLL"); // Create the factory. _input = GorgonInputFactory.CreateInputFactory("GorgonLibrary.Input.GorgonRawPlugIn"); // Create mouse, keyboard and joystick interfaces. _keyboard = _input.CreateKeyboard(this); _mouse = _input.CreatePointingDevice(this); _joystickList = new GorgonJoystick[_input.JoystickDevices.Count]; // Create each joystick interface. for (int i = 0; i < _joystickList.Length; i++) { _joystickList[i] = _input.CreateJoystick(this, _input.JoystickDevices[i].Name); } // Create the graphics interface. _graphics = new GorgonGraphics(); _screen = _graphics.Output.CreateSwapChain("Screen", new GorgonSwapChainSettings { Size = Settings.Default.Resolution, Format = BufferFormat.R8G8B8A8_UIntNormal, IsWindowed = Settings.Default.IsWindowed }); // For the backup image. Used to make it as large as the monitor that we're on. Screen currentScreen = Screen.FromHandle(Handle); // Relocate the window to the center of the screen. Location = new Point(currentScreen.Bounds.Left + (currentScreen.WorkingArea.Width / 2) - ClientSize.Width / 2, currentScreen.Bounds.Top + (currentScreen.WorkingArea.Height / 2) - ClientSize.Height / 2); // Create the 2D renderer. _2D = _graphics.Output.Create2DRenderer(_screen); // Create the text font. _font = _graphics.Fonts.CreateFont("Arial_9pt", new GorgonFontSettings { FontFamilyName = "Arial", FontStyle = FontStyle.Bold, AntiAliasingMode = FontAntiAliasMode.AntiAlias, FontHeightMode = FontHeightMode.Points, Size = 9.0f }); // Enable the mouse. Cursor = Cursors.Cross; _mouse.Enabled = true; _mouse.Exclusive = false; _mouse.PointingDeviceDown += MouseInput; _mouse.PointingDeviceMove += MouseInput; _mouse.PointingDeviceWheelMove += _mouse_PointingDeviceWheelMove; // Enable the keyboard. _keyboard.Enabled = true; _keyboard.Exclusive = false; _keyboard.KeyDown += _keyboard_KeyDown; // Create text sprite. _messageSprite = _2D.Renderables.CreateText("Message", _font, "Using mouse and keyboard."); _messageSprite.Color = Color.Black; // Create a back buffer. _backBuffer = _graphics.Output.CreateRenderTarget("BackBuffer", new GorgonRenderTarget2DSettings { Width = _screen.Settings.Width, Height = _screen.Settings.Height, Format = BufferFormat.R8G8B8A8_UIntNormal }); _backBuffer.Clear(Color.White); var settings = new GorgonTexture2DSettings { Width = currentScreen.Bounds.Width, Height = currentScreen.Bounds.Height, Format = BufferFormat.R8G8B8A8_UIntNormal, Usage = BufferUsage.Staging }; // Clear our backup image to white to match our primary screen. _backupImage = _graphics.Textures.CreateTexture("Backup", settings); using (var textureData = _backupImage.Lock(BufferLockFlags.Write)) { textureData.Data.Fill(0xFF); } // Set the mouse range and position. Cursor.Position = PointToScreen(new Point(Settings.Default.Resolution.Width / 2, Settings.Default.Resolution.Height / 2)); _mouse.SetPosition(Settings.Default.Resolution.Width / 2, Settings.Default.Resolution.Height / 2); _mouse.SetPositionRange(0, 0, Settings.Default.Resolution.Width, Settings.Default.Resolution.Height); // Set gorgon events. _screen.AfterStateTransition += (sender, args) => { OnResizeEnd(EventArgs.Empty); // Reposition after a state change. if (!args.IsWindowed) { return; } Screen monitor = Screen.FromHandle(Handle); Location = new Point(monitor.Bounds.Left + (monitor.WorkingArea.Width / 2) - args.Width / 2, monitor.Bounds.Top + (monitor.WorkingArea.Height / 2) - args.Height / 2); Cursor.Position = PointToScreen(Point.Round(_mouse.Position)); }; Gorgon.ApplicationIdleLoopMethod = Gorgon_Idle; } catch (Exception ex) { GorgonException.Catch(ex, () => GorgonDialogs.ErrorBox(this, ex)); Gorgon.Quit(); } }