add some dx checking routines to the dx plugin + some minor stuff

git-svn-id: https://dolphin-emu.googlecode.com/svn/trunk@5466 8ced0084-cf51-0410-be5f-012b33b47a6e
This commit is contained in:
luisr142004 2010-05-23 02:29:23 +00:00
parent 782d9111e5
commit 1648b84f08
12 changed files with 202 additions and 106 deletions

View File

@ -145,7 +145,36 @@ void ToStringFromFormat(std::string* out, const char* format, ...)
delete[] buf;
}
std::wstring StringFromFormat(const wchar_t* format, ...)
{
int writtenCount = -1;
int newSize = (int)wcslen(format) + 4;
wchar_t *buf = 0;
va_list args;
while (writtenCount < 0)
{
delete [] buf;
buf = new wchar_t[newSize + 1];
va_start(args, format);
writtenCount = _vsnwprintf(buf, newSize, format, args);
va_end(args);
if (writtenCount >= (int)newSize) {
writtenCount = -1;
}
// ARGH! vsnprintf does no longer return -1 on truncation in newer libc!
// WORKAROUND! let's fake the old behaviour (even though it's less efficient).
// TODO: figure out why the fix causes an invalid read in strlen called from vsnprintf :(
// if (writtenCount >= (int)newSize)
// writtenCount = -1;
newSize *= 2;
}
buf[writtenCount] = '\0';
std::wstring temp = buf;
delete[] buf;
return temp;
}
std::string StringFromFormat(const char* format, ...)
{
int writtenCount = -1;
@ -177,7 +206,6 @@ std::string StringFromFormat(const char* format, ...)
return temp;
}
// For Debugging. Read out an u8 array.
std::string ArrayToString(const u8 *data, u32 size, u32 offset, int line_len, bool Spaces)
{
@ -217,7 +245,6 @@ std::string StripSpaces(const std::string &str)
return s.substr(0, i + 1);
}
// "\"hello\"" is turned to "hello"
// This one assumes that the string has already been space stripped in both
// ends, as done by StripSpaces above, for example.
@ -275,12 +302,12 @@ bool TryParseInt(const char* str, int* outVal)
bool TryParseBool(const char* str, bool* output)
{
if ((str[0] == '1') || !strcmp(str, "true") || !strcmp(str, "True") || !strcmp(str, "TRUE"))
if ((str[0] == '1') || !stricmp(str, "true"))
{
*output = true;
return true;
}
else if (str[0] == '0' || !strcmp(str, "false") || !strcmp(str, "False") || !strcmp(str, "FALSE"))
else if (str[0] == '0' || !stricmp(str, "false"))
{
*output = false;
return true;
@ -420,7 +447,6 @@ bool TryParseUInt(const std::string& str, u32* output)
return sscanf(str.c_str(), "%d", output) > 0;
}
int ChooseStringFrom(const char* str, const char* * items)
{
int i = 0;

View File

@ -25,6 +25,7 @@
#include "Common.h"
std::wstring StringFromFormat(const wchar_t* format, ...);
std::string StringFromFormat(const char* format, ...);
void ToStringFromFormat(std::string* out, const char* format, ...);
@ -46,16 +47,25 @@ inline void CharArrayFromFormat(char (& out)[Count], const char* format, ...)
va_end(args);
}
std::wstring StripSpaces(const std::wstring &s);
std::wstring StripQuotes(const std::wstring &s);
//std::wstring StripNewline(const std::string &s);
// Thousand separator. Turns 12345678 into 12,345,678
//std::wstring ThS(int a, bool b = true, int Spaces = 0);
std::string StripSpaces(const std::string &s);
std::string StripQuotes(const std::string &s);
std::string StripNewline(const std::string &s);
// Thousand separator. Turns 12345678 into 12,345,678
std::string ThS(int a, bool b = true, int Spaces = 0);
std::wstring StringFromIntW(int value);
std::wstring StringFromBoolW(bool value);
std::string StringFromInt(int value);
std::string StringFromBool(bool value);
bool TryParseInt(const wchar_t* str, int* outVal);
bool TryParseBool(const wchar_t* str, bool* output);
bool TryParseUInt(const std::wstring& str, u32* output);
bool TryParseInt(const char* str, int* outVal);
bool TryParseBool(const char* str, bool* output);
bool TryParseUInt(const std::string& str, u32* output);

View File

@ -104,6 +104,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="1"
DelayLoadDLLs="d3dx9_42.dll"
/>
<Tool
Name="VCALinkTool"
@ -216,6 +217,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="17"
DelayLoadDLLs="d3dx9_42.dll"
/>
<Tool
Name="VCALinkTool"
@ -315,6 +317,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="1"
DelayLoadDLLs="d3dx9d_42.dll"
/>
<Tool
Name="VCALinkTool"
@ -413,6 +416,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="17"
DelayLoadDLLs="d3dx9d_42.dll"
/>
<Tool
Name="VCALinkTool"
@ -522,6 +526,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="1"
DelayLoadDLLs="d3dx9_42.dll"
/>
<Tool
Name="VCALinkTool"
@ -632,6 +637,7 @@
DataExecutionPrevention="0"
ImportLibrary="$(PlatformName)\$(ConfigurationName)\$(TargetName).lib"
TargetMachine="17"
DelayLoadDLLs="d3dx9_42.dll"
/>
<Tool
Name="VCALinkTool"

View File

@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/
#include "Common.h"
#include "StringUtil.h"
#include "D3DBase.h"
#include "D3DUtil.h"
@ -187,6 +188,25 @@ const int TS[6][2] =
{D3DTSS_ALPHAARG2, D3DTA_DIFFUSE },
};
bool DXCheck( std::wstring& msg )
{
std::wstring dll =
#ifdef _DEBUG
StringFromFormat( _T("d3dx9d_%d.dll"), D3DX_SDK_VERSION);
#else
StringFromFormat( _T("d3dx9_%d.dll"), D3DX_SDK_VERSION);
#endif
HINSTANCE hDll = LoadLibrary(dll.c_str());
if( !hDll )
{
msg = _T("Please make sure that you have the latest version of DirectX 9.0c correctly installed.");
return false;
} else
msg = _T("DirectX9 is up to date and ready to be used!");
FreeLibrary( hDll );
return true;
}
static LPDIRECT3DPIXELSHADER9 ps_old = NULL;
static LPDIRECT3DVERTEXSHADER9 vs_old = NULL;

View File

@ -76,4 +76,5 @@ namespace D3D
void drawClearQuad(u32 Color,float z,IDirect3DPixelShader9 *PShader,IDirect3DVertexShader9 *Vshader);
void SaveRenderStates();
void RestoreRenderStates();
bool DXCheck(std::wstring&);
}

View File

@ -16,6 +16,7 @@
// http://code.google.com/p/dolphin-emu/
#include <windowsx.h>
#include <Richedit.h>
#include "resource.h"
#include "W32Util/PropertySheet.h"
@ -23,31 +24,30 @@
#include "FileUtil.h"
#include "D3DBase.h"
#include "D3DUtil.h"
#include "VideoConfig.h"
#include "TextureCache.h"
// TODO: remove if/when ini files use unicode
#define ComboBox_GetTextA(hwndCtl, lpch, cchMax) GetWindowTextA((hwndCtl), (lpch), (cchMax))
const char *aspect_ratio_names[4] = {
"Auto",
"Force 16:9 Widescreen",
"Force 4:3 Standard",
"Stretch to Window",
const TCHAR *aspect_ratio_names[4] = {
_T("Auto"),
_T("Force 16:9 Widescreen"),
_T("Force 4:3 Standard"),
_T("Stretch to Window"),
};
struct TabDirect3D : public W32Util::Tab
{
void Init(HWND hDlg)
{
WCHAR tempwstr[2000];
TCHAR tempstr[2000];
for (int i = 0; i < D3D::GetNumAdapters(); i++)
{
const D3D::Adapter &adapter = D3D::GetAdapter(i);
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, adapter.ident.Description, -1, tempwstr, 2000);
ComboBox_AddString(GetDlgItem(hDlg, IDC_ADAPTER),tempwstr);
stprintf_s( tempstr, _T("%hs"), adapter.ident.Description );
ComboBox_AddString(GetDlgItem(hDlg, IDC_ADAPTER), tempstr);
}
const D3D::Adapter &adapter = D3D::GetAdapter(g_Config.iAdapter);
@ -55,8 +55,8 @@ struct TabDirect3D : public W32Util::Tab
for (int i = 0; i < (int)adapter.aa_levels.size(); i++)
{
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, adapter.aa_levels[i].name, -1, tempwstr, 2000);
ComboBox_AddString(GetDlgItem(hDlg, IDC_ANTIALIASMODE), tempwstr);
stprintf_s( tempstr, _T("%hs"), adapter.aa_levels[i].name );
ComboBox_AddString(GetDlgItem(hDlg, IDC_ANTIALIASMODE), tempstr);
}
ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ANTIALIASMODE), g_Config.iMultisampleMode);
@ -67,8 +67,7 @@ struct TabDirect3D : public W32Util::Tab
for (int i = 0; i < 4; i++)
{
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, aspect_ratio_names[i], -1, tempwstr, 2000);
ComboBox_AddString(GetDlgItem(hDlg, IDC_ASPECTRATIO), tempwstr);
ComboBox_AddString(GetDlgItem(hDlg, IDC_ASPECTRATIO), aspect_ratio_names[i]);
}
ComboBox_SetCurSel(GetDlgItem(hDlg, IDC_ASPECTRATIO), g_Config.iAspectRatio);
@ -96,6 +95,14 @@ struct TabDirect3D : public W32Util::Tab
Button_Enable(GetDlgItem(hDlg, IDC_SAFE_TEXTURE_CACHE_FAST),g_Config.bSafeTextureCache);
Button_SetCheck(GetDlgItem(hDlg, IDC_EFB_ACCESS_ENABLE), g_Config.bEFBAccessEnable);
std::wstring str;
if( !D3D::DXCheck(str) ) {
SNDMSG( GetDlgItem(hDlg, IDC_DXCHK), EM_AUTOURLDETECT, TRUE, 0 );
SNDMSG( GetDlgItem(hDlg, IDC_DXCHK), EM_SETEVENTMASK, 0, ENM_LINK );
str.append( _T("\nhttp://www.microsoft.com/downloads/details.aspx?FamilyID=2da43d38-db71-4c1b-bc6a-9b6652cd92a3") );
}
Edit_SetText(GetDlgItem(hDlg, IDC_DXCHK), str.c_str());
}
void Command(HWND hDlg,WPARAM wParam)
@ -122,6 +129,23 @@ struct TabDirect3D : public W32Util::Tab
}
}
int Notify(HWND hDlg, LPARAM lParam)
{
switch (((LPNMHDR)lParam)->code) {
case EN_LINK:
{
ENLINK* enl = (ENLINK*)lParam;
if( enl->msg == WM_LBUTTONDOWN ) {
TCHAR dxlink[256];
TEXTRANGE txtrng = {enl->chrg, dxlink};
SNDMSG( GetDlgItem(hDlg, IDC_DXCHK), EM_GETTEXTRANGE, 0, (LPARAM)&txtrng );
ShellExecute( NULL, NULL, dxlink, NULL, NULL, SW_SHOWNORMAL );
}
} break;
}
return 0;
}
void Apply(HWND hDlg)
{
g_Config.iAdapter = ComboBox_GetCurSel(GetDlgItem(hDlg, IDC_ADAPTER));

View File

@ -194,11 +194,12 @@ namespace W32Util
break;
case WM_NOTIFY:
{
LPPSHNOTIFY lppsn = (LPPSHNOTIFY) lParam;
HWND sheet = lppsn->hdr.hwndFrom;
switch(lppsn->hdr.code) {
LPNMHDR lpnmh = (LPNMHDR) lParam;
HWND sheet = lpnmh->hwndFrom;
switch(lpnmh->code) {
case PSN_APPLY:
tab->Apply(hDlg);
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, PSNRET_NOERROR);
break;
case PSN_SETACTIVE:
PropSheet_SetWizButtons(GetParent(hDlg),
@ -206,12 +207,17 @@ namespace W32Util
(tab->HasNext()?PSWIZB_NEXT:0) |
(tab->HasFinish()?PSWIZB_FINISH:0));
break;
case PSN_KILLACTIVE:
SetWindowLongPtr(hDlg, DWLP_MSGRESULT, FALSE);
break;
case PSN_WIZNEXT:
tab->Apply(hDlg); //maybe not always good
break;
case PSN_WIZBACK:
case PSN_RESET: //cancel
break;
default:
return tab->Notify(hDlg, lParam);
}
}
break;

View File

@ -12,6 +12,7 @@ namespace W32Util
PropSheet *sheet; //back pointer ..
virtual void Init(HWND hDlg) {}
virtual void Command(HWND hDlg, WPARAM wParam) {}
virtual int Notify(HWND, LPARAM) {return 0;}
virtual void Apply(HWND hDlg) {}
virtual bool HasPrev() {return true;}
virtual bool HasFinish() {return false;}

View File

@ -15,10 +15,6 @@
// Official SVN repository and contact information can be found at
// http://code.google.com/p/dolphin-emu/
#include <tchar.h>
#include <windows.h>
#include <d3dx9.h>
#include "Common.h"
#include "Atomic.h"
#include "Thread.h"
@ -173,9 +169,9 @@ unsigned int Callback_PeekMessages()
void UpdateFPSDisplay(const char *text)
{
char temp[512];
sprintf_s(temp, 512, "SVN R%i: DX9: %s", SVN_REV, text);
SetWindowTextA(EmuWindow::GetWnd(), temp);
TCHAR temp[512];
swprintf_s(temp, 512, _T("SVN R%i: DX9: %hs"), SVN_REV, text);
SetWindowText(EmuWindow::GetWnd(), temp);
}
void GetDllInfo (PLUGIN_INFO* _PluginInfo)
@ -193,7 +189,8 @@ void GetDllInfo (PLUGIN_INFO* _PluginInfo)
#endif
}
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals) {
void SetDllGlobals(PLUGIN_GLOBALS* _pPluginGlobals)
{
globals = _pPluginGlobals;
LogManager::SetInstance((LogManager*)globals->logManager);
}
@ -206,9 +203,12 @@ void DllAbout(HWND _hParent)
void DllConfig(HWND _hParent)
{
// If not initialized, only init D3D so we can enumerate resolutions.
if (!s_PluginInitialized) D3D::Init();
if (!s_PluginInitialized)
D3D::Init();
HINSTANCE hREd = LoadLibrary(_T("riched20.dll"));
DlgSettings_Show(g_hInstance, _hParent);
if (!s_PluginInitialized) D3D::Shutdown();
if (!s_PluginInitialized)
D3D::Shutdown();
}
void Initialize(void *init)
@ -231,10 +231,19 @@ void Initialize(void *init)
}
else if (FAILED(D3D::Init()))
{
MessageBox(GetActiveWindow(), _T("Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed."), _T("Fatal Error"), MB_OK);
MessageBox(GetActiveWindow(), _T("Unable to initialize Direct3D. Please make sure that you have the latest version of DirectX 9.0c correctly installed."), _T("Fatal Error"), MB_ICONERROR|MB_OK);
return;
}
std::wstring msg;
if( !D3D::DXCheck(msg) )
{
msg.insert( 0, _T("Unable to initialize Direct3D. ") );
msg.append( _T("\n\nHave a nice crash. :P") );
MessageBox( (HWND)g_VideoInitialize.pWindowHandle, msg.c_str(), _T("Critical Error"), MB_ICONERROR|MB_OK );
ShellExecute( NULL, NULL, _T("http://www.microsoft.com/downloads/details.aspx?FamilyID=2da43d38-db71-4c1b-bc6a-9b6652cd92a3"), NULL, NULL, SW_SHOWNORMAL );
}
g_VideoInitialize.pPeekMessages = &Callback_PeekMessages;
g_VideoInitialize.pUpdateFPSDisplay = &UpdateFPSDisplay;

