From eb8e1c04219444d24c45ed59ba9de4d2f58c58ed Mon Sep 17 00:00:00 2001 From: jarmonik Date: Tue, 9 Jan 2024 11:10:05 +0200 Subject: [PATCH] Cleaned up video configuration, added message box for failed device creation. --- OVP/D3D9Client/D3D9Client.cpp | 9 +++++---- OVP/D3D9Client/D3D9Frame.cpp | 4 ++-- OVP/D3D9Client/Log.cpp | 9 +++++++++ OVP/D3D9Client/Log.h | 1 + OVP/D3D9Client/VideoTab.cpp | 17 ++++++++++------- OVP/D3D9Client/VideoTab.h | 1 - Orbitersdk/include/GraphicsAPI.h | 10 ++++++---- Src/Orbiter/Config.cpp | 7 +++++++ Src/Orbiter/Config.h | 2 ++ Src/Orbiter/GraphicsAPI.cpp | 4 ++++ Src/Orbiter/TabVideo.cpp | 4 ++++ 11 files changed, 50 insertions(+), 18 deletions(-) diff --git a/OVP/D3D9Client/D3D9Client.cpp b/OVP/D3D9Client/D3D9Client.cpp index dbdc78bc9..4a459431f 100644 --- a/OVP/D3D9Client/D3D9Client.cpp +++ b/OVP/D3D9Client/D3D9Client.cpp @@ -195,16 +195,16 @@ DLLCLBK void ExitModule(HINSTANCE hDLL) delete TileCatalog; delete Config; delete g_pConst; - delete g_client; - - DebugControls::Release(); - AtmoControls::Release(); if (g_client) { oapiUnregisterGraphicsClient(g_client); + delete g_client; g_client = 0; } + DebugControls::Release(); + AtmoControls::Release(); + #ifdef _NVAPI_H if (bNVAPI) if (NvAPI_Unload()==NVAPI_OK) LogAlw("[nVidia API Unloaded]"); #endif @@ -330,6 +330,7 @@ bool D3D9Client::clbkInitialise() } else { oapiWriteLog("[D3D9][ERROR] Failed to create DirectX9"); + FailedDeviceError(); return false; } diff --git a/OVP/D3D9Client/D3D9Frame.cpp b/OVP/D3D9Client/D3D9Frame.cpp index d61333fb8..d31bc5a83 100644 --- a/OVP/D3D9Client/D3D9Frame.cpp +++ b/OVP/D3D9Client/D3D9Frame.cpp @@ -156,10 +156,10 @@ HRESULT CD3DFramework9::Initialize(HWND _hWnd, GraphicsClient::VIDEODATA *vData) bAAEnabled = (Config->SceneAntialias != 0); bIsFullscreen = vData->fullscreen; bNoVSync = vData->novsync; - dwFSMode = (vData->modeidx>>8)&0xFF; + dwFSMode = vData->style; bGDIBB = vData->trystencil; Adapter = vData->deviceidx; - Mode = vData->modeidx&0xFF; + Mode = vData->modeidx; LogAlw("[VideoConfiguration] Adapter=%u, ModeIndex=%u", Adapter, Mode); diff --git a/OVP/D3D9Client/Log.cpp b/OVP/D3D9Client/Log.cpp index ac8e1152b..2a8a9f86d 100644 --- a/OVP/D3D9Client/Log.cpp +++ b/OVP/D3D9Client/Log.cpp @@ -59,6 +59,15 @@ void MissingRuntimeError() "D3D9Client Initialization Failed", MB_OK); } +//------------------------------------------------------------------------------------------- +// +void FailedDeviceError() +{ + MessageBoxA(NULL, + "DirectX9 Device Failed. Try to enable EnableDX12Wrapper from D3D9Client.cfg", + "D3D9Client Initialization Failed", MB_OK); +} + //------------------------------------------------------------------------------------------- // void RuntimeError(const char* File, const char* Fnc, UINT Line) diff --git a/OVP/D3D9Client/Log.h b/OVP/D3D9Client/Log.h index ad115f36d..9b8b325fd 100644 --- a/OVP/D3D9Client/Log.h +++ b/OVP/D3D9Client/Log.h @@ -64,6 +64,7 @@ double D3D9GetTime(); void D3D9SetTime(D3D9Time &inout, double ref); void MissingRuntimeError(); +void FailedDeviceError(); void LogAttribs(DWORD attrib, DWORD w, DWORD h, LPCSTR origin); #define HALT() { RuntimeError(__FILE__,__FUNCTION__,__LINE__); } diff --git a/OVP/D3D9Client/VideoTab.cpp b/OVP/D3D9Client/VideoTab.cpp index 3fa9e411b..265dc2dcc 100644 --- a/OVP/D3D9Client/VideoTab.cpp +++ b/OVP/D3D9Client/VideoTab.cpp @@ -169,7 +169,7 @@ bool VideoTab::Initialise() data->trystencil = false; SendDlgItemMessage(hTab, IDC_VID_DEVICE, CB_RESETCONTENT, 0, 0); - SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0); + SendDlgItemMessage(hTab, IDC_VID_MODE, CB_RESETCONTENT, 0, 0); SendDlgItemMessage(hTab, IDC_VID_BPP, CB_RESETCONTENT, 0, 0); ScanAtmoCfgs(); @@ -179,6 +179,7 @@ bool VideoTab::Initialise() if (nAdapter == 0) { LogErr("VideoTab::Initialize() No DirectX9 Adapters Found"); + FailedDeviceError(); return false; } @@ -201,6 +202,7 @@ bool VideoTab::Initialise() if (nModes == 0) { LogErr("VideoTab::Initialize() No Display Modes Available"); + FailedDeviceError(); } for (UINT k=0;kmodeidx>>8)&0xFF, 0); + SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_SETCURSEL, data->style, 0); //SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC5), "Resolution"); SetWindowText(GetDlgItem(hTab, IDC_VID_STATIC6), "Full Screen Mode"); - SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0); + SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx, 0); SendDlgItemMessage(hTab, IDC_VID_VSYNC, BM_SETCHECK, data->novsync ? BST_CHECKED : BST_UNCHECKED, 0); SetWindowText(GetDlgItem(hTab, IDC_VID_WIDTH), std::to_string(data->winw).c_str()); @@ -258,7 +260,7 @@ void VideoTab::SelectMode(DWORD index) { GraphicsClient::VIDEODATA *data = gclient->GetVideoData(); SendDlgItemMessage(hTab, IDC_VID_MODE, CB_GETITEMDATA, index, 0); - data->modeidx = index + data->modeidx&0xFF00; + data->modeidx = index; } @@ -303,7 +305,7 @@ bool VideoTab::SelectAdapter(DWORD index) SendDlgItemMessageA(hTab, IDC_VID_MODE, CB_SETITEMDATA, k, (LPARAM)(mode.Height<<16 | mode.Width)); } - SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx&0xFF, 0); + SendDlgItemMessage(hTab, IDC_VID_MODE, CB_SETCURSEL, data->modeidx, 0); } return true; @@ -395,8 +397,9 @@ void VideoTab::UpdateConfigData() GraphicsClient::VIDEODATA *data = gclient->GetVideoData(); // device parameters - data->deviceidx = (int)SendDlgItemMessageA(hTab, IDC_VID_DEVICE, CB_GETCURSEL, 0, 0); - data->modeidx = (int)SendDlgItemMessage(hTab, IDC_VID_MODE, CB_GETCURSEL, 0, 0) + ((int)SendDlgItemMessageA(hTab, IDC_VID_BPP, CB_GETCURSEL, 0, 0)<<8); + data->deviceidx = (int)SendDlgItemMessage (hTab, IDC_VID_DEVICE, CB_GETCURSEL, 0, 0); + data->modeidx = (int)SendDlgItemMessage (hTab, IDC_VID_MODE, CB_GETCURSEL, 0, 0); + data->style = SendDlgItemMessage (hTab, IDC_VID_BPP, CB_GETCURSEL, 0, 0); data->fullscreen = (SendDlgItemMessage (hTab, IDC_VID_FULL, BM_GETCHECK, 0, 0) == BST_CHECKED); data->novsync = (SendDlgItemMessage (hTab, IDC_VID_VSYNC, BM_GETCHECK, 0, 0) == BST_CHECKED); data->pageflip = (SendDlgItemMessage (hTab, IDC_VID_PAGEFLIP, BM_GETCHECK, 0, 0) == BST_CHECKED); diff --git a/OVP/D3D9Client/VideoTab.h b/OVP/D3D9Client/VideoTab.h index 4ef007625..db101440b 100644 --- a/OVP/D3D9Client/VideoTab.h +++ b/OVP/D3D9Client/VideoTab.h @@ -51,7 +51,6 @@ class VideoTab { void SaveSetupState(HWND hWnd); void ScanAtmoCfgs(); bool GetConfigName(const char* file, string& cfg, string& planet); - void LoadAtmoCfg(); oapi::D3D9Client *gclient; HINSTANCE hOrbiterInst; // orbiter instance handle diff --git a/Orbitersdk/include/GraphicsAPI.h b/Orbitersdk/include/GraphicsAPI.h index cbe6bcad3..114436b34 100644 --- a/Orbitersdk/include/GraphicsAPI.h +++ b/Orbitersdk/include/GraphicsAPI.h @@ -836,10 +836,12 @@ class OAPIFUNC GraphicsClient: public Module { bool trystencil; ///< stencil buffer flag bool novsync; ///< no vsync flag bool pageflip; ///< allow page flipping in fullscreen - int deviceidx; ///< video device index - int modeidx; ///< video mode index - int winw; ///< window width - int winh; ///< window height + int deviceidx; ///< video device (adapter) index + int modeidx; ///< video mode index (fullscreen resolution) + int winw; ///< window/screen width + int winh; ///< window/screen height + int outputidx; ///< video output + int style; ///< true fullscreen, fulscreen window, window with taskbar }; /** diff --git a/Src/Orbiter/Config.cpp b/Src/Orbiter/Config.cpp index a9218226d..c03b7312d 100644 --- a/Src/Orbiter/Config.cpp +++ b/Src/Orbiter/Config.cpp @@ -180,6 +180,8 @@ CFG_RECPLAYPRM CfgRecPlayPrm_default = { CFG_DEVPRM CfgDevPrm_default = { -1, // Device_idx (-1=undefined) 0, // Device_mode + 0, + 0, true, // bForceEnum (enumerate devices at each simulation start) false, // bFullscreen (default to window mode) false, // bStereo (no stereo support) @@ -515,6 +517,8 @@ bool Config::Load(const char *fname) // Device information GetInt (ifs, "DeviceIndex", CfgDevPrm.Device_idx); if (GetInt (ifs, "ModeIndex", i)) CfgDevPrm.Device_mode = (DWORD)i; + if (GetInt(ifs, "OutputIndex", i)) CfgDevPrm.Device_out = (DWORD)i; + if (GetInt(ifs, "Style", i)) CfgDevPrm.Device_style = (DWORD)i; GetBool (ifs, "DeviceForceEnum", CfgDevPrm.bForceEnum); GetBool (ifs, "Fullscreen", CfgDevPrm.bFullscreen); GetBool (ifs, "Stereo", CfgDevPrm.bStereo); @@ -1219,6 +1223,9 @@ BOOL Config::Write (const char *fname) const ofs << "\n; === Device settings ===\n"; ofs << "DeviceIndex = " << CfgDevPrm.Device_idx << '\n'; ofs << "ModeIndex = " << CfgDevPrm.Device_mode << '\n'; + ofs << "OutputIndex" << CfgDevPrm.Device_out << '\n'; + ofs << "Style" << CfgDevPrm.Device_style << '\n'; + if (CfgDevPrm.bForceEnum != CfgDevPrm_default.bForceEnum || bEchoAll) ofs << "DeviceForceEnum = " << BoolStr (CfgDevPrm.bForceEnum) << '\n'; if (CfgDevPrm.bFullscreen != CfgDevPrm_default.bFullscreen || bEchoAll) diff --git a/Src/Orbiter/Config.h b/Src/Orbiter/Config.h index bc1a2f22c..2796610f5 100644 --- a/Src/Orbiter/Config.h +++ b/Src/Orbiter/Config.h @@ -205,6 +205,8 @@ struct CFG_RECPLAYPRM { struct CFG_DEVPRM { int Device_idx; // index of default device DWORD Device_mode; // index of default fullscreen mode + DWORD Device_out; // device output + DWORD Device_style; // Rendering layout bool bForceEnum; // force enumeration, bypass device.dat bool bFullscreen; // use window mode bool bStereo; // use stereo mode diff --git a/Src/Orbiter/GraphicsAPI.cpp b/Src/Orbiter/GraphicsAPI.cpp index 8fd818197..f9a6d9921 100644 --- a/Src/Orbiter/GraphicsAPI.cpp +++ b/Src/Orbiter/GraphicsAPI.cpp @@ -48,6 +48,8 @@ GraphicsClient::GraphicsClient (HINSTANCE hInstance): Module (hInstance) VideoData.pageflip = true; VideoData.deviceidx = -1; VideoData.modeidx = 0; + VideoData.outputidx = 0; + VideoData.style = 1; VideoData.winw = 1024; VideoData.winh = 768; surfBltTgt = RENDERTGT_NONE; @@ -98,6 +100,8 @@ bool GraphicsClient::clbkInitialise () VideoData.novsync = cfg->CfgDevPrm.bNoVsync; VideoData.pageflip = cfg->CfgDevPrm.bPageflip; VideoData.deviceidx = cfg->CfgDevPrm.Device_idx; + VideoData.outputidx = cfg->CfgDevPrm.Device_out; + VideoData.style = cfg->CfgDevPrm.Device_style; VideoData.modeidx = (int)cfg->CfgDevPrm.Device_mode; VideoData.winw = (int)cfg->CfgDevPrm.WinW; VideoData.winh = (int)cfg->CfgDevPrm.WinH; diff --git a/Src/Orbiter/TabVideo.cpp b/Src/Orbiter/TabVideo.cpp index b6e6acbd6..3e56f8b9d 100644 --- a/Src/Orbiter/TabVideo.cpp +++ b/Src/Orbiter/TabVideo.cpp @@ -127,6 +127,8 @@ void orbiter::DefVideoTab::SetConfig (Config *cfg) cfg->CfgDevPrm.WinH = data->winh; cfg->CfgDevPrm.Device_idx = data->deviceidx; cfg->CfgDevPrm.Device_mode = data->modeidx; + cfg->CfgDevPrm.Device_out = data->outputidx; + cfg->CfgDevPrm.Device_style= data->style; } else { // should not be required cfg->CfgDevPrm.bFullscreen = false; @@ -138,6 +140,8 @@ void orbiter::DefVideoTab::SetConfig (Config *cfg) cfg->CfgDevPrm.WinH = 300; cfg->CfgDevPrm.Device_idx = 0; cfg->CfgDevPrm.Device_mode = 0; + cfg->CfgDevPrm.Device_out = 0; + cfg->CfgDevPrm.Device_style= 1; } cfg->CfgDevPrm.bStereo = false; // not currently set }