DX11: Add texture dumping and hires texture loading support.
[dolphin.git] / Source / Plugins / Plugin_VideoDX11 / Src / DlgSettings.cpp
blobfa136dcb834963886051c49494717334b4061cd5
1 // Copyright (C) 2003 Dolphin Project.
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.
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.
12 // A copy of the GPL 2.0 should have been included with the program.
13 // If not, see http://www.gnu.org/licenses/
15 // Official SVN repository and contact information can be found at
16 // http://code.google.com/p/dolphin-emu/
18 #include <vector>
19 #include <windowsx.h>
21 #include "resource.h"
22 #include "W32Util/PropertySheet.h"
23 #include "FileUtil.h"
25 #include "D3DBase.h"
26 #include "VideoConfig.h"
27 #include "TextureCache.h"
28 using std::vector;
30 const char* aspect_ratio_names[4] = {
31 "Auto",
32 "Force 16:9 Widescreen",
33 "Force 4:3 Standard",
34 "Stretch to Window",
37 vector<IDXGIAdapter*> CreateAdapterList()
39 vector<IDXGIAdapter*> adapters;
40 IDXGIFactory* factory;
41 IDXGIAdapter* ad;
42 HRESULT hr = CreateDXGIFactory(__uuidof(IDXGIFactory), (void**)&factory);
43 if (FAILED(hr)) MessageBox(NULL, _T("Failed to create IDXGIFactory object"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
45 while (factory->EnumAdapters(adapters.size(), &ad) != DXGI_ERROR_NOT_FOUND)
46 adapters.push_back(ad);
48 if (adapters.size() == 0) MessageBox(NULL, _T("Couldn't find any devices!"), _T("Dolphin Direct3D 11 plugin"), MB_OK | MB_ICONERROR);
49 factory->Release();
50 return adapters;
53 void DestroyAdapterList(vector<IDXGIAdapter*> &adapters)
55 while (!adapters.empty())
57 adapters.back()->Release();
58 adapters.pop_back();
62 struct TabDirect3D : public W32Util::Tab
64 void Init(HWND hDlg)
66 WCHAR tempwstr[2000];
67 HRESULT hr;
69 vector<IDXGIAdapter*> adapters = CreateAdapterList();
70 for (vector<IDXGIAdapter*>::iterator it = adapters.begin();it != adapters.end();++it)
72 DXGI_ADAPTER_DESC desc;
73 hr = (*it)->GetDesc(&desc);
74 if (SUCCEEDED(hr)) ComboBox_AddString(GetDlgItem(hDlg, IDC_ADAPTER), desc.Description);
75 else
77 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, "Unknown device", -1, tempwstr, 2000);
78 ComboBox_AddString(GetDlgItem(hDlg, IDC_ADAPTER), tempwstr);
81 DestroyAdapterList(adapters);
82 ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ADAPTER), g_Config.iAdapter);
84 for (unsigned int i = 0; i < 4; i++)
86 MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, aspect_ratio_names[i], -1, tempwstr, 2000);
87 ComboBox_AddString(GetDlgItem(hDlg, IDC_ASPECTRATIO), tempwstr);
89 ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ASPECTRATIO), g_Config.iAspectRatio);
91 Button_SetCheck(GetDlgItem(hDlg, IDC_WIDESCREEN_HACK), g_Config.bWidescreenHack);
92 Button_SetCheck(GetDlgItem(hDlg, IDC_VSYNC), g_Config.bVSync);
93 Button_SetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE), g_Config.bSafeTextureCache);
94 Button_SetCheck(GetDlgItem(hDlg, IDC_DLIST_CACHING), g_Config.bDlistCachingEnable);
95 Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLEPIXELLIGHTING), g_Config.bEnablePixelLigting);
99 if (g_Config.iSafeTextureCache_ColorSamples == 0)
101 Button_SetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_SAFE), true);
103 else
105 if (g_Config.iSafeTextureCache_ColorSamples > 128)
107 Button_SetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_NORMAL), true);
109 else
111 Button_SetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_FAST), true);
114 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_SAFE), g_Config.bSafeTextureCache);
115 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_NORMAL), g_Config.bSafeTextureCache);
116 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_FAST), g_Config.bSafeTextureCache);
118 Button_SetCheck(GetDlgItem(hDlg, IDC_EFB_ACCESS_ENABLE), g_Config.bEFBAccessEnable);
121 void Command(HWND hDlg,WPARAM wParam)
123 switch (LOWORD(wParam))
125 case IDC_ASPECTRATIO:
126 g_Config.iAspectRatio = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_ASPECTRATIO));
127 break;
128 case IDC_ADAPTER:
129 g_Config.iAdapter = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_ADAPTER));
130 break;
131 case IDC_VSYNC:
132 g_Config.bVSync = Button_GetCheck(GetDlgItem(hDlg, IDC_VSYNC)) ? true : false;
133 break;
134 case IDC_WIDESCREEN_HACK:
135 g_Config.bWidescreenHack = Button_GetCheck(GetDlgItem(hDlg, IDC_WIDESCREEN_HACK)) ? true : false;
136 break;
137 case IDC_SAFE_TEXTURE_CACHE:
138 g_Config.bSafeTextureCache = Button_GetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE)) == 0 ? false : true;
139 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_SAFE), g_Config.bSafeTextureCache);
140 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_NORMAL), g_Config.bSafeTextureCache);
141 Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_FAST), g_Config.bSafeTextureCache);
142 break;
143 case IDC_DLIST_CACHING:
144 g_Config.bDlistCachingEnable = Button_GetCheck(GetDlgItem(hDlg, IDC_DLIST_CACHING)) == 0 ? false : true;
145 break;
146 case IDC_ENABLEPIXELLIGHTING:
147 g_Config.bEnablePixelLigting = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLEPIXELLIGHTING)) == 0 ? false : true;
148 break;
149 case IDC_EFB_ACCESS_ENABLE:
150 g_Config.bEFBAccessEnable = Button_GetCheck(GetDlgItem(hDlg, IDC_EFB_ACCESS_ENABLE)) == 0 ? false : true;
151 break;
152 default:
153 break;
157 void Apply(HWND hDlg)
159 if (Button_GetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_SAFE)))
161 g_Config.iSafeTextureCache_ColorSamples = 0;
163 else
165 if (Button_GetCheck(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_NORMAL)))
167 if (g_Config.iSafeTextureCache_ColorSamples < 512)
169 g_Config.iSafeTextureCache_ColorSamples = 512;
172 else
174 if (g_Config.iSafeTextureCache_ColorSamples > 128 || g_Config.iSafeTextureCache_ColorSamples == 0)
176 g_Config.iSafeTextureCache_ColorSamples = 128;
180 g_Config.Save((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
184 struct TabAdvanced : public W32Util::Tab
186 void Init(HWND hDlg)
188 Button_SetCheck(GetDlgItem(hDlg, IDC_OSDHOTKEY), g_Config.bOSDHotKey);
189 Button_SetCheck(GetDlgItem(hDlg, IDC_OVERLAYFPS), g_Config.bShowFPS);
190 Button_SetCheck(GetDlgItem(hDlg, IDC_OVERLAYSTATS), g_Config.bOverlayStats);
191 Button_SetCheck(GetDlgItem(hDlg, IDC_OVERLAYPROJSTATS), g_Config.bOverlayProjStats);
192 Button_SetCheck(GetDlgItem(hDlg, IDC_WIREFRAME), g_Config.bWireFrame);
193 Button_SetCheck(GetDlgItem(hDlg, IDC_DISABLEFOG), g_Config.bDisableFog);
194 Button_SetCheck(GetDlgItem(hDlg, IDC_ENABLEEFBCOPY), !g_Config.bEFBCopyDisable);
196 Button_SetCheck(GetDlgItem(hDlg, IDC_TEXFMT_OVERLAY), g_Config.bTexFmtOverlayEnable);
197 Button_SetCheck(GetDlgItem(hDlg, IDC_TEXFMT_CENTER), g_Config.bTexFmtOverlayCenter);
198 Button_GetCheck(GetDlgItem(hDlg, IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg,IDC_TEXFMT_CENTER), false);
200 Button_SetCheck(GetDlgItem(hDlg, IDC_FORCEANISOTROPY),g_Config.iMaxAnisotropy > 1);
201 Button_SetCheck(GetDlgItem(hDlg, IDC_EFBSCALEDCOPY), g_Config.bCopyEFBScaled);
203 Button_SetCheck(GetDlgItem(hDlg, IDC_LOADHIRESTEXTURE),g_Config.bHiresTextures);
204 Button_SetCheck(GetDlgItem(hDlg, IDC_DUMPTEXTURES),g_Config.bDumpTextures);
206 if (Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLEEFBCOPY))) Button_Enable(GetDlgItem(hDlg,IDC_EFBSCALEDCOPY), true);
207 else Button_Enable(GetDlgItem(hDlg, IDC_EFBSCALEDCOPY), false);
209 void Command(HWND hDlg,WPARAM wParam)
211 switch (LOWORD(wParam))
213 case IDC_TEXFMT_OVERLAY:
214 Button_GetCheck(GetDlgItem(hDlg, IDC_TEXFMT_OVERLAY)) ? Button_Enable(GetDlgItem(hDlg, IDC_TEXFMT_CENTER), true) : Button_Enable(GetDlgItem(hDlg, IDC_TEXFMT_CENTER), false);
215 break;
217 case IDC_ENABLEEFBCOPY:
218 if (Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLEEFBCOPY))) Button_Enable(GetDlgItem(hDlg, IDC_EFBSCALEDCOPY), true);
219 else Button_Enable(GetDlgItem(hDlg, IDC_EFBSCALEDCOPY), false);
220 break;
222 default: break;
225 void Apply(HWND hDlg)
227 g_Config.bTexFmtOverlayEnable = Button_GetCheck(GetDlgItem(hDlg, IDC_TEXFMT_OVERLAY)) ? true : false;
228 g_Config.bTexFmtOverlayCenter = Button_GetCheck(GetDlgItem(hDlg, IDC_TEXFMT_CENTER)) ? true : false;
230 g_Config.bOSDHotKey = Button_GetCheck(GetDlgItem(hDlg, IDC_OSDHOTKEY)) ? true : false;
231 g_Config.bShowFPS = Button_GetCheck(GetDlgItem(hDlg, IDC_OVERLAYFPS)) ? true : false;
232 g_Config.bOverlayStats = Button_GetCheck(GetDlgItem(hDlg, IDC_OVERLAYSTATS)) ? true : false;
233 g_Config.bOverlayProjStats = Button_GetCheck(GetDlgItem(hDlg, IDC_OVERLAYPROJSTATS)) ? true : false;
234 g_Config.bWireFrame = Button_GetCheck(GetDlgItem(hDlg, IDC_WIREFRAME)) ? true : false;
235 g_Config.bDisableFog = Button_GetCheck(GetDlgItem(hDlg, IDC_DISABLEFOG)) ? true : false;
236 g_Config.bEFBCopyDisable = Button_GetCheck(GetDlgItem(hDlg, IDC_ENABLEEFBCOPY)) ? false : true;
237 g_Config.bCopyEFBToTexture = !g_Config.bEFBCopyDisable;
238 g_Config.bDumpFrames = false;
239 g_Config.bShowShaderErrors = true;
240 g_Config.bUseNativeMips = true;
242 g_Config.iMaxAnisotropy = Button_GetCheck(GetDlgItem(hDlg, IDC_FORCEANISOTROPY)) ? 16 : 1;
243 g_Config.bForceFiltering = false;
244 g_Config.bHiresTextures = Button_GetCheck(GetDlgItem(hDlg, IDC_LOADHIRESTEXTURE)) ? true : false;
245 g_Config.bDumpTextures = Button_GetCheck(GetDlgItem(hDlg, IDC_DUMPTEXTURES)) ? true : false;
246 g_Config.bCopyEFBScaled = Button_GetCheck(GetDlgItem(hDlg, IDC_EFBSCALEDCOPY)) ? true : false;
247 g_Config.Save((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
251 struct TabAbout : public W32Util::Tab
253 void Init(HWND hDlg) {}
254 void Command(HWND hDlg,WPARAM wParam) {}
255 void Apply(HWND hDlg) {}
258 void DlgSettings_Show(HINSTANCE hInstance, HWND _hParent)
260 bool tfoe = g_Config.bTexFmtOverlayEnable;
261 bool tfoc = g_Config.bTexFmtOverlayCenter;
263 g_Config.Load((std::string(File::GetUserPath(D_CONFIG_IDX)) + "gfx_dx11.ini").c_str());
264 W32Util::PropSheet sheet;
265 sheet.Add(new TabDirect3D, (LPCTSTR)IDD_SETTINGS, _T("Direct3D"));
266 sheet.Add(new TabAdvanced, (LPCTSTR)IDD_ADVANCED, _T("Advanced"));
267 sheet.Add(new TabAbout, (LPCTSTR)IDD_ABOUT, _T("About"));
269 #ifdef DEBUGFAST
270 sheet.Show(hInstance,_hParent,_T("DX11 Graphics Plugin (DEBUGFAST)"));
271 #elif defined _DEBUG
272 sheet.Show(hInstance,_hParent,_T("DX11 Graphics Plugin (DEBUG)"));
273 #else
274 sheet.Show(hInstance,_hParent,_T("DX11 Graphics Plugin"));
275 #endif
277 if ((tfoe != g_Config.bTexFmtOverlayEnable) ||
278 ((g_Config.bTexFmtOverlayEnable) && ( tfoc != g_Config.bTexFmtOverlayCenter)))
280 TextureCache::Invalidate(false);