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.
This commit is contained in:
Robert Osfield
2010-02-12 11:45:00 +00:00
parent 9434b764a8
commit a673abac3d
4 changed files with 25 additions and 23 deletions

View File

@@ -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)

View File

@@ -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

View File

@@ -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

View File

@@ -114,20 +114,21 @@ using namespace osg;
static osg::ApplicationUsageProxy Notify_e0(osg::ApplicationUsage::ENVIRONMENTAL_VARIABLE, "OSG_NOTIFY_LEVEL <mode>", "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<osg::NotifyStreamBuffer *>(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;