openscenegraph
RenderLeaf
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 OSGUTIL_RENDERLEAF
15#define OSGUTIL_RENDERLEAF 1
16
17#include <osg/ref_ptr>
18#include <osg/Matrix>
19#include <osg/Drawable>
20#include <osg/State>
21
22#include <osgUtil/Export>
23
24namespace osgUtil {
25
26#define OSGUTIL_RENDERBACKEND_USE_REF_PTR
27
28// Forward declare StateGraph
29class StateGraph;
30
31/** Container class for all data required for rendering of drawables.
32 */
33class OSGUTIL_EXPORT RenderLeaf : public osg::Referenced
34{
35 public:
36
37
38 inline RenderLeaf(osg::Drawable* drawable,osg::RefMatrix* projection,osg::RefMatrix* modelview, float depth=0.0f, unsigned int traversalOrderNumber=0):
39 osg::Referenced(false),
40 _parent(0),
41 _drawable(drawable),
42 _projection(projection),
43 _modelview(modelview),
44 _depth(depth),
45 _traversalOrderNumber(traversalOrderNumber)
46 {
47 _dynamic = (drawable->getDataVariance()==osg::Object::DYNAMIC);
48 }
49
50
51 inline void set(osg::Drawable* drawable,osg::RefMatrix* projection,osg::RefMatrix* modelview, float depth=0.0f, unsigned int traversalOrderNumber=0)
52 {
53 _parent = 0;
54 _drawable = drawable;
55 _projection = projection;
56 _modelview = modelview;
57 _depth = depth;
58 _dynamic = (drawable->getDataVariance()==osg::Object::DYNAMIC);
59 _traversalOrderNumber = traversalOrderNumber;
60 }
61
62 inline void reset()
63 {
64 _parent = 0;
65 _drawable = 0;
66 _projection = 0;
67 _modelview = 0;
68 _depth = 0.0f;
69 _dynamic = false;
70 _traversalOrderNumber = 0;
71 }
72
73 virtual void render(osg::RenderInfo& renderInfo,RenderLeaf* previous);
74
75 virtual void resizeGLObjectBuffers(unsigned int maxSize)
76 {
77 if (_drawable) _drawable->resizeGLObjectBuffers(maxSize);
78 }
79
80 virtual void releaseGLObjects(osg::State* state=0) const
81 {
82 if (_drawable) _drawable->releaseGLObjects(state);
83 }
84
85 /// Allow StateGraph to change the RenderLeaf's _parent.
86 friend class osgUtil::StateGraph;
87
88 public:
89
90
91
92 StateGraph* _parent;
93
94#ifdef OSGUTIL_RENDERBACKEND_USE_REF_PTR
95 osg::ref_ptr<osg::Drawable> _drawable;
96 const osg::Drawable* getDrawable() const { return _drawable.get(); }
97#else
98 osg::Drawable* _drawable;
99 const osg::Drawable* getDrawable() const { return _drawable; }
100#endif
101 osg::ref_ptr<osg::RefMatrix> _projection;
102 osg::ref_ptr<osg::RefMatrix> _modelview;
103 float _depth;
104 bool _dynamic;
105 unsigned int _traversalOrderNumber;
106
107 private:
108
109 /// disallow creation of blank RenderLeaf as this isn't useful.
110 RenderLeaf():
111 osg::Referenced(false),
112 _parent(0),
113 _drawable(0),
114 _projection(0),
115 _modelview(0),
116 _depth(0.0f),
117 _traversalOrderNumber(0) {}
118
119 /// disallow copy construction.
120 RenderLeaf(const RenderLeaf&):osg::Referenced(false) {}
121 /// disallow copy operator.
122 RenderLeaf& operator = (const RenderLeaf&) { return *this; }
123
124};
125
126}
127
128#endif