From f67942cf033d7f8359c0cfe3d4abb818ad36fd73 Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Thu, 22 Apr 2010 16:01:38 +0000 Subject: [PATCH] From Alok Priyadashi, "The attached patch fixes - compile errors on windows when compiled with UNICODE flag - warnings for duplicate WIN32_LEAN_AND_MEAN. I think this should better fixed by adding WIN32_LEAN_AND_MEAN to vcproj preprocessor list." --- src/OpenThreads/win32/CMakeLists.txt | 2 + src/OpenThreads/win32/HandleHolder.h | 3 - .../win32/Win32BarrierPrivateData.h | 6 - src/OpenThreads/win32/Win32Condition.h | 186 +++++++----------- .../win32/Win32ConditionPrivateData.h | 6 - src/OpenThreads/win32/Win32MutexPrivateData.h | 6 +- .../win32/Win32ThreadPrivateData.h | 6 - src/osg/GLExtensions.cpp | 8 +- .../osgViewer/GraphicsWindow.cpp | 21 +- .../osgViewer/ViewerEventHandlers.cpp | 13 ++ 10 files changed, 114 insertions(+), 143 deletions(-) diff --git a/src/OpenThreads/win32/CMakeLists.txt b/src/OpenThreads/win32/CMakeLists.txt index 5863a53e4..ed92a8d60 100644 --- a/src/OpenThreads/win32/CMakeLists.txt +++ b/src/OpenThreads/win32/CMakeLists.txt @@ -3,6 +3,8 @@ SET(LIB_NAME OpenThreads) SET(LIB_PUBLIC_HEADERS ${OpenThreads_PUBLIC_HEADERS}) +ADD_DEFINITIONS(-DWIN32_LEAN_AND_MEAN) +ADD_DEFINITIONS(-D_WIN32_WINNT=0x0400) SOURCE_GROUP("Header Files" FILES ${LIB_PUBLIC_HEADERS}) SET_SOURCE_FILES_PROPERTIES(${LIB_PUBLIC_HEADERS} PROPERTIES HEADER_FILE_ONLY ON) diff --git a/src/OpenThreads/win32/HandleHolder.h b/src/OpenThreads/win32/HandleHolder.h index 026ab9d44..26a469040 100644 --- a/src/OpenThreads/win32/HandleHolder.h +++ b/src/OpenThreads/win32/HandleHolder.h @@ -19,10 +19,7 @@ #ifndef _HandleHolder_H_ #define _HandleHolder_H_ -#ifndef _WINDOWS_ -#define WIN32_LEAN_AND_MEAN #include -#endif /************************************************************************/ /* Class that holds HANDLES ensuring proper destruction */ diff --git a/src/OpenThreads/win32/Win32BarrierPrivateData.h b/src/OpenThreads/win32/Win32BarrierPrivateData.h index 68d33a532..7452d9b71 100644 --- a/src/OpenThreads/win32/Win32BarrierPrivateData.h +++ b/src/OpenThreads/win32/Win32BarrierPrivateData.h @@ -18,12 +18,6 @@ #ifndef _Win32BARRIERPRIVATEDATA_H_ #define _Win32BARRIERPRIVATEDATA_H_ -#ifndef _WINDOWS_ -#define WIN32_LEAN_AND_MEAN -#define _WIN32_WINNT 0x0400 -#include -#endif - #include #include diff --git a/src/OpenThreads/win32/Win32Condition.h b/src/OpenThreads/win32/Win32Condition.h index 23b34207f..270a67e4f 100644 --- a/src/OpenThreads/win32/Win32Condition.h +++ b/src/OpenThreads/win32/Win32Condition.h @@ -11,10 +11,8 @@ * OpenSceneGraph Public License for more details. */ -#ifndef _WIN32VODITIONPRODUCER_CONDITION -#define PRODUCER_CONDITION - -#ifdef WIN32 +#ifndef _WIN32CONDITION_H_ +#define _WIN32CONDITION_H_ #include "Mutex.h" @@ -23,85 +21,85 @@ namespace OpenThreads { class Win32ConditionImpl { public: - /// number of waiters. - long waiters_; + /// number of waiters. + long waiters_; - Condition(long max = 0L) - { - waiters_ = 0; - sema_ = CreateSemaphore(NULL,0,0x7fffffff,NULL); - waiters_done_ = CreateEvent(NULL,FALSE,FALSE,NULL); - } + Condition(long max = 0L) + { + waiters_ = 0; + sema_ = CreateSemaphore(NULL,0,0x7fffffff,NULL); + waiters_done_ = CreateEvent(NULL,FALSE,FALSE,NULL); + } - ~Condition() - { - // CloseHandle(sema_); - // CloseHandle(waiters_done_); - } + ~Condition() + { + // CloseHandle(sema_); + // CloseHandle(waiters_done_); + } - inline int broadcast () - { - waiters_lock_.lock(); - int have_waiters = 0; + inline int broadcast () + { + waiters_lock_.lock(); + int have_waiters = 0; - if (waiters_ > 0) - { - // We are broadcasting, even if there is just one waiter... - // Record the fact that we are broadcasting. This helps the - // wait() method know how to optimize itself. Be sure to - // set this with the held. - was_broadcast_ = 1; - have_waiters = 1; - } - waiters_lock_.unlock(); - - int result = 0; - if (have_waiters) - { - // Wake up all the waiters. - ReleaseSemaphore(sema_,waiters_,NULL); - WaitForSingleObject(waiters_done_,INFINITE) ; - // This is okay, even without the held because - // no other waiter threads can wake up to access it. - was_broadcast_ = 0; - } - return result; - } + if (waiters_ > 0) + { + // We are broadcasting, even if there is just one waiter... + // Record the fact that we are broadcasting. This helps the + // wait() method know how to optimize itself. Be sure to + // set this with the held. + was_broadcast_ = 1; + have_waiters = 1; + } + waiters_lock_.unlock(); + + int result = 0; + if (have_waiters) + { + // Wake up all the waiters. + ReleaseSemaphore(sema_,waiters_,NULL); + WaitForSingleObject(waiters_done_,INFINITE) ; + // This is okay, even without the held because + // no other waiter threads can wake up to access it. + was_broadcast_ = 0; + } + return result; + } - inline int wait (Mutex& external_mutex) - { - // Prevent race conditions on the count. - waiters_lock_.lock(); - waiters_++; - waiters_lock_.unlock(); - - int result = 0; - + inline int wait (Mutex& external_mutex) + { + // Prevent race conditions on the count. + waiters_lock_.lock(); + waiters_++; + waiters_lock_.unlock(); + + int result = 0; + external_mutex.unlock(); - - DWORD dwResult = WaitForSingleObject(sema_,INFINITE); - if(dwResult != WAIT_OBJECT_0) - result = (int)dwResult; - - // Reacquire lock to avoid race conditions on the count. - waiters_lock_.lock(); - - // We're ready to return, so there's one less waiter. - waiters_--; - - int last_waiter = was_broadcast_ && waiters_ == 0; - - // Release the lock so that other collaborating threads can make - // progress. - waiters_lock_.unlock(); - - if (result != -1 && last_waiter) - SetEvent(waiters_done_); - - external_mutex.lock(); - - return result; - } + + DWORD dwResult = WaitForSingleObject(sema_,INFINITE); + if(dwResult != WAIT_OBJECT_0) + result = (int)dwResult; + + // Reacquire lock to avoid race conditions on the count. + waiters_lock_.lock(); + + // We're ready to return, so there's one less waiter. + waiters_--; + + int last_waiter = was_broadcast_ && waiters_ == 0; + + // Release the lock so that other collaborating threads can make + // progress. + waiters_lock_.unlock(); + + if (result != -1 && last_waiter) + SetEvent(waiters_done_); + + external_mutex.lock(); + + return result; + } protected: @@ -122,38 +120,6 @@ protected: size_t was_broadcast_; }; -#else -#include -namespace Producer { - -class PR_EXPORT Condition -{ -public: - /// number of waiters. - Condition(long max) - { - pthread_cond_init( &_cond, 0L ); - } - - ~Condition() - { - } - - inline int broadcast () - { - return pthread_cond_broadcast(&_cond); - } - - inline int wait (Mutex& external_mutex) - { - return pthread_cond_wait(&_cond); - } - - -protected: - pthread_cond_t _cond; -}; -#endif } -#endif \ No newline at end of file +#endif diff --git a/src/OpenThreads/win32/Win32ConditionPrivateData.h b/src/OpenThreads/win32/Win32ConditionPrivateData.h index 810c74f1e..950f4e5ff 100644 --- a/src/OpenThreads/win32/Win32ConditionPrivateData.h +++ b/src/OpenThreads/win32/Win32ConditionPrivateData.h @@ -19,12 +19,6 @@ #ifndef _WIN32CONDITIONPRIVATEDATA_H_ #define _WIN32CONDITIONPRIVATEDATA_H_ -#ifndef _WINDOWS_ -#define WIN32_LEAN_AND_MEAN -#define _WIN32_WINNT 0x0400 -#include -#endif - #include #include "Win32ThreadPrivateData.h" diff --git a/src/OpenThreads/win32/Win32MutexPrivateData.h b/src/OpenThreads/win32/Win32MutexPrivateData.h index dd196dcc7..e632ac101 100644 --- a/src/OpenThreads/win32/Win32MutexPrivateData.h +++ b/src/OpenThreads/win32/Win32MutexPrivateData.h @@ -19,12 +19,8 @@ #ifndef _Win32MUTEXPRIVATEDATA_H_ #define _Win32MUTEXPRIVATEDATA_H_ - -#ifndef _WINDOWS_ -#define WIN32_LEAN_AND_MEAN -#define _WIN32_WINNT 0x0400 // was missing : adegli #include -#endif + namespace OpenThreads { class Win32MutexPrivateData { diff --git a/src/OpenThreads/win32/Win32ThreadPrivateData.h b/src/OpenThreads/win32/Win32ThreadPrivateData.h index 554edb811..07f12d2c2 100644 --- a/src/OpenThreads/win32/Win32ThreadPrivateData.h +++ b/src/OpenThreads/win32/Win32ThreadPrivateData.h @@ -17,12 +17,6 @@ #ifndef _Win32PRIVATEDATA_H_ #define _Win32PRIVATEDATA_H_ -#ifndef _WINDOWS_ -#define WIN32_LEAN_AND_MEAN -#define _WIN32_WINNT 0x0400 -#include -#endif - #include #include #include "HandleHolder.h" diff --git a/src/osg/GLExtensions.cpp b/src/osg/GLExtensions.cpp index a363dc567..53b0a3d67 100644 --- a/src/osg/GLExtensions.cpp +++ b/src/osg/GLExtensions.cpp @@ -345,7 +345,9 @@ std::string& osg::getGLExtensionDisableString() #if defined(WIN32) - #define WIN32_LEAN_AND_MEAN + #ifndef WIN32_LEAN_AND_MEAN + #define WIN32_LEAN_AND_MEAN + #endif // WIN32_LEAN_AND_MEAN #ifndef NOMINMAX #define NOMINMAX #endif // NOMINMAX @@ -375,10 +377,10 @@ void* osg::getGLExtensionFuncPtr(const char *funcName) #if defined(WIN32) #if defined(OSG_GLES2_AVAILABLE) - static HMODULE hmodule = GetModuleHandle("libGLESv2.dll"); + static HMODULE hmodule = GetModuleHandle(TEXT("libGLESv2.dll")); return convertPointerType(GetProcAddress(hmodule, funcName)); #elif defined(OSG_GLES1_AVAILABLE) - static HMODULE hmodule = GetModuleHandle("libgles_cm.dll"); + static HMODULE hmodule = GetModuleHandleA(TEXT("libgles_cm.dll")); return convertPointerType(GetProcAddress(hmodule, funcName)); #else return convertPointerType(wglGetProcAddress(funcName)); diff --git a/src/osgWrappers/introspection/osgViewer/GraphicsWindow.cpp b/src/osgWrappers/introspection/osgViewer/GraphicsWindow.cpp index 02e3ee605..2509421d6 100644 --- a/src/osgWrappers/introspection/osgViewer/GraphicsWindow.cpp +++ b/src/osgWrappers/introspection/osgViewer/GraphicsWindow.cpp @@ -157,11 +157,21 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow) __void__setCursor__MouseCursor, "Set mouse cursor to a specific shape. ", ""); + I_Method1(void, setSyncToVBlank, IN, bool, on, + Properties::VIRTUAL, + __void__setSyncToVBlank__bool, + "Create a new mouse cursor from the usual bitmap data. ", + "Set sync-to-vblank. "); + I_Method0(bool, getSyncToVBlank, + Properties::NON_VIRTUAL, + __bool__getSyncToVBlank, + "", + ""); I_Method0(bool, valid, Properties::VIRTUAL, __bool__valid, - "Create a new mouse cursor from the usual bitmap data. ", - "Return whether a valid and usable GraphicsContext has been created. "); + "Return whether a valid and usable GraphicsContext has been created. ", + ""); I_Method0(bool, realizeImplementation, Properties::VIRTUAL, __bool__realizeImplementation, @@ -223,6 +233,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindow) I_SimpleProperty(osgGA::EventQueue *, EventQueue, __osgGA_EventQueue_P1__getEventQueue, __void__setEventQueue__osgGA_EventQueue_P1); + I_SimpleProperty(bool, SyncToVBlank, + __bool__getSyncToVBlank, + __void__setSyncToVBlank__bool); I_SimpleProperty(bool, WindowDecoration, __bool__getWindowDecoration, __void__setWindowDecoration__bool); @@ -269,8 +282,8 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::GraphicsWindowEmbedded) I_Method0(bool, valid, Properties::VIRTUAL, __bool__valid, - "Create a new mouse cursor from the usual bitmap data. ", - "Return whether a valid and usable GraphicsContext has been created. "); + "Return whether a valid and usable GraphicsContext has been created. ", + ""); I_Method0(bool, realizeImplementation, Properties::VIRTUAL, __bool__realizeImplementation, diff --git a/src/osgWrappers/introspection/osgViewer/ViewerEventHandlers.cpp b/src/osgWrappers/introspection/osgViewer/ViewerEventHandlers.cpp index 5061b1bd8..4c8b6f120 100644 --- a/src/osgWrappers/introspection/osgViewer/ViewerEventHandlers.cpp +++ b/src/osgWrappers/introspection/osgViewer/ViewerEventHandlers.cpp @@ -444,6 +444,16 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::StatsHandler) __int__getKeyEventPrintsOutStats, "", ""); + I_Method1(void, setKeyEventToggleVSync, IN, int, key, + Properties::NON_VIRTUAL, + __void__setKeyEventToggleVSync__int, + "", + ""); + I_Method0(int, getKeyEventToggleVSync, + Properties::NON_VIRTUAL, + __int__getKeyEventToggleVSync, + "", + ""); I_Method0(double, getBlockMultiplier, Properties::NON_VIRTUAL, __double__getBlockMultiplier, @@ -531,6 +541,9 @@ BEGIN_OBJECT_REFLECTOR(osgViewer::StatsHandler) I_SimpleProperty(int, KeyEventPrintsOutStats, __int__getKeyEventPrintsOutStats, __void__setKeyEventPrintsOutStats__int); + I_SimpleProperty(int, KeyEventToggleVSync, + __int__getKeyEventToggleVSync, + __void__setKeyEventToggleVSync__int); I_SimpleProperty(int, KeyEventTogglesOnScreenStats, __int__getKeyEventTogglesOnScreenStats, __void__setKeyEventTogglesOnScreenStats__int);