diff --git a/plugins/zzogl-pg/opengl/GLWin.h b/plugins/zzogl-pg/opengl/GLWin.h index ef093579e..bab0833ba 100644 --- a/plugins/zzogl-pg/opengl/GLWin.h +++ b/plugins/zzogl-pg/opengl/GLWin.h @@ -29,6 +29,9 @@ #undef CreateWindow // Undo Windows.h global namespace pollution +extern void SetDeviceSize(int nNewWidth, int nNewHeight); +extern void OnFKey(int key, int shift); + class GLWindow { private: @@ -52,6 +55,7 @@ class GLWindow public: char title[256]; + Size backbuffer; void SwapGLBuffers(); bool ReleaseContext(); @@ -66,13 +70,21 @@ class GLWindow void SetTitle(char *strtitle); void ResizeCheck(); void ProcessEvents(); + + void UpdateWindowSize(int nNewWidth, int nNewHeight) + { + FUNCLOG + backbuffer.w = std::max(nNewWidth, 16); + backbuffer.h = std::max(nNewHeight, 16); + + if (!(conf.fullscreen())) + { + conf.width = nNewWidth; + conf.height = nNewHeight; + } + } }; - extern GLWindow GLWin; -extern void ChangeWindowSize(int nNewWidth, int nNewHeight); -extern void SetChangeDeviceSize(int nNewWidth, int nNewHeight); -extern int nBackbufferWidth, nBackbufferHeight; -extern void OnFKey(int key, int shift); #endif // GLWIN_H_INCLUDED diff --git a/plugins/zzogl-pg/opengl/GLWin32.cpp b/plugins/zzogl-pg/opengl/GLWin32.cpp index 28fa88395..ee68fce0d 100644 --- a/plugins/zzogl-pg/opengl/GLWin32.cpp +++ b/plugins/zzogl-pg/opengl/GLWin32.cpp @@ -47,14 +47,14 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) case WM_SIZE: nWindowWidth = lParam & 0xffff; nWindowHeight = lParam >> 16; - ChangeWindowSize(nWindowWidth, nWindowHeight); + UpdateWindowSize(nWindowWidth, nWindowHeight); break; case WM_SIZING: // if button is 0, then just released so can resize if (GetSystemMetrics(SM_SWAPBUTTON) ? !GetAsyncKeyState(VK_RBUTTON) : !GetAsyncKeyState(VK_LBUTTON)) { - SetChangeDeviceSize(nWindowWidth, nWindowHeight); + SetDeviceSize(nWindowWidth, nWindowHeight); } break; @@ -189,8 +189,8 @@ bool GLWindow::DisplayWindow(int _width, int _height) if (conf.fullscreen()) { - nBackbufferWidth = rcdesktop.right - rcdesktop.left; - nBackbufferHeight = rcdesktop.bottom - rcdesktop.top; + backbuffer.w = rcdesktop.right - rcdesktop.left; + backbuffer.h = rcdesktop.bottom - rcdesktop.top; dwExStyle = WS_EX_APPWINDOW; dwStyle = WS_POPUP; @@ -200,8 +200,8 @@ bool GLWindow::DisplayWindow(int _width, int _height) { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; - nBackbufferWidth = _width; - nBackbufferHeight = _height; + backbuffer.w = _width; + backbuffer.h = _height; } dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN; @@ -209,8 +209,8 @@ bool GLWindow::DisplayWindow(int _width, int _height) rc.left = 0; rc.top = 0; - rc.right = nBackbufferWidth; - rc.bottom = nBackbufferHeight; + rc.right = backbuffer.h; + rc.bottom = backbuffer.h; AdjustWindowRectEx(&rc, dwStyle, false, dwExStyle); int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2; int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 2; @@ -225,8 +225,8 @@ bool GLWindow::DisplayWindow(int _width, int _height) DEVMODE dmScreenSettings; memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); dmScreenSettings.dmSize = sizeof(dmScreenSettings); - dmScreenSettings.dmPelsWidth = nBackbufferWidth; - dmScreenSettings.dmPelsHeight = nBackbufferHeight; + dmScreenSettings.dmPelsWidth = backbuffer.w; + dmScreenSettings.dmPelsHeight = backbuffer.h; dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; @@ -387,7 +387,7 @@ void GLWindow::ProcessEvents() { conf.zz_options.fullscreen = !conf.zz_options.fullscreen; - SetChangeDeviceSize( + SetDeviceSize( (conf.fullscreen()) ? 1280 : conf.width, (conf.fullscreen()) ? 960 : conf.height); } diff --git a/plugins/zzogl-pg/opengl/GLWinX11.cpp b/plugins/zzogl-pg/opengl/GLWinX11.cpp index 4635b15af..d71a41ab3 100644 --- a/plugins/zzogl-pg/opengl/GLWinX11.cpp +++ b/plugins/zzogl-pg/opengl/GLWinX11.cpp @@ -138,7 +138,7 @@ void GLWindow::GetWindowSize() XUnlockDisplay(glDisplay); // update the gl buffer size - ChangeWindowSize(width, height); + UpdateWindowSize(width, height); ZZLog::Dev_Log("Resolution %dx%d. Depth %d bpp. Position (%d,%d)", width, height, depth, conf.x, conf.y); } @@ -255,8 +255,8 @@ void GLWindow::ToggleFullscreen() bool GLWindow::DisplayWindow(int _width, int _height) { - nBackbufferWidth = _width; - nBackbufferHeight = _height; + backbuffer.w = _width; + backbuffer.h = _height; if (!CreateVisual()) return false; @@ -342,7 +342,7 @@ void GLWindow::ResizeCheck() width = event.xconfigure.width; height = event.xconfigure.height; Force43Ratio(); - ChangeWindowSize(width, height); + UpdateWindowSize(width, height); } if (!fullScreen) { diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index d0e16c738..42e60ef78 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -23,6 +23,7 @@ #include "GLWin.h" #include "ZZoglFlushHack.h" + using namespace std; extern void SaveSnapshot(const char* filename); @@ -45,7 +46,7 @@ float fFPS = 0; void (*GSirq)(); u8* g_pBasePS2Mem = NULL; -std::string s_strIniPath("inis/"); // Air's new ini path (r2361) +string s_strIniPath("inis/"); // Air's new ini path (r2361) bool SaveStateExists = true; // We could not know save slot status before first change occured const char* SaveStateFile = NULL; // Name of SaveFile for access check. @@ -76,10 +77,16 @@ extern void WriteBilinear(); extern void ZZDestroy(); extern bool ZZCreate(int width, int height); extern void ZZGSStateReset(); +extern int ZZSave(s8* pbydata); +extern bool ZZLoad(s8* pbydata); // switches the render target to the real target, flushes the current render targets and renders the real image extern void RenderCRTC(int interlace); +#if defined(_WIN32) && defined(_DEBUG) +HANDLE g_hCurrentThread = NULL; +#endif + extern int VALIDATE_THRESH; extern u32 TEXDESTROY_THRESH; @@ -124,10 +131,6 @@ void CALLBACK GSsetGameCRC(int crc, int options) inited = true; memset(GSC_list, 0, sizeof(GSC_list)); - // for(int i = 0; i < NUMBER_OF_TITLES; i++) - // { - // GSC_list[i] = GSC_Null; - // } GSC_list[Okami] = GSC_Okami; GSC_list[MetalGearSolid3] = GSC_MetalGearSolid3; @@ -268,10 +271,6 @@ s32 CALLBACK GSinit() return 0; } -#if defined(_WIN32) && defined(_DEBUG) -HANDLE g_hCurrentThread = NULL; -#endif - __forceinline void InitMisc() { WriteBilinear(); @@ -415,13 +414,12 @@ void CALLBACK GSmakeSnapshot(char *path) if ((bmpfile = fopen(filename, "wb")) == NULL) { char strdir[255]; + sprintf(strdir, "%s", path); #ifdef _WIN32 - sprintf(strdir, "%s", path); CreateDirectory(strdir, NULL); #else - sprintf(strdir, "mkdir %s", path); - system(strdir); + mkdir(path, 0777); #endif if ((bmpfile = fopen(filename, "wb")) == NULL) return; @@ -562,9 +560,6 @@ int CALLBACK GSsetupRecording(int start, void* pData) return 1; } -int ZZSave(s8* pbydata); -bool ZZLoad(s8* pbydata); - s32 CALLBACK GSfreeze(int mode, freezeData *data) { FUNCLOG diff --git a/plugins/zzogl-pg/opengl/Util.h b/plugins/zzogl-pg/opengl/Util.h index 09039459e..756e86f3f 100644 --- a/plugins/zzogl-pg/opengl/Util.h +++ b/plugins/zzogl-pg/opengl/Util.h @@ -22,16 +22,21 @@ #ifdef _WIN32 + #include #include "Utilities/RedtapeWindows.h" + #include #include + #include #include #include "glprocs.h" #else // linux basic definitions +#include + #include #include #include @@ -40,7 +45,6 @@ #endif - #define GSdefs //Pcsx2Defs is included in Dependencies.h. @@ -72,6 +76,11 @@ typedef struct int x, y; } Point; +typedef struct +{ + int w, h; +} Size; + typedef struct { int x0, y0; diff --git a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp index faf836475..1b0f44644 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp @@ -65,21 +65,21 @@ void AdjustTransToAspect(float4& v) float f; const float mult = 1 / 32767.0f; - if (conf.width * nBackbufferHeight > conf.height * nBackbufferWidth) // limited by width + if (conf.width * GLWin.backbuffer.h > conf.height * GLWin.backbuffer.w) // limited by width { // change in ratio - f = ((float)nBackbufferWidth / (float)conf.width) / ((float)nBackbufferHeight / (float)conf.height); + f = ((float)GLWin.backbuffer.w / (float)conf.width) / ((float)GLWin.backbuffer.h / (float)conf.height); v.y *= f; v.w *= f; // scanlines mess up when not aligned right - v.y += (1 - (float)modf(v.y * (float)nBackbufferHeight * 0.5f + 0.05f, &temp)) * 2.0f / (float)nBackbufferHeight; - v.w += (1 - (float)modf(v.w * (float)nBackbufferHeight * 0.5f + 0.05f, &temp)) * 2.0f / (float)nBackbufferHeight; + v.y += (1 - (float)modf(v.y * (float)GLWin.backbuffer.h * 0.5f + 0.05f, &temp)) * 2.0f / (float)GLWin.backbuffer.h; + v.w += (1 - (float)modf(v.w * (float)GLWin.backbuffer.h * 0.5f + 0.05f, &temp)) * 2.0f / (float)GLWin.backbuffer.h; } else // limited by height { - f = ((float)nBackbufferHeight / (float)conf.height) / ((float)nBackbufferWidth / (float)conf.width); - f -= (float)modf(f * nBackbufferWidth, &temp) / (float)nBackbufferWidth; + f = ((float)GLWin.backbuffer.h / (float)conf.height) / ((float)GLWin.backbuffer.w / (float)conf.width); + f -= (float)modf(f * GLWin.backbuffer.w, &temp) / (float)GLWin.backbuffer.w; v.x *= f; v.z *= f; } @@ -211,7 +211,7 @@ inline void RenderStartHelper(u32 bInterlace) glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer - glViewport(0, 0, nBackbufferWidth, nBackbufferHeight); + glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h); // if interlace, only clear every other vsync if (!bInterlace) @@ -642,7 +642,7 @@ void DrawText(const char* pstr, int left, int top, u32 color) v.SetColor(color); glColor3f(v.z, v.y, v.x); - font_p->printString(pstr, left * 2.0f / (float)nBackbufferWidth - 1, 1 - top * 2.0f / (float)nBackbufferHeight, 0); + font_p->printString(pstr, left * 2.0f / (float)GLWin.backbuffer.w - 1, 1 - top * 2.0f / (float)GLWin.backbuffer.h, 0); ZZshGLEnableProfile(); } @@ -670,7 +670,7 @@ inline void MakeSnapshot() DrawText(str, left + 1, top + 1, 0xff000000); DrawText(str, left, top, 0xffc0ffff); - if (SaveRenderTarget(strSnapshot != "" ? strSnapshot.c_str() : "temp.jpg", nBackbufferWidth, -nBackbufferHeight, 0)) //(conf.options.tga_snap)?0:1) ) { + if (SaveRenderTarget(strSnapshot != "" ? strSnapshot.c_str() : "temp.jpg", GLWin.backbuffer.w, -GLWin.backbuffer.h, 0)) //(conf.options.tga_snap)?0:1) ) { { char str[255]; sprintf(str, "saved %s\n", strSnapshot.c_str()); diff --git a/plugins/zzogl-pg/opengl/ZZoglCRTC.h b/plugins/zzogl-pg/opengl/ZZoglCRTC.h index 6a3f9dfa8..5ca9830e7 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCRTC.h +++ b/plugins/zzogl-pg/opengl/ZZoglCRTC.h @@ -62,7 +62,6 @@ extern void ProcessMessages(); void AdjustTransToAspect(float4& v); void ZZGSStateReset(); -extern int nBackbufferWidth, nBackbufferHeight; // Interlace texture is lazy 1*(height) array of 1 and 0. // If its height (named s_nInterlaceTexWidth here) is hanging we must redo diff --git a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp index fae4fd316..d81f26f21 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp @@ -89,7 +89,6 @@ inline void CreateOtherCheck(); inline bool CreateOpenShadersFile(); void ZZGSStateReset(); -extern int nBackbufferWidth, nBackbufferHeight; //------------------ Dummies #ifdef _WIN32 @@ -373,13 +372,13 @@ inline bool CreateOpenShadersFile() // Read all extensions name and fill mapGLExtensions inline bool CreateFillExtensionsMap() { + string temp(""); int max_ext = 0; glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); PFNGLGETSTRINGIPROC glGetStringi = 0; glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); - string temp(""); for (GLint i = 0; i < max_ext; i++) { string extension((const char*)glGetStringi(GL_EXTENSIONS, i)); @@ -512,7 +511,7 @@ bool ZZCreate(int _width, int _height) //s_bWriteDepth = true; GL_BLEND_ALL(GL_ONE, GL_ONE, GL_ONE, GL_ONE); - glViewport(0, 0, nBackbufferWidth, nBackbufferHeight); // Reset The Current Viewport + glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h); // Reset The Current Viewport glMatrixMode(GL_PROJECTION); glLoadIdentity(); diff --git a/plugins/zzogl-pg/opengl/ZZoglShoots.cpp b/plugins/zzogl-pg/opengl/ZZoglShoots.cpp index af96b974e..7455f0fd6 100644 --- a/plugins/zzogl-pg/opengl/ZZoglShoots.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglShoots.cpp @@ -47,9 +47,6 @@ extern "C" #include "jpeglib.h" } - -extern int nBackbufferWidth, nBackbufferHeight; - //------------------ Defines #define TGA_FILE_NAME_MAX_LENGTH 20 #define MAX_NUMBER_SAVED_TGA 200 @@ -355,15 +352,15 @@ void CaptureFrame() { if ((!s_avicapturing) || (!s_aviinit)) return; - vector data(nBackbufferWidth*nBackbufferHeight); - glReadPixels(0, 0, nBackbufferWidth, nBackbufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); + vector data(GLWin.backbuffer.w * GLWin.backbuffer.h); + glReadPixels(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); if (glGetError() != GL_NO_ERROR) return; #ifdef _WIN32 int fps = SMODE1->CMOD == 3 ? 50 : 60; - bool bSuccess = ADD_FRAME_FROM_DIB_TO_AVI("AAAA", fps, nBackbufferWidth, nBackbufferHeight, 32, &data[0]); + bool bSuccess = ADD_FRAME_FROM_DIB_TO_AVI("AAAA", fps, GLWin.backbuffer.w, GLWin.backbuffer.h, 32, &data[0]); if (!bSuccess) { diff --git a/plugins/zzogl-pg/opengl/zerogs.cpp b/plugins/zzogl-pg/opengl/zerogs.cpp index a8a0721a9..432d4ee84 100644 --- a/plugins/zzogl-pg/opengl/zerogs.cpp +++ b/plugins/zzogl-pg/opengl/zerogs.cpp @@ -33,7 +33,6 @@ int s_nNewWidth = -1, s_nNewHeight = -1; primInfo *prim; //////////////////// // State parameters -int nBackbufferWidth, nBackbufferHeight; int g_nDepthUpdateCount = 0; static ZeroGSInit s_ZeroGSInit; @@ -130,20 +129,7 @@ void ZZGSStateReset() vb[1].ictx = 1; } -void ChangeWindowSize(int nNewWidth, int nNewHeight) -{ - FUNCLOG - nBackbufferWidth = max(nNewWidth, 16); - nBackbufferHeight = max(nNewHeight, 16); - - if (!(conf.fullscreen())) - { - conf.width = nNewWidth; - conf.height = nNewHeight; - } -} - -void SetChangeDeviceSize(int nNewWidth, int nNewHeight) +void SetDeviceSize(int nNewWidth, int nNewHeight) { FUNCLOG s_nNewWidth = nNewWidth; @@ -160,13 +146,13 @@ void ChangeDeviceSize(int nNewWidth, int nNewHeight) { FUNCLOG - int oldwidth = nBackbufferWidth, oldheight = nBackbufferHeight; + Size oldSize = GLWin.backbuffer; if (!ZZCreate(nNewWidth&~7, nNewHeight&~7)) { ZZLog::Error_Log("Failed to recreate, changing to old device."); - if (!ZZCreate(oldwidth, oldheight)) + if (!ZZCreate(oldSize.w, oldSize.h)) { SysMessage("Failed to create device, exiting..."); exit(0); @@ -229,7 +215,7 @@ void SetAA(int mode) // DisableAllgl() ; // SetShaderCaller("RenderCustom"); // -// glViewport(0, 0, nBackbufferWidth, nBackbufferHeight); +// glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h); // // // play custom animation // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);