/// <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; }
protected void EnumerateDevices(GraphicsAdapterInfo adapterInfo, ArrayList adapterFormatList) { DeviceType[] devTypeArray = new DeviceType[] {DeviceType.Hardware, DeviceType.Software, DeviceType.Reference}; foreach (DeviceType devType in devTypeArray) { GraphicsDeviceInfo deviceInfo = new GraphicsDeviceInfo(); deviceInfo.AdapterOrdinal = adapterInfo.AdapterOrdinal; deviceInfo.DevType = devType; try { deviceInfo.Caps = Manager.GetDeviceCaps(adapterInfo.AdapterOrdinal, devType); } catch (DirectXException) { continue; } // Get info for each devicecombo on this device EnumerateDeviceCombos(deviceInfo, adapterFormatList); // If at least one devicecombo for this device is found, // add the deviceInfo to the list if (deviceInfo.DeviceComboList.Count == 0) { continue; } adapterInfo.DeviceInfoList.Add(deviceInfo); } }
/// <summary> /// Init graphics device /// </summary> /// <returns>true if a good device was found, false otherwise</returns> /// protected bool Init() { Log.Debug("D3D: Init()"); // 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); // get display adapter info _enumerationSettings.ConfirmDeviceCallback = ConfirmDevice; _enumerationSettings.Enumerate(); AdapterInfo = FindAdapterForScreen(GUIGraphicsContext.currentScreen); 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); } // Initialize D3D Device InitializeDevice(); return true; }
/// <summary> /// Enumerates available D3D adapters, devices, modes, etc. /// </summary> public void Enumerate() { foreach (AdapterInformation ai in Manager.Adapters) { ArrayList adapterFormatList = new ArrayList(); GraphicsAdapterInfo adapterInfo = new GraphicsAdapterInfo(); adapterInfo.AdapterOrdinal = ai.Adapter; adapterInfo.AdapterDetails = ai.Information; // Get list of all display modes on this adapter. // Also build a temporary list of all display adapter formats. foreach (DisplayMode displayMode in ai.SupportedDisplayModes) { if (displayMode.Width < AppMinFullscreenWidth) { continue; } if (displayMode.Height < AppMinFullscreenHeight) { continue; } if (D3DUtil.GetColorChannelBits(displayMode.Format) < AppMinColorChannelBits) { continue; } adapterInfo.DisplayModeList.Add(displayMode); if (!adapterFormatList.Contains(displayMode.Format)) { adapterFormatList.Add(displayMode.Format); } } // Sort displaymode list DisplayModeComparer dmc = new DisplayModeComparer(); adapterInfo.DisplayModeList.Sort(dmc); // Get info for each device on this adapter EnumerateDevices(adapterInfo, adapterFormatList); // If at least one device on this adapter is available and compatible // with the app, add the adapterInfo to the list if (adapterInfo.DeviceInfoList.Count == 0) { continue; } AdapterInfoList.Add(adapterInfo); } }