View File

@ -1,6 +1,6 @@
//{{NO_DEPENDENCIES}}
// Microsoft Visual C++ generated include file.
// Used by Resource.rc
// Used by resource.rc
//
#define IDD_ABOUT 102
#define IDD_SETTINGS 103
@ -8,10 +8,7 @@
#define IDD_ADVANCED 105
#define IDC_ADAPTER 1001
#define IDC_ANTIALIASMODE 1002
#define IDC_RESOLUTION 1003
#define IDC_VSYNC 1006
#define IDC_ASPECT_16_9 1008
#define IDC_ASPECT_4_3 1009
#define IDC_WIDESCREEN_HACK 1010
#define IDC_SAFE_TEXTURE_CACHE 1011
#define IDC_EFB_ACCESS_ENABLE 1012
@ -31,18 +28,15 @@
#define IDC_FORCEFILTERING 1026
#define IDC_ENABLEXFB 1026
#define IDC_FORCEANISOTROPY 1027
#define IDC_ENABLEXFB2 1027
#define IDC_ENABLEREALXFB 1027
#define IDC_LOADHIRESTEXTURE 1028
#define IDC_EFBSCALEDCOPY 1029
#define IDC_OSDHOTKEY 1030
#define IDC_COMBO2 1040
#define IDC_ASPECTRATIO 1040
#define IDC_SAFE_TEXTURE_CACHE_SAFE 1041
#define IDC_SAFE_TEXTURE_CACHE_NORMAL 1042
#define IDC_RADIO3 1043
#define IDC_SAFE_TEXTURE_CACHE_FAST 1043
#define IDC_CHECK1 1100
#define IDC_DXCHK 1046
#define IDC_USENATIVEMIPS 1100
#define IDC_STATIC -1
@ -52,7 +46,7 @@
#ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 106
#define _APS_NEXT_COMMAND_VALUE 40001
#define _APS_NEXT_CONTROL_VALUE 1044
#define _APS_NEXT_CONTROL_VALUE 1047
#define _APS_NEXT_SYMED_VALUE 101
#endif
#endif

