Text3D 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  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 OSGTEXT_TEXT3D
  14. #define OSGTEXT_TEXT3D 1
  15. #include <osgText/TextBase>
  16. #include <osgText/Style>
  17. namespace osgText {
  18. class OSGTEXT_EXPORT Text3D : public osgText::TextBase
  19. {
  20. public:
  21. /** Deprecated.*/
  22. enum RenderMode
  23. {
  24. PER_FACE,
  25. PER_GLYPH
  26. };
  27. Text3D();
  28. Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
  29. META_Object(osgText,Text3D)
  30. /** Get the Charactere Depth of text. */
  31. float getCharacterDepth() const;
  32. /** Set the Charactere Depth of text. */
  33. void setCharacterDepth(float characterDepth);
  34. /** Deprecated, value is now ignored. */
  35. RenderMode getRenderMode() const { return _renderMode; }
  36. /** Deprecated, value is now ignored. */
  37. void setRenderMode(RenderMode renderMode) { _renderMode = renderMode; }
  38. /** Get the wall StateSet */
  39. osg::StateSet* getWallStateSet() { return _wallStateSet.get(); }
  40. /** Get the wall StateSet */
  41. const osg::StateSet* getWallStateSet() const { return _wallStateSet.get(); }
  42. /** Get or create the wall StateSet */
  43. osg::StateSet* getOrCreateWallStateSet()
  44. {
  45. if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet;
  46. return _wallStateSet.get();
  47. }
  48. /** Set the wall StateSet */
  49. void setWallStateSet(osg::StateSet* wallStateSet) { _wallStateSet = wallStateSet; }
  50. /** Get the back StateSet */
  51. osg::StateSet* getBackStateSet() { return _backStateSet.get(); }
  52. /** Get the back StateSet */
  53. osg::StateSet* getBackStateSet() const { return _backStateSet.get(); }
  54. /** Get or create the back StateSet */
  55. osg::StateSet* getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
  56. /** Set the back StateSet */
  57. void setBackStateSet(osg::StateSet* backStateSet) { _backStateSet = backStateSet; }
  58. /** Draw the text.*/
  59. virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
  60. /** return false, osgText::Text does not support accept(AttributeFunctor&).*/
  61. virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
  62. /** return true, osgText::Text does support accept(ConstAttributeFunctor&).*/
  63. virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return false; }
  64. /** accept an ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.*/
  65. virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;
  66. /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/
  67. virtual bool supports(const osg::PrimitiveFunctor&) const { return false; }
  68. /** accept a PrimtiveFunctor and call its methods to tell it about the internal primtives that this Drawable has.*/
  69. virtual void accept(osg::PrimitiveFunctor& pf) const;
  70. /** Resize any per context GLObject buffers to specified size. */
  71. virtual void resizeGLObjectBuffers(unsigned int maxSize);
  72. /** If State is non-zero, this function releases OpenGL objects for
  73. * the specified graphics context. Otherwise, releases OpenGL objexts
  74. * for all graphics contexts. */
  75. virtual void releaseGLObjects(osg::State* state=0) const;
  76. // make Font a friend to allow it set the _font to 0 if the font is
  77. // forcefully unloaded.
  78. friend class Font;
  79. virtual osg::BoundingBox computeBoundingBox() const;
  80. protected:
  81. virtual ~Text3D() {}
  82. String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
  83. void computeGlyphRepresentation();
  84. void copyAndOffsetPrimitiveSets(osg::Geometry::PrimitiveSetList& dest_PrimitiveSetList, osg::Geometry::PrimitiveSetList& src_PrimitiveSetList, unsigned int offset);
  85. osg::Geometry::PrimitiveSetList _frontPrimitiveSetList;
  86. osg::Geometry::PrimitiveSetList _wallPrimitiveSetList;
  87. osg::Geometry::PrimitiveSetList _backPrimitiveSetList;
  88. // ** glyph and other information to render the glyph
  89. struct GlyphRenderInfo
  90. {
  91. GlyphRenderInfo(GlyphGeometry* glyphGeometry, osg::Vec3 & pos):
  92. _glyphGeometry(glyphGeometry),
  93. _position(pos) {}
  94. osg::ref_ptr<GlyphGeometry> _glyphGeometry;
  95. osg::Vec3 _position;
  96. };
  97. typedef std::vector<GlyphRenderInfo> LineRenderInfo;
  98. typedef std::vector<LineRenderInfo> TextRenderInfo;
  99. TextRenderInfo _textRenderInfo;
  100. // deprecated value no longer used.
  101. RenderMode _renderMode;
  102. osg::ref_ptr<osg::StateSet> _wallStateSet;
  103. osg::ref_ptr<osg::StateSet> _backStateSet;
  104. };
  105. }
  106. #endif