From a673abac3daa1ee52d885131472929a55b81124b Mon Sep 17 00:00:00 2001 From: Robert Osfield Date: Fri, 12 Feb 2010 11:45:00 +0000 Subject: [PATCH] Introduced OSG_WARN, OSG_NOTICE, OSG_INFO, OSG_DEBUG convinience macros that map to OSG_NOTIFY(osg::WARN) etc. Introduced the OSG_NOTIFY_DISABLE Cmake variable + include/osg/Config #define to control whether the OpenSceneGraph build should disable the notification system completely. By setting OSG_NOTIFY_DISABLE to ON in CMake and then rebuilding the the OSG you can get a slightly smaller (~1%) and more slightly efficient library which can be good for shipping applications, but with downside of reduced ability to detect runtime problems and their causes. --- CMakeLists.txt | 2 ++ include/osg/Notify | 22 ++++++++++++---------- src/osg/Config.in | 1 + src/osg/Notify.cpp | 23 ++++++++++------------- 4 files changed, 25 insertions(+), 23 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e611de63f..e88e451a4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -264,6 +264,8 @@ ENDIF(WIN32) #luigi#ENDIF(UNIX) ######################################################################################################## +OPTION(OSG_NOTIFY_DISABLED "Set to ON to build OpenSceneGraph with the noitfy() disabled." OFF) + OPTION(OSG_USE_FLOAT_MATRIX "Set to ON to build OpenSceneGraph with float Matrix instead of double." OFF) MARK_AS_ADVANCED(OSG_USE_FLOAT_MATRIX) diff --git a/include/osg/Notify b/include/osg/Notify index ac110a559..09235a661 100644 --- a/include/osg/Notify +++ b/include/osg/Notify @@ -45,12 +45,16 @@ extern OSG_EXPORT void setNotifyLevel(NotifySeverity severity); /** get the notify level. */ extern OSG_EXPORT NotifySeverity getNotifyLevel(); -/** is notification enabled, given the current setNotifyLevel() setting? */ -extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity); - /** initialize notify level. */ extern OSG_EXPORT bool initNotifyLevel(); +#ifdef OSG_NOTIFY_DISABLED + inline bool isNotifyEnabled(NotifySeverity) { return false; } +#else + /** is notification enabled, given the current setNotifyLevel() setting? */ + extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity); +#endif + /** notify messaging function for providing fatal through to verbose * debugging messages. Level of messages sent to the console can * be controlled by setting the NotifyLevel either within your @@ -76,13 +80,11 @@ extern OSG_EXPORT std::ostream& notify(const NotifySeverity severity); inline std::ostream& notify(void) { return notify(osg::INFO); } #define OSG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level) - -#if _DEBUG - #define OSG_DEBUG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level) -#else - // when using an optimized build use if (false) to tell the compiler to ignore the rest of the notify. - #define OSG_DEBUG_NOTIFY(level) if (false) osg::notify(level) -#endif +#define OSG_FATAL OSG_NOTIFY(osg::FALTAL) +#define OSG_WARN OSG_NOTIFY(osg::WARN) +#define OSG_NOTICE OSG_NOTIFY(osg::NOTICE) +#define OSG_INFO OSG_NOTIFY(osg::INFO) +#define OSG_DEBUG OSG_NOTIFY(osg::DEBUG_INFO) /** Handler processing output of notification stream. It acts as a sink to * notification messages. It is called when notification stream needs to be diff --git a/src/osg/Config.in b/src/osg/Config.in index d8df6439f..37dd9c448 100644 --- a/src/osg/Config.in +++ b/src/osg/Config.in @@ -23,6 +23,7 @@ #ifndef OSG_CONFIG #define OSG_CONFIG 1 +#cmakedefine OSG_NOTIFY_DISABLED #cmakedefine OSG_USE_FLOAT_MATRIX #cmakedefine OSG_USE_FLOAT_PLANE #cmakedefine OSG_USE_FLOAT_BOUNDINGSPHERE diff --git a/src/osg/Notify.cpp b/src/osg/Notify.cpp index dc3e1b3ab..7137916cb 100644 --- a/src/osg/Notify.cpp +++ b/src/osg/Notify.cpp @@ -114,20 +114,21 @@ using namespace osg; static osg::ApplicationUsageProxy Notify_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_NOTIFY_LEVEL ", "FATAL | WARN | NOTICE | DEBUG_INFO | DEBUG_FP | DEBUG | INFO | ALWAYS"); +static bool s_NeedNotifyInit = true; static osg::NotifySeverity g_NotifyLevel = osg::NOTICE; static osg::NullStream *g_NullStream; static osg::NotifyStream *g_NotifyStream; void osg::setNotifyLevel(osg::NotifySeverity severity) { - osg::initNotifyLevel(); + if (s_NeedNotifyInit) osg::initNotifyLevel(); g_NotifyLevel = severity; } osg::NotifySeverity osg::getNotifyLevel() { - osg::initNotifyLevel(); + if (s_NeedNotifyInit) osg::initNotifyLevel(); return g_NotifyLevel; } @@ -140,19 +141,16 @@ void osg::setNotifyHandler(osg::NotifyHandler *handler) osg::NotifyHandler* osg::getNotifyHandler() { - osg::initNotifyLevel(); + if (s_NeedNotifyInit) osg::initNotifyLevel(); osg::NotifyStreamBuffer *buffer = static_cast(g_NotifyStream->rdbuf()); return buffer ? buffer->getNotifyHandler() : 0; } bool osg::initNotifyLevel() { - static bool s_NotifyInit = false; static osg::NullStream s_NullStream; static osg::NotifyStream s_NotifyStream; - if (s_NotifyInit) return true; - g_NullStream = &s_NullStream; g_NotifyStream = &s_NotifyStream; @@ -193,26 +191,25 @@ bool osg::initNotifyLevel() if (buffer && !buffer->getNotifyHandler()) buffer->setNotifyHandler(new StandardNotifyHandler); - s_NotifyInit = true; + s_NeedNotifyInit = false; return true; } +#ifndef OSG_NOTIFY_DISABLED bool osg::isNotifyEnabled( osg::NotifySeverity severity ) { + if (s_NeedNotifyInit) osg::initNotifyLevel(); return severity<=g_NotifyLevel; } +#endif std::ostream& osg::notify(const osg::NotifySeverity severity) { - static bool initialized = false; - if (!initialized) - { - initialized = osg::initNotifyLevel(); - } + if (s_NeedNotifyInit) osg::initNotifyLevel(); - if (severity<=g_NotifyLevel) + if (osg::isNotifyEnabled(severity)) { g_NotifyStream->setCurrentSeverity(severity); return *g_NotifyStream;