Advertisement
Guest User

VideoConfig.cpp

a guest
Dec 19th, 2012
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.14 KB | None | 0 0
  1. // Copyright (C) 2003 Dolphin Project.
  2.  
  3. // This program is free software: you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation, version 2.0.
  6.  
  7. // This program is distributed in the hope that it will be useful,
  8. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. // GNU General Public License 2.0 for more details.
  11.  
  12. // A copy of the GPL 2.0 should have been included with the program.
  13. // If not, see http://www.gnu.org/licenses/
  14.  
  15. // Official SVN repository and contact information can be found at
  16. // http://code.google.com/p/dolphin-emu/
  17.  
  18. #include <cmath>
  19.  
  20. #include "Common.h"
  21. #include "IniFile.h"
  22. #include "VideoConfig.h"
  23. #include "VideoCommon.h"
  24. #include "FileUtil.h"
  25.  
  26. VideoConfig g_Config;
  27. VideoConfig g_ActiveConfig;
  28.  
  29. void UpdateActiveConfig()
  30. {
  31. g_ActiveConfig = g_Config;
  32. }
  33.  
  34. VideoConfig::VideoConfig()
  35. {
  36. bRunning = false;
  37.  
  38. // Needed for the first frame, I think
  39. fAspectRatioHackW = 1;
  40. fAspectRatioHackH = 1;
  41.  
  42. // disable all features by default
  43. backend_info.APIType = API_NONE;
  44. backend_info.bUseRGBATextures = false;
  45. backend_info.bSupports3DVision = false;
  46. }
  47.  
  48. void VideoConfig::Load(const char *ini_file)
  49. {
  50. std::string temp;
  51. IniFile iniFile;
  52. iniFile.Load(ini_file);
  53.  
  54. iniFile.Get("Hardware", "VSync", &bVSync, 0); // Hardware
  55. iniFile.Get("Settings", "wideScreenHack", &bWidescreenHack, false);
  56. iniFile.Get("Settings", "AspectRatio", &iAspectRatio, (int)ASPECT_AUTO);
  57. iniFile.Get("Settings", "Crop", &bCrop, false);
  58. iniFile.Get("Settings", "UseXFB", &bUseXFB, 0);
  59. iniFile.Get("Settings", "UseRealXFB", &bUseRealXFB, 0);
  60. iniFile.Get("Settings", "SafeTextureCacheColorSamples", &iSafeTextureCache_ColorSamples,128);
  61. iniFile.Get("Settings", "ShowFPS", &bShowFPS, false); // Settings
  62. iniFile.Get("Settings", "LogFPSToFile", &bLogFPSToFile, false);
  63. iniFile.Get("Settings", "ShowInputDisplay", &bShowInputDisplay, false);
  64. iniFile.Get("Settings", "OverlayStats", &bOverlayStats, false);
  65. iniFile.Get("Settings", "OverlayProjStats", &bOverlayProjStats, false);
  66. iniFile.Get("Settings", "ShowEFBCopyRegions", &bShowEFBCopyRegions, false);
  67. iniFile.Get("Settings", "DLOptimize", &iCompileDLsLevel, 0);
  68. iniFile.Get("Settings", "DumpTextures", &bDumpTextures, 0);
  69. iniFile.Get("Settings", "HiresTextures", &bHiresTextures, 0);
  70. iniFile.Get("Settings", "DumpEFBTarget", &bDumpEFBTarget, 0);
  71. iniFile.Get("Settings", "DumpFrames", &bDumpFrames, 0);
  72. iniFile.Get("Settings", "FreeLook", &bFreeLook, 0);
  73. iniFile.Get("Settings", "UseFFV1", &bUseFFV1, 0);
  74. iniFile.Get("Settings", "AnaglyphStereo", &bAnaglyphStereo, false);
  75. iniFile.Get("Settings", "AnaglyphStereoSeparation", &iAnaglyphStereoSeparation, 200);
  76. iniFile.Get("Settings", "AnaglyphFocalAngle", &iAnaglyphFocalAngle, 0);
  77. iniFile.Get("Settings", "EnablePixelLighting", &bEnablePixelLighting, 0);
  78. iniFile.Get("Settings", "EnablePerPixelDepth", &bEnablePerPixelDepth, 0);
  79.  
  80. iniFile.Get("Settings", "MSAA", &iMultisampleMode, 0);
  81. iniFile.Get("Settings", "EFBScale", &iEFBScale, 2); // native
  82.  
  83. iniFile.Get("Settings", "DstAlphaPass", &bDstAlphaPass, false);
  84.  
  85. iniFile.Get("Settings", "TexFmtOverlayEnable", &bTexFmtOverlayEnable, 0);
  86. iniFile.Get("Settings", "TexFmtOverlayCenter", &bTexFmtOverlayCenter, 0);
  87. iniFile.Get("Settings", "WireFrame", &bWireFrame, 0);
  88. <<<<<<< HEAD
  89. =======
  90. iniFile.Get("Settings", "DisableLighting", &bDisableLighting, 0);
  91. iniFile.Get("Settings", "DisableTexturing", &bDisableTexturing, 0);
  92. >>>>>>> parent of 1dd6b97... Remove "Disable Lighting".
  93. iniFile.Get("Settings", "DisableFog", &bDisableFog, 0);
  94.  
  95. iniFile.Get("Settings", "EnableOpenCL", &bEnableOpenCL, false);
  96. iniFile.Get("Settings", "OMPDecoder", &bOMPDecoder, false);
  97.  
  98. iniFile.Get("Settings", "EnableShaderDebugging", &bEnableShaderDebugging, false);
  99.  
  100. iniFile.Get("Enhancements", "ForceFiltering", &bForceFiltering, 0);
  101. iniFile.Get("Enhancements", "MaxAnisotropy", &iMaxAnisotropy, 0); // NOTE - this is x in (1 << x)
  102. iniFile.Get("Enhancements", "PostProcessingShader", &sPostProcessingShader, "");
  103. iniFile.Get("Enhancements", "Enable3dVision", &b3DVision, false);
  104.  
  105. iniFile.Get("Hacks", "EFBAccessEnable", &bEFBAccessEnable, true);
  106. iniFile.Get("Hacks", "DlistCachingEnable", &bDlistCachingEnable,false);
  107. iniFile.Get("Hacks", "EFBCopyEnable", &bEFBCopyEnable, true);
  108. iniFile.Get("Hacks", "EFBCopyDisableHotKey", &bOSDHotKey, 0);
  109. iniFile.Get("Hacks", "EFBToTextureEnable", &bCopyEFBToTexture, true);
  110. iniFile.Get("Hacks", "EFBScaledCopy", &bCopyEFBScaled, true);
  111. iniFile.Get("Hacks", "EFBCopyCacheEnable", &bEFBCopyCacheEnable, false);
  112. iniFile.Get("Hacks", "EFBEmulateFormatChanges", &bEFBEmulateFormatChanges, false);
  113.  
  114. iniFile.Get("Hardware", "Adapter", &iAdapter, 0);
  115.  
  116. // Load common settings
  117. iniFile.Load(File::GetUserPath(F_DOLPHINCONFIG_IDX));
  118. bool bTmp;
  119. iniFile.Get("Interface", "UsePanicHandlers", &bTmp, true);
  120. SetEnableAlert(bTmp);
  121. }
  122.  
  123. void VideoConfig::GameIniLoad(const char *ini_file)
  124. {
  125. IniFile iniFile;
  126. iniFile.Load(ini_file);
  127.  
  128. iniFile.GetIfExists("Video_Hardware", "VSync", &bVSync);
  129.  
  130. iniFile.GetIfExists("Video_Settings", "wideScreenHack", &bWidescreenHack);
  131. iniFile.GetIfExists("Video_Settings", "AspectRatio", &iAspectRatio);
  132. iniFile.GetIfExists("Video_Settings", "Crop", &bCrop);
  133. iniFile.GetIfExists("Video_Settings", "UseXFB", &bUseXFB);
  134. iniFile.GetIfExists("Video_Settings", "UseRealXFB", &bUseRealXFB);
  135. iniFile.GetIfExists("Video_Settings", "SafeTextureCacheColorSamples", &iSafeTextureCache_ColorSamples);
  136. iniFile.GetIfExists("Video_Settings", "DLOptimize", &iCompileDLsLevel);
  137. iniFile.GetIfExists("Video_Settings", "HiresTextures", &bHiresTextures);
  138. iniFile.GetIfExists("Video_Settings", "AnaglyphStereo", &bAnaglyphStereo);
  139. iniFile.GetIfExists("Video_Settings", "AnaglyphStereoSeparation", &iAnaglyphStereoSeparation);
  140. iniFile.GetIfExists("Video_Settings", "AnaglyphFocalAngle", &iAnaglyphFocalAngle);
  141. iniFile.GetIfExists("Video_Settings", "EnablePixelLighting", &bEnablePixelLighting);
  142. iniFile.GetIfExists("Video_Settings", "EnablePerPixelDepth", &bEnablePerPixelDepth);
  143. iniFile.GetIfExists("Video_Settings", "MSAA", &iMultisampleMode);
  144. iniFile.GetIfExists("Video_Settings", "EFBScale", &iEFBScale); // integral
  145. iniFile.GetIfExists("Video_Settings", "DstAlphaPass", &bDstAlphaPass);
  146. <<<<<<< HEAD
  147. =======
  148. iniFile.GetIfExists("Video_Settings", "DisableLighting", &bDisableLighting);
  149. iniFile.GetIfExists("Video_Settings", "DisableTexturing", &bDisableTexturing);
  150. >>>>>>> parent of 1dd6b97... Remove "Disable Lighting".
  151. iniFile.GetIfExists("Video_Settings", "DisableFog", &bDisableFog);
  152. iniFile.GetIfExists("Video_Settings", "EnableOpenCL", &bEnableOpenCL);
  153. iniFile.GetIfExists("Video_Settings", "OMPDecoder", &bOMPDecoder);
  154.  
  155. iniFile.GetIfExists("Video_Enhancements", "ForceFiltering", &bForceFiltering);
  156. iniFile.GetIfExists("Video_Enhancements", "MaxAnisotropy", &iMaxAnisotropy); // NOTE - this is x in (1 << x)
  157. iniFile.GetIfExists("Video_Enhancements", "PostProcessingShader", &sPostProcessingShader);
  158. iniFile.GetIfExists("Video_Enhancements", "Enable3dVision", &b3DVision);
  159.  
  160. iniFile.GetIfExists("Video_Hacks", "EFBAccessEnable", &bEFBAccessEnable);
  161. iniFile.GetIfExists("Video_Hacks", "DlistCachingEnable", &bDlistCachingEnable);
  162. iniFile.GetIfExists("Video_Hacks", "EFBCopyEnable", &bEFBCopyEnable);
  163. iniFile.GetIfExists("Video_Hacks", "EFBToTextureEnable", &bCopyEFBToTexture);
  164. iniFile.GetIfExists("Video_Hacks", "EFBScaledCopy", &bCopyEFBScaled);
  165. iniFile.GetIfExists("Video_Hacks", "EFBCopyCacheEnable", &bEFBCopyCacheEnable);
  166. iniFile.GetIfExists("Video_Hacks", "EFBEmulateFormatChanges", &bEFBEmulateFormatChanges);
  167.  
  168. iniFile.GetIfExists("Video", "ProjectionHack", &iPhackvalue[0]);
  169. iniFile.GetIfExists("Video", "PH_SZNear", &iPhackvalue[1]);
  170. iniFile.GetIfExists("Video", "PH_SZFar", &iPhackvalue[2]);
  171. iniFile.GetIfExists("Video", "PH_ExtraParam", &iPhackvalue[3]);
  172. iniFile.GetIfExists("Video", "PH_ZNear", &sPhackvalue[0]);
  173. iniFile.GetIfExists("Video", "PH_ZFar", &sPhackvalue[1]);
  174. iniFile.GetIfExists("Video", "ZTPSpeedupHack", &bZTPSpeedHack);
  175. iniFile.GetIfExists("Video", "UseBBox", &bUseBBox);
  176. }
  177.  
  178. void VideoConfig::VerifyValidity()
  179. {
  180. // TODO: Check iMaxAnisotropy value
  181. if (iAdapter < 0 || iAdapter > ((int)backend_info.Adapters.size() - 1)) iAdapter = 0;
  182. if (iMultisampleMode < 0 || iMultisampleMode >= (int)backend_info.AAModes.size()) iMultisampleMode = 0;
  183. if (!backend_info.bSupports3DVision) b3DVision = false;
  184. if (!backend_info.bSupportsFormatReinterpretation) bEFBEmulateFormatChanges = false;
  185. if (!backend_info.bSupportsPixelLighting) bEnablePixelLighting = false;
  186. }
  187.  
  188. void VideoConfig::Save(const char *ini_file)
  189. {
  190. IniFile iniFile;
  191. iniFile.Load(ini_file);
  192. iniFile.Set("Hardware", "VSync", bVSync);
  193. iniFile.Set("Settings", "AspectRatio", iAspectRatio);
  194. iniFile.Set("Settings", "Crop", bCrop);
  195. iniFile.Set("Settings", "wideScreenHack", bWidescreenHack);
  196. iniFile.Set("Settings", "UseXFB", bUseXFB);
  197. iniFile.Set("Settings", "UseRealXFB", bUseRealXFB);
  198. iniFile.Set("Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
  199. iniFile.Set("Settings", "ShowFPS", bShowFPS);
  200. iniFile.Set("Settings", "LogFPSToFile", bLogFPSToFile);
  201. iniFile.Set("Settings", "ShowInputDisplay", bShowInputDisplay);
  202. iniFile.Set("Settings", "OverlayStats", bOverlayStats);
  203. iniFile.Set("Settings", "OverlayProjStats", bOverlayProjStats);
  204. iniFile.Set("Settings", "DLOptimize", iCompileDLsLevel);
  205. iniFile.Set("Settings", "Show", iCompileDLsLevel);
  206. iniFile.Set("Settings", "DumpTextures", bDumpTextures);
  207. iniFile.Set("Settings", "HiresTextures", bHiresTextures);
  208. iniFile.Set("Settings", "DumpEFBTarget", bDumpEFBTarget);
  209. iniFile.Set("Settings", "DumpFrames", bDumpFrames);
  210. iniFile.Set("Settings", "FreeLook", bFreeLook);
  211. iniFile.Set("Settings", "UseFFV1", bUseFFV1);
  212. iniFile.Set("Settings", "AnaglyphStereo", bAnaglyphStereo);
  213. iniFile.Set("Settings", "AnaglyphStereoSeparation", iAnaglyphStereoSeparation);
  214. iniFile.Set("Settings", "AnaglyphFocalAngle", iAnaglyphFocalAngle);
  215. iniFile.Set("Settings", "EnablePixelLighting", bEnablePixelLighting);
  216. iniFile.Set("Settings", "EnablePerPixelDepth", bEnablePerPixelDepth);
  217.  
  218.  
  219. iniFile.Set("Settings", "ShowEFBCopyRegions", bShowEFBCopyRegions);
  220. iniFile.Set("Settings", "MSAA", iMultisampleMode);
  221. iniFile.Set("Settings", "EFBScale", iEFBScale);
  222. iniFile.Set("Settings", "TexFmtOverlayEnable", bTexFmtOverlayEnable);
  223. iniFile.Set("Settings", "TexFmtOverlayCenter", bTexFmtOverlayCenter);
  224. iniFile.Set("Settings", "Wireframe", bWireFrame);
  225. <<<<<<< HEAD
  226. =======
  227. iniFile.Set("Settings", "DisableLighting", bDisableLighting);
  228. iniFile.Set("Settings", "DisableTexturing", bDisableTexturing);
  229. >>>>>>> parent of 1dd6b97... Remove "Disable Lighting".
  230. iniFile.Set("Settings", "DstAlphaPass", bDstAlphaPass);
  231. iniFile.Set("Settings", "DisableFog", bDisableFog);
  232.  
  233. iniFile.Set("Settings", "EnableOpenCL", bEnableOpenCL);
  234. iniFile.Set("Settings", "OMPDecoder", bOMPDecoder);
  235.  
  236. iniFile.Set("Settings", "EnableShaderDebugging", bEnableShaderDebugging);
  237.  
  238. iniFile.Set("Enhancements", "ForceFiltering", bForceFiltering);
  239. iniFile.Set("Enhancements", "MaxAnisotropy", iMaxAnisotropy);
  240. iniFile.Set("Enhancements", "PostProcessingShader", sPostProcessingShader);
  241. iniFile.Set("Enhancements", "Enable3dVision", b3DVision);
  242.  
  243. iniFile.Set("Hacks", "EFBAccessEnable", bEFBAccessEnable);
  244. iniFile.Set("Hacks", "DlistCachingEnable", bDlistCachingEnable);
  245. iniFile.Set("Hacks", "EFBCopyEnable", bEFBCopyEnable);
  246. iniFile.Set("Hacks", "EFBCopyDisableHotKey", bOSDHotKey);
  247. iniFile.Set("Hacks", "EFBToTextureEnable", bCopyEFBToTexture);
  248. iniFile.Set("Hacks", "EFBScaledCopy", bCopyEFBScaled);
  249. iniFile.Set("Hacks", "EFBCopyCacheEnable", bEFBCopyCacheEnable);
  250. iniFile.Set("Hacks", "EFBEmulateFormatChanges", bEFBEmulateFormatChanges);
  251.  
  252. iniFile.Set("Hardware", "Adapter", iAdapter);
  253.  
  254. iniFile.Save(ini_file);
  255. }
  256.  
  257. void VideoConfig::GameIniSave(const char* default_ini, const char* game_ini)
  258. {
  259. // wxWidgets doesn't provide us with a nice way to change 3-state checkboxes into 2-state ones
  260. // This would allow us to make the "default config" dialog layout to be 2-state based, but the
  261. // "game config" layout to be 3-state based (with the 3rd state being "use default")
  262. // Since we can't do that, we instead just save anything which differs from the default config
  263. // TODO: Make this less ugly
  264.  
  265. VideoConfig defCfg;
  266. defCfg.Load(default_ini);
  267.  
  268. IniFile iniFile;
  269. iniFile.Load(game_ini);
  270.  
  271. #define SET_IF_DIFFERS(section, key, member) { if ((member) != (defCfg.member)) iniFile.Set((section), (key), (member)); else iniFile.DeleteKey((section), (key)); }
  272.  
  273. SET_IF_DIFFERS("Video_Hardware", "VSync", bVSync);
  274.  
  275. SET_IF_DIFFERS("Video_Settings", "wideScreenHack", bWidescreenHack);
  276. SET_IF_DIFFERS("Video_Settings", "AspectRatio", iAspectRatio);
  277. SET_IF_DIFFERS("Video_Settings", "Crop", bCrop);
  278. SET_IF_DIFFERS("Video_Settings", "UseXFB", bUseXFB);
  279. SET_IF_DIFFERS("Video_Settings", "UseRealXFB", bUseRealXFB);
  280. SET_IF_DIFFERS("Video_Settings", "SafeTextureCacheColorSamples", iSafeTextureCache_ColorSamples);
  281. SET_IF_DIFFERS("Video_Settings", "DLOptimize", iCompileDLsLevel);
  282. SET_IF_DIFFERS("Video_Settings", "HiresTextures", bHiresTextures);
  283. SET_IF_DIFFERS("Video_Settings", "AnaglyphStereo", bAnaglyphStereo);
  284. SET_IF_DIFFERS("Video_Settings", "AnaglyphStereoSeparation", iAnaglyphStereoSeparation);
  285. SET_IF_DIFFERS("Video_Settings", "AnaglyphFocalAngle", iAnaglyphFocalAngle);
  286. SET_IF_DIFFERS("Video_Settings", "EnablePixelLighting", bEnablePixelLighting);
  287. SET_IF_DIFFERS("Video_Settings", "EnablePerPixelDepth", bEnablePerPixelDepth);
  288. SET_IF_DIFFERS("Video_Settings", "MSAA", iMultisampleMode);
  289. SET_IF_DIFFERS("Video_Settings", "EFBScale", iEFBScale); // integral
  290. SET_IF_DIFFERS("Video_Settings", "DstAlphaPass", bDstAlphaPass);
  291. <<<<<<< HEAD
  292. =======
  293. SET_IF_DIFFERS("Video_Settings", "DisableLighting", bDisableLighting);
  294. SET_IF_DIFFERS("Video_Settings", "DisableTexturing", bDisableTexturing);
  295. >>>>>>> parent of 1dd6b97... Remove "Disable Lighting".
  296. SET_IF_DIFFERS("Video_Settings", "DisableFog", bDisableFog);
  297. SET_IF_DIFFERS("Video_Settings", "EnableOpenCL", bEnableOpenCL);
  298. SET_IF_DIFFERS("Video_Settings", "OMPDecoder", bOMPDecoder);
  299.  
  300. SET_IF_DIFFERS("Video_Enhancements", "ForceFiltering", bForceFiltering);
  301. SET_IF_DIFFERS("Video_Enhancements", "MaxAnisotropy", iMaxAnisotropy); // NOTE - this is x in (1 << x)
  302. SET_IF_DIFFERS("Video_Enhancements", "PostProcessingShader", sPostProcessingShader);
  303. SET_IF_DIFFERS("Video_Enhancements", "Enable3dVision", b3DVision);
  304.  
  305. SET_IF_DIFFERS("Video_Hacks", "EFBAccessEnable", bEFBAccessEnable);
  306. SET_IF_DIFFERS("Video_Hacks", "DlistCachingEnable", bDlistCachingEnable);
  307. SET_IF_DIFFERS("Video_Hacks", "EFBCopyEnable", bEFBCopyEnable);
  308. SET_IF_DIFFERS("Video_Hacks", "EFBToTextureEnable", bCopyEFBToTexture);
  309. SET_IF_DIFFERS("Video_Hacks", "EFBScaledCopy", bCopyEFBScaled);
  310. SET_IF_DIFFERS("Video_Hacks", "EFBCopyCacheEnable", bEFBCopyCacheEnable);
  311. SET_IF_DIFFERS("Video_Hacks", "EFBEmulateFormatChanges", bEFBEmulateFormatChanges);
  312.  
  313. iniFile.Save(game_ini);
  314. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement