diff --git a/win32/COpenGL.cpp b/win32/COpenGL.cpp index fef6c993..132ddc75 100644 --- a/win32/COpenGL.cpp +++ b/win32/COpenGL.cpp @@ -4,6 +4,7 @@ #include "../gfx.h" #include "../display.h" #include "wsnes9x.h" +#include #include "../filter/hq2x.h" #include "../filter/2xsai.h" @@ -113,7 +114,7 @@ void COpenGL::DeInitialize() { initDone = false; if(shaderCompiled) - SetShaders(NULL,NULL); + SetShaders(NULL); DestroyDrawSurface(); wglMakeCurrent(NULL,NULL); if(hRC) { @@ -304,10 +305,10 @@ bool COpenGL::ApplyDisplayChanges(void) if(wglSwapIntervalEXT) { wglSwapIntervalEXT(GUI.Vsync?1:0); } - if(GUI.shaderEnabled && GUI.GLSLvertexShaderFileName && GUI.GLSLfragmentShaderFileName) - SetShaders(GUI.GLSLfragmentShaderFileName,GUI.GLSLvertexShaderFileName); + if(GUI.shaderEnabled && GUI.GLSLshaderFileName) + SetShaders(GUI.GLSLshaderFileName); else - SetShaders(NULL,NULL); + SetShaders(NULL); RECT windowSize; GetClientRect(hWnd,&windowSize); @@ -480,9 +481,13 @@ char *ReadFileContents(const TCHAR *filename) } -bool COpenGL::SetShaders(const TCHAR *fragmentFileName,const TCHAR *vertexFileName) +bool COpenGL::SetShaders(const TCHAR *glslFileName) { char *fragment=NULL, *vertex=NULL; + IXMLDOMDocument * pXMLDoc = NULL; + IXMLDOMNode * pXDN = NULL; + HRESULT hr; + BSTR queryString, nodeContent; shaderCompiled = false; @@ -502,7 +507,7 @@ bool COpenGL::SetShaders(const TCHAR *fragmentFileName,const TCHAR *vertexFileNa shaderProgram = 0; } - if(fragmentFileName==NULL||vertexFileName==NULL) + if(glslFileName==NULL || *glslFileName==TEXT('\0')) return true; if(!LoadShaderFunctions()) { @@ -511,24 +516,76 @@ bool COpenGL::SetShaders(const TCHAR *fragmentFileName,const TCHAR *vertexFileNa return false; } - if(*fragmentFileName!=TEXT('\0')) { - fragment = ReadFileContents(fragmentFileName); - if (!fragment) { - TCHAR errorMsg[MAX_PATH + 50]; - _stprintf(errorMsg,TEXT("Error loading GLSL fragment shader file:\n%s"),fragmentFileName); - MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), - MB_OK|MB_ICONEXCLAMATION); - } + hr = CoCreateInstance(CLSID_DOMDocument,NULL,CLSCTX_INPROC_SERVER,IID_PPV_ARGS(&pXMLDoc)); + + if(FAILED(hr)) { + MessageBox(NULL, TEXT("Error creating XML Parser"), TEXT("Shader Loading Error"), + MB_OK|MB_ICONEXCLAMATION); + return false; } - if(*vertexFileName!=TEXT('\0')) { - vertex = ReadFileContents (vertexFileName); - if (!vertex) { - TCHAR errorMsg[MAX_PATH + 50]; - _stprintf(errorMsg,TEXT("Error loading GLSL vertex shader file:\n%s"),vertexFileName); - MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), - MB_OK|MB_ICONEXCLAMATION); + VARIANT fileName; + VARIANT_BOOL ret; + fileName.vt = VT_BSTR; +#ifdef UNICODE + fileName.bstrVal = SysAllocString(glslFileName); +#else + wchar_t tempfilename[MAX_PATH]; + MultiByteToWideChar(CP_UTF8,0,glslFileName,-1,tempfilename,MAX_PATH); + fileName.bstrVal = SysAllocString(tempfilename); +#endif + hr = pXMLDoc->load(fileName,&ret); + SysFreeString(fileName.bstrVal); + + if(FAILED(hr) || hr==S_FALSE) { + TCHAR errorMsg[MAX_PATH + 50]; + _stprintf(errorMsg,TEXT("Error loading GLSL shader file:\n%s"),glslFileName); + MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), + MB_OK|MB_ICONEXCLAMATION); + pXMLDoc->Release(); + return false; + } + + queryString=SysAllocString(L"/shader/fragment"); + hr = pXMLDoc->selectSingleNode(queryString,&pXDN); + SysFreeString(queryString); + + if(hr == S_OK) { + hr = pXDN->get_text(&nodeContent); + if(hr == S_OK) { + int requiredChars = WideCharToMultiByte(CP_ACP,0,nodeContent,-1,fragment,0,NULL,NULL); + fragment = new char[requiredChars]; + WideCharToMultiByte(CP_UTF8,0,nodeContent,-1,fragment,requiredChars,NULL,NULL); } + SysFreeString(nodeContent); + pXDN->Release(); + pXDN = NULL; + } + + queryString=SysAllocString(L"/shader/vertex"); + hr = pXMLDoc->selectSingleNode(queryString,&pXDN); + SysFreeString(queryString); + + if(hr == S_OK) { + hr = pXDN->get_text(&nodeContent); + if(hr == S_OK) { + int requiredChars = WideCharToMultiByte(CP_ACP,0,nodeContent,-1,vertex,0,NULL,NULL); + vertex = new char[requiredChars]; + WideCharToMultiByte(CP_UTF8,0,nodeContent,-1,vertex,requiredChars,NULL,NULL); + } + SysFreeString(nodeContent); + pXDN->Release(); + pXDN = NULL; + } + + pXMLDoc->Release(); + + if(!fragment && !vertex) { + TCHAR errorMsg[MAX_PATH + 50]; + _stprintf(errorMsg,TEXT("No vertex or fragment program in file:\n%s"),glslFileName); + MessageBox(NULL, errorMsg, TEXT("Shader Loading Error"), + MB_OK|MB_ICONEXCLAMATION); + return false; } shaderProgram = glCreateProgram (); diff --git a/win32/COpenGL.h b/win32/COpenGL.h index f9fedc3c..edacfc07 100644 --- a/win32/COpenGL.h +++ b/win32/COpenGL.h @@ -240,7 +240,7 @@ private: PFNWGLSWAPINTERVALEXTPROC wglSwapIntervalEXT; - bool SetShaders(const TCHAR *fragment,const TCHAR *vertex); + bool SetShaders(const TCHAR *glslFileName); bool LoadShaderFunctions(); bool LoadPBOFunctions(); void CreateDrawSurface(void); diff --git a/win32/rsrc/resource.h b/win32/rsrc/resource.h index e1deca8e..b896f5e0 100644 --- a/win32/rsrc/resource.h +++ b/win32/rsrc/resource.h @@ -101,10 +101,9 @@ #define IDC_MULTICART_EDITB 1092 #define IDC_PAUSESPIN 1093 #define IDC_DWNRIGHT 1093 -#define IDC_SHADER_GLSL_VERTEX_FILE 1093 +#define IDC_SHADER_GLSL_FILE 1093 #define IDC_SYNCBYRESET 1094 #define IDC_DOWN 1094 -#define IDC_SHADER_GLSL_FRAGMENT_FILE 1094 #define IDC_SENDROM 1095 #define IDC_DWNLEFT 1095 #define IDC_ACTASSERVER 1096 @@ -350,8 +349,7 @@ #define IDC_SHADER_ENABLED 3015 #define IDC_SHADER_HLSL_BROWSE 3016 #define IDC_SHADER_GROUP 3017 -#define IDC_SHADER_GLSL_VERTEX_BROWSE 3018 -#define IDC_SHADER_GLSL_FRAGMENT_BROWSE 3019 +#define IDC_SHADER_GLSL_BROWSE 3018 #define ID_FILE_EXIT 40001 #define ID_WINDOW_HIDEMENUBAR 40004 #define ID_FILE_AVI_RECORDING 40005 diff --git a/win32/rsrc/snes9x.rc b/win32/rsrc/snes9x.rc index 08bdd138..5867cb9c 100644 --- a/win32/rsrc/snes9x.rc +++ b/win32/rsrc/snes9x.rc @@ -173,13 +173,13 @@ BEGIN CONTROL "Sync By Reset",IDC_SYNCBYRESET,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,10,90,174,15 END -IDD_NEWDISPLAY DIALOGEX 0, 0, 353, 285 +IDD_NEWDISPLAY DIALOGEX 0, 0, 353, 259 STYLE DS_SETFONT | DS_MODALFRAME | DS_3DLOOK | DS_CENTER | WS_POPUP | WS_CLIPCHILDREN | WS_CAPTION CAPTION "Display Settings" FONT 8, "MS Sans Serif", 0, 0, 0x1 BEGIN - DEFPUSHBUTTON "OK",IDOK,239,263,50,14 - PUSHBUTTON "Cancel",IDCANCEL,296,263,50,14 + DEFPUSHBUTTON "OK",IDOK,239,237,50,14 + PUSHBUTTON "Cancel",IDCANCEL,296,237,50,14 COMBOBOX IDC_OUTPUTMETHOD,68,17,101,38,CBS_DROPDOWNLIST | WS_VSCROLL | WS_TABSTOP CONTROL "Fullscreen",IDC_FULLSCREEN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,36,48,10 CONTROL "Emulate Fullscreen",IDC_EMUFULLSCREEN,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,47,75,10 @@ -205,7 +205,7 @@ BEGIN CONTROL "Extend Height of SNES Image",IDC_HEIGHT_EXTEND,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,135,111,10 CONTROL "Display messages before applying filters",IDC_MESSAGES_IN_IMAGE, "Button",BS_AUTOCHECKBOX | WS_TABSTOP,187,146,140,10 - GROUPBOX "",IDC_SHADER_GROUP,8,162,338,97,0,WS_EX_TRANSPARENT + GROUPBOX "",IDC_SHADER_GROUP,8,162,338,71,0,WS_EX_TRANSPARENT EDITTEXT IDC_SHADER_HLSL_FILE,13,184,306,14,ES_AUTOHSCROLL | WS_DISABLED PUSHBUTTON "...",IDC_SHADER_HLSL_BROWSE,322,184,19,14,WS_DISABLED GROUPBOX "Frame Skipping:",IDC_STATIC,7,113,167,46,0,WS_EX_TRANSPARENT @@ -219,12 +219,9 @@ BEGIN LTEXT "Output Method",IDC_STATIC,10,19,51,11 CONTROL "Use Shader",IDC_SHADER_ENABLED,"Button",BS_AUTOCHECKBOX | WS_TABSTOP,11,162,52,9 LTEXT "HLSL Effect File",IDC_STATIC,13,173,104,8 - EDITTEXT IDC_SHADER_GLSL_VERTEX_FILE,13,213,306,14,ES_AUTOHSCROLL | WS_DISABLED - PUSHBUTTON "...",IDC_SHADER_GLSL_VERTEX_BROWSE,322,213,19,14,WS_DISABLED - LTEXT "GLSL vertex shader",IDC_STATIC,13,202,104,8 - EDITTEXT IDC_SHADER_GLSL_FRAGMENT_FILE,13,240,306,14,ES_AUTOHSCROLL | WS_DISABLED - PUSHBUTTON "...",IDC_SHADER_GLSL_FRAGMENT_BROWSE,322,240,19,14,WS_DISABLED - LTEXT "GLSL fragment shader",IDC_STATIC,13,229,104,8 + EDITTEXT IDC_SHADER_GLSL_FILE,13,213,306,14,ES_AUTOHSCROLL | WS_DISABLED + PUSHBUTTON "...",IDC_SHADER_GLSL_BROWSE,322,213,19,14,WS_DISABLED + LTEXT "GLSL shader",IDC_STATIC,13,202,104,8 END IDD_CHEATER DIALOGEX 0, 0, 262, 218 @@ -592,7 +589,7 @@ BEGIN LEFTMARGIN, 7 RIGHTMARGIN, 346 TOPMARGIN, 7 - BOTTOMMARGIN, 277 + BOTTOMMARGIN, 251 END IDD_CHEATER, DIALOG diff --git a/win32/snes9xw.vcproj b/win32/snes9xw.vcproj index bcc1ff4e..176029f3 100644 --- a/win32/snes9xw.vcproj +++ b/win32/snes9xw.vcproj @@ -85,7 +85,7 @@ /> Release(); } } +#endif void S9xSetRecentGames () { @@ -4130,7 +4132,9 @@ void S9xSetRecentGames () InsertMenuItem (recent, 0xFF00 + i, FALSE, &mii); } +#ifdef UNICODE Win7_CreateJumpList(); +#endif } } } @@ -6923,7 +6927,7 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) static bool prevStretch, prevAspectRatio, prevHeightExtend, prevAutoDisplayMessages, prevVideoMemory, prevShaderEnabled; static int prevAspectWidth; static OutputMethod prevOutputMethod; - static TCHAR prevHLSLShaderFile[MAX_PATH],prevGLSLvertexShaderFile[MAX_PATH],prevGLSLfragmentShaderFile[MAX_PATH]; + static TCHAR prevHLSLShaderFile[MAX_PATH],prevGLSLShaderFile[MAX_PATH]; switch(msg) { @@ -6952,8 +6956,7 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) prevAutoDisplayMessages = Settings.AutoDisplayMessages != 0; prevShaderEnabled = GUI.shaderEnabled; lstrcpy(prevHLSLShaderFile,GUI.HLSLshaderFileName); - lstrcpy(prevGLSLvertexShaderFile,GUI.GLSLvertexShaderFileName); - lstrcpy(prevGLSLfragmentShaderFile,GUI.GLSLfragmentShaderFileName); + lstrcpy(prevGLSLShaderFile,GUI.GLSLshaderFileName); _stprintf(s,TEXT("Current: %dx%d %dbit %dHz"),GUI.FullscreenMode.width,GUI.FullscreenMode.height,GUI.FullscreenMode.depth,GUI.FullscreenMode.rate); @@ -7025,14 +7028,11 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) SendDlgItemMessage(hDlg, IDC_SHADER_ENABLED, BM_SETCHECK, (WPARAM)BST_CHECKED, 0); EnableWindow(GetDlgItem(hDlg, IDC_SHADER_HLSL_FILE),TRUE); EnableWindow(GetDlgItem(hDlg, IDC_SHADER_HLSL_BROWSE),TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FRAGMENT_FILE),TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FRAGMENT_BROWSE),TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_VERTEX_FILE),TRUE); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_VERTEX_BROWSE),TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FILE),TRUE); + EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_BROWSE),TRUE); } SetDlgItemText(hDlg,IDC_SHADER_HLSL_FILE,GUI.HLSLshaderFileName); - SetDlgItemText(hDlg,IDC_SHADER_GLSL_VERTEX_FILE,GUI.GLSLvertexShaderFileName); - SetDlgItemText(hDlg,IDC_SHADER_GLSL_FRAGMENT_FILE,GUI.GLSLfragmentShaderFileName); + SetDlgItemText(hDlg,IDC_SHADER_GLSL_FILE,GUI.GLSLshaderFileName); lpfnOldWndProc = (WNDPROC)SetWindowLongPtr(GetDlgItem(hDlg,IDC_SHADER_GROUP),GWLP_WNDPROC,(LONG_PTR)GroupBoxCheckBoxTitle); @@ -7189,14 +7189,11 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GROUP),GUI.shaderEnabled); EnableWindow(GetDlgItem(hDlg, IDC_SHADER_HLSL_FILE),GUI.shaderEnabled); EnableWindow(GetDlgItem(hDlg, IDC_SHADER_HLSL_BROWSE),GUI.shaderEnabled); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_VERTEX_FILE),GUI.shaderEnabled); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_VERTEX_BROWSE),GUI.shaderEnabled); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FRAGMENT_FILE),GUI.shaderEnabled); - EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FRAGMENT_BROWSE),GUI.shaderEnabled); + EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_FILE),GUI.shaderEnabled); + EnableWindow(GetDlgItem(hDlg, IDC_SHADER_GLSL_BROWSE),GUI.shaderEnabled); GetDlgItemText(hDlg,IDC_SHADER_HLSL_FILE,GUI.HLSLshaderFileName,MAX_PATH); - GetDlgItemText(hDlg,IDC_SHADER_GLSL_VERTEX_FILE,GUI.GLSLvertexShaderFileName,MAX_PATH); - GetDlgItemText(hDlg,IDC_SHADER_GLSL_FRAGMENT_FILE,GUI.GLSLfragmentShaderFileName,MAX_PATH); + GetDlgItemText(hDlg,IDC_SHADER_GLSL_FILE,GUI.GLSLshaderFileName,MAX_PATH); WinDisplayApplyChanges(); WinRefreshDisplay(); break; @@ -7219,8 +7216,8 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) WinRefreshDisplay(); } break; - case IDC_SHADER_GLSL_VERTEX_BROWSE: - GetDlgItemText(hDlg,IDC_SHADER_GLSL_VERTEX_FILE,openFileName,MAX_PATH); + case IDC_SHADER_GLSL_BROWSE: + GetDlgItemText(hDlg,IDC_SHADER_GLSL_FILE,openFileName,MAX_PATH); ZeroMemory((LPVOID)&ofn, sizeof(OPENFILENAME)); ofn.lStructSize = sizeof(OPENFILENAME); @@ -7232,27 +7229,8 @@ INT_PTR CALLBACK DlgFunky(HWND hDlg, UINT msg, WPARAM wParam, LPARAM lParam) ofn.nMaxFile = MAX_PATH; ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; if(GetOpenFileName(&ofn)) { - SetDlgItemText(hDlg,IDC_SHADER_GLSL_VERTEX_FILE,openFileName); - lstrcpy(GUI.GLSLvertexShaderFileName,openFileName); - WinDisplayApplyChanges(); - WinRefreshDisplay(); - } - break; - case IDC_SHADER_GLSL_FRAGMENT_BROWSE: - GetDlgItemText(hDlg,IDC_SHADER_GLSL_FRAGMENT_FILE,openFileName,MAX_PATH); - ZeroMemory((LPVOID)&ofn, sizeof(OPENFILENAME)); - - ofn.lStructSize = sizeof(OPENFILENAME); - ofn.hwndOwner = hDlg; - ofn.lpstrFilter = TEXT("All Files\0*.*\0\0"); - ofn.lpstrFile = openFileName; - ofn.lpstrTitle = TEXT("Select Shader"); - ofn.lpstrDefExt = TEXT("*.*"); - ofn.nMaxFile = MAX_PATH; - ofn.Flags = OFN_FILEMUSTEXIST | OFN_HIDEREADONLY; - if(GetOpenFileName(&ofn)) { - SetDlgItemText(hDlg,IDC_SHADER_GLSL_FRAGMENT_FILE,openFileName); - lstrcpy(GUI.GLSLfragmentShaderFileName,openFileName); + SetDlgItemText(hDlg,IDC_SHADER_GLSL_FILE,openFileName); + lstrcpy(GUI.GLSLshaderFileName,openFileName); WinDisplayApplyChanges(); WinRefreshDisplay(); } @@ -7432,8 +7410,7 @@ updateFilterBox2: GUI.HeightExtend = prevHeightExtend; GUI.shaderEnabled = prevShaderEnabled; lstrcpy(GUI.HLSLshaderFileName,prevHLSLShaderFile); - lstrcpy(GUI.GLSLvertexShaderFileName,prevGLSLvertexShaderFile); - lstrcpy(GUI.GLSLfragmentShaderFileName,prevGLSLfragmentShaderFile); + lstrcpy(GUI.GLSLshaderFileName,prevGLSLShaderFile); } EndDialog(hDlg,0); diff --git a/win32/wsnes9x.h b/win32/wsnes9x.h index 3844a983..6e561ed0 100644 --- a/win32/wsnes9x.h +++ b/win32/wsnes9x.h @@ -315,8 +315,7 @@ struct sGUI { bool Vsync; bool shaderEnabled; TCHAR HLSLshaderFileName[MAX_PATH]; - TCHAR GLSLvertexShaderFileName[MAX_PATH]; - TCHAR GLSLfragmentShaderFileName[MAX_PATH]; + TCHAR GLSLshaderFileName[MAX_PATH]; bool IgnoreNextMouseMove; RECT window_size;