From f257f614121329f716eabae558900e950c61e30a Mon Sep 17 00:00:00 2001 From: nitsuja Date: Sat, 28 Nov 2009 23:30:55 +0000 Subject: [PATCH] switching the renderer to SoftRasterizer instead of None in the case that the OpenGL renderer fails --- desmume/src/render3D.cpp | 4 +++- desmume/src/render3D.h | 2 +- desmume/src/windows/hotkey.cpp | 3 +-- desmume/src/windows/main.cpp | 27 ++++++++++++++++++++------- desmume/src/windows/main.h | 2 ++ 5 files changed, 27 insertions(+), 11 deletions(-) diff --git a/desmume/src/render3D.cpp b/desmume/src/render3D.cpp index 03650a2f0..1618e962e 100644 --- a/desmume/src/render3D.cpp +++ b/desmume/src/render3D.cpp @@ -42,7 +42,7 @@ void NDS_3D_SetDriver (int core3DIndex) gpu3D = core3DList[cur3DCore]; } -void NDS_3D_ChangeCore(int newCore) +bool NDS_3D_ChangeCore(int newCore) { gpu3D->NDS_3D_Close(); NDS_3D_SetDriver(newCore); @@ -50,5 +50,7 @@ void NDS_3D_ChangeCore(int newCore) { NDS_3D_SetDriver(GPU3D_NULL); gpu3D->NDS_3D_Init(); + return false; } + return true; } diff --git a/desmume/src/render3D.h b/desmume/src/render3D.h index 877afa4d8..5a8c9af9c 100644 --- a/desmume/src/render3D.h +++ b/desmume/src/render3D.h @@ -61,7 +61,7 @@ extern GPU3DInterface gpu3DNull; extern GPU3DInterface *gpu3D; void NDS_3D_SetDriver (int core3DIndex); -void NDS_3D_ChangeCore(int newCore); +bool NDS_3D_ChangeCore(int newCore); #endif diff --git a/desmume/src/windows/hotkey.cpp b/desmume/src/windows/hotkey.cpp index 2d8d2449c..b58058a3d 100644 --- a/desmume/src/windows/hotkey.cpp +++ b/desmume/src/windows/hotkey.cpp @@ -378,8 +378,7 @@ void HK_ToggleRasterizer(int, bool justPressed) { cur3DCore = GPU3D_SWRAST; else cur3DCore = GPU3D_OPENGL; - NDS_3D_ChangeCore(cur3DCore); - WritePrivateProfileInt("3D", "Renderer", cur3DCore, IniName); + Change3DCoreWithFallbackAndSave(cur3DCore); } //====================================================================================== diff --git a/desmume/src/windows/main.cpp b/desmume/src/windows/main.cpp index 32e96abfa..2477ab920 100644 --- a/desmume/src/windows/main.cpp +++ b/desmume/src/windows/main.cpp @@ -2134,6 +2134,9 @@ static void RefreshMicSettings() } } +#define GPU3D_NULL_SAVED -1 +#define GPU3D_DEFAULT GPU3D_OPENGL + DWORD wmTimerRes; int _main() { @@ -2471,12 +2474,16 @@ int _main() hKeyInputTimer = timeSetEvent (KeyInRepeatMSec, 0, KeyInputTimer, 0, TIME_PERIODIC); - cur3DCore = GetPrivateProfileInt("3D", "Renderer", GPU3D_OPENGL, IniName); + cur3DCore = GetPrivateProfileInt("3D", "Renderer", GPU3D_DEFAULT, IniName); + if(cur3DCore == GPU3D_NULL_SAVED) + cur3DCore = GPU3D_NULL; + else if(cur3DCore == GPU3D_NULL) // this value shouldn't be saved anymore + cur3DCore = GPU3D_DEFAULT; CommonSettings.GFX3D_HighResolutionInterpolateColor = GetPrivateProfileBool("3D", "HighResolutionInterpolateColor", 1, IniName); CommonSettings.GFX3D_EdgeMark = GetPrivateProfileBool("3D", "EnableEdgeMark", 1, IniName); CommonSettings.GFX3D_Fog = GetPrivateProfileBool("3D", "EnableFog", 1, IniName); //CommonSettings.gfx3d_flushMode = GetPrivateProfileInt("3D", "AlternateFlush", 0, IniName); - NDS_3D_ChangeCore(cur3DCore); + Change3DCoreWithFallbackAndSave(cur3DCore); #ifdef BETA_VERSION EnableMenuItem (mainMenu, IDM_SUBMITBUGREPORT, MF_GRAYED); @@ -4991,6 +4998,14 @@ LRESULT CALLBACK WindowProcedure (HWND hwnd, UINT message, WPARAM wParam, LPARAM return DefWindowProc (hwnd, message, wParam, lParam); } +void Change3DCoreWithFallbackAndSave(int newCore, int fallbackCore) +{ + if(!NDS_3D_ChangeCore(newCore) && newCore != fallbackCore) + NDS_3D_ChangeCore(fallbackCore); + int gpu3dSaveValue = ((cur3DCore != GPU3D_NULL) ? cur3DCore : GPU3D_NULL_SAVED); + WritePrivateProfileInt("3D", "Renderer", gpu3dSaveValue, IniName); +} + LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) { switch(msg) @@ -5021,8 +5036,7 @@ LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) CommonSettings.GFX3D_HighResolutionInterpolateColor = IsDlgCheckboxChecked(hw,IDC_INTERPOLATECOLOR); CommonSettings.GFX3D_EdgeMark = IsDlgCheckboxChecked(hw,IDC_3DSETTINGS_EDGEMARK); CommonSettings.GFX3D_Fog = IsDlgCheckboxChecked(hw,IDC_3DSETTINGS_FOG); - NDS_3D_ChangeCore(ComboBox_GetCurSel(GetDlgItem(hw, IDC_3DCORE))); - WritePrivateProfileInt("3D", "Renderer", cur3DCore, IniName); + Change3DCoreWithFallbackAndSave(ComboBox_GetCurSel(GetDlgItem(hw, IDC_3DCORE))); WritePrivateProfileInt("3D", "HighResolutionInterpolateColor", CommonSettings.GFX3D_HighResolutionInterpolateColor?1:0, IniName); WritePrivateProfileInt("3D", "EnableEdgeMark", CommonSettings.GFX3D_EdgeMark?1:0, IniName); WritePrivateProfileInt("3D", "EnableFog", CommonSettings.GFX3D_Fog?1:0, IniName); @@ -5037,9 +5051,8 @@ LRESULT CALLBACK GFX3DSettingsDlgProc(HWND hw, UINT msg, WPARAM wp, LPARAM lp) case IDC_DEFAULT: { - NDS_3D_ChangeCore(GPU3D_OPENGL); - ComboBox_SetCurSel(GetDlgItem(hw, IDC_3DCORE), GPU3D_OPENGL); - WritePrivateProfileInt("3D", "Renderer", GPU3D_OPENGL, IniName); + Change3DCoreWithFallbackAndSave(GPU3D_DEFAULT); + ComboBox_SetCurSel(GetDlgItem(hw, IDC_3DCORE), cur3DCore); //CommonSettings.gfx3d_flushMode = 0; //WritePrivateProfileInt("3D", "AlternateFlush", CommonSettings.gfx3d_flushMode, IniName); } diff --git a/desmume/src/windows/main.h b/desmume/src/windows/main.h index 2f730455b..065ae5396 100644 --- a/desmume/src/windows/main.h +++ b/desmume/src/windows/main.h @@ -27,6 +27,8 @@ extern bool ShowLagFrameCounter; #define GPU3D_OPENGL 1 #define GPU3D_SWRAST 2 +extern void Change3DCoreWithFallbackAndSave(int newCore, int fallbackCore=GPU3D_SWRAST); + extern int backupmemorytype; extern u32 backupmemorysize;