1/* -*-c++-*- OpenSceneGraph - Copyright (C) 1998-2006 Robert Osfield
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.
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.
15#define OSG_GLOBJECTS 1
17#include <osg/Referenced>
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);
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);
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);
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);
46class OSG_EXPORT GraphicsObject : public osg::Referenced
52 virtual ~GraphicsObject();
56class OSG_EXPORT GraphicsObjectManager : public osg::Referenced
59 GraphicsObjectManager(const std::string& name, unsigned int contextID);
61 unsigned int getContextID() const { return _contextID; }
63 /** Signal that a new frame has started.*/
64 virtual void newFrame(osg::FrameStamp* /*fs*/) {}
66 virtual void resetStats() {}
67 virtual void reportStats(std::ostream& /*out*/) {}
68 virtual void recomputeStats(std::ostream& /*out*/) const {}
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;
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;
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;
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;
91 virtual ~GraphicsObjectManager();
94 unsigned int _contextID;
98class OSG_EXPORT GLObjectManager : public GraphicsObjectManager
101 GLObjectManager(const std::string& name, unsigned int contextID);
103 virtual void flushDeletedGLObjects(double currentTime, double& availableTime);
105 virtual void flushAllDeletedGLObjects();
107 virtual void deleteAllGLObjects();
109 virtual void discardAllGLObjects();
111 /** schedule a GL object for deletion by the graphics thread.*/
112 virtual void scheduleGLObjectForDeletion(GLuint globj);
114 /** implementation of the actual creation of an GL object - subclasses from GLObjectManager must implement the appropriate GL calls.*/
115 virtual GLuint createGLObject();
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;
121 virtual ~GLObjectManager();
123 typedef std::list<GLuint> GLObjectHandleList;
124 OpenThreads::Mutex _mutex;
125 GLObjectHandleList _deleteGLObjectHandles;