Outline 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // -*-c++-*-
  2. /*
  3. * OpenSceneGraph - Copyright (C) 1998-2009 Robert Osfield
  4. *
  5. * This library is open source and may be redistributed and/or modified under
  6. * the terms of the OpenSceneGraph Public License (OSGPL) version 0.0 or
  7. * (at your option) any later version. The full license is in LICENSE file
  8. * included with this distribution, and on the openscenegraph.org website.
  9. *
  10. * This library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * OpenSceneGraph Public License for more details.
  14. */
  15. /*
  16. * osgFX::Outline - Copyright (C) 2004,2009 Ulrich Hertlein
  17. */
  18. #ifndef OSGFX_OUTLINE_
  19. #define OSGFX_OUTLINE_
  20. #include <osgFX/Export>
  21. #include <osgFX/Effect>
  22. namespace osgFX
  23. {
  24. /**
  25. * Outline effect.
  26. * This effect draws a stencil buffer-based outline around an object.
  27. * Color and width of the outline can be modified.
  28. * To function correctly the context must be setup with a stencil buffer
  29. * and the stencil buffer must be cleared to zero before each render.
  30. *
  31. * osg::DisplaySettings::instance()->setMinimumNumStencilBits(1);
  32. * camera->setClearMask(clearMask | GL_STENCIL_BUFFER_BIT);
  33. * camera->setClearStencil(0);
  34. */
  35. class OSGFX_EXPORT Outline : public Effect
  36. {
  37. public:
  38. /// Constructor.
  39. Outline();
  40. /// Copy constructor.
  41. Outline(const Outline& copy, const osg::CopyOp& op = osg::CopyOp::SHALLOW_COPY) : Effect(copy, op) {
  42. _width = copy._width;
  43. _color = copy._color;
  44. _technique = copy._technique;
  45. }
  46. // Effect class info
  47. META_Effect(osgFX, Outline, "Outline",
  48. "Stencil buffer based object outline effect.\n"
  49. "This effect needs a properly setup stencil buffer.",
  50. "Ulrich Hertlein");
  51. /// Set outline width.
  52. void setWidth(float w);
  53. /// Get outline width.
  54. float getWidth() const {
  55. return _width;
  56. }
  57. /// Set outline color.
  58. void setColor(const osg::Vec4& color);
  59. /// Get outline color.
  60. const osg::Vec4& getColor() const {
  61. return _color;
  62. }
  63. protected:
  64. /// Destructor.
  65. virtual ~Outline() {
  66. }
  67. /// Define available techniques.
  68. bool define_techniques();
  69. private:
  70. /// Outline width.
  71. float _width;
  72. /// Outline color.
  73. osg::Vec4 _color;
  74. /// Technique.
  75. class OutlineTechnique;
  76. OutlineTechnique* _technique;
  77. };
  78. }
  79. #endif