diff options
| author | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2010-08-18 01:34:01 +0000 |
|---|---|---|
| committer | SND\weimingzhi_cp <SND\weimingzhi_cp@e17a0e51-4ae3-4d35-97c3-1a29b211df97> | 2010-08-18 01:34:01 +0000 |
| commit | c4f5208806fe4136b19cce9f63f03820fc49d0cf (patch) | |
| tree | c1f42770d9fc0f88538993f0fb4cc78c364c056e /plugins/peopsxgl/gpu.c | |
| parent | c4a77870fcb7793bd5a7611b9994a5b15a335a3c (diff) | |
| download | pcsxr-c4f5208806fe4136b19cce9f63f03820fc49d0cf.tar.gz | |
peopsxgl: Readded windows support.
git-svn-id: https://pcsxr.svn.codeplex.com/svn/pcsxr@56180 e17a0e51-4ae3-4d35-97c3-1a29b211df97
Diffstat (limited to 'plugins/peopsxgl/gpu.c')
| -rw-r--r-- | plugins/peopsxgl/gpu.c | 291 |
1 files changed, 288 insertions, 3 deletions
diff --git a/plugins/peopsxgl/gpu.c b/plugins/peopsxgl/gpu.c index 307a1ed9..bde3f4a4 100644 --- a/plugins/peopsxgl/gpu.c +++ b/plugins/peopsxgl/gpu.c @@ -20,6 +20,9 @@ //#define NOVMODE
#include "stdafx.h"
+
+#ifndef _WINDOWS
+
#include "config.h"
#ifndef NOVMODE
@@ -28,6 +31,8 @@ static XF86VidModeModeInfo **modes=0; static int iOldMode=0;
#endif
+#endif
+
#define _IN_GPU
#include "externals.h"
@@ -40,6 +45,10 @@ static int iOldMode=0; #include "menu.h"
#include "fps.h"
#include "key.h"
+#ifdef _WINDOWS
+#include "resource.h"
+#include "ssave.h"
+#endif
#ifdef ENABLE_NLS
#include <libintl.h>
#include <locale.h>
@@ -49,7 +58,7 @@ static int iOldMode=0; #define _(x) (x)
#define N_(x) (x)
#endif
-
+
////////////////////////////////////////////////////////////////////////
// PPDK developer must change libraryName field and can change revision and build
////////////////////////////////////////////////////////////////////////
@@ -84,6 +93,10 @@ BOOL bNeedInterlaceUpdate=FALSE; BOOL bNeedRGB24Update=FALSE;
BOOL bChangeWinMode=FALSE;
+#ifdef _WINDOWS
+extern HGLRC GLCONTEXT;
+#endif
+
uint32_t ulStatusControl[256];
////////////////////////////////////////////////////////////////////////
@@ -168,8 +181,15 @@ char * GPUgetLibInfos(void) // snapshot funcs (saves screen to bitmap / text infos into file)
////////////////////////////////////////////////////////////////////////
+#ifdef _WINDOWS
+char * GetConfigInfos(HWND hW)
+#else
char * GetConfigInfos(int hW)
+#endif
{
+#ifdef _WINDOWS
+ HDC hdc;HGLRC hglrc;
+#endif
char szO[2][4]={"off","on "};
char szTxt[256];
char * pB=(char *)malloc(32767);
@@ -177,11 +197,21 @@ char * GetConfigInfos(int hW) if(!pB) return NULL;
*pB=0;
//----------------------------------------------------//
- sprintf(szTxt,"Plugin: %s %d.%d.%d\r\n",libraryName,version,revision,build);
+ sprintf(szTxt,"Plugin: %s %d.%d.%d (mod)\r\n",libraryName,version,revision,build);
strcat(pB,szTxt);
sprintf(szTxt,"Author: %s\r\n",PluginAuthor);
strcat(pB,szTxt);
+#ifdef _WINDOWS
+ if(hW)
+ {
+ hdc = GetDC(hW);
+ bSetupPixelFormat(hdc);
+ hglrc = wglCreateContext(hdc);
+ wglMakeCurrent(hdc, hglrc);
+ }
+#endif
+
sprintf(szTxt,"Card vendor: %s\r\n",(char *)glGetString(GL_VENDOR));
strcat(pB,szTxt);
sprintf(szTxt,"GFX card: %s\r\n",(char *)glGetString(GL_RENDERER));
@@ -191,6 +221,16 @@ char * GetConfigInfos(int hW) //strcat(pB,(char *)glGetString(GL_EXTENSIONS));
//strcat(pB,"\r\n\r\n");
+#ifdef _WINDOWS
+ if(hW)
+ {
+ wglMakeCurrent(NULL, NULL);
+ wglDeleteContext(hglrc);
+ ReleaseDC(hW,hdc);
+ }
+ //----------------------------------------------------//
+#endif
+
if(hW && bWindowMode)
sprintf(szTxt,"Resolution/Color:\r\n- %dx%d ",LOWORD(iWinSize),HIWORD(iWinSize));
else
@@ -328,7 +368,11 @@ void DoTextSnapShot(int iNum) {
FILE *txtfile;char szTxt[256];char * pB;
+#ifdef _WINDOWS
+ sprintf(szTxt,"snap\\pcsx%04d.txt",iNum);
+#else
sprintf(szTxt,"%s/pcsx%04d.txt",getenv("HOME"),iNum);
+#endif
if((txtfile=fopen(szTxt,"wb"))==NULL)
return;
@@ -393,7 +437,11 @@ void DoSnapShot(void) do
{
snapshotnr++;
+#ifdef _WINDOWS
+ sprintf(filename,"snap/pcsx%04d.bmp",snapshotnr);
+#else
sprintf(filename,"%s/pcsx%04d.bmp",getenv("HOME"),snapshotnr);
+#endif
bmpfile=fopen(filename,"rb");
if(bmpfile==NULL)break;
fclose(bmpfile);
@@ -421,6 +469,9 @@ void DoSnapShot(void) free(snapshotdumpmem);
DoTextSnapShot(snapshotnr);
+#ifdef _WINDOWS
+ MessageBeep((UINT)-1);
+#endif
}
void CALLBACK GPUmakeSnapshot(void)
@@ -509,6 +560,140 @@ long CALLBACK GPUinit() // GPU OPEN: funcs to open up the gpu display (Windows)
////////////////////////////////////////////////////////////////////////
+#ifdef _WINDOWS
+
+void ChangeDesktop() // change destop resolution
+{
+ DEVMODE dv;long lRes,iTry=0;
+
+ while(iTry<10) // keep on hammering...
+ {
+ memset(&dv,0,sizeof(DEVMODE));
+ dv.dmSize=sizeof(DEVMODE);
+ dv.dmBitsPerPel=iColDepth;
+ dv.dmPelsWidth=iResX;
+ dv.dmPelsHeight=iResY;
+
+ dv.dmFields=DM_BITSPERPEL|DM_PELSWIDTH|DM_PELSHEIGHT;
+
+ lRes=ChangeDisplaySettings(&dv,0); // ...hammering the anvil
+
+ if(lRes==DISP_CHANGE_SUCCESSFUL) return;
+ iTry++;Sleep(10);
+ }
+}
+
+////////////////////////////////////////////////////////////////////////
+// OPEN interface func: attention!
+// some emus are calling this func in their main Window thread,
+// but all other interface funcs (to draw stuff) in a different thread!
+// that's a problem, since OGL is thread safe! Therefore we cannot
+// initialize the OGL stuff right here, we simply set a "bIsFirstFrame = TRUE"
+// flag, to initialize OGL on the first real draw call.
+// btw, we also call this open func ourselfes, each time when the user
+// is changing between fullscreen/window mode (ENTER key)
+// btw part 2: in windows the plugin gets the window handle from the
+// main emu, and doesn't create it's own window (if it would do it,
+// some PAD or SPU plugins would not work anymore)
+////////////////////////////////////////////////////////////////////////
+
+HMENU hPSEMenu=NULL;
+
+long CALLBACK GPUopen(HWND hwndGPU)
+{
+ HDC hdc;RECT r;DEVMODE dv;
+
+ hWWindow = hwndGPU; // store hwnd globally
+
+ InitKeyHandler(); // init key handler (subclass window)
+
+ if(bChangeWinMode) // user wants to change fullscreen/window mode?
+ {
+ ReadWinSizeConfig(); // -> get sizes again
+ }
+ else // first real startup
+ {
+ ReadConfig(); // -> read config from registry
+
+ SetFrameRateConfig(); // -> setup frame rate stuff
+ }
+
+ if(iNoScreenSaver) EnableScreenSaver(FALSE); // at least we can try
+
+
+ memset(&dv,0,sizeof(DEVMODE));
+ dv.dmSize=sizeof(DEVMODE);
+ EnumDisplaySettings(NULL,ENUM_CURRENT_SETTINGS,&dv);
+
+ bIsFirstFrame = TRUE; // flag: we have to init OGL later in windows!
+
+ if(bWindowMode) // win mode?
+ {
+ DWORD dw=GetWindowLong(hWWindow, GWL_STYLE); // -> adjust wnd style (owndc needed by some stupid ogl drivers)
+ dw&=~WS_THICKFRAME;
+ dw|=WS_BORDER|WS_CAPTION|CS_OWNDC;
+ SetWindowLong(hWWindow, GWL_STYLE, dw);
+
+ hPSEMenu=GetMenu(hWWindow); // -> hide emu menu (if any)
+ if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
+
+ iResX=LOWORD(iWinSize);iResY=HIWORD(iWinSize);
+ ShowWindow(hWWindow,SW_SHOWNORMAL);
+
+ MoveWindow(hWWindow, // -> center wnd
+ GetSystemMetrics(SM_CXFULLSCREEN)/2-iResX/2,
+ GetSystemMetrics(SM_CYFULLSCREEN)/2-iResY/2,
+ iResX+GetSystemMetrics(SM_CXFIXEDFRAME)+3,
+ iResY+GetSystemMetrics(SM_CYFIXEDFRAME)+GetSystemMetrics(SM_CYCAPTION)+3,
+ TRUE);
+ UpdateWindow(hWWindow); // -> let windows do some update
+
+ if(dv.dmBitsPerPel==16 || dv.dmBitsPerPel==32) // -> overwrite user color info with desktop color info
+ iColDepth=dv.dmBitsPerPel;
+ }
+ else // fullscreen mode:
+ {
+ if(dv.dmBitsPerPel!=(unsigned int)iColDepth || // -> check, if we have to change resolution
+ dv.dmPelsWidth !=(unsigned int)iResX ||
+ dv.dmPelsHeight!=(unsigned int)iResY)
+ bChangeRes=TRUE; else bChangeRes=FALSE;
+
+ if(bChangeRes) ChangeDesktop(); // -> change the res (had to do an own func because of some MS 'optimizations')
+
+ SetWindowLong(hWWindow, GWL_STYLE, CS_OWNDC); // -> adjust wnd style as well (to be sure)
+
+ hPSEMenu=GetMenu(hWWindow); // -> hide menu
+ if(hPSEMenu!=NULL) SetMenu(hWWindow,NULL);
+ ShowWindow(hWWindow,SW_SHOWMAXIMIZED); // -> max mode
+ }
+
+ rRatioRect.left = rRatioRect.top=0;
+ rRatioRect.right = iResX;
+ rRatioRect.bottom = iResY;
+
+ r.left=r.top=0;r.right=iResX;r.bottom=iResY; // hack for getting a clean black window until OGL gets initialized
+ hdc = GetDC(hWWindow);
+ FillRect(hdc,&r,(HBRUSH)GetStockObject(BLACK_BRUSH));
+ bSetupPixelFormat(hdc);
+ ReleaseDC(hWWindow,hdc);
+
+ bDisplayNotSet = TRUE;
+ bSetClip=TRUE;
+
+ SetFixes(); // setup game fixes
+
+ InitializeTextureStore(); // init texture mem
+
+// lGPUstatusRet = 0x74000000;
+
+// with some emus, we could do the OGL init right here... oh my
+// if(bIsFirstFrame) GLinitialize();
+
+ return 0;
+}
+
+#else
+
////////////////////////////////////////////////////////////////////////
// LINUX GPU OPEN: func to open up the gpu display (X stuff)
// please note: in linux we are creating our own display, and we return
@@ -844,10 +1029,36 @@ long GPUopen(unsigned long * disp,char * CapText,char * CfgFile) return -1;
}
+#endif
+
////////////////////////////////////////////////////////////////////////
// close
////////////////////////////////////////////////////////////////////////
+#ifdef _WINDOWS
+
+long CALLBACK GPUclose() // WINDOWS CLOSE
+{
+ ExitKeyHandler();
+
+ GLcleanup(); // close OGL
+
+ if(bChangeRes) // change res back
+ ChangeDisplaySettings(NULL,0);
+
+ if(hPSEMenu) // set menu again
+ SetMenu(hWWindow,hPSEMenu);
+
+ if(pGfxCardScreen) free(pGfxCardScreen); // free helper memory
+ pGfxCardScreen=0;
+
+ if(iNoScreenSaver) EnableScreenSaver(TRUE); // enable screen saver again
+
+ return 0;
+}
+
+#else
+
long GPUclose() // LINUX CLOSE
{
GLcleanup(); // close OGL
@@ -860,6 +1071,8 @@ long GPUclose() // LINUX CLOSE return 0;
}
+#endif
+
////////////////////////////////////////////////////////////////////////
// I shot the sheriff... last function called from emu
////////////////////////////////////////////////////////////////////////
@@ -1180,6 +1393,11 @@ void updateDisplay(void) // UPDATE DISPLAY {
BOOL bBlur=FALSE;
+#ifdef _WINDOWS
+ HDC hdc=GetDC(hWWindow); // windows:
+ wglMakeCurrent(hdc,GLCONTEXT); // -> make context current again
+#endif
+
bFakeFrontBuffer=FALSE;
bRenderFrontBuffer=FALSE;
@@ -1267,7 +1485,11 @@ void updateDisplay(void) // UPDATE DISPLAY if(!bSkipNextFrame)
{
if(iDrawnSomething)
+#ifdef _WINDOWS
+ SwapBuffers(wglGetCurrentDC()); // -> to skip or not to skip
+#else
glXSwapBuffers(display,window);
+#endif
}
if(dwActFixes&0x180) // -> special old frame skipping: skip max one in a row
{
@@ -1280,7 +1502,11 @@ void updateDisplay(void) // UPDATE DISPLAY else // no skip ?
{
if(iDrawnSomething)
+#ifdef _WINDOWS
+ SwapBuffers(wglGetCurrentDC()); // -> swap
+#else
glXSwapBuffers(display,window);
+#endif
}
iDrawnSomething=0;
@@ -1364,6 +1590,10 @@ void updateDisplay(void) // UPDATE DISPLAY rRatioRect.bottom+i4);
}
+#ifdef _WINDOWS
+ ReleaseDC(hWWindow,hdc); // ! important !
+#endif
+
if(ulKeybits&KEY_RESETTEXSTORE) ResetStuff(); // reset on gpu mode changes? do it before next frame is filled
}
@@ -1390,8 +1620,18 @@ void updateFrontDisplay(void) if(gTexPicName) DisplayPic();
if(ulKeybits&KEY_SHOWFPS) DisplayText();
+#ifdef _WINDOWS
+ { // windows:
+ HDC hdc=GetDC(hWWindow);
+ wglMakeCurrent(hdc,GLCONTEXT); // -> make current again
+ if(iDrawnSomething)
+ SwapBuffers(wglGetCurrentDC()); // -> swap
+ ReleaseDC(hWWindow,hdc); // -> ! important !
+ }
+#else
if(iDrawnSomething) // linux:
glXSwapBuffers(display,window);
+#endif
if(iBlurBuffer) UnBlurBackBuffer();
}
@@ -1596,6 +1836,20 @@ void updateDisplayIfChanged(void) }
////////////////////////////////////////////////////////////////////////
+// window mode <-> fullscreen mode (windows)
+////////////////////////////////////////////////////////////////////////
+
+#ifdef _WINDOWS
+void ChangeWindowMode(void)
+ {
+ GPUclose();
+ bWindowMode=!bWindowMode;
+ GPUopen(hWWindow);
+ bChangeWinMode=FALSE;
+ }
+#endif
+
+////////////////////////////////////////////////////////////////////////
// swap update check (called by psx vsync function)
////////////////////////////////////////////////////////////////////////
@@ -1706,6 +1960,10 @@ void CALLBACK GPUupdateLace(void) {
updateDisplay();
}
+
+#ifdef _WINDOWS
+ if(bChangeWinMode) ChangeWindowMode();
+#endif
}
////////////////////////////////////////////////////////////////////////
@@ -1751,7 +2009,11 @@ uint32_t CALLBACK GPUreadStatus(void) void CALLBACK GPUwriteStatus(uint32_t gdata)
{
uint32_t lCommand=(gdata>>24)&0xff;
-
+
+#ifdef _WINDOWS
+ if(bIsFirstFrame) GLinitialize(); // real ogl startup (needed by some emus)
+#endif
+
ulStatusControl[lCommand]=gdata;
switch(lCommand)
@@ -2641,6 +2903,8 @@ void CALLBACK GPUwriteData(uint32_t gdata) // call config dlg
////////////////////////////////////////////////////////////////////////
+#ifndef _WINDOWS
+
void StartCfgTool(char *arg) // linux: start external cfg tool
{
char cfg[256];
@@ -2682,6 +2946,19 @@ long CALLBACK GPUconfigure(void) return 0;
}
+#else
+
+long CALLBACK GPUconfigure(void)
+{
+ HWND hWP=GetActiveWindow();
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_CFGDLG),
+ hWP,(DLGPROC)CfgDlgProc);
+
+ return 0;
+}
+
+#endif
+
////////////////////////////////////////////////////////////////////////
// sets all kind of act fixes
////////////////////////////////////////////////////////////////////////
@@ -2758,7 +3035,15 @@ long CALLBACK GPUdmaChain(uint32_t *baseAddrL, uint32_t addr) void CALLBACK GPUabout(void)
{
+#ifdef _WINDOWS
+ HWND hWP=GetActiveWindow(); // to be sure
+ DialogBox(hInst,MAKEINTRESOURCE(IDD_DIALOG_ABOUT),
+ hWP,(DLGPROC)AboutDlgProc);
+#else
+
StartCfgTool("ABOUT");
+
+#endif
}
////////////////////////////////////////////////////////////////////////
|
