Changeset 11057

Show
Ignore:
Timestamp:
02/12/10 12:45:00 (3 years ago)
Author:
robert
Message:

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.

Location:
OpenSceneGraph/trunk
Files:
4 modified

Legend:

Unmodified
Added
Removed
  • OpenSceneGraph/trunk/CMakeLists.txt

    r11055 r11057  
    264264#luigi#ENDIF(UNIX) 
    265265######################################################################################################## 
     266 
     267OPTION(OSG_NOTIFY_DISABLED "Set to ON to build OpenSceneGraph with the noitfy() disabled." OFF) 
    266268 
    267269OPTION(OSG_USE_FLOAT_MATRIX "Set to ON to build OpenSceneGraph with float Matrix instead of double." OFF) 
  • OpenSceneGraph/trunk/include/osg/Notify

    r11047 r11057  
    4646extern OSG_EXPORT NotifySeverity getNotifyLevel(); 
    4747 
    48 /** is notification enabled, given the current setNotifyLevel() setting? */ 
    49 extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity); 
    50  
    5148/** initialize notify level. */ 
    5249extern OSG_EXPORT bool initNotifyLevel(); 
     50 
     51#ifdef OSG_NOTIFY_DISABLED 
     52    inline bool isNotifyEnabled(NotifySeverity) { return false; } 
     53#else 
     54    /** is notification enabled, given the current setNotifyLevel() setting? */ 
     55    extern OSG_EXPORT bool isNotifyEnabled(NotifySeverity severity); 
     56#endif 
    5357 
    5458/** notify messaging function for providing fatal through to verbose 
     
    7781 
    7882#define OSG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level) 
    79  
    80 #if _DEBUG 
    81     #define OSG_DEBUG_NOTIFY(level) if (isNotifyEnabled(level)) osg::notify(level) 
    82 #else 
    83     // when using an optimized build use if (false) to tell the compiler to ignore the rest of the notify. 
    84     #define OSG_DEBUG_NOTIFY(level) if (false) osg::notify(level) 
    85 #endif 
     83#define OSG_FATAL OSG_NOTIFY(osg::FALTAL) 
     84#define OSG_WARN OSG_NOTIFY(osg::WARN) 
     85#define OSG_NOTICE OSG_NOTIFY(osg::NOTICE) 
     86#define OSG_INFO OSG_NOTIFY(osg::INFO) 
     87#define OSG_DEBUG OSG_NOTIFY(osg::DEBUG_INFO) 
    8688 
    8789/** Handler processing output of notification stream. It acts as a sink to  
  • OpenSceneGraph/trunk/src/osg/Config.in

    r10772 r11057  
    2424#define OSG_CONFIG 1 
    2525 
     26#cmakedefine OSG_NOTIFY_DISABLED 
    2627#cmakedefine OSG_USE_FLOAT_MATRIX 
    2728#cmakedefine OSG_USE_FLOAT_PLANE 
  • OpenSceneGraph/trunk/src/osg/Notify.cpp

    r10764 r11057  
    115115static osg::ApplicationUsageProxy Notify_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_NOTIFY_LEVEL <mode>", "FATAL | WARN | NOTICE | DEBUG_INFO | DEBUG_FP | DEBUG | INFO | ALWAYS"); 
    116116 
     117static bool s_NeedNotifyInit = true; 
    117118static osg::NotifySeverity g_NotifyLevel = osg::NOTICE; 
    118119static osg::NullStream *g_NullStream; 
     
    121122void osg::setNotifyLevel(osg::NotifySeverity severity) 
    122123{ 
    123     osg::initNotifyLevel(); 
     124    if (s_NeedNotifyInit) osg::initNotifyLevel(); 
    124125    g_NotifyLevel = severity; 
    125126} 
     
    128129osg::NotifySeverity osg::getNotifyLevel() 
    129130{ 
    130     osg::initNotifyLevel(); 
     131    if (s_NeedNotifyInit) osg::initNotifyLevel(); 
    131132    return g_NotifyLevel; 
    132133} 
     
    141142osg::NotifyHandler* osg::getNotifyHandler() 
    142143{ 
    143     osg::initNotifyLevel(); 
     144    if (s_NeedNotifyInit) osg::initNotifyLevel(); 
    144145    osg::NotifyStreamBuffer *buffer = static_cast<osg::NotifyStreamBuffer *>(g_NotifyStream->rdbuf()); 
    145146    return buffer ? buffer->getNotifyHandler() : 0; 
     
    148149bool osg::initNotifyLevel() 
    149150{ 
    150     static bool s_NotifyInit = false; 
    151151    static osg::NullStream s_NullStream; 
    152152    static osg::NotifyStream s_NotifyStream; 
    153  
    154     if (s_NotifyInit) return true; 
    155153 
    156154    g_NullStream = &s_NullStream; 
     
    194192        buffer->setNotifyHandler(new StandardNotifyHandler); 
    195193 
    196     s_NotifyInit = true; 
     194    s_NeedNotifyInit = false; 
    197195 
    198196    return true; 
     
    200198} 
    201199 
     200#ifndef OSG_NOTIFY_DISABLED 
    202201bool osg::isNotifyEnabled( osg::NotifySeverity severity ) 
    203202{ 
     203    if (s_NeedNotifyInit) osg::initNotifyLevel(); 
    204204    return severity<=g_NotifyLevel; 
    205205} 
     206#endif 
    206207 
    207208std::ostream& osg::notify(const osg::NotifySeverity severity) 
    208209{ 
    209     static bool initialized = false; 
    210     if (!initialized)  
    211     { 
    212         initialized = osg::initNotifyLevel(); 
    213     } 
    214  
    215     if (severity<=g_NotifyLevel) 
     210    if (s_NeedNotifyInit) osg::initNotifyLevel(); 
     211 
     212    if (osg::isNotifyEnabled(severity)) 
    216213    { 
    217214        g_NotifyStream->setCurrentSeverity(severity);