View File

@ -12,13 +12,11 @@
#undef APSTUDIO_READONLY_SYMBOLS
/////////////////////////////////////////////////////////////////////////////
// English (U.S.) resources
// English (United States) resources
#if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU)
#ifdef _WIN32
LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
#pragma code_page(1252)
#endif //_WIN32
/////////////////////////////////////////////////////////////////////////////
//
@ -37,7 +35,7 @@ BEGIN
END
IDD_SETTINGS DIALOGEX 0, 0, 244, 183
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_BORDER | WS_SYSMENU
STYLE DS_SETFONT | DS_FIXEDSYS | WS_CHILD | WS_VISIBLE | WS_BORDER | WS_SYSMENU
FONT 8, "MS Shell Dlg", 0, 0, 0x0
BEGIN
LTEXT "&Graphics card:",IDC_STATIC,9,9,49,8
@ -54,6 +52,7 @@ BEGIN
CONTROL "Safe",IDC_SAFE_TEXTURE_CACHE_SAFE,"Button",BS_AUTORADIOBUTTON,117,105,27,10
CONTROL "Normal",IDC_SAFE_TEXTURE_CACHE_NORMAL,"Button",BS_AUTORADIOBUTTON,154,105,38,10
CONTROL "Fast",IDC_SAFE_TEXTURE_CACHE_FAST,"Button",BS_AUTORADIOBUTTON,198,105,30,10
CONTROL "",IDC_DXCHK,"RichEdit20W",ES_MULTILINE | ES_READONLY | WS_BORDER | WS_TABSTOP,30,126,186,50
END
IDD_ADVANCED DIALOGEX 0, 0, 244, 200
@ -120,8 +119,8 @@ BEGIN
RIGHTMARGIN, 237
VERTGUIDE, 7
VERTGUIDE, 68
VERTGUIDE, 81
VERTGUIDE, 87
VERTGUIDE, 109
VERTGUIDE, 161
TOPMARGIN, 7
BOTTOMMARGIN, 176
END
@ -167,7 +166,7 @@ END
2 TEXTINCLUDE
BEGIN
"#include <windows.h\0"
"#include <windows.h>\0"
END
3 TEXTINCLUDE
@ -178,7 +177,7 @@ END
#endif // APSTUDIO_INVOKED
#endif // English (U.S.) resources
#endif // English (United States) resources
/////////////////////////////////////////////////////////////////////////////