void device_DeviceReset(object sender, EventArgs e) { if (DeviceReset != null) { DeviceReset.Invoke(sender, e); } }
public void ResetDevice(int width, int height) { DeviceResetting?.Invoke(this, EventArgs.Empty); _parameters.BackBufferWidth = Math.Max(_parameters.BackBufferWidth, width); _parameters.BackBufferHeight = Math.Max(_parameters.BackBufferHeight, height); GraphicsDevice.Reset(_parameters); DeviceReset?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Resets the graphics device to whichever is bigger out of the specified /// resolution or its current size. This behavior means the device will /// demand-grow to the largest of all its GraphicsDeviceControl clients. /// </summary> public void ResetDevice(int width, int height) { DeviceResetting?.Invoke(this, EventArgs.Empty); parameters.BackBufferWidth = Math.Max(parameters.BackBufferWidth, width); parameters.BackBufferHeight = Math.Max(parameters.BackBufferHeight, height); // TODO Replacement for this ? //graphicsDevice.Reset(parameters); DeviceReset?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Saves the current screen at a scaled resolution /// </summary> /// <param name="filename">The file name to save the screenshot too</param> /// <param name="size">The size to scale the resolution down too</param> public void Screenshot(string filename, Size size) { #region Sanity checks if (filename == null) { throw new ArgumentNullException(nameof(filename)); } #endregion if (size.Width > RenderSize.Width || size.Height > RenderSize.Height) { throw new ArgumentException(Resources.InvalidScreenshotSize, nameof(size)); } // Backup PostRender delegate and deactiavte it Action postRender = PreRender; PreRender = null; var sizeBackup = new Size(); if (size != RenderSize) { // The size needs to be changed // Backup current size and replace it with new size sizeBackup = RenderSize; RenderSize = size; // Update everything hooked to the engine DeviceLost?.Invoke(); DeviceReset?.Invoke(); } // Render one frame for screenshot Render(0, true); // Copy the BackBuffer to the file Surface.ToFile(BackBuffer, filename, ImageFileFormat.Jpg, new Rectangle(new Point(), size)); Log.Info("Screenshot created"); if (sizeBackup != Size.Empty) { // The size was changed // Restore the original viewport RenderSize = sizeBackup; // Update everything hooked to the engine DeviceLost?.Invoke(); DeviceReset?.Invoke(); // Render one frame to restore original configuration Render(0, true); } // Restore PostRender delegate PreRender = postRender; }
/// <summary> /// Resets the graphics device to whichever is bigger out of the specified /// resolution or its current size. This behavior means the device will /// demand-grow to the largest of all its GraphicsDeviceControl clients. /// </summary> public void ResetDevice(int width, int height) { if (DeviceResetting != null) { DeviceResetting(this, EventArgs.Empty); } parameters.BackBufferWidth = Math.Max(parameters.BackBufferWidth, width); parameters.BackBufferHeight = Math.Max(parameters.BackBufferHeight, height); //graphicsDevice.Reset(parameters); DeviceReset?.Invoke(this, EventArgs.Empty); }
/// <summary> /// Resets the engine /// </summary> private void Reset() { // Set flag to prevent infinite loop of resets _isResetting = true; #region Cleanup Log.Info("Clearing Direct3D resources"); BackBuffer.Dispose(); DeviceLost?.Invoke(); #endregion #region Wait // Wait in case the device isn't ready to be reset while (Device.TestCooperativeLevel() == ResultCode.DeviceLost) { Thread.Sleep(100); WinForms.Application.DoEvents(); } // Catch internal driver errors var result = Device.TestCooperativeLevel(); if (result != ResultCode.DeviceNotReset && result != ResultCode.Success) { throw new Direct3D9Exception(result); } #endregion #region Reset Log.Info("Resetting Direct3D device"); Log.Info("Presentation parameters:\n" + PresentParams); Device.Reset(PresentParams); // Setup the default values for the Direct3D device and restore resources SetupTextureFiltering(); RenderViewport = Device.Viewport; BackBuffer = Device.GetBackBuffer(0, 0); DeviceReset?.Invoke(); State.Reset(); Performance.Reset(); #endregion _isResetting = NeedsReset = false; }
/// <summary> /// Resets the graphics device to whichever is bigger out of the specified /// resolution or its current size. This behavior means the device will /// demand-grow to the largest of all its GraphicsDeviceControl clients. /// </summary> public void ResetDevice(int width, int height) { var newWidth = Math.Max(_parameters.BackBufferWidth, width); var newHeight = Math.Max(_parameters.BackBufferHeight, height); if (newWidth != _parameters.BackBufferWidth || newHeight != _parameters.BackBufferHeight) { DeviceResetting?.Invoke(this, EventArgs.Empty); _parameters.BackBufferWidth = newWidth; _parameters.BackBufferHeight = newHeight; GraphicsDevice.Reset(_parameters); DeviceReset?.Invoke(this, EventArgs.Empty); GraphicsDevice.PresentationParameters.RenderTargetUsage = RenderTargetUsage.PreserveContents; } }
/// <summary> /// Create a new instance of the dummy. The constructor will autom. add the instance itself to the <see cref="D3D11Host.Services"/> container of <see cref="host"/>. /// </summary> /// <param name="host"></param> public WpfGraphicsDeviceService(WpfGame host) { _host = host ?? throw new ArgumentNullException(nameof(host)); if (host.Services.GetService(typeof(IGraphicsDeviceService)) != null) { throw new NotSupportedException("A graphics device service is already registered."); } if (host.GraphicsDevice == null) { throw new ArgumentException("Provided host graphics device is null."); } GraphicsDevice = host.GraphicsDevice; _host.GraphicsDevice.DeviceReset += (sender, args) => DeviceReset?.Invoke(this, args); _host.GraphicsDevice.DeviceResetting += (sender, args) => DeviceResetting?.Invoke(this, args); host.Services.AddService(typeof(IGraphicsDeviceService), this); host.Services.AddService(typeof(IGraphicsDeviceManager), this); }
protected virtual void OnDeviceReset(object sender, EventArgs args) { DeviceReset?.Invoke(sender, args); }
public void ResetDevice(int width, int height) { DeviceResetting?.Invoke(this, EventArgs.Empty); DeviceReset?.Invoke(this, EventArgs.Empty); }
internal void OnDeviceReset(EventArgs e) => DeviceReset?.Invoke(this, e);
// FIXME: Why does the GraphicsDeviceManager not know enough about the // GraphicsDevice to raise these events without help? internal void OnDeviceReset() { DeviceReset?.Invoke(this); }
} // Initialize #endregion #region On Device Reset /// <summary> /// If the device is recreated then the controls have to be invalidated so that they redraw. /// </summary> private static void OnDeviceReset(object sender, System.EventArgs e) { if (DeviceReset != null) DeviceReset.Invoke(sender, new EventArgs()); } // OnPrepareGraphicsDevice
protected virtual void OnDeviceReset(EventArgs e) { DeviceReset?.Invoke(this, e); }
private void GraphicsDevice_DeviceReset(object sender, EventArgs e) { DeviceReset?.Invoke(this, e); }