openscenegraph
GLObjects
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_GLOBJECTS
15#define OSG_GLOBJECTS 1
16
17#include <osg/Referenced>
18#include <osg/GL>
19#include <list>
20#include <string>
21
22namespace osg {
23
24// forward declare
25class FrameStamp;
26
27/** Flush all deleted OpenGL objects within the specified availableTime.
28 * Note, must be called from a thread which has current the graphics context associated with contextID. */
29extern OSG_EXPORT void flushDeletedGLObjects(unsigned int contextID, double currentTime, double& availableTime);
30
31/** Flush all deleted OpenGL objects.
32 * Note, must be called from a thread which has current the graphics context associated with contextID. */
33extern OSG_EXPORT void flushAllDeletedGLObjects(unsigned int contextID);
34
35/** Do a GL delete all OpenGL objects.
36 * Note, must be called from a thread which has current the graphics context associated with contextID. */
37extern OSG_EXPORT void deleteAllGLObjects(unsigned int contextID);
38
39/** Discard all OpenGL objects.
40 * Note, unlike deleteAllGLjects discard does not
41 * do any OpenGL calls so can be called from any thread, but as a consequence it
42 * also doesn't remove the associated OpenGL resource so discard should only be
43 * called when the associated graphics context is being/has been closed. */
44extern OSG_EXPORT void discardAllGLObjects(unsigned int contextID);
45
46class OSG_EXPORT GraphicsObject : public osg::Referenced
47{
48 public:
49 GraphicsObject();
50
51 protected:
52 virtual ~GraphicsObject();
53};
54
55
56class OSG_EXPORT GraphicsObjectManager : public osg::Referenced
57{
58 public:
59 GraphicsObjectManager(const std::string& name, unsigned int contextID);
60
61 unsigned int getContextID() const { return _contextID; }
62
63 /** Signal that a new frame has started.*/
64 virtual void newFrame(osg::FrameStamp* /*fs*/) {}
65
66 virtual void resetStats() {}
67 virtual void reportStats(std::ostream& /*out*/) {}
68 virtual void recomputeStats(std::ostream& /*out*/) const {}
69
70
71 /** Flush all deleted OpenGL objects within the specified availableTime.
72 * Note, must be called from a thread which has current the graphics context associated with contextID. */
73 virtual void flushDeletedGLObjects(double currentTime, double& availableTime) = 0;
74
75 /** Flush all deleted OpenGL objects.
76 * Note, must be called from a thread which has current the graphics context associated with contextID. */
77 virtual void flushAllDeletedGLObjects() = 0;
78
79 /** Do a GL delete all OpenGL objects.
80 * Note, must be called from a thread which has current the graphics context associated with contextID. */
81 virtual void deleteAllGLObjects() = 0;
82
83 /** Discard all OpenGL objects.
84 * Note, unlike deleteAllGLjects discard does not
85 * do any OpenGL calls so can be called from any thread, but as a consequence it
86 * also doesn't remove the associated OpenGL resource so discard should only be
87 * called when the associated graphics context is being/has been closed. */
88 virtual void discardAllGLObjects() = 0;
89
90 protected:
91 virtual ~GraphicsObjectManager();
92
93 std::string _name;
94 unsigned int _contextID;
95
96};
97
98class OSG_EXPORT GLObjectManager : public GraphicsObjectManager
99{
100public:
101 GLObjectManager(const std::string& name, unsigned int contextID);
102
103 virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
104
105 virtual void flushAllDeletedGLObjects();
106
107 virtual void deleteAllGLObjects();
108
109 virtual void discardAllGLObjects();
110
111 /** schedule a GL object for deletion by the graphics thread.*/
112 virtual void scheduleGLObjectForDeletion(GLuint globj);
113
114 /** implementation of the actual creation of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
115 virtual GLuint createGLObject();
116
117 /** implementation of the actual deletion of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
118 virtual void deleteGLObject(GLuint globj) = 0;
119
120protected:
121 virtual ~GLObjectManager();
122
123 typedef std::list<GLuint> GLObjectHandleList;
124 OpenThreads::Mutex _mutex;
125 GLObjectHandleList _deleteGLObjectHandles;
126
127};
128
129
130}
131
132#endif