GregMiscellaneous: zzogl-pg: Work on the GLWin functions a bit.

git-svn-id: http://pcsx2.googlecode.com/svn/branches/GregMiscellaneous@4017 96395faa-99c1-11dd-bbfe-3dabce05a288
This commit is contained in:
arcum42 2010-11-14 01:38:10 +00:00
parent 0779f7bc32
commit 951d45677f
10 changed files with 70 additions and 73 deletions

View File

@ -29,6 +29,9 @@
#undef CreateWindow // Undo Windows.h global namespace pollution #undef CreateWindow // Undo Windows.h global namespace pollution
extern void SetDeviceSize(int nNewWidth, int nNewHeight);
extern void OnFKey(int key, int shift);
class GLWindow class GLWindow
{ {
private: private:
@ -52,6 +55,7 @@ class GLWindow
public: public:
char title[256]; char title[256];
Size backbuffer;
void SwapGLBuffers(); void SwapGLBuffers();
bool ReleaseContext(); bool ReleaseContext();
@ -66,13 +70,21 @@ class GLWindow
void SetTitle(char *strtitle); void SetTitle(char *strtitle);
void ResizeCheck(); void ResizeCheck();
void ProcessEvents(); 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 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 #endif // GLWIN_H_INCLUDED

View File

@ -47,14 +47,14 @@ LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
case WM_SIZE: case WM_SIZE:
nWindowWidth = lParam & 0xffff; nWindowWidth = lParam & 0xffff;
nWindowHeight = lParam >> 16; nWindowHeight = lParam >> 16;
ChangeWindowSize(nWindowWidth, nWindowHeight); UpdateWindowSize(nWindowWidth, nWindowHeight);
break; break;
case WM_SIZING: case WM_SIZING:
// if button is 0, then just released so can resize // if button is 0, then just released so can resize
if (GetSystemMetrics(SM_SWAPBUTTON) ? !GetAsyncKeyState(VK_RBUTTON) : !GetAsyncKeyState(VK_LBUTTON)) if (GetSystemMetrics(SM_SWAPBUTTON) ? !GetAsyncKeyState(VK_RBUTTON) : !GetAsyncKeyState(VK_LBUTTON))
{ {
SetChangeDeviceSize(nWindowWidth, nWindowHeight); SetDeviceSize(nWindowWidth, nWindowHeight);
} }
break; break;
@ -189,8 +189,8 @@ bool GLWindow::DisplayWindow(int _width, int _height)
if (conf.fullscreen()) if (conf.fullscreen())
{ {
nBackbufferWidth = rcdesktop.right - rcdesktop.left; backbuffer.w = rcdesktop.right - rcdesktop.left;
nBackbufferHeight = rcdesktop.bottom - rcdesktop.top; backbuffer.h = rcdesktop.bottom - rcdesktop.top;
dwExStyle = WS_EX_APPWINDOW; dwExStyle = WS_EX_APPWINDOW;
dwStyle = WS_POPUP; dwStyle = WS_POPUP;
@ -200,8 +200,8 @@ bool GLWindow::DisplayWindow(int _width, int _height)
{ {
dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE;
dwStyle = WS_OVERLAPPEDWINDOW; dwStyle = WS_OVERLAPPEDWINDOW;
nBackbufferWidth = _width; backbuffer.w = _width;
nBackbufferHeight = _height; backbuffer.h = _height;
} }
dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN; dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN;
@ -209,8 +209,8 @@ bool GLWindow::DisplayWindow(int _width, int _height)
rc.left = 0; rc.left = 0;
rc.top = 0; rc.top = 0;
rc.right = nBackbufferWidth; rc.right = backbuffer.h;
rc.bottom = nBackbufferHeight; rc.bottom = backbuffer.h;
AdjustWindowRectEx(&rc, dwStyle, false, dwExStyle); AdjustWindowRectEx(&rc, dwStyle, false, dwExStyle);
int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2; int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2;
int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 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; DEVMODE dmScreenSettings;
memset(&dmScreenSettings, 0, sizeof(dmScreenSettings)); memset(&dmScreenSettings, 0, sizeof(dmScreenSettings));
dmScreenSettings.dmSize = sizeof(dmScreenSettings); dmScreenSettings.dmSize = sizeof(dmScreenSettings);
dmScreenSettings.dmPelsWidth = nBackbufferWidth; dmScreenSettings.dmPelsWidth = backbuffer.w;
dmScreenSettings.dmPelsHeight = nBackbufferHeight; dmScreenSettings.dmPelsHeight = backbuffer.h;
dmScreenSettings.dmBitsPerPel = 32; dmScreenSettings.dmBitsPerPel = 32;
dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT; dmScreenSettings.dmFields = DM_BITSPERPEL | DM_PELSWIDTH | DM_PELSHEIGHT;
@ -387,7 +387,7 @@ void GLWindow::ProcessEvents()
{ {
conf.zz_options.fullscreen = !conf.zz_options.fullscreen; conf.zz_options.fullscreen = !conf.zz_options.fullscreen;
SetChangeDeviceSize( SetDeviceSize(
(conf.fullscreen()) ? 1280 : conf.width, (conf.fullscreen()) ? 1280 : conf.width,
(conf.fullscreen()) ? 960 : conf.height); (conf.fullscreen()) ? 960 : conf.height);
} }

View File

@ -138,7 +138,7 @@ void GLWindow::GetWindowSize()
XUnlockDisplay(glDisplay); XUnlockDisplay(glDisplay);
// update the gl buffer size // 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); 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) bool GLWindow::DisplayWindow(int _width, int _height)
{ {
nBackbufferWidth = _width; backbuffer.w = _width;
nBackbufferHeight = _height; backbuffer.h = _height;
if (!CreateVisual()) return false; if (!CreateVisual()) return false;
@ -342,7 +342,7 @@ void GLWindow::ResizeCheck()
width = event.xconfigure.width; width = event.xconfigure.width;
height = event.xconfigure.height; height = event.xconfigure.height;
Force43Ratio(); Force43Ratio();
ChangeWindowSize(width, height); UpdateWindowSize(width, height);
} }
if (!fullScreen) { if (!fullScreen) {

View File

@ -23,6 +23,7 @@
#include "GLWin.h" #include "GLWin.h"
#include "ZZoglFlushHack.h" #include "ZZoglFlushHack.h"
using namespace std; using namespace std;
extern void SaveSnapshot(const char* filename); extern void SaveSnapshot(const char* filename);
@ -45,7 +46,7 @@ float fFPS = 0;
void (*GSirq)(); void (*GSirq)();
u8* g_pBasePS2Mem = NULL; 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 bool SaveStateExists = true; // We could not know save slot status before first change occured
const char* SaveStateFile = NULL; // Name of SaveFile for access check. const char* SaveStateFile = NULL; // Name of SaveFile for access check.
@ -76,10 +77,16 @@ extern void WriteBilinear();
extern void ZZDestroy(); extern void ZZDestroy();
extern bool ZZCreate(int width, int height); extern bool ZZCreate(int width, int height);
extern void ZZGSStateReset(); 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 // switches the render target to the real target, flushes the current render targets and renders the real image
extern void RenderCRTC(int interlace); extern void RenderCRTC(int interlace);
#if defined(_WIN32) && defined(_DEBUG)
HANDLE g_hCurrentThread = NULL;
#endif
extern int VALIDATE_THRESH; extern int VALIDATE_THRESH;
extern u32 TEXDESTROY_THRESH; extern u32 TEXDESTROY_THRESH;
@ -124,10 +131,6 @@ void CALLBACK GSsetGameCRC(int crc, int options)
inited = true; inited = true;
memset(GSC_list, 0, sizeof(GSC_list)); 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[Okami] = GSC_Okami;
GSC_list[MetalGearSolid3] = GSC_MetalGearSolid3; GSC_list[MetalGearSolid3] = GSC_MetalGearSolid3;
@ -268,10 +271,6 @@ s32 CALLBACK GSinit()
return 0; return 0;
} }
#if defined(_WIN32) && defined(_DEBUG)
HANDLE g_hCurrentThread = NULL;
#endif
__forceinline void InitMisc() __forceinline void InitMisc()
{ {
WriteBilinear(); WriteBilinear();
@ -415,13 +414,12 @@ void CALLBACK GSmakeSnapshot(char *path)
if ((bmpfile = fopen(filename, "wb")) == NULL) if ((bmpfile = fopen(filename, "wb")) == NULL)
{ {
char strdir[255]; char strdir[255];
sprintf(strdir, "%s", path);
#ifdef _WIN32 #ifdef _WIN32
sprintf(strdir, "%s", path);
CreateDirectory(strdir, NULL); CreateDirectory(strdir, NULL);
#else #else
sprintf(strdir, "mkdir %s", path); mkdir(path, 0777);
system(strdir);
#endif #endif
if ((bmpfile = fopen(filename, "wb")) == NULL) return; if ((bmpfile = fopen(filename, "wb")) == NULL) return;
@ -562,9 +560,6 @@ int CALLBACK GSsetupRecording(int start, void* pData)
return 1; return 1;
} }
int ZZSave(s8* pbydata);
bool ZZLoad(s8* pbydata);
s32 CALLBACK GSfreeze(int mode, freezeData *data) s32 CALLBACK GSfreeze(int mode, freezeData *data)
{ {
FUNCLOG FUNCLOG

View File

@ -22,16 +22,21 @@
#ifdef _WIN32 #ifdef _WIN32
#include <io.h> #include <io.h>
#include "Utilities/RedtapeWindows.h" #include "Utilities/RedtapeWindows.h"
#include <windows.h> #include <windows.h>
#include <windowsx.h> #include <windowsx.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glext.h> #include <GL/glext.h>
#include "glprocs.h" #include "glprocs.h"
#else // linux basic definitions #else // linux basic definitions
#include <sys/stat.h>
#include <GL/glew.h> #include <GL/glew.h>
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glext.h> #include <GL/glext.h>
@ -40,7 +45,6 @@
#endif #endif
#define GSdefs #define GSdefs
//Pcsx2Defs is included in Dependencies.h. //Pcsx2Defs is included in Dependencies.h.
@ -72,6 +76,11 @@ typedef struct
int x, y; int x, y;
} Point; } Point;
typedef struct
{
int w, h;
} Size;
typedef struct typedef struct
{ {
int x0, y0; int x0, y0;

View File

@ -65,21 +65,21 @@ void AdjustTransToAspect(float4& v)
float f; float f;
const float mult = 1 / 32767.0f; 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 // 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.y *= f;
v.w *= f; v.w *= f;
// scanlines mess up when not aligned right // 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.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)nBackbufferHeight * 0.5f + 0.05f, &temp)) * 2.0f / (float)nBackbufferHeight; 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 else // limited by height
{ {
f = ((float)nBackbufferHeight / (float)conf.height) / ((float)nBackbufferWidth / (float)conf.width); f = ((float)GLWin.backbuffer.h / (float)conf.height) / ((float)GLWin.backbuffer.w / (float)conf.width);
f -= (float)modf(f * nBackbufferWidth, &temp) / (float)nBackbufferWidth; f -= (float)modf(f * GLWin.backbuffer.w, &temp) / (float)GLWin.backbuffer.w;
v.x *= f; v.x *= f;
v.z *= f; v.z *= f;
} }
@ -211,7 +211,7 @@ inline void RenderStartHelper(u32 bInterlace)
glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0); // switch to the backbuffer 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 interlace, only clear every other vsync
if (!bInterlace) if (!bInterlace)
@ -642,7 +642,7 @@ void DrawText(const char* pstr, int left, int top, u32 color)
v.SetColor(color); v.SetColor(color);
glColor3f(v.z, v.y, v.x); 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(); ZZshGLEnableProfile();
} }
@ -670,7 +670,7 @@ inline void MakeSnapshot()
DrawText(str, left + 1, top + 1, 0xff000000); DrawText(str, left + 1, top + 1, 0xff000000);
DrawText(str, left, top, 0xffc0ffff); 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]; char str[255];
sprintf(str, "saved %s\n", strSnapshot.c_str()); sprintf(str, "saved %s\n", strSnapshot.c_str());

View File

@ -62,7 +62,6 @@ extern void ProcessMessages();
void AdjustTransToAspect(float4& v); void AdjustTransToAspect(float4& v);
void ZZGSStateReset(); void ZZGSStateReset();
extern int nBackbufferWidth, nBackbufferHeight;
// Interlace texture is lazy 1*(height) array of 1 and 0. // Interlace texture is lazy 1*(height) array of 1 and 0.
// If its height (named s_nInterlaceTexWidth here) is hanging we must redo // If its height (named s_nInterlaceTexWidth here) is hanging we must redo

View File

@ -89,7 +89,6 @@ inline void CreateOtherCheck();
inline bool CreateOpenShadersFile(); inline bool CreateOpenShadersFile();
void ZZGSStateReset(); void ZZGSStateReset();
extern int nBackbufferWidth, nBackbufferHeight;
//------------------ Dummies //------------------ Dummies
#ifdef _WIN32 #ifdef _WIN32
@ -373,13 +372,13 @@ inline bool CreateOpenShadersFile()
// Read all extensions name and fill mapGLExtensions // Read all extensions name and fill mapGLExtensions
inline bool CreateFillExtensionsMap() inline bool CreateFillExtensionsMap()
{ {
string temp("");
int max_ext = 0; int max_ext = 0;
glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext);
PFNGLGETSTRINGIPROC glGetStringi = 0; PFNGLGETSTRINGIPROC glGetStringi = 0;
glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi");
string temp("");
for (GLint i = 0; i < max_ext; i++) for (GLint i = 0; i < max_ext; i++)
{ {
string extension((const char*)glGetStringi(GL_EXTENSIONS, i)); string extension((const char*)glGetStringi(GL_EXTENSIONS, i));
@ -512,7 +511,7 @@ bool ZZCreate(int _width, int _height)
//s_bWriteDepth = true; //s_bWriteDepth = true;
GL_BLEND_ALL(GL_ONE, GL_ONE, GL_ONE, GL_ONE); 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); glMatrixMode(GL_PROJECTION);
glLoadIdentity(); glLoadIdentity();

View File

@ -47,9 +47,6 @@ extern "C"
#include "jpeglib.h" #include "jpeglib.h"
} }
extern int nBackbufferWidth, nBackbufferHeight;
//------------------ Defines //------------------ Defines
#define TGA_FILE_NAME_MAX_LENGTH 20 #define TGA_FILE_NAME_MAX_LENGTH 20
#define MAX_NUMBER_SAVED_TGA 200 #define MAX_NUMBER_SAVED_TGA 200
@ -355,15 +352,15 @@ void CaptureFrame()
{ {
if ((!s_avicapturing) || (!s_aviinit)) return; if ((!s_avicapturing) || (!s_aviinit)) return;
vector<u32> data(nBackbufferWidth*nBackbufferHeight); vector<u32> data(GLWin.backbuffer.w * GLWin.backbuffer.h);
glReadPixels(0, 0, nBackbufferWidth, nBackbufferHeight, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]); glReadPixels(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h, GL_RGBA, GL_UNSIGNED_BYTE, &data[0]);
if (glGetError() != GL_NO_ERROR) return; if (glGetError() != GL_NO_ERROR) return;
#ifdef _WIN32 #ifdef _WIN32
int fps = SMODE1->CMOD == 3 ? 50 : 60; 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) if (!bSuccess)
{ {

View File

@ -33,7 +33,6 @@ int s_nNewWidth = -1, s_nNewHeight = -1;
primInfo *prim; primInfo *prim;
//////////////////// ////////////////////
// State parameters // State parameters
int nBackbufferWidth, nBackbufferHeight;
int g_nDepthUpdateCount = 0; int g_nDepthUpdateCount = 0;
static ZeroGSInit s_ZeroGSInit; static ZeroGSInit s_ZeroGSInit;
@ -130,20 +129,7 @@ void ZZGSStateReset()
vb[1].ictx = 1; vb[1].ictx = 1;
} }
void ChangeWindowSize(int nNewWidth, int nNewHeight) void SetDeviceSize(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)
{ {
FUNCLOG FUNCLOG
s_nNewWidth = nNewWidth; s_nNewWidth = nNewWidth;
@ -160,13 +146,13 @@ void ChangeDeviceSize(int nNewWidth, int nNewHeight)
{ {
FUNCLOG FUNCLOG
int oldwidth = nBackbufferWidth, oldheight = nBackbufferHeight; Size oldSize = GLWin.backbuffer;
if (!ZZCreate(nNewWidth&~7, nNewHeight&~7)) if (!ZZCreate(nNewWidth&~7, nNewHeight&~7))
{ {
ZZLog::Error_Log("Failed to recreate, changing to old device."); 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..."); SysMessage("Failed to create device, exiting...");
exit(0); exit(0);
@ -229,7 +215,7 @@ void SetAA(int mode)
// DisableAllgl() ; // DisableAllgl() ;
// SetShaderCaller("RenderCustom"); // SetShaderCaller("RenderCustom");
// //
// glViewport(0, 0, nBackbufferWidth, nBackbufferHeight); // glViewport(0, 0, GLWin.backbuffer.w, GLWin.backbuffer.h);
// //
// // play custom animation // // play custom animation
// glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT); // glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT | GL_STENCIL_BUFFER_BIT);