RenderLeaf 3.9 KB

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