From e4d42b1e7b0a58d8630686bd29a6f27b0a7e8771 Mon Sep 17 00:00:00 2001 From: arcum42 Date: Fri, 30 Apr 2010 04:40:31 +0000 Subject: [PATCH] zzogl-pg: Work on reducing the amount of platform specific code a bit. git-svn-id: http://pcsx2.googlecode.com/svn/trunk@2927 96395faa-99c1-11dd-bbfe-3dabce05a288 --- plugins/zzogl-pg/opengl/GLWin32.cpp | 7 + plugins/zzogl-pg/opengl/GS.h | 2 +- plugins/zzogl-pg/opengl/GSmain.cpp | 219 ++++++++---------------- plugins/zzogl-pg/opengl/Util.h | 43 ++++- plugins/zzogl-pg/opengl/Win32/Win32.cpp | 20 +++ plugins/zzogl-pg/opengl/ZZoglCRTC.cpp | 4 +- plugins/zzogl-pg/opengl/ZZoglFlush.cpp | 40 ++--- plugins/zzogl-pg/opengl/zerogs.cpp | 6 +- plugins/zzogl-pg/opengl/zerogs.h | 32 ++-- 9 files changed, 174 insertions(+), 199 deletions(-) diff --git a/plugins/zzogl-pg/opengl/GLWin32.cpp b/plugins/zzogl-pg/opengl/GLWin32.cpp index ce6fb43f14..0bb5edf95d 100644 --- a/plugins/zzogl-pg/opengl/GLWin32.cpp +++ b/plugins/zzogl-pg/opengl/GLWin32.cpp @@ -125,6 +125,13 @@ bool GLWindow::CreateWindow(void *pDisplay) if (GShwnd == NULL) return false; if (pDisplay != NULL) *(HWND*)pDisplay = GShwnd; + + // set just in case + SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc); + + ShowWindow( GShwnd, SW_SHOWDEFAULT ); + UpdateWindow( GShwnd ); + SetFocus(GShwnd); return (pDisplay != NULL); } diff --git a/plugins/zzogl-pg/opengl/GS.h b/plugins/zzogl-pg/opengl/GS.h index b71ec17a72..87875b9ffe 100644 --- a/plugins/zzogl-pg/opengl/GS.h +++ b/plugins/zzogl-pg/opengl/GS.h @@ -444,7 +444,7 @@ union tex_0_info if (tbw == 0) return 64; else - return (tbw << 6); + return ((u32)tbw << 6); } u32 psm_fix() { diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index a50b5b9c2a..972e46f3ea 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -115,25 +115,12 @@ static u64 luPerfFreq; GLWindow GLWin; #ifdef _WIN32 - HWND GShwnd = NULL; - -void SysMessage(const char *fmt, ...) { - va_list list; - char tmp[512]; - - va_start(list,fmt); - vsprintf(tmp,fmt,list); - va_end(list); - MessageBox(0, tmp, "GSsoftdx Msg", 0); -} -#else +#endif u32 THR_KeyEvent = 0; // Value for key event processing between threads bool THR_bShift = false; -#endif - namespace ZZLog { bool IsLogging() @@ -639,35 +626,32 @@ void OnKeyboardF1(int shift) { HANDLE g_hCurrentThread = NULL; #endif + extern LRESULT WINAPI MsgProc( HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam ); extern HINSTANCE hInst; -void CALLBACK GSconfigure() { - DialogBox(hInst, - MAKEINTRESOURCE(IDD_CONFIG), - GetActiveWindow(), - (DLGPROC)ConfigureDlgProc); - - if( g_nPixelShaderVer == SHADER_REDUCED ) - conf.bilinear = 0; -} +#endif s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread) { + FUNCLOG + bool err; g_GSMultiThreaded = multithread; ZZLog::GS_Log("Calling GSopen."); +#ifdef _WIN32 #ifdef _DEBUG g_hCurrentThread = GetCurrentThread(); #endif - -// assert( GSirq != NULL ); +#endif + LoadConfig(); strcpy(GStitle, Title); + err = GLWin.CreateWindow(pDsp); if (!err) @@ -675,92 +659,91 @@ s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread) ZZLog::GS_Log("Failed to create window. Exiting..."); return -1; } - + ZZLog::Error_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor); - ZZLog::Error_Log("Creating ZZOgl."); - //if (conf.record) recOpen(); + ZZLog::Error_Log("Creating ZZOgl window."); + if (!ZeroGS::Create(conf.width, conf.height)) return -1; - ZZLog::Error_Log("initialization successful"); + ZZLog::Error_Log("Initialization successful."); - if( conf.bilinear == 2 ) + switch(conf.bilinear) { - ZeroGS::AddMessage("forced bilinear filtering - on", 1000); - } - else if( conf.bilinear == 1 ) - { - ZeroGS::AddMessage("normal bilinear filtering - on", 1000); - } + case 2: + ZeroGS::AddMessage("bilinear filtering - forced", 1000); + break; - if( conf.aa ) + case 1: + ZeroGS::AddMessage("bilinear filtering - normal", 1000); + break; + + default: + break; + } + + if (conf.aa) { char strtitle[64]; - sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa], 1000); - ZeroGS::AddMessage(strtitle); + sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]); + ZeroGS::AddMessage(strtitle,1000); } - // set just in case - SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc); - - ShowWindow( GShwnd, SW_SHOWDEFAULT ); - UpdateWindow( GShwnd ); - SetFocus(GShwnd); - - ZZLog::GS_Log("GSopen finished."); - - LARGE_INTEGER temp; - QueryPerformanceFrequency(&temp); - luPerfFreq = temp.QuadPart; - + luPerfFreq = GetCPUTicks(); gs.path[0].mode = gs.path[1].mode = gs.path[2].mode = 0; + + ZZLog::GS_Log("GSopen finished."); return 0; } +#ifdef _WIN32 void ProcessMessages() { MSG msg; + ZeroMemory( &msg, sizeof(msg) ); + while( 1 ) { - if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) ) + if (PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE)) { switch( msg.message ) { case WM_KEYDOWN : - if( msg.wParam == VK_F5 ) + int my_KeyEvent = msg.wParam; + bool my_bShift = !!(GetKeyState(VK_SHIFT) & 0x8000); + + switch (msg.wParam) { - OnKeyboardF5(GetKeyState(VK_SHIFT)&0x8000); + case VK_F5: + OnKeyboardF5(my_bShift); + break; + case VK_F6: + OnKeyboardF6(my_bShift); + break; + case VK_F7: + OnKeyboardF7(my_bShift); + break; + case VK_F9: + OnKeyboardF9(my_bShift); + break; + case VK_ESCAPE: + if (conf.options & GSOPTION_FULLSCREEN) + { + // destroy that msg + conf.options &= ~GSOPTION_FULLSCREEN; + ZeroGS::ChangeDeviceSize(conf.width, conf.height); + UpdateWindow(GShwnd); + continue; // so that msg doesn't get sent + } + else + { + SendMessage(GShwnd, WM_DESTROY, 0, 0); + //g_bHidden = 1; + return; + } + break; } - else if( msg.wParam == VK_F6 ) - { - OnKeyboardF6(GetKeyState(VK_SHIFT)&0x8000); - } - else if( msg.wParam == VK_F7 ) - { - OnKeyboardF7(GetKeyState(VK_SHIFT)&0x8000); - } - else if( msg.wParam == VK_F9 ) - { - OnKeyboardF9(GetKeyState(VK_SHIFT)&0x8000); - } - else if( msg.wParam == VK_ESCAPE ) - { - - if( conf.options & GSOPTION_FULLSCREEN ) { - // destroy that msg - conf.options &= ~GSOPTION_FULLSCREEN; - ZeroGS::ChangeDeviceSize(conf.width, conf.height); - UpdateWindow(GShwnd); - continue; // so that msg doesn't get sent - } - else { - SendMessage(GShwnd, WM_DESTROY, 0, 0); - //g_bHidden = 1; - return; - } - } - break; } @@ -773,7 +756,7 @@ void ProcessMessages() } } - if ((GetKeyState(VK_MENU)&0x8000) && (GetKeyState(VK_RETURN)&0x8000)) + if ((GetKeyState(VK_MENU) & 0x8000) && (GetKeyState(VK_RETURN) & 0x8000)) { conf.options ^= GSOPTION_FULLSCREEN; @@ -781,61 +764,10 @@ void ProcessMessages() (conf.options&GSOPTION_FULLSCREEN) ? 1280 : conf.width, (conf.options&GSOPTION_FULLSCREEN) ? 960 : conf.height); } - -// if( conf.fullscreen && (GetKeyState(VK_ESCAPE)&0x8000)) { -// conf.fullscreen &= ~GSOPTION_FULLSCREEN; -// ZeroGS::SetChangeDeviceSize(conf.width, conf.height); -// } - - //if( conf.interlace && g_nGenVars + g_nTexVars + g_nAlphaVars + g_nResolve == 0 ) - // CSR->FIELD = 0; // 0 should always be the repeating at 0 } #else // linux -s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread) -{ - FUNCLOG - - ZZLog::GS_Log("Calling GSopen."); - -// assert( GSirq != NULL ); - LoadConfig(); - - strcpy(GStitle, Title); - - GLWin.CreateWindow(pDsp); - - ZZLog::Error_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor); - ZZLog::Error_Log("Creating zerogs."); - //if (conf.record) recOpen(); - if (!ZeroGS::Create(conf.width, conf.height)) return -1; - - ZZLog::Error_Log("Initialization successful."); - - if( conf.bilinear == 2 ) - { - ZeroGS::AddMessage("bilinear filtering - forced", 1000); - } - else if( conf.bilinear == 1 ) - { - ZeroGS::AddMessage("bilinear filtering - normal", 1000); - } - if( conf.aa ) - { - char strtitle[64]; - sprintf(strtitle, "anti-aliasing - %s", s_aa[conf.aa]); - ZeroGS::AddMessage(strtitle,1000); - } - - ZZLog::GS_Log("GSopen finished."); - - gs.path[0].mode = gs.path[1].mode = gs.path[2].mode = 0; - luPerfFreq = 1; - - return 0; -} - void ProcessMessages() { FUNCLOG @@ -843,7 +775,7 @@ void ProcessMessages() // check resizing GLWin.ResizeCheck(); - if ( THR_KeyEvent ) { // This values was passed from GSKeyEvents witch could be in another thread + if ( THR_KeyEvent ) { // This values was passed from GSKeyEvents which could be in another thread int my_KeyEvent = THR_KeyEvent; bool my_bShift = THR_bShift; THR_KeyEvent = 0; @@ -1100,18 +1032,7 @@ s32 CALLBACK GSfreeze(int mode, freezeData *data) #include using namespace std; -#ifdef _WIN32 - -__forceinline u64 GET_PROFILE_TIME() -{ - LARGE_INTEGER lu; - QueryPerformanceCounter(&lu); - return lu.QuadPart; -} -#else -#define GET_PROFILE_TIME() //GetCpuTick() -#endif - +#define GET_PROFILE_TIME() GetCPUTicks() struct DVPROFSTRUCT; diff --git a/plugins/zzogl-pg/opengl/Util.h b/plugins/zzogl-pg/opengl/Util.h index b242a5372d..ec5db7e9c5 100644 --- a/plugins/zzogl-pg/opengl/Util.h +++ b/plugins/zzogl-pg/opengl/Util.h @@ -95,13 +95,8 @@ static __forceinline void pcsx2_aligned_free(void* pmem) inline unsigned long timeGetTime() { -#ifdef _WIN32 - _timeb t; - _ftime(&t); -#else timeb t; ftime(&t); -#endif return (unsigned long)(t.time*1000+t.millitm); } @@ -299,6 +294,44 @@ extern "C" void * memcpy_amd(void *dest, const void *src, size_t n); extern "C" u8 memcmp_mmx(const void *dest, const void *src, int n); #endif +// Copied from Utilities; remove later. +#ifdef __LINUX__ +static __forceinline void InitCPUTicks() +{ +} + +static __forceinline u64 GetTickFrequency() +{ + return 1000000; // unix measures in microseconds +} + +static __forceinline u64 GetCPUTicks() +{ + struct timeval t; + gettimeofday(&t, NULL); + return ((u64)t.tv_sec*GetTickFrequency())+t.tv_usec; +} +#else +static __aligned16 LARGE_INTEGER lfreq; + +static __forceinline void InitCPUTicks() +{ + QueryPerformanceFrequency( &lfreq ); +} + +static __forceinline u64 GetTickFrequency() +{ + return lfreq.QuadPart; +} + +static __forceinline u64 GetCPUTicks() +{ + LARGE_INTEGER count; + QueryPerformanceCounter( &count ); + return count.QuadPart; +} +#endif + template class CInterfacePtr { diff --git a/plugins/zzogl-pg/opengl/Win32/Win32.cpp b/plugins/zzogl-pg/opengl/Win32/Win32.cpp index be7a46df1a..1e5437eaec 100644 --- a/plugins/zzogl-pg/opengl/Win32/Win32.cpp +++ b/plugins/zzogl-pg/opengl/Win32/Win32.cpp @@ -5,6 +5,7 @@ #include "resrc1.h" #include "GS.h" +#include "zerogsshaders.h" #include "Win32.h" #include @@ -210,6 +211,15 @@ BOOL CALLBACK AboutDlgProc(HWND hW, UINT uMsg, WPARAM wParam, LPARAM lParam) { return FALSE; } +void CALLBACK GSconfigure() { + DialogBox(hInst, + MAKEINTRESOURCE(IDD_CONFIG), + GetActiveWindow(), + (DLGPROC)ConfigureDlgProc); + + if (g_nPixelShaderVer == SHADER_REDUCED) conf.bilinear = 0; +} + s32 CALLBACK GStest() { return 0; } @@ -250,3 +260,13 @@ char *SysLibError() { void SysCloseLibrary(void *lib) { FreeLibrary((HINSTANCE)lib); } + +void SysMessage(const char *fmt, ...) { + va_list list; + char tmp[512]; + + va_start(list,fmt); + vsprintf(tmp,fmt,list); + va_end(list); + MessageBox(0, tmp, "GSsoftdx Msg", 0); +} diff --git a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp index 4585b5d278..a432a482e7 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCRTC.cpp @@ -45,8 +45,8 @@ BOOL g_bSaveFinalFrame = 0; // saves the input to the CRTC //------------------ variables #ifdef _WIN32 -extern HDC hDC; // Private GDI Device Context -extern HGLRC hRC; // Permanent Rendering Context +extern HDC hDC; // Private GDI Device Context +extern HGLRC hRC; // Permanent Rendering Context #endif BOOL g_bCRTCBilinear = TRUE; diff --git a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp index d6a35f42d5..bd85d2f382 100644 --- a/plugins/zzogl-pg/opengl/ZZoglFlush.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglFlush.cpp @@ -19,12 +19,6 @@ // Realisation of Flush -- drawing function of GS -//------------------ Includes -//#if defined(_WIN32) -//# include -//# include "resource.h" -//#endif - #include #include "GS.h" @@ -1244,23 +1238,23 @@ inline void AlphaSaveTarget(VB& curvb) { #ifdef _DEBUG return; // Do nothing - if( g_bSaveFlushedFrame & 0xf ) { -#ifdef _WIN32 - CreateDirectory("frames", NULL); -#else - char* strdir=""; - sprintf(strdir, "mkdir %s", "frames"); - system(strdir); -#endif - char str[255]; - sprintf(str, "frames/frame%.4d.tga", g_SaveFrameNum++); - if( (g_bSaveFlushedFrame & 2) ) { - //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // switch to the backbuffer - //glFlush(); - //SaveTexture("tex.jpg", GL_TEXTURE_RECTANGLE_NV, curvb.prndr->ptex, RW(curvb.prndr->fbw), RH(curvb.prndr->fbh)); - SaveRenderTarget(str, RW(curvb.prndr->fbw), RH(curvb.prndr->fbh), 0); - } - } +// if( g_bSaveFlushedFrame & 0xf ) { +//#ifdef _WIN32 +// CreateDirectory("frames", NULL); +//#else +// char* strdir=""; +// sprintf(strdir, "mkdir %s", "frames"); +// system(strdir); +//#endif +// char str[255]; +// sprintf(str, "frames/frame%.4d.tga", g_SaveFrameNum++); +// if( (g_bSaveFlushedFrame & 2) ) { +// //glBindFramebufferEXT( GL_FRAMEBUFFER_EXT, 0 ); // switch to the backbuffer +// //glFlush(); +// //SaveTexture("tex.jpg", GL_TEXTURE_RECTANGLE_NV, curvb.prndr->ptex, RW(curvb.prndr->fbw), RH(curvb.prndr->fbh)); +// SaveRenderTarget(str, RW(curvb.prndr->fbw), RH(curvb.prndr->fbh), 0); +// } +// } #endif } diff --git a/plugins/zzogl-pg/opengl/zerogs.cpp b/plugins/zzogl-pg/opengl/zerogs.cpp index 66dff44bb0..562bd7b5db 100644 --- a/plugins/zzogl-pg/opengl/zerogs.cpp +++ b/plugins/zzogl-pg/opengl/zerogs.cpp @@ -54,8 +54,8 @@ extern int g_nFrame, g_nRealFrame; //-------------------------- Variables #ifdef _WIN32 -HDC hDC=NULL; // Private GDI Device Context -HGLRC hRC=NULL; // Permanent Rendering Context +HDC hDC=NULL; // Private GDI Device Context +HGLRC hRC=NULL; // Permanent Rendering Context #endif bool g_bIsLost = 0; // ZZ @@ -182,9 +182,7 @@ public: g_pbyGSClut = (u8*)_aligned_malloc(256*8, 1024); // need 512 alignment! memset(g_pbyGSClut, 0, 256*8); -//#ifndef _WIN32 memset(&GLWin, 0, sizeof(GLWin)); -//#endif } ~ZeroGSInit() { _aligned_free(g_pbyGSMemory); g_pbyGSMemory = NULL; diff --git a/plugins/zzogl-pg/opengl/zerogs.h b/plugins/zzogl-pg/opengl/zerogs.h index 2d7372d436..d159645cec 100644 --- a/plugins/zzogl-pg/opengl/zerogs.h +++ b/plugins/zzogl-pg/opengl/zerogs.h @@ -27,26 +27,27 @@ #include "PS2Etypes.h" #include "PS2Edefs.h" -#ifndef _WIN32 -// adding glew support instead of glXGetProcAddress (thanks to scaught) -# include -#endif - // Need this before gl.h #ifdef _WIN32 -# include -#endif +#include #include #include +#include "glprocs.h" -#ifndef _WIN32 -# include - inline void* wglGetProcAddress(const char* x) { - return (void*)glXGetProcAddress((const GLubyte*)x); - } #else -# include "glprocs.h" + +// adding glew support instead of glXGetProcAddress (thanks to scaught) +#include +#include +#include +#include + +inline void* wglGetProcAddress(const char* x) +{ + return (void*)glXGetProcAddress((const GLubyte*)x); +} + #endif #include @@ -348,9 +349,10 @@ extern float g_fiGPU_TEXWIDTH; #define GPU_TEXMASKWIDTH (1024 >> MASKDIVISOR) // bitwise mask width for region repeat mode #ifdef _WIN32 -extern HDC hDC; // Private GDI Device Context -extern HGLRC hRC; // Permanent Rendering Context +extern HDC hDC; // Private GDI Device Context +extern HGLRC hRC; // Permanent Rendering Context #endif + extern bool g_bIsLost; // Context is lost -- could not draw extern u32 ptexBlocks; // holds information on block tiling