From 10b5f0d041cf4558f1ceb522b3fb18b4a0b32ed1 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 14 Nov 2008 17:03:59 +0000 Subject: [PATCH] From Wojciech Lewandowski, "Attached are modifications to GraphicsWindowWin32. By default workaround is set to off. But could be activated/decativated via CMake as well as system environment variable. I also modified src\osgViewer\CMakeLists.txt to turn off this workaround by default as suggested." --- CMakeLists.txt | 3 - .../osgViewer/api/Win32/GraphicsWindowWin32 | 1 + src/osgViewer/CMakeLists.txt | 2 +- src/osgViewer/GraphicsWindowWin32.cpp | 79 +++++++++++-------- 4 files changed, 49 insertions(+), 36 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index c86ffb4eb..2aa6f2125 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -350,9 +350,6 @@ ENDIF(PKG_CONFIG_FOUND) - - - # # Test to determine if we want the "tripledot" form of the GLU tesselator callback. # diff --git a/include/osgViewer/api/Win32/GraphicsWindowWin32 b/include/osgViewer/api/Win32/GraphicsWindowWin32 index 0ef0f4199..1a95464a5 100644 --- a/include/osgViewer/api/Win32/GraphicsWindowWin32 +++ b/include/osgViewer/api/Win32/GraphicsWindowWin32 @@ -185,6 +185,7 @@ class OSGVIEWER_EXPORT GraphicsWindowWin32 : public osgViewer::GraphicsWindow std::map _keyMap; + bool _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues; }; } diff --git a/src/osgViewer/CMakeLists.txt b/src/osgViewer/CMakeLists.txt index 74cb02ac6..b2a016a69 100644 --- a/src/osgViewer/CMakeLists.txt +++ b/src/osgViewer/CMakeLists.txt @@ -46,7 +46,7 @@ IF(WIN32) # There were also serious issues with render to texture cameras. # Workaround repeats makeCurrentContext call as it was found that this causes the problems to dissapear. # - OPTION(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND "Set to ON if you have NVidia board and drivers earlier than 177.92 ver" ON) + OPTION(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND "Set to ON if you have NVidia board and drivers earlier than 177.92 ver" OFF) MARK_AS_ADVANCED(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND) IF(OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND) ADD_DEFINITIONS(-DOSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND) diff --git a/src/osgViewer/GraphicsWindowWin32.cpp b/src/osgViewer/GraphicsWindowWin32.cpp index 753313c48..19b52581c 100644 --- a/src/osgViewer/GraphicsWindowWin32.cpp +++ b/src/osgViewer/GraphicsWindowWin32.cpp @@ -20,6 +20,7 @@ #include #include +#include #include #include @@ -31,6 +32,8 @@ using namespace osgViewer; namespace osgViewer { +static osg::ApplicationUsageProxy GraphicsWindowWin32_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE,"OSG_WIN32_NV_MULTIMON_MULTITHREAD_WORKAROUND on/off","Enable/disable duplicate makeCurrentContext call used as workaround for WinXP/NVidia/MultiView/MulitThread isues (pre 178.13 drivers)."); + // // Defines from the WGL_ARB_pixel_format specification document // See http://www.opengl.org/registry/specs/ARB/wgl_pixel_format.txt @@ -978,7 +981,8 @@ GraphicsWindowWin32::GraphicsWindowWin32( osg::GraphicsContext::Traits* traits ) _closeWindow(false), _destroyWindow(false), _destroying(false), - _appMouseCursor(LeftArrowCursor) + _appMouseCursor(LeftArrowCursor), + _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues( false ) { _traits = traits; if (_traits->useCursor) setCursor(LeftArrowCursor); @@ -1024,6 +1028,38 @@ void GraphicsWindowWin32::init() _initialized = _ownsWindow ? createWindow() : setWindow(windowHandle); _valid = _initialized; + + // 2008/10/03 + // Few days ago NVidia released WHQL certified drivers ver 178.13. + // These drivers (as well as former beta ver 177.92) were free from the bug described below. + // So it looks like its high time to make the workaround inactive by default. + // If you happen to still use earlier drivers and have problems consider changing to new ones or + // activate OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND macro def through CMake advanced vars. +#ifdef OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND + + // 2008/05/12 + // Workaround for Bugs in NVidia drivers for windows XP / multithreaded / dualview / multicore CPU + // affects GeForce 6x00, 7x00, 8x00 boards (others were not tested) driver versions 174.xx - 175.xx + // pre 174.xx had other issues so reverting is not an option (statitistics, fbo) + // drivers release 175.16 is the latest currently available + // + // When using OpenGL in threaded app ( main thread sets up context / renderer thread draws using it ) + // first wglMakeCurrent seems to not work right and screw OpenGL context driver data: + // 1: succesive drawing shows a number of artifacts in TriangleStrips and TriangleFans + // 2: weird behaviour of FramBufferObjects (glGenFramebuffer generates already generated ids ...) + // Looks like repeating wglMakeCurrent call fixes all these issues + // wglMakeCurrent call can impact performance so I try to minimize number of + // wglMakeCurrent calls by checking current HDC and GL context + // and repeat wglMakeCurrent only when they change for current thread + + _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues = true; +#endif + + const char* str = getenv("OSG_WIN32_NV_MULTIMON_MULTITHREAD_WORKAROUND"); + if (str) + { + _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues = (strcmp(str, "on")==0 || strcmp(str, "ON")==0 || strcmp(str, "On")==0 ); + } } bool GraphicsWindowWin32::createWindow() @@ -1664,39 +1700,18 @@ bool GraphicsWindowWin32::makeCurrentImplementation() return false; } - // 2008/10/03 - // Few days ago NVidia released WHQL certified drivers ver 178.13. - // These drivers (as well as former beta ver 177.92) were free from the bug described below. - // So it looks like its high time to undef the workaround. - // If you happen to still use earlier drivers and have problems consider changing to new ones or - // activate OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND macro def through CMake advanced vars. -#ifdef OSG_MULTIMONITOR_MULTITHREAD_WIN32_NVIDIA_WORKAROUND - - // 2008/05/12 - // Workaround for Bugs in NVidia drivers for windows XP / multithreaded / dualview / multicore CPU - // affects GeForce 6x00, 7x00, 8x00 boards (others were not tested) driver versions 174.xx - 175.xx - // pre 174.xx had other issues so reverting is not an option (statitistics, fbo) - // drivers release 175.16 is the latest currently available - // - // When using OpenGL in threaded app ( main thread sets up context / renderer thread draws using it ) - // first wglMakeCurrent seems to not work right and screw OpenGL context driver data: - // 1: succesive drawing shows a number of artifacts in TriangleStrips and TriangleFans - // 2: weird behaviour of FramBufferObjects (glGenFramebuffer generates already generated ids ...) - // Looks like repeating wglMakeCurrent call fixes all these issues - // wglMakeCurrent call can impact performance so I try to minimize number of - // wglMakeCurrent calls by checking current HDC and GL context - // and repeat wglMakeCurrent only when they change for current thread - - if( ::wglGetCurrentDC() != _hdc || - ::wglGetCurrentContext() != _hglrc ) - { - if (!::wglMakeCurrent(_hdc, _hglrc)) - { - reportErrorForScreen("GraphicsWindowWin32::makeCurrentImplementation() - Unable to set current OpenGL rendering context", _traits->screenNum, ::GetLastError()); - return false; + if( _applyWorkaroundForMultimonitorMultithreadNVidiaWin32Issues ) + { + if( ::wglGetCurrentDC() != _hdc || + ::wglGetCurrentContext() != _hglrc ) + { + if (!::wglMakeCurrent(_hdc, _hglrc)) + { + reportErrorForScreen("GraphicsWindowWin32::makeCurrentImplementation() - Unable to set current OpenGL rendering context", _traits->screenNum, ::GetLastError()); + return false; + } } } -#endif if (!::wglMakeCurrent(_hdc, _hglrc)) {