//--------------------------------------------------------------- #endregion //--------------------------------------------------------------- //--------------------------------------------------------------- #region Methods //--------------------------------------------------------------- /// <summary> /// Initializes the GraphicsEngine with the given settings. /// </summary> /// <param name="control">The control to use for graphics output.</param> /// <param name="settings">The settings for initializing the engine.</param> /// <returns>Returns the device object if successful - null otherwise.</returns> public Device Init(Control control, GraphicsSettings settings) { if (Devices.Length <= settings.DeviceIndex) { throw new IndexOutOfRangeException("The GraphicsSettings.DeviceIndex is out of range!"); } this.device = Devices[settings.DeviceIndex]; settings.Control = control; #if DEBUG if (settings.VertexProcessing == VertexProcessing.PureHardware) { settings.VertexProcessing = VertexProcessing.Hardware; } #endif device.Switch(settings); // Preclear screens for (int i = 0; i < 2; i++) { device.BeginScene(); device.Clear(ClearFlags.All); device.EndScene(); device.Present(); } return(device); }
/// <summary> /// Tries to initialize the GraphicsEngine with the given settings and the NVidia Performane HeadUpDisplay. /// </summary> /// <remarks>Some of the GraphicsSettings may be overriden for using the NVPerfHUD. To use this feature, the /// NVPerfHUD must be installed.</remarks> /// <param name="control">The control to use for visualization.</param> /// <param name="settings">The GraphicsSettings for initialization.</param> /// <returns>Returns the device object if successful - null otherwise.</returns> public Device InitNVPerfHud(Control control, GraphicsSettings settings) { for (int i = 0; i < this.Devices.Length; i++) { Device device = this.Devices[i]; if (device.Description == "NVIDIA NVPerfHUD") { if (settings.VertexProcessing == VertexProcessing.PureHardware) { settings.VertexProcessing = VertexProcessing.Hardware; } settings.DeviceType = DeviceType.Reference; settings.DeviceIndex = i; Init(control, settings); return(device); } } Device dev = Init(control, settings); Purple.Log.Warning("Failed to initialize the NVIDIA NVPerfHUD!"); return(dev); }
/// <summary> /// Switches the current graphics mode. /// </summary> /// <param name="settings">The new settings.</param> public void Switch(GraphicsSettings settings) { // Is this our first time we initialize the graphics device? If not cleanup stuff. bool wasInitialized = Control != null; // remove resizing events if (wasInitialized) { Form oldForm = (Control.TopLevelControl as Form); oldForm.Resize -= new EventHandler(OnResizeControl); control.Resize -= new EventHandler(OnResizeControl); } // do we have assigned a new target control? if (settings.Control != null) { this.control = settings.Control; } // if not assign the current one else { settings.Control = this.control; } Form form = (Control.TopLevelControl as Form); form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; if (wasInitialized) { TextureManager.Instance.Release(); } if (device.Switch(settings)) { if (wasInitialized) { TextureManager.Instance.Recreate(); } // reset fullScreen/windowed stuff Control targetControl; if (settings.FullScreen) { targetControl = form; form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; } else { targetControl = control; form.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Sizable; } if (!form.Visible) { form.Show(); // necessay to prevent OutOfMemoryException when assigning: pp.DeviceWindow = form; } form.Left = 0; form.Top = 0; form.ClientSize = new System.Drawing.Size(settings.Width, settings.Height); targetControl.Resize += new EventHandler(OnResizeControl); Viewport = new Viewport(0, 0, targetControl.ClientSize.Width, targetControl.ClientSize.Height); Purple.Log.Spam("Device was (re)created - groovy!"); } else { Purple.Log.Spam("Couldn't creat device!"); } }