/// <summary> /// Init graphics device /// </summary> /// <returns>true if a good device was found, false otherwise</returns> /// protected bool Init() { Log.Debug("D3D: Init()"); // Reset Adapter AdapterInfo = null; // log information about available adapters var enumeration = new D3DEnumeration(); enumeration.Enumerate(); foreach (GraphicsAdapterInfo ai in enumeration.AdapterInfoList) { Log.Debug("D3D: Init Adapter #{0}: {1} - Driver: {2} ({3}) - DeviceName: {4}", ai.AdapterOrdinal, ai.AdapterDetails.Description, ai.AdapterDetails.DriverName, ai.AdapterDetails.DriverVersion, ai.AdapterDetails.DeviceName); } // Set up cursor _renderTarget.Cursor = Cursors.Default; // if our render target is the main window and we haven't said ignore the menus, add our menu if (Windowed) { Menu = _menuStripMain; } // Initialize the application timer DXUtil.Timer(DirectXTimer.Start); int adapIntCount = 0; // get display adapter info OnEnumeration(); // Reset counter adapIntCount = 0; while (AdapterInfo == null && adapIntCount < numberOfRetriesAdaptor) { try { Log.Debug("D3D: Starting and find Adapter info - retry #{0}", adapIntCount); adapIntCount++; AdapterInfo = FindAdapterForScreen(GUIGraphicsContext.currentScreen); if (AdapterInfo == null) { OnEnumeration(); } if (AdapterInfo != null) { Log.Debug("D3D: Starting and find Adapter #{0}: {1} - retry #{2}", AdapterInfo.AdapterOrdinal, AdapterInfo, adapIntCount); } else { Log.Debug("D3D: Adapter info is not detected - retry #{0}", adapIntCount); } } catch (Exception ex) { Log.Error("D3D: Starting and find AdapterInfo exception {0}", ex); AdapterInfo = null; } } if (!Windowed) { Log.Info("D3D: Starting in full screen"); if (AutoHideTaskbar && !MinimizeOnStartup) { HideTaskBar(true); } FormBorderStyle = FormBorderStyle.None; MaximizeBox = false; MinimizeBox = false; Menu = null; var newBounds = GUIGraphicsContext.currentScreen.Bounds; Bounds = newBounds; ClientSize = newBounds.Size; Log.Info("D3D: Client size: {0}x{1} - Screen: {2}x{3}", ClientSize.Width, ClientSize.Height, GUIGraphicsContext.currentScreen.Bounds.Width, GUIGraphicsContext.currentScreen.Bounds.Height); } // Backup bounds when native resolution is not (1024x768) if (GUIGraphicsContext.currentScreen.Bounds.Width != 1024 && GUIGraphicsContext.currentScreen.Bounds.Height != 768) { Log.Debug("D3D: backups screen Bounds {0}", Bounds); _backupBounds = GUIGraphicsContext.currentScreen.Bounds; _backupscreen = GUIGraphicsContext.currentScreen; } if (!successful) { // Initialize D3D Device InitializeDevice(); } return true; }
/// <summary> /// /// </summary> protected virtual void OnEnumeration() { _enumerationSettings = new D3DEnumeration(); int enumIntCount = 0; bool ConfirmDeviceCheck = false; // get display adapter info while (ConfirmDeviceCheck != true && enumIntCount < numberOfRetriesEnum) { try { Log.Debug("D3D: Starting and find Enumeration Settings - retry {0}", enumIntCount); _enumerationSettings.ConfirmDeviceCallback = ConfirmDevice; try { _enumerationSettings.Enumerate(); ConfirmDeviceCheck = true; } catch (Exception ex) { Log.Error("D3D: failed to _enumerationSettings exception {0}", ex); _enumerationSettings = new D3DEnumeration(); } } catch (Exception ex) { Log.Error("D3D: Starting and find _enumerationSettings exception {0}", ex); _enumerationSettings = new D3DEnumeration(); } enumIntCount++; } }