root/OpenSceneGraph/trunk/include/osg/Geode @ 13041

Revision 13041, 6.5 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • 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_GEODE
15#define OSG_GEODE 1
16
17#include <osg/Node>
18#include <osg/NodeVisitor>
19#include <osg/Drawable>
20
21namespace osg {
22
23/** A \c Geode is a "geometry node", that is, a leaf node on the scene graph
24  * that can have "renderable things" attached to it. In OSG, renderable things
25  * are represented by objects from the \c Drawable class, so a \c Geode is a
26  * \c Node whose purpose is grouping <tt>Drawable</tt>s.
27*/
28class OSG_EXPORT Geode : public Node
29{
30    public:
31
32        typedef std::vector< ref_ptr<Drawable> > DrawableList;
33
34        Geode();
35
36        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
37        Geode(const Geode&,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
38
39        META_Node(osg, Geode);
40
41        virtual Geode* asGeode() { return this; }
42        virtual const Geode* asGeode() const { return this; }
43
44        /** Add a \c Drawable to the \c Geode.
45          * If \c drawable is not \c NULL and is not contained in the \c Geode
46          * then increment its reference count, add it to the drawables list and
47          * dirty the bounding sphere to force it to be recomputed on the next
48          * call to \c getBound().
49          * @param drawable The \c Drawable to be added to the \c Geode.
50          * @return  \c true for success; \c false otherwise.
51        */
52        virtual bool addDrawable( Drawable *drawable );
53
54        /** Remove a \c Drawable from the \c Geode.
55          * Equivalent to <tt>removeDrawable(getDrawableIndex(drawable)</tt>.
56          * @param drawable The drawable to be removed.
57          * @return \c true if at least one \c Drawable was removed. \c false
58          *         otherwise.
59        */
60        virtual bool removeDrawable( Drawable *drawable );
61
62        /** Remove <tt>Drawable</tt>(s) from the specified position in
63          * <tt>Geode</tt>'s drawable list.
64          * @param i The index of the first \c Drawable to remove.
65          * @param numDrawablesToRemove The number of <tt>Drawable</tt> to
66          *        remove.
67          * @return \c true if at least one \c Drawable was removed. \c false
68          *         otherwise.
69        */
70        virtual bool removeDrawables(unsigned int i,unsigned int numDrawablesToRemove=1);
71
72        /** Replace specified Drawable with another Drawable.
73         * Equivalent to <tt>setDrawable(getDrawableIndex(origDraw),newDraw)</tt>,
74         * see docs for \c setDrawable() for further details on implementation.
75        */
76        virtual bool replaceDrawable( Drawable *origDraw, Drawable *newDraw );
77
78        /** Set \c Drawable at position \c i.
79          * Decrement the reference count origGSet and increments the
80          * reference count of newGset, and dirty the bounding sphere
81          * to force it to recompute on next getBound() and returns true.
82          * If origDrawable is not found then return false and do not
83          * add newGset.  If newGset is NULL then return false and do
84          * not remove origGset.
85          * @return \c true if set correctly, \c false on failure
86          *         (if node==NULL || i is out of range).
87        */
88        virtual bool setDrawable( unsigned int i, Drawable* drawable );
89
90        /** Return the number of <tt>Drawable</tt>s currently attached to the
91          * \c Geode.
92        */
93        inline unsigned int getNumDrawables() const { return _drawables.size(); }
94
95        /** Return the \c Drawable at position \c i.*/
96        inline Drawable* getDrawable( unsigned int i ) { return _drawables[i].get(); }
97
98        /** Return the \c Drawable at position \c i.*/
99        inline const Drawable* getDrawable( unsigned int i ) const { return _drawables[i].get(); }
100
101        /** Return \c true if a given \c Drawable is contained within \c Geode.*/
102        inline bool containsDrawable(const Drawable* gset) const
103        {
104            for (DrawableList::const_iterator itr=_drawables.begin();
105                 itr!=_drawables.end();
106                 ++itr)
107            {
108                if (itr->get()==gset) return true;
109            }
110            return false;
111        }
112
113        /** Get the index number of \c drawable.
114          * @return A value between 0 and <tt>getNumDrawables()-1</tt> if
115          *         \c drawable is found; if not found, then
116          *         <tt>getNumDrawables()</tt> is returned.
117        */
118        inline unsigned int getDrawableIndex( const Drawable* drawable ) const
119        {
120            for (unsigned int drawableNum=0;drawableNum<_drawables.size();++drawableNum)
121            {
122                if (_drawables[drawableNum]==drawable) return drawableNum;
123            }
124            return _drawables.size(); // drawable not found.
125        }
126
127        /** Get the list of drawables.*/
128        const DrawableList& getDrawableList() const { return _drawables; }
129
130        /** Compile OpenGL Display List for each drawable.*/
131        void compileDrawables(RenderInfo& renderInfo);
132
133        /** Return the Geode's bounding box, which is the union of all the
134          * bounding boxes of the geode's drawables.*/
135        inline const BoundingBox& getBoundingBox() const
136        {
137            if(!_boundingSphereComputed) getBound();
138            return _bbox;
139        }
140
141        virtual BoundingSphere computeBound() const;
142
143        /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
144        virtual void setThreadSafeRefUnref(bool threadSafe);
145
146        /** Resize any per context GLObject buffers to specified size. */
147        virtual void resizeGLObjectBuffers(unsigned int maxSize);
148
149        /** If State is non-zero, this function releases any associated OpenGL objects for
150           * the specified graphics context. Otherwise, releases OpenGL objects
151           * for all graphics contexts. */
152        virtual void releaseGLObjects(osg::State* = 0) const;
153
154
155    protected:
156
157        virtual ~Geode();
158
159
160        mutable osg::BoundingBox        _bbox;
161        DrawableList                    _drawables;
162
163};
164
165}
166
167#endif
Note: See TracBrowser for help on using the browser.