ContextData
Go to the documentation of this file.
/* -*-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_CONTEXTDATA
#define OSG_CONTEXTDATA 1
#include <osg/GraphicsContext>
namespace osg {
class OSG_EXPORT ContextData : public GraphicsObjectManager
{
public:
ContextData(unsigned int contextID);
void incrementUsageCount() { ++_numContexts; }
void decrementUsageCount() { --_numContexts; }
void setNumContexts(unsigned int numContexts) { _numContexts = numContexts; }
unsigned int getNumContexts() const { return _numContexts; }
void setCompileContext(osg::GraphicsContext* gc) { _compileContext = gc; }
osg::GraphicsContext* getCompileContext() { return _compileContext.get(); }
template<typename T>
T* get()
{
const std::type_info* id(&typeid(T));
osg::ref_ptr<osg::Referenced>& ptr = _managerMap[id];
if (!ptr)
{
ptr = new T(_contextID);
}
return static_cast<T*>(ptr.get());
}
template<typename T>
const T* get() const
{
const std::type_info* id(&typeid(T));
ManagerMap::const_iterator itr = _managerMap.find(id);
if (itr==_managerMap.end()) return 0;
else return itr->second.get();
}
template<typename T>
void set(T* ptr)
{
const std::type_info* id(&typeid(T));
_managerMap[id] = ptr;
}
virtual void newFrame(osg::FrameStamp*);
virtual void resetStats();
virtual void reportStats(std::ostream& out);
virtual void recomputeStats(std::ostream& out) const;
virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
virtual void flushAllDeletedGLObjects();
virtual void deleteAllGLObjects();
virtual void discardAllGLObjects();
public:
static unsigned int createNewContextID();
static unsigned int getMaxContextID();
static void incrementContextIDUsageCount(unsigned int contextID);
static void decrementContextIDUsageCount(unsigned int contextID);
typedef GraphicsContext::GraphicsContexts GraphicsContexts;
static GraphicsContexts getAllRegisteredGraphicsContexts();
static GraphicsContexts getRegisteredGraphicsContexts(unsigned int contextID);
static void setCompileContext(unsigned int contextID, GraphicsContext* gc);
static GraphicsContext* getOrCreateCompileContext(unsigned int contextID);
static GraphicsContext* getCompileContext(unsigned int contextID);
static void registerGraphicsContext(GraphicsContext* gc);
static void unregisterGraphicsContext(GraphicsContext* gc);
protected:
virtual ~ContextData();
unsigned int _numContexts;
osg::ref_ptr<osg::GraphicsContext> _compileContext;
// ManagerMap contains GL Extentsions objects used by StateAttribue to call OpenGL extensions/advanced features
typedef std::map<const std::type_info*, osg::ref_ptr<osg::Referenced> > ManagerMap;
ManagerMap _managerMap;
};
extern OSG_EXPORT ContextData* getContextData(unsigned int contextID);
extern OSG_EXPORT ContextData* getOrCreateContextData(unsigned int contextID);
template<typename T>
inline T* get(unsigned int contextID)
{
ContextData* gc = getOrCreateContextData(contextID);
return gc->get<T>();
}
// specialize for ContextData to avoid ContextData being nested within itself.
template<> inline ContextData* get<ContextData>(unsigned int contextID) { return getOrCreateContextData(contextID); }
}
#endif
GraphicsContext
osg::ContextData
Definition ContextData:22
osg::ContextData::reportStats
virtual void reportStats(std::ostream &out)
osg::ContextData::setNumContexts
void setNumContexts(unsigned int numContexts)
Definition ContextData:29
osg::ContextData::~ContextData
virtual ~ContextData()
osg::ContextData::getNumContexts
unsigned int getNumContexts() const
Definition ContextData:30
osg::ContextData::decrementContextIDUsageCount
static void decrementContextIDUsageCount(unsigned int contextID)
osg::ContextData::set
void set(T *ptr)
Definition ContextData:63
osg::ContextData::_numContexts
unsigned int _numContexts
Definition ContextData:136
osg::ContextData::deleteAllGLObjects
virtual void deleteAllGLObjects()
osg::ContextData::resetStats
virtual void resetStats()
osg::ContextData::flushAllDeletedGLObjects
virtual void flushAllDeletedGLObjects()
osg::ContextData::recomputeStats
virtual void recomputeStats(std::ostream &out) const
osg::ContextData::incrementContextIDUsageCount
static void incrementContextIDUsageCount(unsigned int contextID)
osg::ContextData::getCompileContext
static GraphicsContext * getCompileContext(unsigned int contextID)
osg::ContextData::ManagerMap
std::map< const std::type_info *, osg::ref_ptr< osg::Referenced > > ManagerMap
Definition ContextData:140
osg::ContextData::get
const T * get() const
Definition ContextData:53
osg::ContextData::discardAllGLObjects
virtual void discardAllGLObjects()
osg::ContextData::getCompileContext
osg::GraphicsContext * getCompileContext()
Definition ContextData:33
osg::ContextData::registerGraphicsContext
static void registerGraphicsContext(GraphicsContext *gc)
osg::ContextData::newFrame
virtual void newFrame(osg::FrameStamp *)
osg::ContextData::flushDeletedGLObjects
virtual void flushDeletedGLObjects(double currentTime, double &availableTime)
osg::ContextData::_managerMap
ManagerMap _managerMap
Definition ContextData:141
osg::ContextData::_compileContext
osg::ref_ptr< osg::GraphicsContext > _compileContext
Definition ContextData:137
osg::ContextData::setCompileContext
void setCompileContext(osg::GraphicsContext *gc)
Definition ContextData:32
osg::ContextData::getAllRegisteredGraphicsContexts
static GraphicsContexts getAllRegisteredGraphicsContexts()
osg::ContextData::unregisterGraphicsContext
static void unregisterGraphicsContext(GraphicsContext *gc)
osg::ContextData::decrementUsageCount
void decrementUsageCount()
Definition ContextData:27
osg::ContextData::createNewContextID
static unsigned int createNewContextID()
osg::ContextData::getRegisteredGraphicsContexts
static GraphicsContexts getRegisteredGraphicsContexts(unsigned int contextID)
osg::ContextData::getMaxContextID
static unsigned int getMaxContextID()
osg::ContextData::ContextData
ContextData(unsigned int contextID)
osg::ContextData::get
T * get()
Definition ContextData:38
osg::ContextData::GraphicsContexts
GraphicsContext::GraphicsContexts GraphicsContexts
Definition ContextData:110
osg::ContextData::setCompileContext
static void setCompileContext(unsigned int contextID, GraphicsContext *gc)
osg::ContextData::getOrCreateCompileContext
static GraphicsContext * getOrCreateCompileContext(unsigned int contextID)
osg::ContextData::incrementUsageCount
void incrementUsageCount()
Definition ContextData:26
osg::FrameStamp
Definition FrameStamp:35
osg::GraphicsContext
Definition GraphicsContext:30
osg::GraphicsContext::GraphicsContexts
std::vector< GraphicsContext * > GraphicsContexts
Definition GraphicsContext:272
osg::GraphicsObjectManager::_contextID
unsigned int _contextID
Definition GLObjects:94
osg::GraphicsObjectManager::GraphicsObjectManager
GraphicsObjectManager(const std::string &name, unsigned int contextID)
osg::ref_ptr
Definition ref_ptr:32
osg::ref_ptr::get
T * get() const
Definition ref_ptr:117
osg
Definition AlphaFunc:19
osg::get< ContextData >
ContextData * get< ContextData >(unsigned int contextID)
Definition ContextData:159
osg::getContextData
OSG_EXPORT ContextData * getContextData(unsigned int contextID)
osg::getOrCreateContextData
OSG_EXPORT ContextData * getOrCreateContextData(unsigned int contextID)
osg::get
T * get(unsigned int contextID)
Definition ContextData:152
OSG_EXPORT
#define OSG_EXPORT
Definition osg/Export:39