root/OpenSceneGraph/trunk/include/osg/PagedLOD @ 8994

Revision 8994, 6.9 kB (checked in by robert, 6 years ago)

Added the ability to release OpenGL objects in PagedLOD subgrphs that are no longer being rendered.

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
Line 
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_PagedLOD
15#define OSG_PagedLOD 1
16
17#include <osg/LOD>
18
19namespace osg {
20
21/** PagedLOD.
22*/
23class OSG_EXPORT PagedLOD : public LOD
24{
25    public :
26   
27        PagedLOD();
28
29        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
30        PagedLOD(const PagedLOD&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
31
32        META_Node(osg, PagedLOD);
33       
34       
35
36        virtual void traverse(NodeVisitor& nv);
37       
38        virtual bool addChild(Node *child);
39
40        virtual bool addChild(Node *child, float min, float max);
41
42        virtual bool addChild(Node *child, float min, float max,const std::string& filename, float priorityOffset=0.0f, float priorityScale=1.0f);
43
44        virtual bool removeChildren(unsigned int pos,unsigned int numChildrenToRemove=1);
45       
46
47
48        /** Set the database path to prepend to children's filenames.*/
49        void setDatabasePath(const std::string& path);
50
51        /** Get the database path used to prepend to children's filenames.*/
52        inline const std::string& getDatabasePath() const { return _databasePath; }
53
54       
55        struct OSG_EXPORT PerRangeData
56        {
57            PerRangeData();
58            PerRangeData(const PerRangeData& prd);
59            PerRangeData& operator = (const PerRangeData& prd);
60
61            std::string                     _filename;
62            float                           _priorityOffset;
63            float                           _priorityScale;
64            double                          _timeStamp;
65            int                             _frameNumber;
66            int                             _frameNumberOfLastReleaseGLObjects;
67            osg::ref_ptr<osg::Referenced>   _databaseRequest;
68        };
69
70        typedef std::vector<PerRangeData> PerRangeDataList;
71       
72        void setFileName(unsigned int childNo, const std::string& filename) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._filename=filename; }
73        const std::string& getFileName(unsigned int childNo) const { return _perRangeDataList[childNo]._filename; }
74        unsigned int getNumFileNames() const { return _perRangeDataList.size(); }
75
76
77        void setPriorityOffset(unsigned int childNo, float priorityOffset) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityOffset=priorityOffset; }
78        float getPriorityOffset(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityOffset; }
79        unsigned int getNumPriorityOffsets() const { return _perRangeDataList.size(); }
80
81        void setPriorityScale(unsigned int childNo, float priorityScale) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._priorityScale=priorityScale; }
82        float getPriorityScale(unsigned int childNo) const { return _perRangeDataList[childNo]._priorityScale; }
83        unsigned int getNumPriorityScales() const { return _perRangeDataList.size(); }
84
85
86        void setTimeStamp(unsigned int childNo, double timeStamp) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._timeStamp=timeStamp; }
87        double getTimeStamp(unsigned int childNo) const { return _perRangeDataList[childNo]._timeStamp; }
88        unsigned int getNumTimeStamps() const { return _perRangeDataList.size(); }
89
90        void setFrameNumber(unsigned int childNo, int frameNumber) { expandPerRangeDataTo(childNo); _perRangeDataList[childNo]._frameNumber=frameNumber; }
91        double getFrameNumber(unsigned int childNo) const { return _perRangeDataList[childNo]._frameNumber; }
92        unsigned int getNumFrameNumbers() const { return _perRangeDataList.size(); }
93
94
95        /** Return the DatabaseRequest object used by the DatabasePager to keep track of file load requests
96          * being carried on behalf of the DatabasePager.
97          * Note, in normal OSG usage you should not set this value yourself, as this will be managed by
98          * the osgDB::DatabasePager.*/
99        osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) { return _perRangeDataList[childNo]._databaseRequest; }
100       
101        /** Return the const DatabaseRequest object.*/
102        const osg::ref_ptr<osg::Referenced>& getDatabaseRequest(unsigned int childNo) const { return _perRangeDataList[childNo]._databaseRequest; }
103
104
105        /** Set the frame number of the last time that this PageLOD node was traversed.
106          * Note, this frame number is automatically set by the traverse() method for all traversals (update, cull etc.).
107          */
108        inline void setFrameNumberOfLastTraversal(int frameNumber) { _frameNumberOfLastTraversal=frameNumber; }
109
110        /** Get the frame number of the last time that this PageLOD node was traversed.*/
111        inline int getFrameNumberOfLastTraversal() const { return _frameNumberOfLastTraversal; }
112
113
114        /** Set the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
115        inline void setNumChildrenThatCannotBeExpired(unsigned int num) { _numChildrenThatCannotBeExpired = num; }
116
117        /** Get the number of children that the PagedLOD must keep around, even if they are older than their expiry time.*/
118        unsigned int getNumChildrenThatCannotBeExpired() const { return _numChildrenThatCannotBeExpired; }
119
120        /** Remove the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
121          * The removed children are added to the removeChildren list passed into the method,
122          * this allows the children to be deleted later at the caller's discretion.
123          * Return true if children are removed, false otherwise. */
124        virtual bool removeExpiredChildren(double expiryTime, int expiryFrame, NodeList& removedChildren);
125
126        /** Release the GL Objects of the children from the PagedLOD which haven't been visited since specified expiry time and expiry frame number.
127          * Return true if any children have release called upon them, false otherwise. */
128        virtual bool releaseGLObjectsOnExpiredChildren(double releaseTime, int releaseFrame);
129       
130    protected :
131   
132        virtual ~PagedLOD();
133       
134        void expandPerRangeDataTo(unsigned int pos);
135
136        std::string         _databasePath;
137
138        int                 _frameNumberOfLastTraversal;
139        unsigned int        _numChildrenThatCannotBeExpired;
140        PerRangeDataList    _perRangeDataList;
141};
142
143}
144
145#endif
Note: See TracBrowser for help on using the browser.