diff --git a/plugins/zzogl-pg/opengl/GLWin.h b/plugins/zzogl-pg/opengl/GLWin.h index ea5c7c8e12..ef093579e6 100644 --- a/plugins/zzogl-pg/opengl/GLWin.h +++ b/plugins/zzogl-pg/opengl/GLWin.h @@ -51,6 +51,8 @@ class GLWindow u32 width, height, depth; public: + char title[256]; + void SwapGLBuffers(); bool ReleaseContext(); diff --git a/plugins/zzogl-pg/opengl/GLWin32.cpp b/plugins/zzogl-pg/opengl/GLWin32.cpp index 29e5d3149b..28fa88395e 100644 --- a/plugins/zzogl-pg/opengl/GLWin32.cpp +++ b/plugins/zzogl-pg/opengl/GLWin32.cpp @@ -122,7 +122,11 @@ bool GLWindow::CreateWindow(void *pDisplay) hInstance, // Instance NULL); // Don't Pass Anything To WM_CREATE - if (GShwnd == NULL) return false; + if (GShwnd == NULL) + { + ZZLog::Error_Log("Failed to create window. Exiting..."); + return false; + } if (pDisplay != NULL) *(HWND*)pDisplay = GShwnd; @@ -135,6 +139,7 @@ bool GLWindow::CreateWindow(void *pDisplay) SetFocus(GShwnd); + if (pDisplay == NULL) ZZLog::Error_Log("Failed to create window. Exiting..."); return (pDisplay != NULL); } @@ -195,6 +200,8 @@ bool GLWindow::DisplayWindow(int _width, int _height) { dwExStyle = WS_EX_APPWINDOW | WS_EX_WINDOWEDGE; dwStyle = WS_OVERLAPPEDWINDOW; + nBackbufferWidth = _width; + nBackbufferHeight = _height; } dwStyle |= WS_CLIPSIBLINGS | WS_CLIPCHILDREN; diff --git a/plugins/zzogl-pg/opengl/GLWinX11.cpp b/plugins/zzogl-pg/opengl/GLWinX11.cpp index 8d1b65999d..4635b15aff 100644 --- a/plugins/zzogl-pg/opengl/GLWinX11.cpp +++ b/plugins/zzogl-pg/opengl/GLWinX11.cpp @@ -34,7 +34,11 @@ bool GLWindow::CreateWindow(void *pDisplay) glDisplay = XOpenDisplay(0); glScreen = DefaultScreen(glDisplay); - if (pDisplay == NULL) return false; + if (pDisplay == NULL) + { + ZZLog::Error_Log("Failed to create window. Exiting..."); + return false; + } *(Display**)pDisplay = glDisplay; @@ -251,6 +255,9 @@ void GLWindow::ToggleFullscreen() bool GLWindow::DisplayWindow(int _width, int _height) { + nBackbufferWidth = _width; + nBackbufferHeight = _height; + if (!CreateVisual()) return false; /* create a GLX context */ diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index 5179187088..d0e16c7388 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -34,7 +34,6 @@ extern void SaveSnapshot(const char* filename); GLWindow GLWin; GSinternal gs; GSconf conf; -char GStitle[256]; int ppf, g_GSMultiThreaded, CurrentSavestate = 0; int g_LastCRC = 0, g_TransferredToGPU = 0, s_frameskipping = 0; @@ -269,22 +268,23 @@ s32 CALLBACK GSinit() return 0; } -#ifdef _WIN32 - -#ifdef _DEBUG +#if defined(_WIN32) && defined(_DEBUG) HANDLE g_hCurrentThread = NULL; #endif - -extern LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); -extern HINSTANCE hInst; -#endif +__forceinline void InitMisc() +{ + WriteBilinear(); + WriteAA(); + InitProfile(); + InitPath(); + ResetRegs(); +} s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread) { FUNCLOG - bool err = false; g_GSMultiThreaded = multithread; ZZLog::WriteLn("Calling GSopen."); @@ -294,28 +294,16 @@ s32 CALLBACK GSopen(void *pDsp, char *Title, int multithread) #endif LoadConfig(); - strcpy(GStitle, Title); + strcpy(GLWin.title, Title); ZZLog::GS_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor); - err = GLWin.CreateWindow(pDsp); - if (!err) - { - ZZLog::Error_Log("Failed to create window. Exiting..."); - return -1; - } - ZZLog::WriteLn("Creating ZZOgl window."); - - if (!ZZCreate(conf.width, conf.height)) return -1; + if ((!GLWin.CreateWindow(pDsp)) || (!ZZCreate(conf.width, conf.height))) return -1; ZZLog::WriteLn("Initialization successful."); - WriteBilinear(); - WriteAA(); - InitProfile(); - InitPath(); - ResetRegs(); + InitMisc(); ZZLog::GS_Log("GSopen finished."); return 0; } @@ -336,26 +324,15 @@ s32 CALLBACK GSopen2( void* pDsp, INT32 flags ) #endif LoadConfig(); - strcpy(GStitle, Title); - err = GLWin.GetWindow(pDsp); // Needs to be added. - if (!err) - { - ZZLog::Error_Log("Failed to acquire window. Exiting..."); - return -1; - } - ZZLog::GS_Log("Using %s:%d.%d.%d.", libraryName, zgsrevision, zgsbuild, zgsminor); - if (!ZZCreate2(conf.width, conf.height)) return -1; // Needs to be added. + ZZLog::WriteLn("Capturing ZZOgl window."); + if ((!GLWin.GetWindow(pDsp)) || (!ZZCreate2(conf.width, conf.height))) return -1;// Needs to be added. ZZLog::WriteLn("Initialization successful."); - WriteBilinear(); - WriteAA(); - InitProfile(); - InitPath(); - ResetRegs(); + InitMisc(); ZZLog::GS_Log("GSopen2 finished."); return 0; diff --git a/plugins/zzogl-pg/opengl/Linux/Conf.cpp b/plugins/zzogl-pg/opengl/Linux/Conf.cpp index 4c008e945f..b600421f83 100644 --- a/plugins/zzogl-pg/opengl/Linux/Conf.cpp +++ b/plugins/zzogl-pg/opengl/Linux/Conf.cpp @@ -40,7 +40,7 @@ void SaveConfig() fprintf(f, "mrtdepth = %hhx\n", conf.mrtdepth); fprintf(f, "zzoptions = %x\n", conf.zz_options._u32); - fprintf(f, "options = %x\n", conf.hacks); + fprintf(f, "options = %x\n", conf.hacks._u32); fprintf(f, "bilinear = %hhx\n", conf.bilinear); fprintf(f, "aliasing = %hhx\n", conf.aa); fprintf(f, "width = %x\n", conf.width); diff --git a/plugins/zzogl-pg/opengl/ZZLog.cpp b/plugins/zzogl-pg/opengl/ZZLog.cpp index dc0f4c07bb..191d81733d 100644 --- a/plugins/zzogl-pg/opengl/ZZLog.cpp +++ b/plugins/zzogl-pg/opengl/ZZLog.cpp @@ -314,7 +314,7 @@ void Dev_Log(const char *fmt, ...) void Debug_Log(const char *fmt, ...) { -#if _DEBUG +#ifdef _DEBUG va_list list; va_start(list, fmt); diff --git a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp index 8a44c45db7..fae4fd316c 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp @@ -126,7 +126,7 @@ void (APIENTRY *zgsBlendFuncSeparateEXT)(GLenum, GLenum, GLenum, GLenum) = NULL; extern u8* s_lpShaderResources; // String's for shader file in developer mode -#ifdef DEVBUILD +#ifdef ZEROGS_DEVBUILD char* EFFECT_NAME = ""; char* EFFECT_DIR = ""; #endif @@ -277,18 +277,21 @@ inline void CreateOtherCheck() #endif } -// open shader file according to build target -inline bool CreateOpenShadersFile() +#ifdef _WIN32 +__forceinline bool LoadShadersFromRes() { -#ifndef DEVBUILD -# ifdef _WIN32 HRSRC hShaderSrc = FindResource(hInst, MAKEINTRESOURCE(IDR_SHADERS), RT_RCDATA); assert(hShaderSrc != NULL); HGLOBAL hShaderGlob = LoadResource(hInst, hShaderSrc); assert(hShaderGlob != NULL); s_lpShaderResources = (u8*)LockResource(hShaderGlob); -# else // not _WIN32 + return true; +} +#else + +__forceinline bool LoadShadersFromDat() +{ FILE* fres = fopen("ps2hw.dat", "rb"); if (fres == NULL) @@ -309,9 +312,12 @@ inline bool CreateOpenShadersFile() fseek(fres, 0, SEEK_SET); fread(s_lpShaderResources, s, 1, fres); s_lpShaderResources[s] = 0; -# endif // _WIN32 -#else // defined(ZEROGS_DEVBUILD) -# ifndef _WIN32 // NOT WINDOWS + + return true; +} + +__forceinline bool LoadShadersFromFX() +{ // test if ps2hw.fx exists char tempstr[255]; char curwd[255]; @@ -339,58 +345,55 @@ inline bool CreateOpenShadersFile() sprintf(EFFECT_DIR, "%s/%s", curwd, tempstr); sprintf(EFFECT_NAME, "%sps2hw.fx", EFFECT_DIR); + + return true; +} +#endif + + +// open shader file according to build target + +inline bool CreateOpenShadersFile() +{ +#ifndef DEVBUILD +# ifdef _WIN32 + return LoadShadersFromRes(); +# else // not _WIN32 + return LoadShadersFromDat(); +# endif // _WIN32 +#else // defined(ZEROGS_DEVBUILD) +# ifndef _WIN32 // NOT WINDOWS + return LoadShadersFromFX(); + + // No else clause? #endif #endif // !defined(ZEROGS_DEVBUILD) - return true; } // Read all extensions name and fill mapGLExtensions inline bool CreateFillExtensionsMap() { - // fill the opengl extension map - const char* ptoken = (const char*)glGetString(GL_EXTENSIONS); + int max_ext = 0; + glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); + + PFNGLGETSTRINGIPROC glGetStringi = 0; + glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); - if (ptoken == NULL) return false; - - int prevlog = conf.log; - - conf.log = 1; - - ZZLog::GS_Log("Supported OpenGL Extensions:\n%s\n", ptoken); // write to the log file - - // Probably a better way to do it, but seems to crash. - /*int n; - glGetIntegerv(GL_NUM_EXTENSIONS, &n); - ZZLog::GS_Log("Supported OpenGL Extensions:\n"); - for (int i = 0; i < n; i++) + string temp(""); + for (GLint i = 0; i < max_ext; i++) { - ZZLog::GS_Log("%s/n", (const char*)glGetStringi(GL_EXTENSIONS, i)); - }*/ - - conf.log = prevlog; - - // insert all exts into mapGLExtensions - - const char* pend = NULL; - - while (ptoken != NULL) - { - pend = strchr(ptoken, ' '); - - if (pend != NULL) - { - mapGLExtensions[string(ptoken, pend-ptoken)]; - } - else - { - mapGLExtensions[string(ptoken)]; - break; - } - - ptoken = pend; - - while (*ptoken == ' ') ++ptoken; + string extension((const char*)glGetStringi(GL_EXTENSIONS, i)); + mapGLExtensions[extension]; + + temp = temp + extension; + if (i != (max_ext - 1)) temp += ", "; } + + // Write the extension list to the log, but only write it to the screen on a debug build. +#ifndef _DEBUG + ZZLog::Log("%d supported OpenGL Extensions: %s\n", max_ext, temp.c_str()); +#endif + ZZLog::Debug_Log("%d supported OpenGL Extensions: %s\n", max_ext, temp.c_str()); return true; } @@ -434,14 +437,10 @@ bool ZZCreate(int _width, int _height) { GLenum err = GL_NO_ERROR; bool bSuccess = true; - int i; ZZDestroy(); ZZGSStateReset(); - nBackbufferWidth = _width; - nBackbufferHeight = _height; - if (!GLWin.DisplayWindow(_width, _height)) return false; conf.mrtdepth = 0; // for now @@ -560,7 +559,7 @@ bool ZZCreate(int _width, int _height) g_vboBuffers.resize(VB_NUMBUFFERS); glGenBuffers((GLsizei)g_vboBuffers.size(), &g_vboBuffers[0]); - for (i = 0; i < (int)g_vboBuffers.size(); ++i) + for (int i = 0; i < (int)g_vboBuffers.size(); ++i) { glBindBuffer(GL_ARRAY_BUFFER, g_vboBuffers[i]); glBufferData(GL_ARRAY_BUFFER, 0x100*sizeof(VertexGPU), NULL, GL_STREAM_DRAW); @@ -676,7 +675,7 @@ bool ZZCreate(int _width, int _height) vector conv16to32data(256*256); - for (i = 0; i < 256*256; ++i) + for (int i = 0; i < 256*256; ++i) { u32 tempcol = RGBA16to32(i); // have to flip r and b @@ -700,7 +699,7 @@ bool ZZCreate(int _width, int _height) u32* dst = &conv32to16data[0]; - for (i = 0; i < 32; ++i) + for (int i = 0; i < 32; ++i) { for (int j = 0; j < 32; ++j) { diff --git a/plugins/zzogl-pg/opengl/zerogs.cpp b/plugins/zzogl-pg/opengl/zerogs.cpp index f7859d8bc6..a8a0721a9b 100644 --- a/plugins/zzogl-pg/opengl/zerogs.cpp +++ b/plugins/zzogl-pg/opengl/zerogs.cpp @@ -166,7 +166,7 @@ void ChangeDeviceSize(int nNewWidth, int nNewHeight) { ZZLog::Error_Log("Failed to recreate, changing to old device."); - if (ZZCreate(oldwidth, oldheight)) + if (!ZZCreate(oldwidth, oldheight)) { SysMessage("Failed to create device, exiting..."); exit(0);