OpenSceneGraph 3.6.5
ContextData
Go to the documentation of this file.
1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
2 *
3 * This library is open source and may be redistributed and/or modified under
4 * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
5 * (at your option) any later version. The full license is in LICENSE file
6 * included with this distribution, and on the openscenegraph.org website.
7 *
8 * This library is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * OpenSceneGraph Public License for more details.
12*/
13
14#ifndef OSG_CONTEXTDATA
15#define OSG_CONTEXTDATA 1
16
17#include <osg/GraphicsContext>
18
19namespace osg {
20
22{
23 public:
24 ContextData(unsigned int contextID);
25
28
29 void setNumContexts(unsigned int numContexts) { _numContexts = numContexts; }
30 unsigned int getNumContexts() const { return _numContexts; }
31
34
37 template<typename T>
38 T* get()
39 {
40 const std::type_info* id(&typeid(T));
42 if (!ptr)
43 {
44 ptr = new T(_contextID);
45 }
46 return static_cast<T*>(ptr.get());
47 }
48
52 template<typename T>
53 const T* get() const
54 {
55 const std::type_info* id(&typeid(T));
56 ManagerMap::const_iterator itr = _managerMap.find(id);
57 if (itr==_managerMap.end()) return 0;
58 else return itr->second.get();
59 }
60
62 template<typename T>
63 void set(T* ptr)
64 {
65 const std::type_info* id(&typeid(T));
66 _managerMap[id] = ptr;
67 }
68
70 virtual void newFrame(osg::FrameStamp*);
71
72 virtual void resetStats();
73 virtual void reportStats(std::ostream& out);
74 virtual void recomputeStats(std::ostream& out) const;
75
78 virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
79
83
86 virtual void deleteAllGLObjects();
87
93 virtual void discardAllGLObjects();
94
95 public:
96
99 static unsigned int createNewContextID();
100
102 static unsigned int getMaxContextID();
103
105 static void incrementContextIDUsageCount(unsigned int contextID);
106
108 static void decrementContextIDUsageCount(unsigned int contextID);
109
111
114
116 static GraphicsContexts getRegisteredGraphicsContexts(unsigned int contextID);
117
119 static void setCompileContext(unsigned int contextID, GraphicsContext* gc);
120
122 static GraphicsContext* getOrCreateCompileContext(unsigned int contextID);
123
125 static GraphicsContext* getCompileContext(unsigned int contextID);
126
129
132
133 protected:
134 virtual ~ContextData();
135
136 unsigned int _numContexts;
138
139 // ManagerMap contains GL Extentsions objects used by StateAttribue to call OpenGL extensions/advanced features
140 typedef std::map<const std::type_info*, osg::ref_ptr<osg::Referenced> > ManagerMap;
142};
143
144
146extern OSG_EXPORT ContextData* getContextData(unsigned int contextID);
147
149extern OSG_EXPORT ContextData* getOrCreateContextData(unsigned int contextID);
150
151template<typename T>
152inline T* get(unsigned int contextID)
153{
154 ContextData* gc = getOrCreateContextData(contextID);
155 return gc->get<T>();
156}
157
158// specialize for ContextData to avoid ContextData being nested within itself.
159template<> inline ContextData* get<ContextData>(unsigned int contextID) { return getOrCreateContextData(contextID); }
160
161}
162
163#endif
The core osg library provides the basic scene graph classes such as Nodes, State and Drawables,...
Definition AlphaFunc:19
ContextData * get< ContextData >(unsigned int contextID)
Definition ContextData:159
OSG_EXPORT ContextData * getContextData(unsigned int contextID)
Get the ContextData for a specific contextID.
OSG_EXPORT ContextData * getOrCreateContextData(unsigned int contextID)
Get or create the ContextData for a specific contextID.
T * get(unsigned int contextID)
Definition ContextData:152
Definition ContextData:22
virtual void reportStats(std::ostream &out)
void setNumContexts(unsigned int numContexts)
Definition ContextData:29
virtual ~ContextData()
unsigned int getNumContexts() const
Definition ContextData:30
static void decrementContextIDUsageCount(unsigned int contextID)
Decrement the usage count associate with a contextID.
void set(T *ptr)
Set a specific GL extensions object pr GraphicsObjectManager.
Definition ContextData:63
unsigned int _numContexts
Definition ContextData:136
virtual void deleteAllGLObjects()
Do a GL delete all OpenGL objects.
virtual void resetStats()
virtual void flushAllDeletedGLObjects()
Flush all deleted OpenGL objects.
virtual void recomputeStats(std::ostream &out) const
static void incrementContextIDUsageCount(unsigned int contextID)
Increment the usage count associate with a contextID.
static GraphicsContext * getCompileContext(unsigned int contextID)
Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specifi...
std::map< const std::type_info *, osg::ref_ptr< osg::Referenced > > ManagerMap
Definition ContextData:140
const T * get() const
Get a specific GL extensions object or GraphicsObjectManager if it already exists in the extension ma...
Definition ContextData:53
virtual void discardAllGLObjects()
Discard all OpenGL objects.
osg::GraphicsContext * getCompileContext()
Definition ContextData:33
static void registerGraphicsContext(GraphicsContext *gc)
Register a GraphicsContext.
virtual void newFrame(osg::FrameStamp *)
Signal that a new frame has started.
virtual void flushDeletedGLObjects(double currentTime, double &availableTime)
Flush all deleted OpenGL objects within the specified availableTime.
ManagerMap _managerMap
Definition ContextData:141
osg::ref_ptr< osg::GraphicsContext > _compileContext
Definition ContextData:137
void setCompileContext(osg::GraphicsContext *gc)
Definition ContextData:32
static GraphicsContexts getAllRegisteredGraphicsContexts()
Get all the registered graphics contexts.
static void unregisterGraphicsContext(GraphicsContext *gc)
Unregister a GraphicsContext.
void decrementUsageCount()
Definition ContextData:27
static unsigned int createNewContextID()
Create a contextID for a new graphics context, this contextID is used to set up the osg::State associ...
static GraphicsContexts getRegisteredGraphicsContexts(unsigned int contextID)
Get all the registered graphics contexts associated with a specific contextID.
static unsigned int getMaxContextID()
Get the current max ContextID.
ContextData(unsigned int contextID)
T * get()
Get a specific GL extensions object or GraphicsObjectManager, initialize if not already present.
Definition ContextData:38
GraphicsContext::GraphicsContexts GraphicsContexts
Definition ContextData:110
static void setCompileContext(unsigned int contextID, GraphicsContext *gc)
Get the GraphicsContext for doing background compilation for GraphicsContexts associated with specifi...
static GraphicsContext * getOrCreateCompileContext(unsigned int contextID)
Get existing or create a new GraphicsContext to do background compilation for GraphicsContexts associ...
void incrementUsageCount()
Definition ContextData:26
Class which encapsulates the frame number, reference time and calendar time of specific frame,...
Definition FrameStamp:35
unsigned int _contextID
Definition GLObjects:94
GraphicsObjectManager(const std::string &name, unsigned int contextID)
Base class for providing Windowing API agnostic access to creating and managing graphics context.
Definition GraphicsContext:30
std::vector< GraphicsContext * > GraphicsContexts
Definition GraphicsContext:272
Smart pointer for handling referenced counted objects.
Definition ref_ptr:32
T * get() const
Definition ref_ptr:117
#define OSG_EXPORT
Definition Export:39

osg logo
Generated at Sun Jul 20 2025 00:00:00 for the OpenSceneGraph by doxygen 1.14.0.