Commit bb4ef9be authored by Lorenz Meier's avatar Lorenz Meier

Added slightly adapted OSG 3.0.1 headers (changed std::isnan to std::fpclassify= FP_NAN)

parent a445c615
......@@ -6,6 +6,7 @@ tags
build
Info.plist
obj
.DS_Store
*.log
*~
*~.skp
......@@ -31,7 +32,6 @@ deploy/qgroundcontrol*
controller_log*
user_config.pri
*.app
*.ncb
*.vcproj
*.vcxproj*
......
/* -*-c++-*- OpenThreads library, Copyright (C) 2008 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef _OPENTHREADS_ATOMIC_
#define _OPENTHREADS_ATOMIC_
#include <OpenThreads/Config>
#include <OpenThreads/Exports>
#if defined(_OPENTHREADS_ATOMIC_USE_BSD_ATOMIC)
# include <libkern/OSAtomic.h>
# define _OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES
#elif defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS) && defined(__i386__)
# define _OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES
#elif defined(_OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED)
# define _OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
# include <atomic.h>
# include "Mutex"
# include "ScopedLock"
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
# include "Mutex"
# include "ScopedLock"
#endif
#if defined(_OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES)
#define _OPENTHREADS_ATOMIC_INLINE
#else
#define _OPENTHREADS_ATOMIC_INLINE inline
#endif
namespace OpenThreads {
/**
* @class Atomic
* @brief This class provides an atomic increment and decrement operation.
*/
class OPENTHREAD_EXPORT_DIRECTIVE Atomic {
public:
Atomic(unsigned value = 0) : _value(value)
{ }
_OPENTHREADS_ATOMIC_INLINE unsigned operator++();
_OPENTHREADS_ATOMIC_INLINE unsigned operator--();
_OPENTHREADS_ATOMIC_INLINE unsigned AND(unsigned value);
_OPENTHREADS_ATOMIC_INLINE unsigned OR(unsigned value);
_OPENTHREADS_ATOMIC_INLINE unsigned XOR(unsigned value);
_OPENTHREADS_ATOMIC_INLINE unsigned exchange(unsigned value = 0);
_OPENTHREADS_ATOMIC_INLINE operator unsigned() const;
private:
Atomic(const Atomic&);
Atomic& operator=(const Atomic&);
#if defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
mutable Mutex _mutex;
#endif
#if defined(_OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED)
volatile long _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_BSD_ATOMIC)
volatile int32_t _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
volatile uint_t _value;
mutable Mutex _mutex; // needed for xor
#else
volatile unsigned _value;
#endif
};
/**
* @class AtomicPtr
* @brief This class provides an atomic pointer assignment using cas operations.
*/
class OPENTHREAD_EXPORT_DIRECTIVE AtomicPtr {
public:
AtomicPtr(void* ptr = 0) : _ptr(ptr)
{ }
~AtomicPtr()
{ _ptr = 0; }
// assigns a new pointer
_OPENTHREADS_ATOMIC_INLINE bool assign(void* ptrNew, const void* const ptrOld);
_OPENTHREADS_ATOMIC_INLINE void* get() const;
private:
AtomicPtr(const AtomicPtr&);
AtomicPtr& operator=(const AtomicPtr&);
#if defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
mutable Mutex _mutex;
#endif
void* volatile _ptr;
};
#if !defined(_OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES)
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::operator++()
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_add_and_fetch(&_value, 1);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __add_and_fetch(&_value, 1);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return atomic_inc_uint_nv(&_value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
return ++_value;
#else
return ++_value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::operator--()
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_sub_and_fetch(&_value, 1);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __sub_and_fetch(&_value, 1);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return atomic_dec_uint_nv(&_value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
return --_value;
#else
return --_value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::AND(unsigned value)
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_fetch_and_and(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __and_and_fetch(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return atomic_and_uint_nv(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
_value &= value;
return _value;
#else
_value &= value;
return _value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::OR(unsigned value)
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_fetch_and_or(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __or_and_fetch(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return atomic_or_uint_nv(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
_value |= value;
return _value;
#else
_value |= value;
return _value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::XOR(unsigned value)
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_fetch_and_xor(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __xor_and_fetch(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
ScopedLock<Mutex> lock(_mutex);
_value ^= value;
return _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
_value ^= value;
return _value;
#else
_value ^= value;
return _value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE unsigned
Atomic::exchange(unsigned value)
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_lock_test_and_set(&_value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __compare_and_swap(&_value, _value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return atomic_cas_uint(&_value, _value, value);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
unsigned oldval = _value;
_value = value;
return oldval;
#else
unsigned oldval = _value;
_value = value;
return oldval;
#endif
}
_OPENTHREADS_ATOMIC_INLINE
Atomic::operator unsigned() const
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
__sync_synchronize();
return _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
__synchronize();
return _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
membar_consumer(); // Hmm, do we need???
return _value;
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
return _value;
#else
return _value;
#endif
}
_OPENTHREADS_ATOMIC_INLINE bool
AtomicPtr::assign(void* ptrNew, const void* const ptrOld)
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
return __sync_bool_compare_and_swap(&_ptr, ptrOld, ptrNew);
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
return __compare_and_swap((unsigned long*)&_ptr, (unsigned long)ptrOld, (unsigned long)ptrNew);
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
return ptrOld == atomic_cas_ptr(&_ptr, const_cast<void*>(ptrOld), ptrNew);
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
if (_ptr != ptrOld)
return false;
_ptr = ptrNew;
return true;
#else
if (_ptr != ptrOld)
return false;
_ptr = ptrNew;
return true;
#endif
}
_OPENTHREADS_ATOMIC_INLINE void*
AtomicPtr::get() const
{
#if defined(_OPENTHREADS_ATOMIC_USE_GCC_BUILTINS)
__sync_synchronize();
return _ptr;
#elif defined(_OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS)
__synchronize();
return _ptr;
#elif defined(_OPENTHREADS_ATOMIC_USE_SUN)
membar_consumer(); // Hmm, do we need???
return _ptr;
#elif defined(_OPENTHREADS_ATOMIC_USE_MUTEX)
ScopedLock<Mutex> lock(_mutex);
return _ptr;
#else
return _ptr;
#endif
}
#endif // !defined(_OPENTHREADS_ATOMIC_USE_LIBRARY_ROUTINES)
}
#endif // _OPENTHREADS_ATOMIC_
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//
// Barrier - C++ barrier class
// ~~~~~~~
//
#ifndef _OPENTHREADS_BARRIER_
#define _OPENTHREADS_BARRIER_
#include <OpenThreads/Exports>
namespace OpenThreads {
/**
* @class Barrier
* @brief This class provides an object-oriented thread barrier interface
*
* @warning It is unwise to use the construct "Barrier barrier" in the
* global namespace on sgi's. The object "barrier"
* will confilict with the c-library sproc function "barrier" and
* unpredictable results may occur. You have been warned.
*/
class OPENTHREAD_EXPORT_DIRECTIVE Barrier {
public:
/**
* Constructor
*/
Barrier(int numThreads=0);
/**
* Destructor
*/
virtual ~Barrier();
/**
* Reset the barrier to it's original state.
*/
virtual void reset();
/**
* Block until numThreads threads have entered the barrier.
*/
virtual void block(unsigned int numThreads=0);
/**
* Release the barrier, now.
*/
virtual void release();
/**
* Return the number of threads currently blocked in the barrier,
* Return -1 if error.
*/
virtual int numThreadsCurrentlyBlocked();
void invalidate();
private:
/**
* Private copy constructor, to prevent tampering.
*/
Barrier(const Barrier &/*b*/) {};
/**
* Private copy assignment, to prevent tampering.
*/
Barrier &operator=(const Barrier &/*b*/) {return *(this);};
/**
* Implementation-specific private data.
*/
void *_prvData;
bool _valid;
};
}
#endif // !_OPENTHREADS_BARRIER_
/* -*-c++-*- OpenThreads - Copyright (C) 1998-2007 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef _OPENTHREADS_BLOCK_
#define _OPENTHREADS_BLOCK_
#include <OpenThreads/Thread>
#include <OpenThreads/Barrier>
#include <OpenThreads/Condition>
#include <OpenThreads/ScopedLock>
namespace OpenThreads {
/** Block is a block that can be used to halt a thread that is waiting another thread to release it.*/
class Block
{
public:
Block():
_released(false) {}
~Block()
{
release();
}
inline bool block()
{
ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if( !_released )
{
return _cond.wait(&_mut)==0;
}
else
{
return true;
}
}
inline bool block(unsigned long timeout)
{
ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if( !_released )
{
return _cond.wait(&_mut, timeout)==0;
}
else
{
return true;
}
}
inline void release()
{
ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (!_released)
{
_released = true;
_cond.broadcast();
}
}
inline void reset()
{
ScopedLock<OpenThreads::Mutex> mutlock(_mut);
_released = false;
}
inline void set(bool doRelease)
{
if (doRelease!=_released)
{
if (doRelease) release();
else reset();
}
}
protected:
Mutex _mut;
Condition _cond;
bool _released;
private:
Block(const Block&) {}
};
/** BlockCount is a block that can be used to halt a thread that is waiting for a specified number of operations to be completed.*/
class BlockCount
{
public:
BlockCount(unsigned int blockCount):
_blockCount(blockCount),
_currentCount(0) {}
~BlockCount()
{
_blockCount = 0;
release();
}
inline void completed()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (_currentCount>0)
{
--_currentCount;
if (_currentCount==0)
{
// osg::notify(osg::NOTICE)<<"Released"<<std::endl;
_cond.broadcast();
}
}
}
inline void block()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (_currentCount)
_cond.wait(&_mut);
}
inline void reset()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (_currentCount!=_blockCount)
{
if (_blockCount==0) _cond.broadcast();
_currentCount = _blockCount;
}
}
inline void release()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> mutlock(_mut);
if (_currentCount)
{
_currentCount = 0;
_cond.broadcast();
}
}
inline void setBlockCount(unsigned int blockCount) { _blockCount = blockCount; }
inline unsigned int getBlockCount() const { return _blockCount; }
inline unsigned int getCurrentCount() const { return _currentCount; }
protected:
OpenThreads::Mutex _mut;
OpenThreads::Condition _cond;
unsigned int _blockCount;
unsigned int _currentCount;
private:
BlockCount(const BlockCount&) {}
};
}
#endif
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//
// Condition - C++ condition class
// ~~~~~~~~~
//
#ifndef _OPENTHREADS_CONDITION_
#define _OPENTHREADS_CONDITION_
#include <OpenThreads/Exports>
#include <OpenThreads/Mutex>
namespace OpenThreads {
/**
* @class Condition
* @brief This class provides an object-oriented thread condition interface.
*/
class OPENTHREAD_EXPORT_DIRECTIVE Condition {
public:
/**
* Constructor
*/
Condition();
/**
* Destructor
*/
virtual ~Condition();
/**
* Wait on a mutex.
*/
virtual int wait(Mutex *mutex);
/**
* Wait on a mutex for a given amount of time (ms)
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int wait(Mutex *mutex, unsigned long int ms);
/**
* Signal a SINGLE thread to wake if it's waiting.
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int signal();
/**
* Wake all threads waiting on this condition.
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int broadcast();
private:
/**
* Private copy constructor, to prevent tampering.
*/
Condition(const Condition &/*c*/) {};
/**
* Private copy assignment, to prevent tampering.
*/
Condition &operator=(const Condition &/*c*/) {return *(this);};
/**
* Implementation-specific data
*/
void *_prvData;
};
}
#endif // !_OPENTHREADS_CONDITION_
/* -*-c++-*- OpenSceneGraph - Copyright (C) 2008 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
/****************************************************************************
* THIS FILE IS AUTOGENERATED BY CMAKE. DO NOT EDIT!
****************************************************************************/
/* Changes to the configuration reflected here can be made with ccmake on
* unix or with cmake-gui on windows. Alternatively you can use cmake's -D
* or -P switches to set some configuration values at cmake configuration time.
*/
#ifndef _OPENTHREADS_CONFIG
#define _OPENTHREADS_CONFIG
#define _OPENTHREADS_ATOMIC_USE_GCC_BUILTINS
/* #undef _OPENTHREADS_ATOMIC_USE_MIPOSPRO_BUILTINS */
/* #undef _OPENTHREADS_ATOMIC_USE_SUN */
/* #undef _OPENTHREADS_ATOMIC_USE_WIN32_INTERLOCKED */
#define _OPENTHREADS_ATOMIC_USE_BSD_ATOMIC
/* #undef _OPENTHREADS_ATOMIC_USE_MUTEX */
/* #undef OT_LIBRARY_STATIC */
#endif
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef _OPENTHREAD_EXPORTS_H_
#define _OPENTHREAD_EXPORTS_H_
#include <OpenThreads/Config>
#ifndef WIN32
#define OPENTHREAD_EXPORT_DIRECTIVE
#else
#if defined( OT_LIBRARY_STATIC )
#define OPENTHREAD_EXPORT_DIRECTIVE
#elif defined( OPENTHREADS_EXPORTS )
#define OPENTHREAD_EXPORT_DIRECTIVE __declspec(dllexport)
#else
#define OPENTHREAD_EXPORT_DIRECTIVE __declspec(dllimport)
#if 0 // Commented out for now
#ifdef _MSC_VER
#ifdef _DEBUG
#pragma comment(lib ,"OpenThreadsWin32d")
#else
#pragma comment(lib, "OpenThreadsWin32")
#endif
#endif
#endif
#endif
#endif
#endif
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//
// Mutex - C++ mutex class
// ~~~~~
//
#ifndef _OPENTHREADS_MUTEX_
#define _OPENTHREADS_MUTEX_
#include <OpenThreads/Exports>
namespace OpenThreads {
/**
* @class Mutex
* @brief This class provides an object-oriented thread mutex interface.
*/
class OPENTHREAD_EXPORT_DIRECTIVE Mutex {
friend class Condition;
public:
enum MutexType
{
MUTEX_NORMAL,
MUTEX_RECURSIVE
};
/**
* Constructor
*/
Mutex(MutexType type=MUTEX_NORMAL);
/**
* Destructor
*/
virtual ~Mutex();
MutexType getMutexType() const { return _mutexType; }
/**
* Lock the mutex
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int lock();
/**
* Unlock the mutex
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int unlock();
/**
* Test if mutex can be locked.
*
* @return 0 if normal, -1 if errno set, errno code otherwise.
*/
virtual int trylock();
private:
/**
* Private copy constructor, to prevent tampering.
*/
Mutex(const Mutex &/*m*/) {};
/**
* Private copy assignment, to prevent tampering.
*/
Mutex &operator=(const Mutex &/*m*/) {return *(this);};
/**
* Implementation-specific private data.
*/
void *_prvData;
MutexType _mutexType;
};
}
#endif // _OPENTHREADS_MUTEX_
/* -*-c++-*- OpenThreads - Copyright (C) 1998-2007 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef _OPENTHREADS_READWRITEMUTEX_
#define _OPENTHREADS_READWRITEMUTEX_
#include <OpenThreads/Thread>
#include <OpenThreads/ReentrantMutex>
namespace OpenThreads {
class ReadWriteMutex
{
public:
ReadWriteMutex():
_readCount(0) {}
virtual ~ReadWriteMutex() {}
virtual int readLock()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_readCountMutex);
int result = 0;
if (_readCount==0)
{
result = _readWriteMutex.lock();
}
++_readCount;
return result;
}
virtual int readUnlock()
{
OpenThreads::ScopedLock<OpenThreads::Mutex> lock(_readCountMutex);
int result = 0;
if (_readCount>0)
{
--_readCount;
if (_readCount==0)
{
result = _readWriteMutex.unlock();
}
}
return result;
}
virtual int writeLock()
{
return _readWriteMutex.lock();
}
virtual int writeUnlock()
{
return _readWriteMutex.unlock();
}
protected:
ReadWriteMutex(const ReadWriteMutex&) {}
ReadWriteMutex& operator = (const ReadWriteMutex&) { return *(this); }
#if 0
ReentrantMutex _readWriteMutex;
ReentrantMutex _readCountMutex;
#else
OpenThreads::Mutex _readWriteMutex;
OpenThreads::Mutex _readCountMutex;
#endif
unsigned int _readCount;
};
class ScopedReadLock
{
public:
ScopedReadLock(ReadWriteMutex& mutex):_mutex(mutex) { _mutex.readLock(); }
~ScopedReadLock() { _mutex.readUnlock(); }
protected:
ReadWriteMutex& _mutex;
ScopedReadLock& operator = (const ScopedReadLock&) { return *this; }
};
class ScopedWriteLock
{
public:
ScopedWriteLock(ReadWriteMutex& mutex):_mutex(mutex) { _mutex.writeLock(); }
~ScopedWriteLock() { _mutex.writeUnlock(); }
protected:
ReadWriteMutex& _mutex;
ScopedWriteLock& operator = (const ScopedWriteLock&) { return *this; }
};
}
#endif
/* -*-c++-*- OpenThreads - Copyright (C) 1998-2007 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef _OPENTHREADS_REENTRANTMUTEX_
#define _OPENTHREADS_REENTRANTMUTEX_
#include <OpenThreads/Thread>
#include <OpenThreads/Mutex>
#include <OpenThreads/ScopedLock>
namespace OpenThreads {
class ReentrantMutex : public OpenThreads::Mutex
{
public:
ReentrantMutex():
Mutex(MUTEX_RECURSIVE) {}
};
}
#endif
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
//
// ScopedLock and ReverseScopedLock templates
// ~~~~~~~
//
#ifndef _ScopedLock_
#define _ScopedLock_
namespace OpenThreads{
template <class M> class ScopedLock
{
private:
M& m_lock;
ScopedLock(const ScopedLock&); // prevent copy
ScopedLock& operator=(const ScopedLock&); // prevent assign
public:
explicit ScopedLock(M& m):m_lock(m) {m_lock.lock();}
~ScopedLock(){m_lock.unlock();}
};
template <class M> class ReverseScopedLock
{
private:
M& m_lock;
ReverseScopedLock(const ReverseScopedLock&); // prevent copy
ReverseScopedLock& operator=(const ReverseScopedLock&); // prevent assign
public:
explicit ReverseScopedLock(M& m):m_lock(m) {m_lock.unlock();}
~ReverseScopedLock(){m_lock.lock();}
};
template <class M> class ScopedPointerLock
{
private:
M* m_lock;
ScopedPointerLock(const ScopedPointerLock&); // prevent copy
ScopedPointerLock& operator=(const ScopedPointerLock&); // prevent assign
public:
explicit ScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->lock();}
~ScopedPointerLock(){ if (m_lock) m_lock->unlock();}
};
template <class M> class ReverseScopedPointerLock
{
private:
M* m_lock;
ReverseScopedPointerLock(const ReverseScopedPointerLock&); // prevent copy
ReverseScopedPointerLock& operator=(const ReverseScopedPointerLock&); // prevent assign
public:
explicit ReverseScopedPointerLock(M* m):m_lock(m) { if (m_lock) m_lock->unlock();}
~ReverseScopedPointerLock(){ if (m_lock) m_lock->lock();}
};
}
#endif
This diff is collapsed.
/* -*-c++-*- OpenThreads library, Copyright (C) 2002 - 2007 The Open Thread Group
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OPENTHREADS_VERSION
#define OPENTHREADS_VERSION 1
#include <OpenThreads/Exports>
extern "C" {
#define OPENTHREADS_MAJOR_VERSION 2
#define OPENTHREADS_MINOR_VERSION 6
#define OPENTHREADS_PATCH_VERSION 0
#define OPENTHREADS_SOVERSION 12
/** OpenThreadsGetVersion() returns the library version number.
* Numbering convention : OpenThreads-1.0 will return 1.0 from OpenThreadsGetVersion. */
extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetVersion();
/** The OpenThreadsGetSOVersion() method returns the OpenSceneGraph soversion number. */
extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetSOVersion();
/** The OpenThreadsGetLibraryName() method returns the library name in human-friendly form. */
extern OPENTHREAD_EXPORT_DIRECTIVE const char* OpenThreadsGetLibraryName();
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ALPHAFUNC
#define OSG_ALPHAFUNC 1
#include <osg/StateAttribute>
#ifndef GL_ALPHA_TEST
#define GL_ALPHA_TEST 0x0BC0
#endif
namespace osg {
/** Encapsulates OpenGL glAlphaFunc.
*/
class OSG_EXPORT AlphaFunc : public StateAttribute
{
public :
enum ComparisonFunction {
NEVER = GL_NEVER,
LESS = GL_LESS,
EQUAL = GL_EQUAL,
LEQUAL = GL_LEQUAL,
GREATER = GL_GREATER,
NOTEQUAL = GL_NOTEQUAL,
GEQUAL = GL_GEQUAL,
ALWAYS = GL_ALWAYS
};
AlphaFunc();
AlphaFunc(ComparisonFunction func,float ref):
_comparisonFunc(func),
_referenceValue(ref) {}
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
AlphaFunc(const AlphaFunc& af,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(af,copyop),
_comparisonFunc(af._comparisonFunc),
_referenceValue(af._referenceValue) {}
META_StateAttribute(osg, AlphaFunc,ALPHAFUNC);
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(AlphaFunc,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_comparisonFunc)
COMPARE_StateAttribute_Parameter(_referenceValue)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_ALPHA_TEST);
return true;
}
inline void setFunction(ComparisonFunction func,float ref)
{
_comparisonFunc = func;
_referenceValue = ref;
}
inline void setFunction(ComparisonFunction func) { _comparisonFunc=func; }
inline ComparisonFunction getFunction() const { return _comparisonFunc; }
inline void setReferenceValue(float value) { _referenceValue=value; }
inline float getReferenceValue() const { return _referenceValue; }
virtual void apply(State& state) const;
protected:
virtual ~AlphaFunc();
ComparisonFunction _comparisonFunc;
float _referenceValue;
};
}
#endif
This diff is collapsed.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_APPLICATIONUSAGE
#define OSG_APPLICATIONUSAGE 1
#include <osg/Referenced>
#include <map>
#include <string>
#include <ostream>
namespace osg {
class OSG_EXPORT ApplicationUsage : public osg::Referenced
{
public:
static ApplicationUsage* instance();
ApplicationUsage() {}
ApplicationUsage(const std::string& commandLineUsage);
typedef std::map<std::string,std::string> UsageMap;
/** The ApplicationName is often displayed when logging errors, and frequently incorporated into the Description (below). */
void setApplicationName(const std::string& name) { _applicationName = name; }
const std::string& getApplicationName() const { return _applicationName; }
/** If non-empty, the Description is typically shown by the Help Handler
* as text on the Help display (which also lists keyboard abbreviations. */
void setDescription(const std::string& desc) { _description = desc; }
const std::string& getDescription() const { return _description; }
enum Type
{
NO_HELP = 0x0,
COMMAND_LINE_OPTION = 0x1,
ENVIRONMENTAL_VARIABLE = 0x2,
KEYBOARD_MOUSE_BINDING = 0x4,
HELP_ALL = KEYBOARD_MOUSE_BINDING|ENVIRONMENTAL_VARIABLE|COMMAND_LINE_OPTION
};
void addUsageExplanation(Type type,const std::string& option,const std::string& explanation);
void setCommandLineUsage(const std::string& explanation) { _commandLineUsage=explanation; }
const std::string& getCommandLineUsage() const { return _commandLineUsage; }
void addCommandLineOption(const std::string& option,const std::string& explanation, const std::string &defaultValue = "");
void setCommandLineOptions(const UsageMap& usageMap) { _commandLineOptions=usageMap; }
const UsageMap& getCommandLineOptions() const { return _commandLineOptions; }
void setCommandLineOptionsDefaults(const UsageMap& usageMap) { _commandLineOptionsDefaults=usageMap; }
const UsageMap& getCommandLineOptionsDefaults() const { return _commandLineOptionsDefaults; }
void addEnvironmentalVariable(const std::string& option,const std::string& explanation, const std::string& defaultValue = "");
void setEnvironmentalVariables(const UsageMap& usageMap) { _environmentalVariables=usageMap; }
const UsageMap& getEnvironmentalVariables() const { return _environmentalVariables; }
void setEnvironmentalVariablesDefaults(const UsageMap& usageMap) { _environmentalVariablesDefaults=usageMap; }
const UsageMap& getEnvironmentalVariablesDefaults() const { return _environmentalVariablesDefaults; }
void addKeyboardMouseBinding(const std::string& option,const std::string& explanation);
void setKeyboardMouseBindings(const UsageMap& usageMap) { _keyboardMouse=usageMap; }
const UsageMap& getKeyboardMouseBindings() const { return _keyboardMouse; }
void getFormattedString(std::string& str, const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,const UsageMap& um,unsigned int widthOfOutput=80,bool showDefaults=false,const UsageMap& ud=UsageMap());
void write(std::ostream& output,unsigned int type=COMMAND_LINE_OPTION, unsigned int widthOfOutput=80,bool showDefaults=false);
void writeEnvironmentSettings(std::ostream& output);
protected:
virtual ~ApplicationUsage() {}
std::string _applicationName;
std::string _description;
std::string _commandLineUsage;
UsageMap _commandLineOptions;
UsageMap _environmentalVariables;
UsageMap _keyboardMouse;
UsageMap _environmentalVariablesDefaults;
UsageMap _commandLineOptionsDefaults;
};
class ApplicationUsageProxy
{
public:
/** register an explanation of commandline/environmentvariable/keyboard mouse usage.*/
ApplicationUsageProxy(ApplicationUsage::Type type,const std::string& option,const std::string& explanation)
{
ApplicationUsage::instance()->addUsageExplanation(type,option,explanation);
}
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ARGUMENTPARSER
#define OSG_ARGUMENTPARSER 1
#include <osg/Export>
#include <osg/ref_ptr>
#include <osg/ApplicationUsage>
#include <map>
#include <string>
#include <ostream>
namespace osg {
class OSG_EXPORT ArgumentParser
{
public:
class OSG_EXPORT Parameter
{
public:
enum ParameterType
{
BOOL_PARAMETER,
FLOAT_PARAMETER,
DOUBLE_PARAMETER,
INT_PARAMETER,
UNSIGNED_INT_PARAMETER,
STRING_PARAMETER
};
union ValueUnion
{
bool* _bool;
float* _float;
double* _double;
int* _int;
unsigned int* _uint;
std::string* _string;
};
Parameter(bool& value) { _type = BOOL_PARAMETER; _value._bool = &value; }
Parameter(float& value) { _type = FLOAT_PARAMETER; _value._float = &value; }
Parameter(double& value) { _type = DOUBLE_PARAMETER; _value._double = &value; }
Parameter(int& value) { _type = INT_PARAMETER; _value._int = &value; }
Parameter(unsigned int& value) { _type = UNSIGNED_INT_PARAMETER; _value._uint = &value; }
Parameter(std::string& value) { _type = STRING_PARAMETER; _value._string = &value; }
Parameter(const Parameter& param) { _type = param._type; _value = param._value; }
Parameter& operator = (const Parameter& param) { _type = param._type; _value = param._value; return *this; }
bool valid(const char* str) const;
bool assign(const char* str);
protected:
ParameterType _type;
ValueUnion _value;
};
/** Return true if the specified string is an option in the form
* -option or --option. */
static bool isOption(const char* str);
/** Return true if string is non-NULL and not an option in the form
* -option or --option. */
static bool isString(const char* str);
/** Return true if specified parameter is a number. */
static bool isNumber(const char* str);
/** Return true if specified parameter is a bool. */
static bool isBool(const char* str);
public:
ArgumentParser(int* argc,char **argv);
void setApplicationUsage(ApplicationUsage* usage) { _usage = usage; }
ApplicationUsage* getApplicationUsage() { return _usage.get(); }
const ApplicationUsage* getApplicationUsage() const { return _usage.get(); }
/** Return the argument count. */
int& argc() { return *_argc; }
/** Return the argument array. */
char** argv() { return _argv; }
/** Return the char* argument at the specified position. */
char* operator [] (int pos) { return _argv[pos]; }
/** Return the const char* argument at the specified position. */
const char* operator [] (int pos) const { return _argv[pos]; }
/** Return the application name, as specified by argv[0] */
std::string getApplicationName() const;
/** Return the position of an occurrence of a string in the argument list.
* Return -1 if no string is found. */
int find(const std::string& str) const;
/** Return true if the specified parameter is an option in the form of
* -option or --option. */
bool isOption(int pos) const;
/** Return true if the specified parameter is a string not in
* the form of an option. */
bool isString(int pos) const;
/** Return true if the specified parameter is a number. */
bool isNumber(int pos) const;
bool containsOptions() const;
/** Remove one or more arguments from the argv argument list,
* and decrement the argc respectively. */
void remove(int pos,int num=1);
/** Return true if the specified argument matches the given string. */
bool match(int pos, const std::string& str) const;
/** Search for an occurrence of a string in the argument list. If found,
* remove that occurrence and return true. Otherwise, return false. */
bool read(const std::string& str);
bool read(const std::string& str, Parameter value1);
bool read(const std::string& str, Parameter value1, Parameter value2);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
bool read(const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
/** If the argument value at the specified position matches the given string,
* and subsequent parameters are also matched, then set the parameter values,
* remove the arguments from the list, and return true. Otherwise, return false. */
bool read(int pos, const std::string& str);
bool read(int pos, const std::string& str, Parameter value1);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7);
bool read(int pos, const std::string& str, Parameter value1, Parameter value2, Parameter value3, Parameter value4, Parameter value5, Parameter value6, Parameter value7, Parameter value8);
enum ErrorSeverity
{
BENIGN = 0,
CRITICAL = 1
};
typedef std::map<std::string,ErrorSeverity> ErrorMessageMap;
/** Return the error flag, true if an error has occurred when reading arguments. */
bool errors(ErrorSeverity severity=BENIGN) const;
/** Report an error message by adding to the ErrorMessageMap. */
void reportError(const std::string& message,ErrorSeverity severity=CRITICAL);
/** For each remaining option, report it as unrecognized. */
void reportRemainingOptionsAsUnrecognized(ErrorSeverity severity=BENIGN);
/** Return the error message, if any has occurred. */
ErrorMessageMap& getErrorMessageMap() { return _errorMessageMap; }
/** Return the error message, if any has occurred. */
const ErrorMessageMap& getErrorMessageMap() const { return _errorMessageMap; }
/** Write error messages to the given ostream, if at or above the given severity. */
void writeErrorMessages(std::ostream& output,ErrorSeverity sevrity=BENIGN);
/** This convenience method handles help requests on the command line.
* Return the type(s) of help requested. The return value of this
* function is suitable for passing into getApplicationUsage()->write().
* If ApplicationUsage::NO_HELP is returned then no help commandline option
* was found on the command line. */
ApplicationUsage::Type readHelpType();
protected:
int* _argc;
char** _argv;
ErrorMessageMap _errorMessageMap;
ref_ptr<ApplicationUsage> _usage;
};
}
#endif
This diff is collapsed.
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_ArrayDispatchers
#define OSG_ArrayDispatchers 1
#include <osg/ref_ptr>
#include <osg/Array>
#include <osg/Matrixd>
#include <osg/GLBeginEndAdapter>
namespace osg {
// forward declare
class State;
class AttributeDispatchMap;
struct AttributeDispatch : public osg::Referenced
{
virtual void assign(const GLvoid*, const IndexArray*) {}
virtual void operator() (unsigned int) {};
};
/** Helper class for managing the dispatch to OpenGL of various attribute arrays such as stored in osg::Geometry.*/
class OSG_EXPORT ArrayDispatchers : public osg::Referenced
{
public:
ArrayDispatchers();
~ArrayDispatchers();
void setState(osg::State* state);
AttributeDispatch* vertexDispatcher(Array* array, IndexArray* indices);
AttributeDispatch* normalDispatcher(Array* array, IndexArray* indices);
AttributeDispatch* colorDispatcher(Array* array, IndexArray* indices);
AttributeDispatch* secondaryColorDispatcher(Array* array, IndexArray* indices);
AttributeDispatch* fogCoordDispatcher(Array* array, IndexArray* indices);
AttributeDispatch* texCoordDispatcher(unsigned int unit, Array* array, IndexArray* indices);
AttributeDispatch* vertexAttribDispatcher(unsigned int unit, Array* array, IndexArray* indices);
void reset();
void setUseGLBeginEndAdapter(bool flag) { _useGLBeginEndAdapter = flag; }
bool getUseGLBeginEndAdapter() const { return _useGLBeginEndAdapter; }
void setUseVertexAttribAlias(bool flag) { _useVertexAttribAlias = flag; }
bool getUseVertexAttribAlias() const { return _useVertexAttribAlias; }
void activate(unsigned int binding, AttributeDispatch* at)
{
if (at) _activeDispatchList[binding].push_back(at);
}
void activateVertexArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexDispatcher(array, indices)); }
void activateColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, colorDispatcher(array, indices)); }
void activateNormalArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, normalDispatcher(array, indices)); }
void activateSecondaryColorArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, secondaryColorDispatcher(array, indices)); }
void activateFogCoordArray(unsigned int binding, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, fogCoordDispatcher(array, indices)); }
void activateTexCoordArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, texCoordDispatcher(unit, array, indices)); }
void activateVertexAttribArray(unsigned int binding, unsigned int unit, osg::Array* array, osg::IndexArray* indices) { if (binding && array) activate(binding, vertexAttribDispatcher(unit, array, indices)); }
void dispatch(unsigned int binding, unsigned int index)
{
AttributeDispatchList& ad = _activeDispatchList[binding];
for(AttributeDispatchList::iterator itr = ad.begin();
itr != ad.end();
++itr)
{
(*(*itr))(index);
}
}
bool active(unsigned int binding) const { return !_activeDispatchList[binding].empty(); }
void Begin(GLenum mode)
{
#ifdef OSG_GL1_AVAILABLE
if (_useGLBeginEndAdapter) _glBeginEndAdapter->Begin(mode);
else ::glBegin(mode);
#else
_glBeginEndAdapter->Begin(mode);
#endif
}
void End()
{
#ifdef OSG_GL1_AVAILABLE
if (_useGLBeginEndAdapter) _glBeginEndAdapter->End();
else ::glEnd();
#else
_glBeginEndAdapter->End();
#endif
}
protected:
void init();
void assignTexCoordDispatchers(unsigned int unit);
void assignVertexAttribDispatchers(unsigned int unit);
bool _initialized;
State* _state;
GLBeginEndAdapter* _glBeginEndAdapter;
AttributeDispatchMap* _vertexDispatchers;
AttributeDispatchMap* _normalDispatchers;
AttributeDispatchMap* _colorDispatchers;
AttributeDispatchMap* _secondaryColorDispatchers;
AttributeDispatchMap* _fogCoordDispatchers;
typedef std::vector<AttributeDispatchMap*> AttributeDispatchMapList;
AttributeDispatchMapList _texCoordDispatchers;
AttributeDispatchMapList _vertexAttribDispatchers;
typedef std::vector<AttributeDispatch*> AttributeDispatchList;
typedef std::vector<AttributeDispatchList> ActiveDispatchList;
ActiveDispatchList _activeDispatchList;
bool _useVertexAttribAlias;
bool _useGLBeginEndAdapter;
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_AUDIOSTREAM
#define OSG_AUDIOSTREAM 1
#include <osg/Image>
#include <stdlib.h>
namespace osg {
/** Pure virtual AudioSink bass class that is used to connect the audio system with AudioStreams. */
class OSG_EXPORT AudioSink : public osg::Object
{
public:
AudioSink();
virtual const char * libraryName() const { return "osg"; }
virtual const char * className() const { return "AudioSinkInterface"; }
virtual void play() = 0;
virtual void pause() = 0;
virtual void stop() = 0;
virtual bool playing() const = 0;
virtual double getDelay() const { return _delay; }
virtual void setDelay(const double delay) { _delay = delay; }
virtual void setVolume(float) {}
virtual float getVolume() const { return 0.0f; }
private:
virtual AudioSink * cloneType() const { return 0; }
virtual AudioSink * clone(const osg::CopyOp &) const { return 0; }
double _delay;
};
/** Pure virtual AudioStream base class. Subclasses provide mechanism for reading/generating audio data*/
class OSG_EXPORT AudioStream : public osg::Object
{
public:
AudioStream();
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
AudioStream(const AudioStream& audio,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const AudioStream*>(obj)!=0; }
virtual const char* libraryName() const { return "osg"; }
virtual const char* className() const { return "AudioStream"; }
virtual void setAudioSink(osg::AudioSink* audio_sink) = 0;
virtual void consumeAudioBuffer(void * const buffer, const size_t size) = 0;
virtual int audioFrequency() const = 0;
virtual int audioNbChannels() const = 0;
enum SampleFormat
{
SAMPLE_FORMAT_U8,
SAMPLE_FORMAT_S16,
SAMPLE_FORMAT_S24,
SAMPLE_FORMAT_S32,
SAMPLE_FORMAT_F32
};
virtual SampleFormat audioSampleFormat() const = 0;
};
} // namespace
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_AUTOTRANSFORM
#define OSG_AUTOTRANSFORM 1
#include <osg/Group>
#include <osg/Transform>
#include <osg/Quat>
#include <osg/Viewport>
namespace osg {
/** AutoTransform is a derived form of Transform that automatically
* scales or rotates to keep its children aligned with screen coordinates.
*/
class OSG_EXPORT AutoTransform : public Transform
{
public :
AutoTransform();
AutoTransform(const AutoTransform& pat,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
virtual osg::Object* cloneType() const { return new AutoTransform (); }
virtual osg::Object* clone(const osg::CopyOp& copyop) const { return new AutoTransform (*this,copyop); }
virtual bool isSameKindAs(const osg::Object* obj) const { return dynamic_cast<const AutoTransform *>(obj)!=NULL; }
virtual const char* className() const { return "AutoTransform"; }
virtual const char* libraryName() const { return "osg"; }
virtual void accept(NodeVisitor& nv);
virtual AutoTransform* asAutoTransform() { return this; }
virtual const AutoTransform* asAutoTransform() const { return this; }
inline void setPosition(const Vec3d& pos) { _position = pos; _matrixDirty=true; dirtyBound(); }
inline const Vec3d& getPosition() const { return _position; }
inline void setRotation(const Quat& quat) { _rotation = quat; _matrixDirty=true; dirtyBound(); }
inline const Quat& getRotation() const { return _rotation; }
inline void setScale(double scale) { setScale(osg::Vec3(scale,scale,scale)); }
void setScale(const Vec3d& scale);
inline const Vec3d& getScale() const { return _scale; }
void setMinimumScale(double minimumScale) { _minimumScale = minimumScale; }
double getMinimumScale() const { return _minimumScale; }
void setMaximumScale(double maximumScale) { _maximumScale = maximumScale; }
double getMaximumScale() const { return _maximumScale; }
inline void setPivotPoint(const Vec3d& pivot) { _pivotPoint = pivot; _matrixDirty=true; dirtyBound(); }
inline const Vec3d& getPivotPoint() const { return _pivotPoint; }
void setAutoUpdateEyeMovementTolerance(float tolerance) { _autoUpdateEyeMovementTolerance = tolerance; }
float getAutoUpdateEyeMovementTolerance() const { return _autoUpdateEyeMovementTolerance; }
enum AutoRotateMode
{
NO_ROTATION,
ROTATE_TO_SCREEN,
ROTATE_TO_CAMERA,
ROTATE_TO_AXIS
};
void setAutoRotateMode(AutoRotateMode mode);
AutoRotateMode getAutoRotateMode() const { return _autoRotateMode; }
/** Set the rotation axis for the AutoTransform's child nodes.
* Only utilized when _autoRotateMode==ROTATE_TO_AXIS. */
void setAxis(const Vec3& axis);
/** Get the rotation axis. */
inline const Vec3& getAxis() const { return _axis; }
/** This normal defines child Nodes' front face direction when unrotated. */
void setNormal(const Vec3& normal);
/** Get the front face direction normal. */
inline const Vec3& getNormal() const { return _normal; }
void setAutoScaleToScreen(bool autoScaleToScreen) { _autoScaleToScreen = autoScaleToScreen; _matrixDirty=true; }
bool getAutoScaleToScreen() const { return _autoScaleToScreen; }
void setAutoScaleTransitionWidthRatio(float ratio) { _autoScaleTransitionWidthRatio = ratio; }
float getAutoScaleTransitionWidthRatio() const { return _autoScaleTransitionWidthRatio; }
virtual bool computeLocalToWorldMatrix(Matrix& matrix,NodeVisitor* nv) const;
virtual bool computeWorldToLocalMatrix(Matrix& matrix,NodeVisitor* nv) const;
virtual BoundingSphere computeBound() const;
protected :
virtual ~AutoTransform() {}
Vec3d _position;
Vec3d _pivotPoint;
double _autoUpdateEyeMovementTolerance;
AutoRotateMode _autoRotateMode;
bool _autoScaleToScreen;
mutable Quat _rotation;
mutable Vec3d _scale;
mutable bool _firstTimeToInitEyePoint;
mutable osg::Vec3 _previousEyePoint;
mutable osg::Vec3 _previousLocalUp;
mutable Viewport::value_type _previousWidth;
mutable Viewport::value_type _previousHeight;
mutable osg::Matrixd _previousProjection;
mutable osg::Vec3d _previousPosition;
double _minimumScale;
double _maximumScale;
double _autoScaleTransitionWidthRatio;
void computeMatrix() const;
mutable bool _matrixDirty;
mutable osg::Matrixd _cachedMatrix;
enum AxisAligned
{
AXIAL_ROT_X_AXIS=ROTATE_TO_AXIS+1,
AXIAL_ROT_Y_AXIS,
AXIAL_ROT_Z_AXIS,
CACHE_DIRTY
};
Vec3 _axis;
Vec3 _normal;
// used internally as cache of which what _axis is aligned to help
// decide which method of rotation to use.
int _cachedMode;
Vec3 _side;
void updateCache();
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BILLBOARD
#define OSG_BILLBOARD 1
#include <osg/Matrix>
#include <osg/Geode>
namespace osg {
/** Billboard is a derived form of Geode that orients its osg::Drawable
* children to face the eye point. Typical uses include trees and
* particle explosions,
*/
class OSG_EXPORT Billboard : public Geode
{
public:
enum Mode {
POINT_ROT_EYE,
POINT_ROT_WORLD,
AXIAL_ROT
};
Billboard();
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
Billboard(const Billboard&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_Node(osg, Billboard);
/** Set the billboard rotation mode. */
void setMode(Mode mode);
/** Get the billboard rotation mode. */
inline Mode getMode() const { return _mode; }
/** Set the rotation axis for the billboard's child Drawables.
* Only utilized when mode==AXIAL_ROT. */
void setAxis(const Vec3& axis);
/** Get the rotation axis. */
inline const Vec3& getAxis() const { return _axis; }
/** This normal defines child Drawables' front face direction when unrotated. */
void setNormal(const Vec3& normal);
/** Get the front face direction normal. */
inline const Vec3& getNormal() const { return _normal; }
/** Set the specified child Drawable's position. */
inline void setPosition(unsigned int i,const Vec3& pos) { _positionList[i] = pos; }
/** Get the specified child Drawable's position. */
inline const Vec3& getPosition(unsigned int i) const { return _positionList[i]; }
/** Type definition for pivot point position list. */
typedef std::vector<Vec3> PositionList;
/** Set the list of pivot point positions. */
inline void setPositionList(PositionList& pl) { _positionList=pl; }
/** Get the list of pivot point positions. */
inline PositionList& getPositionList() { return _positionList; }
/** Get a const list of pivot point positions. */
inline const PositionList& getPositionList() const { return _positionList; }
/** Add a Drawable with a default position of Vec3(0,0,0).
* Call the base-class Geode::addDrawble() to add the given Drawable
* gset as a child. If Geode::addDrawable() returns true, add the
* default position to the pivot point position list and return true.
* Otherwise, return false. */
virtual bool addDrawable( Drawable *gset );
/** Add a Drawable with a specified position.
* Call the base-class Geode::addDrawble() to add the given Drawable
* gset as a child. If Geode::addDrawable() returns true, add the
* given position pos to the pivot point position list and return true.
* Otherwise, return false. */
virtual bool addDrawable(Drawable *gset,const Vec3& pos);
/** Remove a Drawable and its associated position.
* If gset is a child, remove it, decrement its reference count,
* remove its pivot point position. and return true.
* Otherwise, return false. */
virtual bool removeDrawable( Drawable *gset );
bool computeMatrix(Matrix& modelview, const Vec3& eye_local, const Vec3& pos_local) const;
virtual BoundingSphere computeBound() const;
protected:
virtual ~Billboard();
enum AxisAligned
{
AXIAL_ROT_X_AXIS=AXIAL_ROT+1,
AXIAL_ROT_Y_AXIS,
AXIAL_ROT_Z_AXIS,
POINT_ROT_WORLD_Z_AXIS,
CACHE_DIRTY
};
Mode _mode;
Vec3 _axis;
Vec3 _normal;
Matrix _rotateNormalToZAxis;
PositionList _positionList;
// used internally as cache of which what _axis is aligned to help
// decide which method of rotation to use.
int _cachedMode;
Vec3 _side;
void updateCache();
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BLENDCOLOR
#define OSG_BLENDCOLOR 1
#include <osg/GL>
#include <osg/StateAttribute>
#include <osg/ref_ptr>
#include <osg/Vec4>
namespace osg {
/** Encapsulates OpenGL blend/transparency state. */
class OSG_EXPORT BlendColor : public StateAttribute
{
public :
BlendColor();
BlendColor(const osg::Vec4& constantColor);
/** Copy constructor using CopyOp to manage deep vs shallow copy.*/
BlendColor(const BlendColor& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(trans,copyop),
_constantColor(trans._constantColor) {}
META_StateAttribute(osg, BlendColor,BLENDCOLOR);
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(BlendColor,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_constantColor)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_BLEND);
return true;
}
void setConstantColor(const osg::Vec4& color) { _constantColor = color; }
inline osg::Vec4& getConstantColor() { return _constantColor; }
inline const osg::Vec4& getConstantColor() const { return _constantColor; }
virtual void apply(State& state) const;
/** Encapsulates queries of extension availability, obtains extension
* function pointers, and provides convenience wrappers for
* calling extension functions. */
class OSG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
void setBlendColorSupported(bool flag) { _isBlendColorSupported=flag; }
bool isBlendColorSupported() const { return _isBlendColorSupported; }
void glBlendColor(GLclampf red , GLclampf green , GLclampf blue , GLclampf alpha) const;
protected:
~Extensions() {}
typedef void (GL_APIENTRY * GLBlendColorProc) (GLclampf red, GLclampf green, GLclampf blue, GLclampf alpha);
bool _isBlendColorSupported;
GLBlendColorProc _glBlendColor;
};
/** Returns the Extensions object for the given context.
* If createIfNotInitalized is true and the Extensions object doesn't
* exist, getExtensions() creates it on the given context.
* Returns NULL if createIfNotInitalized is false and the Extensions
* object doesn't exist. */
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
/** setExtensions() allows users to override the extensions across graphics contexts.
* Typically used when you have different extensions supported across graphics pipes,
* but need to ensure that they all use the same low common denominator extensions. */
static void setExtensions(unsigned int contextID,Extensions* extensions);
protected :
virtual ~BlendColor();
osg::Vec4 _constantColor;
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BLENDEQUATION
#define OSG_BLENDEQUATION 1
#include <osg/StateAttribute>
#ifndef GL_VERSION_1_2
/* Logic Ops */
#define GL_MIN 0x8007
#define GL_MAX 0x8008
#define GL_FUNC_ADD 0x8006
#define GL_FUNC_SUBTRACT 0x800A
#define GL_FUNC_REVERSE_SUBTRACT 0x800B
#endif
#ifndef GL_LOGIC_OP
#define GL_LOGIC_OP 0x0BF1
#endif
#ifndef GL_ALPHA_MIN_SGIX
#define GL_ALPHA_MIN_SGIX 0x8320
#define GL_ALPHA_MAX_SGIX 0x8321
#endif
namespace osg {
/** Encapsulates OpenGL BlendEquation state. */
class OSG_EXPORT BlendEquation : public StateAttribute
{
public :
enum Equation {
RGBA_MIN = GL_MIN,
RGBA_MAX = GL_MAX,
ALPHA_MIN = GL_ALPHA_MIN_SGIX,
ALPHA_MAX = GL_ALPHA_MAX_SGIX,
LOGIC_OP = GL_LOGIC_OP,
FUNC_ADD = GL_FUNC_ADD,
FUNC_SUBTRACT = GL_FUNC_SUBTRACT,
FUNC_REVERSE_SUBTRACT = GL_FUNC_REVERSE_SUBTRACT
};
BlendEquation();
BlendEquation(Equation equation);
BlendEquation(Equation equationRGB, Equation equationAlpha);
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
BlendEquation(const BlendEquation& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(trans,copyop),
_equationRGB(trans._equationRGB),
_equationAlpha(trans._equationAlpha){}
META_StateAttribute(osg, BlendEquation,BLENDEQUATION);
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(BlendEquation,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_equationRGB)
COMPARE_StateAttribute_Parameter(_equationAlpha)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_BLEND);
return true;
}
inline void setEquation(Equation equation) { _equationRGB = _equationAlpha = equation; }
inline Equation getEquation() const { return _equationRGB; }
inline void setEquationRGB(Equation equation) { _equationRGB = equation; }
inline Equation getEquationRGB() const { return _equationRGB; }
inline void setEquationAlpha(Equation equation) { _equationAlpha = equation; }
inline Equation getEquationAlpha() const { return _equationAlpha; }
virtual void apply(State& state) const;
/** Encapsulates queries of extension availability, obtains extension
* function pointers, and provides convenience wrappers for
* calling extension functions. */
class OSG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
bool isBlendEquationSupported() const { return _isBlendEquationSupported; }
bool isBlendEquationSeparateSupported() const { return _isBlendEquationSeparateSupported; }
bool isSGIXMinMaxSupported() const { return _isSGIXMinMaxSupported; }
bool isLogicOpSupported() const { return _isLogicOpSupported; }
void glBlendEquation(GLenum mode) const;
void glBlendEquationSeparate(GLenum modeRGB, GLenum modeAlpha) const;
protected:
~Extensions() {}
typedef void (GL_APIENTRY * GLBlendEquationProc)(GLenum mode);
typedef void (GL_APIENTRY * GLBlendEquationSeparateProc)(GLenum modeRGB, GLenum modeAlpha);
bool _isBlendEquationSupported;
bool _isBlendEquationSeparateSupported;
bool _isSGIXMinMaxSupported;
bool _isLogicOpSupported;
GLBlendEquationProc _glBlendEquation;
GLBlendEquationSeparateProc _glBlendEquationSeparate;
};
/** Returns the Extensions object for the given context.
* If createIfNotInitalized is true and the Extensions object doesn't
* exist, getExtensions() creates it on the given context.
* Returns NULL if createIfNotInitalized is false and the Extensions
* object doesn't exist. */
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
/** setExtensions() allows users to override the extensions across graphics contexts.
* Typically used when you have different extensions supported across graphics pipes,
* but need to ensure that they all use the same low common denominator extensions. */
static void setExtensions(unsigned int contextID,Extensions* extensions);
protected :
virtual ~BlendEquation();
Equation _equationRGB, _equationAlpha;
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BLENDFUNC
#define OSG_BLENDFUNC 1
#include <osg/StateAttribute>
#ifndef GL_VERSION_1_2
#define GL_CONSTANT_COLOR 0x8001
#define GL_ONE_MINUS_CONSTANT_COLOR 0x8002
#define GL_CONSTANT_ALPHA 0x8003
#define GL_ONE_MINUS_CONSTANT_ALPHA 0x8004
#define GL_BLEND_COLOR 0x8005
#endif
#ifndef GL_VERSION_1_4
#define GL_BLEND_DST_RGB 0x80C8
#define GL_BLEND_SRC_RGB 0x80C9
#define GL_BLEND_DST_ALPHA 0x80CA
#define GL_BLEND_SRC_ALPHA 0x80CB
#endif
namespace osg {
/** Encapsulates OpenGL blend/transparency state.
*
* Blending combines incoming fragment with a fragment
* already present in the target buffer.
*
* OpenGL 1.1 supports following source and destination blending factors:
* GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA,
* GL_DST_ALPHA, GL_ONE_MINUS_DST_ALPHA,
* GL_ZERO, GL_ONE.
*
* Moreover, there are three source-only blending factors:
* GL_DST_COLOR, GL_ONE_MINUS_DST_COLOR, GL_SRC_ALPHA_SATURATE
* and two destination-only blending factors:
* GL_SRC_COLOR, GL_ONE_MINUS_SRC_COLOR.
* OpenGL 1.4 allowed to use these five blending factors
* as both - source and destination blending factors.
*
* Following four source and destination blending factors
* were added by Imaging subset of OpenGL 1.2
* and made mandatory by OpenGL 1.4:
* GL_CONSTANT_COLOR, GL_ONE_MINUS_CONSTANT_COLOR,
* GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA
*
* OpenGL 1.4 further provides glBlendFuncSeparate
* (promoted from GL_EXT_blend_func_separate).
* It makes possible to set blending functions for RGB and Alpha separately.
* Before, it was possible to set just one blending function for RGBA.
*/
class OSG_EXPORT BlendFunc : public StateAttribute
{
public :
BlendFunc();
BlendFunc(GLenum source, GLenum destination);
BlendFunc(GLenum source, GLenum destination, GLenum source_alpha, GLenum destination_alpha);
/** Copy constructor using CopyOp to manage deep vs shallow copy. */
BlendFunc(const BlendFunc& trans,const CopyOp& copyop=CopyOp::SHALLOW_COPY):
StateAttribute(trans,copyop),
_source_factor(trans._source_factor),
_destination_factor(trans._destination_factor),
_source_factor_alpha(trans._source_factor_alpha),
_destination_factor_alpha(trans._destination_factor_alpha) {}
META_StateAttribute(osg, BlendFunc,BLENDFUNC);
/** Return -1 if *this < *rhs, 0 if *this==*rhs, 1 if *this>*rhs. */
virtual int compare(const StateAttribute& sa) const
{
// Check for equal types, then create the rhs variable
// used by the COMPARE_StateAttribute_Parameter macros below.
COMPARE_StateAttribute_Types(BlendFunc,sa)
// Compare each parameter in turn against the rhs.
COMPARE_StateAttribute_Parameter(_source_factor)
COMPARE_StateAttribute_Parameter(_destination_factor)
COMPARE_StateAttribute_Parameter(_source_factor_alpha)
COMPARE_StateAttribute_Parameter(_destination_factor_alpha)
return 0; // Passed all the above comparison macros, so must be equal.
}
virtual bool getModeUsage(StateAttribute::ModeUsage& usage) const
{
usage.usesMode(GL_BLEND);
return true;
}
enum BlendFuncMode {
DST_ALPHA = GL_DST_ALPHA,
DST_COLOR = GL_DST_COLOR,
ONE = GL_ONE,
ONE_MINUS_DST_ALPHA = GL_ONE_MINUS_DST_ALPHA,
ONE_MINUS_DST_COLOR = GL_ONE_MINUS_DST_COLOR,
ONE_MINUS_SRC_ALPHA = GL_ONE_MINUS_SRC_ALPHA,
ONE_MINUS_SRC_COLOR = GL_ONE_MINUS_SRC_COLOR,
SRC_ALPHA = GL_SRC_ALPHA,
SRC_ALPHA_SATURATE = GL_SRC_ALPHA_SATURATE,
SRC_COLOR = GL_SRC_COLOR,
CONSTANT_COLOR = GL_CONSTANT_COLOR,
ONE_MINUS_CONSTANT_COLOR = GL_ONE_MINUS_CONSTANT_COLOR,
CONSTANT_ALPHA = GL_CONSTANT_ALPHA,
ONE_MINUS_CONSTANT_ALPHA = GL_ONE_MINUS_CONSTANT_ALPHA,
ZERO = GL_ZERO
};
inline void setFunction( GLenum source, GLenum destination )
{
_source_factor = source;
_destination_factor = destination;
_source_factor_alpha = source;
_destination_factor_alpha = destination;
}
inline void setFunction( GLenum source_rgb, GLenum destination_rgb, GLenum source_alpha, GLenum destination_alpha )
{
_source_factor = source_rgb;
_destination_factor = destination_rgb;
_source_factor_alpha = source_alpha;
_destination_factor_alpha = destination_alpha;
}
void setSource(GLenum source) { _source_factor = _source_factor_alpha = source; }
inline GLenum getSource() const { return _source_factor; }
void setSourceRGB(GLenum source) { _source_factor = source; }
inline GLenum getSourceRGB() const { return _source_factor; }
void setSourceAlpha(GLenum source) { _source_factor_alpha = source; }
inline GLenum getSourceAlpha() const { return _source_factor_alpha; }
void setDestination(GLenum destination) { _destination_factor = _destination_factor_alpha = destination; }
inline GLenum getDestination() const { return _destination_factor; }
void setDestinationRGB(GLenum destination) { _destination_factor = destination; }
inline GLenum getDestinationRGB() const { return _destination_factor; }
void setDestinationAlpha(GLenum destination) { _destination_factor_alpha = destination; }
inline GLenum getDestinationAlpha() const { return _destination_factor_alpha; }
virtual void apply(State& state) const;
/** Encapsulates queries of extension availability, obtains extension
* function pointers, and provides convenience wrappers for
* calling extension functions. */
class OSG_EXPORT Extensions : public osg::Referenced
{
public:
Extensions(unsigned int contextID);
Extensions(const Extensions& rhs);
void lowestCommonDenominator(const Extensions& rhs);
void setupGLExtensions(unsigned int contextID);
void setBlendFuncSeparateSupported(bool flag) { _isBlendFuncSeparateSupported=flag; }
bool isBlendFuncSeparateSupported() const { return _isBlendFuncSeparateSupported; }
void glBlendFuncSeparate(GLenum sfactorRGB,
GLenum dfactorRGB,
GLenum sfactorAlpha,
GLenum dfactorAlpha) const;
protected:
~Extensions() {}
typedef void (GL_APIENTRY * GLBlendFuncSeparateProc) (GLenum sfactorRGB,
GLenum dfactorRGB,
GLenum sfactorAlpha,
GLenum dfactorAlpha);
bool _isBlendFuncSeparateSupported;
GLBlendFuncSeparateProc _glBlendFuncSeparate;
};
/** Returns the Extensions object for the given context.
* If createIfNotInitalized is true and the Extensions object doesn't
* exist, getExtensions() creates it on the given context.
* Returns NULL if createIfNotInitalized is false and the Extensions
* object doesn't exist. */
static Extensions* getExtensions(unsigned int contextID,bool createIfNotInitalized);
/** setExtensions() allows users to override the extensions across graphics contexts.
* Typically used when you have different extensions supported across graphics pipes,
* but need to ensure that they all use the same low common denominator extensions. */
static void setExtensions(unsigned int contextID,Extensions* extensions);
protected :
virtual ~BlendFunc();
GLenum _source_factor;
GLenum _destination_factor;
GLenum _source_factor_alpha;
GLenum _destination_factor_alpha;
};
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BOUNDINGBOX
#define OSG_BOUNDINGBOX 1
#include <osg/Config>
#include <osg/Export>
#include <osg/Vec3>
#include <osg/Vec3d>
#include <float.h>
namespace osg {
template<typename VT>
class BoundingSphereImpl;
/** General purpose axis-aligned bounding box class for enclosing objects/vertices.
* Bounds leaf objects in a scene such as osg::Drawable objects. Used for frustum
* culling etc.
*/
template<typename VT>
class BoundingBoxImpl
{
public:
typedef VT vec_type;
typedef typename VT::value_type value_type;
/** Minimum extent. (Smallest X, Y, and Z values of all coordinates.) */
vec_type _min;
/** Maximum extent. (Greatest X, Y, and Z values of all coordinates.) */
vec_type _max;
/** Creates an uninitialized bounding box. */
inline BoundingBoxImpl() :
_min(FLT_MAX,
FLT_MAX,
FLT_MAX),
_max(-FLT_MAX,
-FLT_MAX,
-FLT_MAX)
{}
/** Creates a bounding box initialized to the given extents. */
inline BoundingBoxImpl(value_type xmin, value_type ymin, value_type zmin,
value_type xmax, value_type ymax, value_type zmax) :
_min(xmin,ymin,zmin),
_max(xmax,ymax,zmax) {}
/** Creates a bounding box initialized to the given extents. */
inline BoundingBoxImpl(const vec_type& min,const vec_type& max) :
_min(min),
_max(max) {}
/** Clear the bounding box. Erases existing minimum and maximum extents. */
inline void init()
{
_min.set(FLT_MAX,
FLT_MAX,
FLT_MAX);
_max.set(-FLT_MAX,
-FLT_MAX,
-FLT_MAX);
}
/** Returns true if the bounding box extents are valid, false otherwise. */
inline bool valid() const
{
return _max.x()>=_min.x() && _max.y()>=_min.y() && _max.z()>=_min.z();
}
/** Sets the bounding box extents. */
inline void set (value_type xmin, value_type ymin, value_type zmin,
value_type xmax, value_type ymax, value_type zmax)
{
_min.set(xmin,ymin,zmin);
_max.set(xmax,ymax,zmax);
}
/** Sets the bounding box extents. */
inline void set(const vec_type& min,const vec_type& max)
{
_min = min;
_max = max;
}
inline value_type& xMin() { return _min.x(); }
inline value_type xMin() const { return _min.x(); }
inline value_type& yMin() { return _min.y(); }
inline value_type yMin() const { return _min.y(); }
inline value_type& zMin() { return _min.z(); }
inline value_type zMin() const { return _min.z(); }
inline value_type& xMax() { return _max.x(); }
inline value_type xMax() const { return _max.x(); }
inline value_type& yMax() { return _max.y(); }
inline value_type yMax() const { return _max.y(); }
inline value_type& zMax() { return _max.z(); }
inline value_type zMax() const { return _max.z(); }
/** Calculates and returns the bounding box center. */
inline const vec_type center() const
{
return (_min+_max)*0.5;
}
/** Calculates and returns the bounding box radius. */
inline value_type radius() const
{
return sqrt(radius2());
}
/** Calculates and returns the squared length of the bounding box radius.
* Note, radius2() is faster to calculate than radius(). */
inline value_type radius2() const
{
return 0.25*((_max-_min).length2());
}
/** Returns a specific corner of the bounding box.
* pos specifies the corner as a number between 0 and 7.
* Each bit selects an axis, X, Y, or Z from least- to
* most-significant. Unset bits select the minimum value
* for that axis, and set bits select the maximum. */
inline const vec_type corner(unsigned int pos) const
{
return vec_type(pos&1?_max.x():_min.x(),pos&2?_max.y():_min.y(),pos&4?_max.z():_min.z());
}
/** Expands the bounding box to include the given coordinate.
* If the box is uninitialized, set its min and max extents to v. */
inline void expandBy(const vec_type& v)
{
if(v.x()<_min.x()) _min.x() = v.x();
if(v.x()>_max.x()) _max.x() = v.x();
if(v.y()<_min.y()) _min.y() = v.y();
if(v.y()>_max.y()) _max.y() = v.y();
if(v.z()<_min.z()) _min.z() = v.z();
if(v.z()>_max.z()) _max.z() = v.z();
}
/** Expands the bounding box to include the given coordinate.
* If the box is uninitialized, set its min and max extents to
* Vec3(x,y,z). */
inline void expandBy(value_type x,value_type y,value_type z)
{
if(x<_min.x()) _min.x() = x;
if(x>_max.x()) _max.x() = x;
if(y<_min.y()) _min.y() = y;
if(y>_max.y()) _max.y() = y;
if(z<_min.z()) _min.z() = z;
if(z>_max.z()) _max.z() = z;
}
/** Expands this bounding box to include the given bounding box.
* If this box is uninitialized, set it equal to bb. */
void expandBy(const BoundingBoxImpl& bb)
{
if (!bb.valid()) return;
if(bb._min.x()<_min.x()) _min.x() = bb._min.x();
if(bb._max.x()>_max.x()) _max.x() = bb._max.x();
if(bb._min.y()<_min.y()) _min.y() = bb._min.y();
if(bb._max.y()>_max.y()) _max.y() = bb._max.y();
if(bb._min.z()<_min.z()) _min.z() = bb._min.z();
if(bb._max.z()>_max.z()) _max.z() = bb._max.z();
}
/** Expands this bounding box to include the given sphere.
* If this box is uninitialized, set it to include sh. */
void expandBy(const BoundingSphereImpl<VT>& sh)
{
if (!sh.valid()) return;
if(sh._center.x()-sh._radius<_min.x()) _min.x() = sh._center.x()-sh._radius;
if(sh._center.x()+sh._radius>_max.x()) _max.x() = sh._center.x()+sh._radius;
if(sh._center.y()-sh._radius<_min.y()) _min.y() = sh._center.y()-sh._radius;
if(sh._center.y()+sh._radius>_max.y()) _max.y() = sh._center.y()+sh._radius;
if(sh._center.z()-sh._radius<_min.z()) _min.z() = sh._center.z()-sh._radius;
if(sh._center.z()+sh._radius>_max.z()) _max.z() = sh._center.z()+sh._radius;
}
/** Returns the intersection of this bounding box and the specified bounding box. */
BoundingBoxImpl intersect(const BoundingBoxImpl& bb) const
{ return BoundingBoxImpl(osg::maximum(xMin(),bb.xMin()),osg::maximum(yMin(),bb.yMin()),osg::maximum(zMin(),bb.zMin()),
osg::minimum(xMax(),bb.xMax()),osg::minimum(yMax(),bb.yMax()),osg::minimum(zMax(),bb.zMax()));
}
/** Return true if this bounding box intersects the specified bounding box. */
bool intersects(const BoundingBoxImpl& bb) const
{ return osg::maximum(xMin(),bb.xMin()) <= osg::minimum(xMax(),bb.xMax()) &&
osg::maximum(yMin(),bb.yMin()) <= osg::minimum(yMax(),bb.yMax()) &&
osg::maximum(zMin(),bb.zMin()) <= osg::minimum(zMax(),bb.zMax());
}
/** Returns true if this bounding box contains the specified coordinate. */
inline bool contains(const vec_type& v) const
{
return valid() &&
(v.x()>=_min.x() && v.x()<=_max.x()) &&
(v.y()>=_min.y() && v.y()<=_max.y()) &&
(v.z()>=_min.z() && v.z()<=_max.z());
}
};
typedef BoundingBoxImpl<Vec3f> BoundingBoxf;
typedef BoundingBoxImpl<Vec3d> BoundingBoxd;
#ifdef OSG_USE_FLOAT_BOUNDINGBOX
typedef BoundingBoxf BoundingBox;
#else
typedef BoundingBoxd BoundingBox;
#endif
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BOUNDINGSPHERE
#define OSG_BOUNDINGSPHERE 1
#include <osg/Config>
#include <osg/Export>
#include <osg/Vec3f>
#include <osg/Vec3d>
namespace osg {
template<typename VT>
class BoundingBoxImpl;
/** General purpose bounding sphere class for enclosing nodes/objects/vertices.
* Bounds internal osg::Nodes in the scene, assists in view frustum culling,
* etc. Similar in function to BoundingBox, it's quicker for evaluating
* culling but generally will not cull as aggressively because it encloses a
* greater volume.
*/
template<typename VT>
class BoundingSphereImpl
{
public:
typedef VT vec_type;
typedef typename VT::value_type value_type;
vec_type _center;
value_type _radius;
/** Construct a default bounding sphere with radius to -1.0f, representing an invalid/unset bounding sphere.*/
BoundingSphereImpl() : _center(0.0,0.0,0.0),_radius(-1.0) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphereImpl(const vec_type& center, value_type radius) : _center(center),_radius(radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphereImpl(const BoundingSphereImpl& bs) : _center(bs._center),_radius(bs._radius) {}
/** Creates a bounding sphere initialized to the given extents. */
BoundingSphereImpl(const BoundingBoxImpl<VT>& bb) : _center(0.0,0.0,0.0),_radius(-1.0) { expandBy(bb); }
/** Clear the bounding sphere. Reset to default values. */
inline void init()
{
_center.set(0.0,0.0,0.0);
_radius = -1.0;
}
/** Returns true of the bounding sphere extents are valid, false
* otherwise. */
inline bool valid() const { return _radius>=0.0; }
/** Set the bounding sphere to the given center/radius using floats. */
inline void set(const vec_type& center,value_type radius)
{
_center = center;
_radius = radius;
}
/** Returns the center of the bounding sphere. */
inline vec_type& center() { return _center; }
/** Returns the const center of the bounding sphere. */
inline const vec_type& center() const { return _center; }
/** Returns the radius of the bounding sphere. */
inline value_type& radius() { return _radius; }
/** Returns the const radius of the bounding sphere. */
inline value_type radius() const { return _radius; }
/** Returns the squared length of the radius. Note, For performance
* reasons, the calling method is responsible for checking to make
* sure the sphere is valid. */
inline value_type radius2() const { return _radius*_radius; }
/** Expands the sphere to encompass the given point. Repositions the
* sphere center to minimize the radius increase. If the sphere is
* uninitialized, set its center to v and radius to zero. */
template<typename vector_type>
void expandBy(const vector_type& v);
/** Expands the sphere to encompass the given point. Does not
* reposition the sphere center. If the sphere is
* uninitialized, set its center to v and radius to zero. */
template<typename vector_type>
void expandRadiusBy(const vector_type& v);
/** Expands the sphere to encompass the given sphere. Repositions the
* sphere center to minimize the radius increase. If the sphere is
* uninitialized, set its center and radius to match sh. */
void expandBy(const BoundingSphereImpl& sh);
/** Expands the sphere to encompass the given sphere. Does not
* repositions the sphere center. If the sphere is
* uninitialized, set its center and radius to match sh. */
void expandRadiusBy(const BoundingSphereImpl& sh);
/** Expands the sphere to encompass the given box. Repositions the
* sphere center to minimize the radius increase. */
void expandBy(const BoundingBoxImpl<VT>& bb);
/** Expands the sphere to encompass the given box. Does not
* repositions the sphere center. */
void expandRadiusBy(const BoundingBoxImpl<VT>& bb);
/** Returns true if v is within the sphere. */
inline bool contains(const vec_type& v) const
{
return valid() && ((v-_center).length2()<=radius2());
}
/** Returns true if there is a non-empty intersection with the given
* bounding sphere. */
inline bool intersects( const BoundingSphereImpl& bs ) const
{
return valid() && bs.valid() &&
((_center - bs._center).length2() <= (_radius + bs._radius)*(_radius + bs._radius));
}
};
template<typename VT>
template<typename vector_type>
void BoundingSphereImpl<VT>::expandBy(const vector_type& v)
{
if (valid())
{
vec_type dv = v-_center;
value_type r = dv.length();
if (r>_radius)
{
value_type dr = (r-_radius)*0.5;
_center += dv*(dr/r);
_radius += dr;
} // else do nothing as vertex is within sphere.
}
else
{
_center = v;
_radius = 0.0;
}
}
template<typename VT>
template<typename vector_type>
void BoundingSphereImpl<VT>::expandRadiusBy(const vector_type& v)
{
if (valid())
{
value_type r = (v-_center).length();
if (r>_radius) _radius = r;
// else do nothing as vertex is within sphere.
}
else
{
_center = v;
_radius = 0.0;
}
}
template<typename VT>
void BoundingSphereImpl<VT>::expandBy(const BoundingSphereImpl& sh)
{
// ignore operation if incomming BoundingSphere is invalid.
if (!sh.valid()) return;
// This sphere is not set so use the inbound sphere
if (!valid())
{
_center = sh._center;
_radius = sh._radius;
return;
}
// Calculate d == The distance between the sphere centers
double d = ( _center - sh.center() ).length();
// New sphere is already inside this one
if ( d + sh.radius() <= _radius )
{
return;
}
// New sphere completely contains this one
if ( d + _radius <= sh.radius() )
{
_center = sh._center;
_radius = sh._radius;
return;
}
// Build a new sphere that completely contains the other two:
//
// The center point lies halfway along the line between the furthest
// points on the edges of the two spheres.
//
// Computing those two points is ugly - so we'll use similar triangles
double new_radius = (_radius + d + sh.radius() ) * 0.5;
double ratio = ( new_radius - _radius ) / d ;
_center[0] += ( sh.center()[0] - _center[0] ) * ratio;
_center[1] += ( sh.center()[1] - _center[1] ) * ratio;
_center[2] += ( sh.center()[2] - _center[2] ) * ratio;
_radius = new_radius;
}
template<typename VT>
void BoundingSphereImpl<VT>::expandRadiusBy(const BoundingSphereImpl& sh)
{
if (sh.valid())
{
if (valid())
{
value_type r = (sh._center-_center).length()+sh._radius;
if (r>_radius) _radius = r;
// else do nothing as vertex is within sphere.
}
else
{
_center = sh._center;
_radius = sh._radius;
}
}
}
template<typename VT>
void BoundingSphereImpl<VT>::expandBy(const BoundingBoxImpl<VT>& bb)
{
if (bb.valid())
{
if (valid())
{
BoundingBoxImpl<vec_type> newbb(bb);
for(unsigned int c=0;c<8;++c)
{
vec_type v = bb.corner(c)-_center; // get the direction vector from corner
v.normalize(); // normalise it.
v *= -_radius; // move the vector in the opposite direction distance radius.
v += _center; // move to absolute position.
newbb.expandBy(v); // add it into the new bounding box.
}
_center = newbb.center();
_radius = newbb.radius();
}
else
{
_center = bb.center();
_radius = bb.radius();
}
}
}
template<typename VT>
void BoundingSphereImpl<VT>::expandRadiusBy(const BoundingBoxImpl<VT>& bb)
{
if (bb.valid())
{
if (valid())
{
for(unsigned int c=0;c<8;++c)
{
expandRadiusBy(bb.corner(c));
}
}
else
{
_center = bb.center();
_radius = bb.radius();
}
}
}
typedef BoundingSphereImpl<Vec3f> BoundingSpheref;
typedef BoundingSphereImpl<Vec3d> BoundingSphered;
#ifdef OSG_USE_FLOAT_BOUNDINGSPHERE
typedef BoundingSpheref BoundingSphere;
#else
typedef BoundingSphered BoundingSphere;
#endif
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BOUNDSCHECKING
#define OSG_BOUNDSCHECKING 1
#include <osg/Notify>
namespace osg {
/** If value is greater than or equal to minValue do nothing - legal value,
* Otherwise set value to minValue, and warn that valueName was clamped.
* Note this is effectively A=max(A,B). */
template <typename T>
inline void clampGEQUAL(T& value,const T minValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clampping to "<<minValue<<"."<< std::endl;
value = minValue;
}
}
/** If value is less than or equal to maxValue do nothing - legal value,
* Otherwise set value to maxValue, and warn that valueName was clamped.
* Note this is effectively A=min(A,B). */
template <typename T>
inline void clampLEQUAL(T& value,const T maxValue,const char* valueName)
{
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clampping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
/** If value is between or equal to minValue and maxValue do nothing - legal
* value, Otherwise clamp value to specified range and warn that valueName
* was clamped. Equivilant to calling
* clampGEQUAL( value, minValue, valueName );
* clampLEQUAL( value, maxValue, valueName ); */
template <typename T>
inline void clampBetweenRange(T& value,const T minValue,const T maxValue,const char* valueName)
{
if (value<minValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is below permitted minimum, clampping to "<<minValue<<"."<< std::endl;
value = minValue;
}
else
if (value>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<" of "<<value<<" is above permitted maximum, clampping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
/** If value[i] is greater than or equal to minValue do nothing - legal value,
* Otherwise set value[i] to minValue, and warn that valueName[i] was clamped.
* Note this is effectively A[i]=max(A[i],B). */
template <typename A, typename T>
inline void clampArrayElementGEQUAL(A& value,unsigned int i,const T minValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clampping to "<<minValue<<"."<< std::endl;
value[i] = minValue;
}
}
/** If value[i] is less than or equal to maxValue do nothing - legal value,
* Otherwise set value[i] to maxValue, and warn that valueName[i] was clamped.
* Note this is effectively A[i]=min(A[i],B). */
template <typename A, typename T>
inline void clampArrayElementLEQUAL(A& value,unsigned int i,const T maxValue,const char* valueName)
{
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clampping to "<<maxValue<<"."<< std::endl;
value = maxValue;
}
}
/** If value[i] is between or equal to minValue and maxValue do nothing - legal
* value, Otherwise clamp value[i] to specified range and warn that
* valueName[i] was clamped. Equivilant to calling
* clampArrayElementGEQUAL( value, i, minValue, valueName );
* clampArrayElementLEQUAL( value, i, maxValue, valueName ); */
template <typename A, typename T>
inline void clampArrayElementBetweenRange(A& value,unsigned int i,const T minValue,const T maxValue,const char* valueName)
{
if (value[i]<minValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is below permitted minimum, clampping to "<<minValue<<"."<< std::endl;
value[i] = minValue;
}
else
if (value[i]>maxValue)
{
notify(WARN) << "Warning: "<<valueName<<"["<<i<<"] of "<<value[i]<<" is above permitted maximum, clampping to "<<maxValue<<"."<< std::endl;
value[i] = maxValue;
}
}
/** For each element of value[] in the range (first,last), if the element is
* greater than or equal to minValue do nothing - legal value, Otherwise
* clamp the element to minValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArrayElementsGEQUAL(A& value,unsigned int first,unsigned int last,const T minValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementGEQUAL(value,i,minValue,valueName);
}
/** For each element of value[] in the range (first,last), if the element is
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
* the element to maxValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArrayElementsLEQUAL(A& value,unsigned int first,unsigned int last,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementLEQUAL(value,i,maxValue,valueName);
}
/** For each element of value[] in the range (first,last), if the element is
* between or equal to minValue and maxValue do nothing - legal value,
* Otherwise clamp the element to the range and warn that valueName[i] was
* clamped. Equivalent to calling
* clampArrayElementsGEQUAL( value, first, last, minValue, valueName);
* clampArrayElementsLEQUAL( value, first, last, maxValue, valueName); */
template <typename A, typename T>
inline void clampArrayElementsBetweenRange(A& value,unsigned int first,unsigned int last,const T minValue,const T maxValue,const char* valueName)
{
for(unsigned int i=first;i<=last;++i)
clampArrayElementBetweenRange(value,i,minValue,maxValue,valueName);
}
/** For each element of the three-element array value[], if the element is
* greater than or equal to minValue do nothing - legal value, Otherwise
* clamp the element to minValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArray3GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,2u,minValue,valueName);
}
/** For each element of the three-element array value[], if the element is
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
* the element to maxValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArray3LEQUAL(A& value,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,2u,maxValue,valueName);
}
/** For each element of the three-element array value[], if the element is
* between or equal to minValue and maxValue do nothing - legal value,
* Otherwise clamp the element to the range and warn that valueName[i] was
* clamped. Equivalent to calling
* clampArray3GEQUAL( value, minValue, valueName);
* clampArray3LEQUAL( value, maxValue, valueName); */
template <typename A, typename T>
inline void clampArray3BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,2u,minValue,maxValue,valueName);
}
/** For each element of the four-element array value[], if the element is
* greater than or equal to minValue do nothing - legal value, Otherwise
* clamp the element to minValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArray4GEQUAL(A& value,const T minValue,const char* valueName)
{
clampArrayElementsGEQUAL(value,0u,3u,minValue,valueName);
}
/** For each element of the four-element array value[], if the element is
* less than or equal to maxValue do nothing - legal value, Otherwise clamp
* the element to maxValue, and warn that valueName[i] was clamped. */
template <typename A, typename T>
inline void clampArray4LEQUAL(A& value,const T maxValue,const char* valueName)
{
clampArrayElementsLEQUAL(value,0u,3u,maxValue,valueName);
}
/** For each element of the four-element array value[], if the element is
* between or equal to minValue and maxValue do nothing - legal value,
* Otherwise clamp the element to the range and warn that valueName[i] was
* clamped. Equivalent to calling
* clampArray4GEQUAL( value, minValue, valueName);
* clampArray4LEQUAL( value, maxValue, valueName); */
template <typename A, typename T>
inline void clampArray4BetweenRange(A& value,const T minValue,const T maxValue,const char* valueName)
{
clampArrayElementsBetweenRange(value,0u,3u,minValue,maxValue,valueName);
}
}
#endif
/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
* Copyright (C) 2010 Tim Moore
*
* This library is open source and may be redistributed and/or modified under
* the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
* (at your option) any later version. The full license is in LICENSE file
* included with this distribution, and on the openscenegraph.org website.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* OpenSceneGraph Public License for more details.
*/
#ifndef OSG_BUFFERINDEXBINDING
#define OSG_BUFFERINDEXBINDING 1
#include <osg/Export>
#include <osg/BufferObject>
#include <osg/StateAttribute>
#ifndef GL_TRANSFORM_FEEDBACK_BUFFER
#define GL_TRANSFORM_FEEDBACK_BUFFER 0x8C8E
#endif
namespace osg {
class State;
/** Encapsulate binding buffer objects to index targets. This
* specifically supports the uniform buffer and transform feedback
* targets.
*/
// Common implementation superclass
class OSG_EXPORT BufferIndexBinding : public StateAttribute
{
protected:
BufferIndexBinding(GLenum target, GLuint index);
BufferIndexBinding(GLenum target, GLuint index, BufferObject* bo, GLintptr offset,
GLsizeiptr size);
BufferIndexBinding(const BufferIndexBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
public:
// The member value is part of the key to this state attribute in
// the State class. Using the index target, we can seperately
// track the bindings for many different index targets.
virtual unsigned getMember() const { return static_cast<unsigned int>(_index); }
GLenum getTarget() const { return _target; }
/** Get the index target.
*/
GLuint getIndex() const { return _index; }
/** Set the buffer object that will be bound to the index target.
*/
void setBufferObject(BufferObject *bo) { _bufferObject = bo; }
/** Get the buffer object to be bound.
*/
BufferObject* getBufferObject() const { return _bufferObject.get(); }
/** Set the starting offset into the buffer object for data for
the indexed target. Note: the required alignment on the offset
may be quite large (e.g., 256 bytes on NVidia 8600M). This
should be checked with glGetIntegerv(GL_UNIFORM_BUFFER_OFFSET_ALIGNMENT...).
*/
void setOffset(GLintptr offset) { _offset = offset; }
GLintptr getOffset() const { return _offset; }
/** Set the size of data for the indexed target.
*/
void setSize(GLsizeiptr size) { _size = size; }
GLsizeiptr getSize() const { return _size; }
virtual void apply(State& state) const;
protected:
virtual ~BufferIndexBinding();
const GLenum _target;
const GLuint _index;
ref_ptr<BufferObject> _bufferObject;
GLintptr _offset;
GLsizeiptr _size;
};
/** StateAttribute for binding a uniform buffer index target.
*/
class OSG_EXPORT UniformBufferBinding : public BufferIndexBinding
{
public:
UniformBufferBinding();
UniformBufferBinding(GLuint index);
/** Create a binding for a uniform buffer index target.
* @param index the index target
* @param bo associated buffer object
* @param offset offset into buffer object
* @param size size of data in buffer object
*/
UniformBufferBinding(GLuint index, BufferObject* bo, GLintptr offset, GLsizeiptr size);
UniformBufferBinding(const UniformBufferBinding& rhs, const CopyOp& copyop=CopyOp::SHALLOW_COPY);
META_StateAttribute(osg, UniformBufferBinding, UNIFORMBUFFERBINDING);
virtual int compare(const StateAttribute& bb) const
{
COMPARE_StateAttribute_Types(UniformBufferBinding, bb)