diff --git a/CMakeLists.txt b/CMakeLists.txt index f50090bde1..a884a8fa6c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -4,6 +4,37 @@ project(Pcsx2) # Debian-based distributions require at least 2.8.5 due to multiarch. cmake_minimum_required(VERSION 2.8.5) +# Keep OLD policy. Code was updated to support the new one but wasn't tested +# +# cmake version 2.8.9 +# CMP0018 +# Ignore CMAKE_SHARED_LIBRARY__FLAGS variable. +# +# CMake 2.8.8 and lower compiled sources in SHARED and MODULE libraries +# using the value of the undocumented CMAKE_SHARED_LIBRARY__FLAGS +# platform variable. The variable contained platform-specific flags +# needed to compile objects for shared libraries. Typically it included +# a flag such as -fPIC for position independent code but also included +# other flags needed on certain platforms. CMake 2.8.9 and higher +# prefer instead to use the POSITION_INDEPENDENT_CODE target property to +# determine what targets should be position independent, and new +# undocumented platform variables to select flags while ignoring +# CMAKE_SHARED_LIBRARY__FLAGS completely. +# +# The default for either approach produces identical compilation flags, +# but if a project modifies CMAKE_SHARED_LIBRARY__FLAGS from its +# original value this policy determines which approach to use. +# +# The OLD behavior for this policy is to ignore the +# POSITION_INDEPENDENT_CODE property for all targets and use the +# modified value of CMAKE_SHARED_LIBRARY__FLAGS for SHARED and +# MODULE libraries. +# +# The NEW behavior for this policy is to ignore +# CMAKE_SHARED_LIBRARY__FLAGS whether it is modified or not and +# honor the POSITION_INDEPENDENT_CODE target property. +cmake_policy(SET CMP0018 OLD) + # Variable to check that people use the good file set(TOP_CMAKE_WAS_SOURCED TRUE) diff --git a/build.sh b/build.sh index d45f02c6b9..111d955c40 100755 --- a/build.sh +++ b/build.sh @@ -32,6 +32,10 @@ do --glsl) flags="$flags -DGLSL_API=TRUE" ;; + --egl) + echo "Warning EGL needs at lesat MESA 9.0" + flags="$flags -DEGL_API=TRUE" + ;; --clean) clean_build=true ;; @@ -43,6 +47,7 @@ do echo "--release - Build PCSX2 as a Release build." echo "--clean - Do a clean build." echo "--glsl - Replace CG backend of ZZogl by GLSL" + echo "--egl - Replace GLX by EGL (ZZogl plugins only)" exit 1;; esac done @@ -54,16 +59,18 @@ if [ "$flags" != "" ]; then echo "Building pcsx2 with $flags" > install_log.txt fi -if [ ! -d "build" ]; then - mkdir build +if [ "$clean_build" = true ]; then + echo "Doing a clean build." + rm -fr build + # make clean 2>&1 | tee -a ../install_log.txt fi + + +mkdir -p build cd build cmake $flags .. 2>&1 | tee -a ../install_log.txt -if [ "$clean_build" = true ]; then - echo "Doing a clean build." - make clean 2>&1 | tee -a ../install_log.txt -fi + CORE=`grep -w -c processor /proc/cpuinfo` make -j $CORE 2>&1 | tee -a ../install_log.txt make install 2>&1 | tee -a ../install_log.txt diff --git a/cmake/BuildParameters.cmake b/cmake/BuildParameters.cmake index 48e13407db..9a38f61d85 100644 --- a/cmake/BuildParameters.cmake +++ b/cmake/BuildParameters.cmake @@ -19,7 +19,7 @@ # Installation path : -DPACKAGE_MODE=TRUE(follow FHS)|FALSE(local bin/) # Plugin installation path : -DPLUGIN_DIR="/usr/lib/pcsx2" # GL Shader installation path : -DGLSL_SHADER_DIR="/usr/share/games/pcsx2" -# Game DB installation path : -DGAMEINDEX_DIR="/var/games/pcsx2" +# Game DB installation path : -DGAMEINDEX_DIR="/usr/share/games/pcsx2" # Follow XDG standard : -DXDG_STD=TRUE|FALSE #------------------------------------------------------------------------------- @@ -93,7 +93,7 @@ set(CMAKE_SHARED_LIBRARY_CXX_FLAGS "") #------------------------------------------------------------------------------- # Set some default compiler flags #------------------------------------------------------------------------------- -set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing -Wno-unused-function") +set(DEFAULT_WARNINGS "-Wno-write-strings -Wno-format -Wno-unused-parameter -Wno-unused-value -Wstrict-aliasing -Wno-unused-function -Wno-attributes") set(DEFAULT_GCC_FLAG "-m32 -msse -msse2 -march=i686 -pthread ${DEFAULT_WARNINGS}") set(DEFAULT_CPP_FLAG "${DEFAULT_GCC_FLAG} -Wno-invalid-offsetof") diff --git a/cmake/FindEGL.cmake b/cmake/FindEGL.cmake index 33c8948b97..e54dfadf2b 100644 --- a/cmake/FindEGL.cmake +++ b/cmake/FindEGL.cmake @@ -9,8 +9,12 @@ if(EGL_INCLUDE_DIR AND EGL_LIBRARIES) set(EGL_FIND_QUIETLY TRUE) endif(EGL_INCLUDE_DIR AND EGL_LIBRARIES) +INCLUDE(CheckCXXSymbolExists) + # include dir -find_path(EGL_INCLUDE_DIR EGL/egl.h) +find_path(EGL_INCLUDE_DIR EGL/eglext.h) + +CHECK_CXX_SYMBOL_EXISTS(EGL_KHR_create_context "EGL/eglext.h" EGL_GL_CONTEXT_SUPPORT) # finally the library itself find_library(libEGL NAMES EGL) diff --git a/plugins/GSdx/GSDeviceOGL.cpp b/plugins/GSdx/GSDeviceOGL.cpp index 697933ea52..63c4e1dd9f 100644 --- a/plugins/GSdx/GSDeviceOGL.cpp +++ b/plugins/GSdx/GSDeviceOGL.cpp @@ -499,6 +499,11 @@ bool GSDeviceOGL::Reset(int w, int h) return true; } +void GSDeviceOGL::SetVSync(bool enable) +{ + m_wnd->SetVSync(enable); +} + void GSDeviceOGL::Flip() { // FIXME: disable it when code is working @@ -1336,6 +1341,8 @@ void GSDeviceOGL::CompileShaderFromSource(const std::string& glsl_file, const st myfile.close(); } else { fprintf(stderr, "Error opening %s: ", shader_file.c_str()); + *program = 0; + return; } diff --git a/plugins/GSdx/GSDeviceOGL.h b/plugins/GSdx/GSDeviceOGL.h index a3ee5a1888..7b0644d8b2 100644 --- a/plugins/GSdx/GSDeviceOGL.h +++ b/plugins/GSdx/GSDeviceOGL.h @@ -593,6 +593,7 @@ class GSDeviceOGL : public GSDevice bool Create(GSWnd* wnd); bool Reset(int w, int h); void Flip(); + void SetVSync(bool enable); void DrawPrimitive(); void DrawIndexedPrimitive(); diff --git a/plugins/GSdx/GSWnd.cpp b/plugins/GSdx/GSWnd.cpp index d474e5cd26..186a184c58 100644 --- a/plugins/GSdx/GSWnd.cpp +++ b/plugins/GSdx/GSWnd.cpp @@ -213,7 +213,7 @@ void GSWnd::HideFrame() #else GSWnd::GSWnd() - : m_window(NULL), m_Xwindow(0), m_XDisplay(NULL), m_ctx_attached(false) + : m_window(NULL), m_Xwindow(0), m_XDisplay(NULL), m_ctx_attached(false), m_swapinterval(NULL) { } @@ -277,7 +277,7 @@ bool GSWnd::CreateContext(int major, int minor) void GSWnd::AttachContext() { if (!IsContextAttached()) { - fprintf(stderr, "Attach the context\n"); + //fprintf(stderr, "Attach the context\n"); glXMakeCurrent(m_XDisplay, m_Xwindow, m_context); m_ctx_attached = true; } @@ -286,7 +286,7 @@ void GSWnd::AttachContext() void GSWnd::DetachContext() { if (IsContextAttached()) { - fprintf(stderr, "Detach the context\n"); + //fprintf(stderr, "Detach the context\n"); glXMakeCurrent(m_XDisplay, None, NULL); m_ctx_attached = false; } @@ -299,7 +299,7 @@ void GSWnd::CheckContext() if (glXIsDirect(m_XDisplay, m_context)) fprintf(stderr, "glX-Version %d.%d with Direct Rendering\n", glxMajorVersion, glxMinorVersion); else - fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It will be slow\n", glxMajorVersion, glxMinorVersion); + fprintf(stderr, "glX-Version %d.%d with Indirect Rendering !!! It won't support properly opengl\n", glxMajorVersion, glxMinorVersion); } bool GSWnd::Attach(void* handle, bool managed) @@ -319,6 +319,10 @@ bool GSWnd::Attach(void* handle, bool managed) CheckContext(); + PFNGLXSWAPINTERVALMESAPROC m_swapinterval = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapIntervalMESA"); + //PFNGLXSWAPINTERVALMESAPROC m_swapinterval = (PFNGLXSWAPINTERVALMESAPROC)glXGetProcAddress((const GLubyte*) "glXSwapInterval"); + + return true; } @@ -427,6 +431,14 @@ bool GSWnd::SetWindowText(const char* title) return true; } +void GSWnd::SetVSync(bool enable) +{ + // m_swapinterval uses an integer as parameter + // 0 -> disable vsync + // n -> wait n frame + if (m_swapinterval) m_swapinterval((int)enable); +} + void GSWnd::Flip() { glXSwapBuffers(m_XDisplay, m_Xwindow); diff --git a/plugins/GSdx/GSWnd.h b/plugins/GSdx/GSWnd.h index 73b1b5c751..634bc5ce18 100644 --- a/plugins/GSdx/GSWnd.h +++ b/plugins/GSdx/GSWnd.h @@ -69,6 +69,8 @@ class GSWnd int m_renderer; GLXContext m_context; + PFNGLXSWAPINTERVALMESAPROC m_swapinterval; + public: GSWnd(); virtual ~GSWnd(); @@ -93,6 +95,7 @@ public: void Hide(); void HideFrame(); void Flip(); + void SetVSync(bool enable); }; #endif diff --git a/plugins/zzogl-pg/opengl/CMakeLists.txt b/plugins/zzogl-pg/opengl/CMakeLists.txt index 20f48f3696..29276b46d0 100644 --- a/plugins/zzogl-pg/opengl/CMakeLists.txt +++ b/plugins/zzogl-pg/opengl/CMakeLists.txt @@ -54,8 +54,10 @@ else(GLSL_API) endif(GLSL_API) # Select the EGL API -if (EGL_API) +if(EGL_API AND EGL_GL_CONTEXT_SUPPORT) add_definitions(-DEGL_API) +else() + message(WARNING "Current EGL implementation doesn't support openGL context. Fallback to standard GLX.") endif() @@ -173,7 +175,7 @@ target_link_libraries(${Output} ${GLEW_LIBRARY}) # link target with opengl target_link_libraries(${Output} ${OPENGL_LIBRARIES}) -if(EGL_API) +if (EGL_API AND EGL_GL_CONTEXT_SUPPORT) target_link_libraries(${Output} ${EGL_LIBRARIES}) endif() @@ -237,7 +239,7 @@ if(BUILD_REPLAY_LOADERS) endif(NOT GLSL_API) target_link_libraries(${Static} ${GLEW_LIBRARY}) target_link_libraries(${Static} ${OPENGL_LIBRARIES}) -if(EGL_API) +if (EGL_API AND EGL_GL_CONTEXT_SUPPORT) target_link_libraries(${Static} ${EGL_LIBRARIES}) endif() target_link_libraries(${Static} ${X11_LIBRARIES}) diff --git a/plugins/zzogl-pg/opengl/GLWin.h b/plugins/zzogl-pg/opengl/GLWin.h index 633f5f0116..1c2c518856 100644 --- a/plugins/zzogl-pg/opengl/GLWin.h +++ b/plugins/zzogl-pg/opengl/GLWin.h @@ -22,6 +22,7 @@ #ifdef _WIN32 #define GL_WIN32_WINDOW +#define WGL_API #else @@ -44,6 +45,11 @@ #undef CreateWindow // Undo Windows.h global namespace pollution +#ifdef GLX_API +typedef void (APIENTRYP _PFNSWAPINTERVAL)(int); +#endif + + extern void SetDeviceSize(int nNewWidth, int nNewHeight); extern void OnFKey(int key, int shift); @@ -53,16 +59,17 @@ class GLWindow #if defined(GL_X11_WINDOW) void GetWindowSize(); void PrintProtocolVersion(); - +#endif bool CreateContextGL(int, int); bool CreateContextGL(); -#endif #ifdef GLX_API Display *NativeDisplay; Window NativeWindow; - GLXContext context; + GLXContext glxContext; + + _PFNSWAPINTERVAL swapinterval; #endif #ifdef EGL_API @@ -78,6 +85,18 @@ class GLWindow void CloseEGLDisplay(); #endif +#ifdef WGL_API + HWND NativeWindow; + HDC NativeDisplay; // hDC // Private GDI Device Context + HGLRC wglContext; // hRC // Permanent Rendering Context + + bool OpenWGLDisplay(); + void CloseWGLDisplay(); +#endif + + bool vsync_supported; + + public: char title[256]; Size backbuffer; @@ -90,6 +109,11 @@ class GLWindow bool DisplayWindow(int _width, int _height); void SetTitle(char *strtitle); void ProcessEvents(); + + void* GetProcAddress(const char* function); + + void SetVsync(bool enable); + void InitVsync(bool extension); // dummy in EGL void UpdateWindowSize(int nNewWidth, int nNewHeight) { @@ -103,6 +127,14 @@ class GLWindow conf.height = nNewHeight; } } + + GLWindow() { +#ifdef WGL_API + NativeWindow = NULL; + NativeDisplay = NULL; + wglContext = NULL; +#endif + } }; extern GLWindow GLWin; diff --git a/plugins/zzogl-pg/opengl/GLWin32.cpp b/plugins/zzogl-pg/opengl/GLWin32.cpp index 780c5b6260..cbad53f1ca 100644 --- a/plugins/zzogl-pg/opengl/GLWin32.cpp +++ b/plugins/zzogl-pg/opengl/GLWin32.cpp @@ -22,10 +22,6 @@ #ifdef GL_WIN32_WINDOW -HWND GShwnd = NULL; -HDC hDC = NULL; // Private GDI Device Context -HGLRC hRC = NULL; // Permanent Rendering Context - LRESULT WINAPI MsgProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam) { static int nWindowWidth = 0, nWindowHeight = 0; @@ -109,7 +105,7 @@ bool GLWindow::CreateWindow(void *pDisplay) GetWindowRect(GetDesktopWindow(), &rcdesktop); - GShwnd = CreateWindowEx( dwExStyle, // Extended Style For The Window + NativeWindow = CreateWindowEx( dwExStyle, // Extended Style For The Window L"PS2EMU_ZEROGS", // Class Name L"ZZOgl", // Window Title dwStyle, // Selected Window Style @@ -122,22 +118,22 @@ bool GLWindow::CreateWindow(void *pDisplay) hInstance, // Instance NULL); // Don't Pass Anything To WM_CREATE - if (GShwnd == NULL) + if (NativeWindow == NULL) { ZZLog::Error_Log("Failed to create window. Exiting..."); return false; } - if (pDisplay != NULL) *(HWND*)pDisplay = GShwnd; + if (pDisplay != NULL) *(HWND*)pDisplay = NativeWindow; // set just in case - SetWindowLongPtr(GShwnd, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc); + SetWindowLongPtr(NativeWindow, GWLP_WNDPROC, (LPARAM)(WNDPROC)MsgProc); - ShowWindow(GShwnd, SW_SHOWDEFAULT); + ShowWindow(NativeWindow, SW_SHOWDEFAULT); - UpdateWindow(GShwnd); + UpdateWindow(NativeWindow); - SetFocus(GShwnd); + SetFocus(NativeWindow); if (pDisplay == NULL) ZZLog::Error_Log("Failed to create window. Exiting..."); return (pDisplay != NULL); @@ -145,42 +141,37 @@ bool GLWindow::CreateWindow(void *pDisplay) bool GLWindow::ReleaseContext() { - if (hRC) // Do We Have A Rendering Context? + if (wglContext) // Do We Have A Rendering Context? { if (!wglMakeCurrent(NULL, NULL)) // Are We Able To Release The DC And RC Contexts? { MessageBox(NULL, L"Release Of DC And RC Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); } - if (!wglDeleteContext(hRC)) // Are We Able To Delete The RC? + if (!wglDeleteContext(wglContext)) // Are We Able To Delete The RC? { MessageBox(NULL, L"Release Rendering Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); } - hRC = NULL; // Set RC To NULL + wglContext = NULL; // Set RC To NULL } - if (hDC && !ReleaseDC(GShwnd, hDC)) // Are We Able To Release The DC - { - MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); - hDC = NULL; // Set DC To NULL - } + CloseWGLDisplay(); return true; } void GLWindow::CloseWindow() { - if (GShwnd != NULL) + if (NativeWindow != NULL) { - DestroyWindow(GShwnd); - GShwnd = NULL; + DestroyWindow(NativeWindow); + NativeWindow = NULL; } } bool GLWindow::DisplayWindow(int _width, int _height) { - GLuint PixelFormat; // Holds The Results After Searching For A Match DWORD dwExStyle; // Window Extended Style DWORD dwStyle; // Window Style @@ -215,10 +206,10 @@ bool GLWindow::DisplayWindow(int _width, int _height) int X = (rcdesktop.right - rcdesktop.left) / 2 - (rc.right - rc.left) / 2; int Y = (rcdesktop.bottom - rcdesktop.top) / 2 - (rc.bottom - rc.top) / 2; - SetWindowLong(GShwnd, GWL_STYLE, dwStyle); - SetWindowLong(GShwnd, GWL_EXSTYLE, dwExStyle); + SetWindowLong(NativeWindow, GWL_STYLE, dwStyle); + SetWindowLong(NativeWindow, GWL_EXSTYLE, dwExStyle); - SetWindowPos(GShwnd, HWND_TOP, X, Y, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW); + SetWindowPos(NativeWindow, HWND_TOP, X, Y, rc.right - rc.left, rc.bottom - rc.top, SWP_SHOWWINDOW); if (conf.fullscreen()) { @@ -249,6 +240,18 @@ bool GLWindow::DisplayWindow(int _width, int _height) ChangeDisplaySettings(NULL, 0); } + if (!OpenWGLDisplay()) return false; + + if (!CreateContextGL()) return false; + + UpdateWindow(NativeWindow); + + return true; +} + +bool GLWindow::OpenWGLDisplay() +{ + GLuint PixelFormat; // Holds The Results After Searching For A Match PIXELFORMATDESCRIPTOR pfd = // pfd Tells Windows How We Want Things To Be { @@ -272,38 +275,60 @@ bool GLWindow::DisplayWindow(int _width, int _height) 0, 0, 0 // Layer Masks Ignored }; - if (!(hDC = GetDC(GShwnd))) + if (!(NativeDisplay = GetDC(NativeWindow))) { MessageBox(NULL, L"(1) Can't Create A GL Device Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); return false; } - if (!(PixelFormat = ChoosePixelFormat(hDC, &pfd))) + if (!(PixelFormat = ChoosePixelFormat(NativeDisplay, &pfd))) { MessageBox(NULL, L"(2) Can't Find A Suitable PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); return false; } - if (!SetPixelFormat(hDC, PixelFormat, &pfd)) + if (!SetPixelFormat(NativeDisplay, PixelFormat, &pfd)) { MessageBox(NULL, L"(3) Can't Set The PixelFormat.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); return false; } - if (!(hRC = wglCreateContext(hDC))) + return true; +} + +void GLWindow::CloseWGLDisplay() +{ + if (NativeDisplay && !ReleaseDC(NativeWindow, NativeDisplay)) // Are We Able To Release The DC { - MessageBox(NULL, L"(4) Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + MessageBox(NULL, L"Release Device Context Failed.", L"SHUTDOWN ERROR", MB_OK | MB_ICONINFORMATION); + NativeDisplay = NULL; // Set DC To NULL + } +} + +bool GLWindow::CreateContextGL() +{ + return CreateContextGL(2, 0); +} + +bool GLWindow::CreateContextGL(int major, int minor) +{ + if (major <= 2) { + if (!(wglContext = wglCreateContext(NativeDisplay))) + { + MessageBox(NULL, L"(4) Can't Create A GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + return false; + } + + if (!wglMakeCurrent(NativeDisplay, wglContext)) + { + MessageBox(NULL, L"(5) Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); + return false; + } + } else { + // todo return false; } - if (!wglMakeCurrent(hDC, hRC)) - { - MessageBox(NULL, L"(5) Can't Activate The GL Rendering Context.", L"ERROR", MB_OK | MB_ICONEXCLAMATION); - return false; - } - - UpdateWindow(GShwnd); - return true; } @@ -313,13 +338,13 @@ void GLWindow::SwapGLBuffers() if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!"); - SwapBuffers(hDC); + SwapBuffers(NativeDisplay); lastswaptime = timeGetTime(); } void GLWindow::SetTitle(char *strtitle) { - if (!conf.fullscreen()) SetWindowText(GShwnd, wxString::FromUTF8(strtitle)); + if (!conf.fullscreen()) SetWindowText(NativeWindow, wxString::FromUTF8(strtitle)); } extern void ChangeDeviceSize(int nNewWidth, int nNewHeight); @@ -356,12 +381,12 @@ void GLWindow::ProcessEvents() // destroy that msg conf.setFullscreen(false); ChangeDeviceSize(conf.width, conf.height); - UpdateWindow(GShwnd); + UpdateWindow(NativeWindow); continue; // so that msg doesn't get sent } else { - SendMessage(GShwnd, WM_DESTROY, 0, 0); + SendMessage(NativeWindow, WM_DESTROY, 0, 0); return; } @@ -390,5 +415,21 @@ void GLWindow::ProcessEvents() } } +void* GLWindow::GetProcAddress(const char* function) +{ + return (void*)wglGetProcAddress(function); +} + +void GLWindow::InitVsync(bool extension) +{ + vsync_supported = extension; +} + +void GLWindow::SetVsync(bool enable) +{ + if (vsync_supported) { + wglSwapIntervalEXT(0); + } +} #endif diff --git a/plugins/zzogl-pg/opengl/GLWinX11.cpp b/plugins/zzogl-pg/opengl/GLWinX11.cpp index 8b42ae5d21..cab8bfb51e 100644 --- a/plugins/zzogl-pg/opengl/GLWinX11.cpp +++ b/plugins/zzogl-pg/opengl/GLWinX11.cpp @@ -42,7 +42,6 @@ #endif #endif - #ifdef USE_GSOPEN2 bool GLWindow::CreateWindow(void *pDisplay) { @@ -119,15 +118,15 @@ bool GLWindow::ReleaseContext() if (!NativeDisplay) return status; // free the context - if (context) + if (glxContext) { if (!glXMakeCurrent(NativeDisplay, None, NULL)) { ZZLog::Error_Log("Could not release drawing context."); status = false; } - glXDestroyContext(NativeDisplay, context); - context = NULL; + glXDestroyContext(NativeDisplay, glxContext); + glxContext = NULL; } #endif #ifdef EGL_API @@ -192,7 +191,7 @@ void GLWindow::PrintProtocolVersion() glXQueryVersion(NativeDisplay, &glxMajorVersion, &glxMinorVersion); - if (glXIsDirect(NativeDisplay, context)) + if (glXIsDirect(NativeDisplay, glxContext)) ZZLog::Error_Log("glX-Version %d.%d with Direct Rendering", glxMajorVersion, glxMinorVersion); else ZZLog::Error_Log("glX-Version %d.%d with Indirect Rendering !!! It will be slow", glxMajorVersion, glxMinorVersion); @@ -227,21 +226,21 @@ bool GLWindow::CreateContextGL(int major, int minor) XVisualInfo *vi = glXChooseVisual(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl); if (vi == NULL) return NULL; - context = glXCreateContext(NativeDisplay, vi, NULL, GL_TRUE); + glxContext = glXCreateContext(NativeDisplay, vi, NULL, GL_TRUE); XFree(vi); - if (!context) return false; + if (!glxContext) return false; - glXMakeCurrent(NativeDisplay, NativeWindow, context); + glXMakeCurrent(NativeDisplay, NativeWindow, glxContext); return true; } - PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC) glXGetProcAddress((GLubyte *) "glXChooseFBConfig"); + PFNGLXCHOOSEFBCONFIGPROC glXChooseFBConfig = (PFNGLXCHOOSEFBCONFIGPROC)GetProcAddress("glXChooseFBConfig"); int fbcount = 0; GLXFBConfig *fbc = glXChooseFBConfig(NativeDisplay, DefaultScreen(NativeDisplay), attrListDbl, &fbcount); if (!fbc || fbcount < 1) return false; - PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)glXGetProcAddress((const GLubyte*) "glXCreateContextAttribsARB"); + PFNGLXCREATECONTEXTATTRIBSARBPROC glXCreateContextAttribsARB = (PFNGLXCREATECONTEXTATTRIBSARBPROC)GetProcAddress("glXCreateContextAttribsARB"); if (!glXCreateContextAttribsARB) return false; // Create a context @@ -253,22 +252,23 @@ bool GLWindow::CreateContextGL(int major, int minor) GLX_CONTEXT_PROFILE_MASK_ARB, GLX_CONTEXT_COMPATIBILITY_PROFILE_BIT_ARB, //GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB | GLX_CONTEXT_FORWARD_COMPATIBLE_BIT_ARB, // FIXME : Request a debug context to ease opengl development +#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG) GLX_CONTEXT_FLAGS_ARB, GLX_CONTEXT_DEBUG_BIT_ARB, +#endif None }; - context = glXCreateContextAttribsARB(NativeDisplay, fbc[0], 0, true, context_attribs); - if (!context) return false; + glxContext = glXCreateContextAttribsARB(NativeDisplay, fbc[0], 0, true, context_attribs); + if (!glxContext) return false; XSync( NativeDisplay, false); - glXMakeCurrent(NativeDisplay, NativeWindow, context); + glXMakeCurrent(NativeDisplay, NativeWindow, glxContext); return true; } #endif -#if defined(GLX_API) || defined(EGL_API) bool GLWindow::CreateContextGL() { bool ret; @@ -290,10 +290,9 @@ bool GLWindow::CreateContextGL() #endif return ret; } -#endif #ifdef EGL_API -bool GLWindow::CreateContextGL( int major, int minor) +bool GLWindow::CreateContextGL(int major, int minor) { EGLConfig eglConfig; EGLint numConfigs; @@ -305,7 +304,9 @@ bool GLWindow::CreateContextGL( int major, int minor) EGL_CONTEXT_OPENGL_PROFILE_MASK_KHR, EGL_CONTEXT_OPENGL_COMPATIBILITY_PROFILE_BIT_KHR, //EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR | EGL_CONTEXT_OPENGL_FORWARD_COMPATIBLE_BIT_KHR, // FIXME : Request a debug context to ease opengl development +#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG) EGL_CONTEXT_FLAGS_KHR, EGL_CONTEXT_OPENGL_DEBUG_BIT_KHR, +#endif EGL_NONE }; EGLint attrList[] = { @@ -383,6 +384,16 @@ bool GLWindow::DisplayWindow(int _width, int _height) } #endif +void* GLWindow::GetProcAddress(const char *function) +{ +#ifdef EGL_API + return (void*)eglGetProcAddress(function); +#endif +#ifdef GLX_API + return (void*)glXGetProcAddress((const GLubyte*)function); +#endif +} + void GLWindow::SwapGLBuffers() { if (glGetError() != GL_NO_ERROR) ZZLog::Debug_Log("glError before swap!"); @@ -397,6 +408,45 @@ void GLWindow::SwapGLBuffers() // glClear(GL_COLOR_BUFFER_BIT); } +void GLWindow::InitVsync(bool extension) +{ +#ifdef GLX_API + if (extension) { + swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapInterval"); + + if (!swapinterval) + swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapIntervalSGI"); + + if (!swapinterval) + swapinterval = (_PFNSWAPINTERVAL)GetProcAddress("glXSwapIntervalEXT"); + + if (swapinterval) { + swapinterval(0); + vsync_supported = true; + } else { + ZZLog::Error_Log("No support for SwapInterval (framerate clamped to monitor refresh rate),"); + vsync_supported = false; + } + } else { + vsync_supported = false; + } + +#endif +} + +void GLWindow::SetVsync(bool enable) +{ + fprintf(stderr, "change vsync %d\n", enable); +#ifdef EGL_API + eglSwapInterval(eglDisplay, enable); +#endif +#ifdef GLX_API + if (vsync_supported) { + swapinterval(enable); + } +#endif +} + u32 THR_KeyEvent = 0; // Value for key event processing between threads bool THR_bShift = false; bool THR_bCtrl = false; diff --git a/plugins/zzogl-pg/opengl/GSmain.cpp b/plugins/zzogl-pg/opengl/GSmain.cpp index cc9f6443ab..092da9afcf 100644 --- a/plugins/zzogl-pg/opengl/GSmain.cpp +++ b/plugins/zzogl-pg/opengl/GSmain.cpp @@ -488,6 +488,7 @@ EXPORT_C_(void) GSsetVsync(int enabled) ZZLog::Debug_Log("Setting VSync to 0x%x.", enabled); gs.vsync = enabled; + GLWin.SetVsync(enabled); } EXPORT_C_(void) GSvsync(int current_interlace) diff --git a/plugins/zzogl-pg/opengl/ZZGl.h b/plugins/zzogl-pg/opengl/ZZGl.h index de7b0a4335..5814e89368 100644 --- a/plugins/zzogl-pg/opengl/ZZGl.h +++ b/plugins/zzogl-pg/opengl/ZZGl.h @@ -40,11 +40,6 @@ #include #include -inline void* wglGetProcAddress(const char* x) -{ - return (void*)glXGetProcAddress((const GLubyte*)x); -} - #endif #include "Mem.h" diff --git a/plugins/zzogl-pg/opengl/ZZLog.cpp b/plugins/zzogl-pg/opengl/ZZLog.cpp index 207a4820f4..9befc0180a 100644 --- a/plugins/zzogl-pg/opengl/ZZLog.cpp +++ b/plugins/zzogl-pg/opengl/ZZLog.cpp @@ -367,11 +367,14 @@ void Error_Log(const char *fmt, ...) va_end(list); } +#ifdef _DEBUG #define LOUD_DEBUGGING +#endif #ifdef OGL4_LOG void Check_GL_Error() { +#if defined(ZEROGS_DEVBUILD) || defined(_DEBUG) unsigned int count = 64; // max. num. of messages that will be read from the log int bufsize = 2048; unsigned int* sources = new unsigned int[count]; @@ -399,6 +402,7 @@ void Check_GL_Error() delete [] severities; delete [] lengths; delete [] messageLog; +#endif } void GL_Error_Log(unsigned int source, unsigned int type, unsigned int id, unsigned int severity, const char* message) diff --git a/plugins/zzogl-pg/opengl/ZZoglCRTC.h b/plugins/zzogl-pg/opengl/ZZoglCRTC.h index e3741290eb..fc4a1dd42f 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCRTC.h +++ b/plugins/zzogl-pg/opengl/ZZoglCRTC.h @@ -23,11 +23,6 @@ #include #include "targets.h" -#ifdef _WIN32 -extern HDC hDC; // Private GDI Device Context -extern HGLRC hRC; // Permanent Rendering Context -#endif - extern int s_frameskipping; extern float fFPS; extern unsigned char zgsrevision, zgsbuild, zgsminor; diff --git a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp index bc361dd00b..2a4ff7429a 100644 --- a/plugins/zzogl-pg/opengl/ZZoglCreate.cpp +++ b/plugins/zzogl-pg/opengl/ZZoglCreate.cpp @@ -36,8 +36,6 @@ #endif // ----------------- Types -typedef void (APIENTRYP _PFNSWAPINTERVAL)(int); - map mapGLExtensions; extern bool ZZshLoadExtraEffects(); @@ -198,9 +196,9 @@ inline void CreateOtherCheck() } if (IsGLExt("GL_ARB_draw_buffers")) - glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffers"); + glDrawBuffers = (PFNGLDRAWBUFFERSPROC)GLWin.GetProcAddress("glDrawBuffers"); else if (IsGLExt("GL_ATI_draw_buffers")) - glDrawBuffers = (PFNGLDRAWBUFFERSPROC)wglGetProcAddress("glDrawBuffersATI"); + glDrawBuffers = (PFNGLDRAWBUFFERSPROC)GLWin.GetProcAddress("glDrawBuffersATI"); if (!IsGLExt("GL_ARB_multitexture")) @@ -222,27 +220,12 @@ inline void CreateOtherCheck() ZZLog::Error_Log("Could not properly make bitmasks, so some textures will be missed."); #ifdef _WIN32 - if (IsGLExt("WGL_EXT_swap_control") || IsGLExt("EXT_swap_control")) - wglSwapIntervalEXT(0); - + GLWin.InitVsync(IsGLExt("WGL_EXT_swap_control") || IsGLExt("EXT_swap_control")); #else - if (IsGLExt("GLX_SGI_swap_control")) - { - _PFNSWAPINTERVAL swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapInterval"); - - if (!swapinterval) - swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalSGI"); - - if (!swapinterval) - swapinterval = (_PFNSWAPINTERVAL)wglGetProcAddress("glXSwapIntervalEXT"); - - if (swapinterval) - swapinterval(0); - else - ZZLog::Error_Log("No support for SwapInterval (framerate clamped to monitor refresh rate),"); - } - + GLWin.InitVsync(IsGLExt("GLX_SGI_swap_control")); #endif + + GLWin.SetVsync(false); } @@ -358,7 +341,7 @@ inline bool CreateFillExtensionsMap() string all_ext(""); PFNGLGETSTRINGIPROC glGetStringi = 0; - glGetStringi = (PFNGLGETSTRINGIPROC)wglGetProcAddress("glGetStringi"); + glGetStringi = (PFNGLGETSTRINGIPROC)GLWin.GetProcAddress("glGetStringi"); glGetIntegerv(GL_NUM_EXTENSIONS, &max_ext); if (glGetStringi && max_ext) {