root/OpenSceneGraph/trunk/include/osgText/Text3D @ 9881

Revision 9881, 6.1 kB (checked in by robert, 5 years ago)

From David Callu, "Problem:

osgText::Text and osgText::Text3D use the same font file.
The first really load the file and obtain an osgText::Font object,
the second use the cache created during the first load of the
font file, and so obtain an osgText::Font object instead of
osgText::Font3D object. To obtain an osgText::Font3D object,
osgText::Text3D call osgDB::readObjectFile(...) with an option
to specify the plugin we want an osgText::Font3D instead of
osgText::Font.

Generalised Problem:

In osgDB::Registry, loaded file cache is referenced by the name
of this file, so if I load a file with some options, and the cache
already contain object for this filename, I obtain an object
potentially not loaded with my options.

Behaviours:

Cache management is delegate to osgDB::Registry, but cache
coherence (load a file with option then reuse it, deactivate the
cache when load a specific file or don't cached the loaded file)
is user's responsibility.

Text3D solution:

Postfix the font file name by .text3d or something similar and then have the freetype plugin return
osgText::Font3D when it detects this.
This operation is done by osgText::readFont3DFile() which unsure the filename have .text3d as extension.
This is totaly transparent for user, and backward compatible.

BTW, I fix the bug about the Normal of 3D text. Currently, the front and wall face have
the same normal (0,0,1) in the Text3D object coordinate. Now the wall face have its own
normal array computed by the plugin.

BTW 2, I implement
- void Text3D::accept(osg::Drawable::ConstAttributeFunctor?& af) const
- void Text3D::accept(osg::PrimitiveFunctor?& pf) const
so now statistics are well reported.
"

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 OSGTEXT_TEXT3D
15#define OSGTEXT_TEXT3D 1
16
17
18#include <osgText/TextBase>
19#include <osgText/Font3D>
20
21
22namespace osgText {
23
24
25class OSGTEXT_EXPORT Text3D : public osgText::TextBase
26{
27public:
28
29    /** Reder mode used to render the Text.
30     * PER_FACE : render all front face with the default StateSet
31     *                   all wall face with the wall StateSet
32     *                   all back face with the back StateSet (back face of the character, no the OpenGL back face)
33     *
34     * PER_GLYPH : render all Charactere with the default StateSet
35     */
36    enum RenderMode
37    {
38        PER_FACE,
39        PER_GLYPH
40    };
41
42    Text3D();
43    Text3D(const Text3D& text,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY);
44
45    META_Object(osgText,Text3D)
46
47    /** Get the Charactere Depth of text. */
48    float getCharacterDepth() const { return _characterDepth; }
49    /** Set the Charactere Depth of text. */
50    void setCharacterDepth(float characterDepth) { _characterDepth = characterDepth; computeGlyphRepresentation(); }
51
52    /** Get the render mode used to render the text. */
53    RenderMode getRenderMode() const { return _renderMode; }
54    /** Set the render mode used to render the text. */
55    void setRenderMode(RenderMode renderMode) { _renderMode = renderMode; computeGlyphRepresentation(); }
56
57//    /** Get the wall StateSet */
58//    osg::StateSet * getWallStateSet() { return _wallStateSet.get(); }
59//    /** Get or create the wall StateSet */
60//    osg::StateSet * getOrCreateWallStateSet()
61//    {
62//        if (_wallStateSet.valid() == false) _wallStateSet = new osg::StateSet;
63//        return _wallStateSet.get();
64//    }
65//    /** Set the wall StateSet */
66//    void setWallStateSet(osg::StateSet * wallStateSet)  { _wallStateSet = wallStateSet; }
67//
68//    /** Get the back StateSet */
69//    osg::StateSet * getBackStateSet() { return _backStateSet.get(); }
70//    /** Get or create the back StateSet */
71//    osg::StateSet * getOrCreateBackStateSet() { if (_backStateSet.valid() == false) _backStateSet = new osg::StateSet; return _backStateSet.get(); }
72//    /** Set the back StateSet */
73//    void setBackStateSet(osg::StateSet * backStateSet)  { _backStateSet = backStateSet; }
74//
75
76    /** Set the Font to use to render the text.
77      * setFont(0) sets the use of the default font.*/
78    inline void setFont(Font3D* font=0) { setFont(osg::ref_ptr<Font3D>(font)); };
79
80    /** Set the Font to use to render the text.*/
81    void setFont(osg::ref_ptr<Font3D> font);
82
83
84    /** Set the font, loaded from the specified front file, to use to render the text,
85      * setFont("") sets the use of the default font.
86      * See the osgText::readFontFile function for how the font file will be located. */
87    void setFont(const std::string& fontfile);
88
89    /** Get the font. Return 0 if default is being used.*/
90    const Font3D* getFont() const { return _font.get(); }
91
92
93
94
95    /** Draw the text.*/
96    virtual void drawImplementation(osg::RenderInfo& renderInfo) const;
97
98    /** return false, osgText::Text does not support accept(AttributeFunctor&).*/
99    virtual bool supports(const osg::Drawable::AttributeFunctor&) const { return false; }
100
101    /** return true, osgText::Text does support accept(ConstAttributeFunctor&).*/
102    virtual bool supports(const osg::Drawable::ConstAttributeFunctor&) const { return false; }
103
104    /** accept an ConstAttributeFunctor and call its methods to tell it about the interal attributes that this Drawable has.*/
105    virtual void accept(osg::Drawable::ConstAttributeFunctor& af) const;
106
107    /** return true, osgText::Text does support accept(PrimitiveFunctor&) .*/
108    virtual bool supports(const osg::PrimitiveFunctor&) const { return false; }
109
110    /** accept a PrimtiveFunctor and call its methods to tell it about the interal primtives that this Drawable has.*/
111    virtual void accept(osg::PrimitiveFunctor& pf) const;
112
113
114    /** Set whether to use a mutex to ensure ref() and unref() are thread safe.*/
115    virtual void setThreadSafeRefUnref(bool threadSafe);
116
117    /** Resize any per context GLObject buffers to specified size. */
118    virtual void resizeGLObjectBuffers(unsigned int maxSize);
119
120    /** If State is non-zero, this function releases OpenGL objects for
121      * the specified graphics context. Otherwise, releases OpenGL objexts
122      * for all graphics contexts. */
123    virtual void releaseGLObjects(osg::State* state=0) const;
124
125//    // make Font a friend to allow it set the _font to 0 if the font is
126//    // forcefully unloaded.
127    friend class Font3D;
128
129    virtual osg::BoundingBox computeBound() const;
130
131
132protected:
133
134    virtual ~Text3D() {}
135
136    void renderPerGlyph(osg::State & state) const;
137    void renderPerFace(osg::State & state) const;
138
139    String::iterator computeLastCharacterOnLine(osg::Vec2& cursor, String::iterator first,String::iterator last);
140
141    void computeGlyphRepresentation();
142    void computePositions(unsigned int contextID) const;
143
144    // ** glyph and other information to render the glyph
145    struct GlyphRenderInfo
146    {
147        GlyphRenderInfo(Font3D::Glyph3D * glyph, osg::Vec3 & pos) :
148            _glyph(glyph), _position(pos) {}
149
150        osg::ref_ptr<Font3D::Glyph3D> _glyph;
151        osg::Vec3 _position;
152    };
153
154    typedef std::vector<GlyphRenderInfo> LineRenderInfo;
155    typedef std::vector<LineRenderInfo> TextRenderInfo;
156
157    TextRenderInfo _textRenderInfo;
158
159    osg::ref_ptr<Font3D> _font;
160
161    float _characterDepth;
162
163    RenderMode _renderMode;
164
165    osg::ref_ptr<osg::StateSet> _wallStateSet;
166    osg::ref_ptr<osg::StateSet> _backStateSet;
167};
168
169}
170
171
172#endif
Note: See TracBrowser for help on using the browser.