root/OpenSceneGraph/trunk/include/osg/ShapeDrawable @ 13041

Revision 13041, 7.4 kB (checked in by robert, 3 years ago)

Ran script to remove trailing spaces and tabs

  • Property svn:eol-style set to native
  • Property svn:keywords set to Author Date Id Revision
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 OSG_SHAPEDRAWABLE
15#define OSG_SHAPEDRAWABLE 1
16
17#include <osg/Drawable>
18#include <osg/Vec2>
19#include <osg/Vec3>
20#include <osg/Vec4>
21#include <osg/Array>
22#include <osg/PrimitiveSet>
23
24namespace osg {
25
26/** Describe several hints that can be passed to a Tessellator (like the one used
27 *  by \c ShapeDrawable) as a mean to try to influence the way it works.
28 */
29class TessellationHints : public Object
30{
31    public:
32
33    TessellationHints():
34        _TessellationMode(USE_SHAPE_DEFAULTS),
35        _detailRatio(1.0f),
36        _targetNumFaces(100),
37        _createFrontFace(true),
38        _createBackFace(false),
39        _createNormals(true),
40        _createTextureCoords(false),
41        _createTop(true),
42        _createBody(true),
43        _createBottom(true) {}
44
45
46    TessellationHints(const TessellationHints& tess, const CopyOp& copyop=CopyOp::SHALLOW_COPY):
47            Object(tess,copyop),
48        _TessellationMode(tess._TessellationMode),
49            _detailRatio(tess._detailRatio),
50        _targetNumFaces(tess._targetNumFaces),
51        _createFrontFace(tess._createFrontFace),
52        _createBackFace(tess._createBackFace),
53        _createNormals(tess._createNormals),
54        _createTextureCoords(tess._createTextureCoords),
55        _createTop(tess._createTop),
56        _createBody(tess._createBody),
57        _createBottom(tess._createBottom) {}
58
59        META_Object(osg,TessellationHints);
60
61
62        enum TessellationMode
63        {
64            USE_SHAPE_DEFAULTS,
65            USE_TARGET_NUM_FACES
66        };
67
68        inline void setTessellationMode(TessellationMode mode) { _TessellationMode=mode; }
69        inline TessellationMode getTessellationMode() const { return _TessellationMode; }
70
71        inline void setDetailRatio(float ratio) { _detailRatio = ratio; }
72        inline float getDetailRatio() const { return _detailRatio; }
73
74        inline void setTargetNumFaces(unsigned int target) { _targetNumFaces=target; }
75        inline unsigned int getTargetNumFaces() const { return _targetNumFaces; }
76
77        inline void setCreateFrontFace(bool on) { _createFrontFace=on; }
78        inline bool getCreateFrontFace() const { return _createFrontFace; }
79
80        inline void setCreateBackFace(bool on) { _createBackFace=on; }
81        inline bool getCreateBackFace() const { return _createBackFace; }
82
83        inline void setCreateNormals(bool on) { _createNormals=on; }
84        inline bool getCreateNormals() const { return _createNormals; }
85
86        inline void setCreateTextureCoords(bool on) { _createTextureCoords=on; }
87        inline bool getCreateTextureCoords() const { return _createTextureCoords; }
88
89        inline void setCreateTop(bool on) { _createTop=on; }
90        inline bool getCreateTop() const { return _createTop; }
91
92        inline void setCreateBody(bool on) { _createBody=on; }
93        inline bool getCreateBody() const { return _createBody; }
94
95        inline void setCreateBottom(bool on) { _createBottom=on; }
96        inline bool getCreateBottom() const { return _createBottom; }
97
98    protected:
99
100        ~TessellationHints() {}
101
102
103        TessellationMode _TessellationMode;
104
105        float           _detailRatio;
106        unsigned int     _targetNumFaces;
107
108        bool             _createFrontFace;
109        bool             _createBackFace;
110        bool             _createNormals;
111        bool             _createTextureCoords;
112
113        bool             _createTop;
114        bool             _createBody;
115        bool             _createBottom;
116
117};
118
119
120/** Allow the use of <tt>Shape</tt>s as <tt>Drawable</tt>s, so that they can
121 *  be rendered with reduced effort. The implementation of \c ShapeDrawable is
122 *  not geared to efficiency; it's better to think of it as a convenience to
123 *  render <tt>Shape</tt>s easily (perhaps for test or debugging purposes) than
124 *  as the right way to render basic shapes in some efficiency-critical section
125 *  of code.
126 */
127class OSG_EXPORT ShapeDrawable : public Drawable
128{
129    public:
130
131        ShapeDrawable();
132
133        ShapeDrawable(Shape* shape, TessellationHints* hints=0);
134
135        /** Copy constructor using CopyOp to manage deep vs shallow copy.*/
136        ShapeDrawable(const ShapeDrawable& pg,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
137
138        virtual Object* cloneType() const { return new ShapeDrawable(); }
139        virtual Object* clone(const CopyOp& copyop) const { return new ShapeDrawable(*this,copyop); }
140        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const ShapeDrawable*>(obj)!=NULL; }
141        virtual const char* libraryName() const { return "osg"; }
142        virtual const char* className() const { return "ShapeDrawable"; }
143
144        /** Set the color of the shape.*/
145        void setColor(const Vec4& color);
146
147        /** Get the color of the shape.*/
148        const Vec4& getColor() const { return _color; }
149
150        void setTessellationHints(TessellationHints* hints);
151
152        TessellationHints* getTessellationHints() { return _tessellationHints.get(); }
153        const TessellationHints* getTessellationHints() const { return _tessellationHints.get(); }
154
155
156
157        /** Draw ShapeDrawable directly ignoring an OpenGL display list which
158          * could be attached.  This is the internal draw method which does the
159          * drawing itself, and is the method to override when deriving from
160          * ShapeDrawable for user-drawn objects.
161        */
162        virtual void drawImplementation(RenderInfo& renderInfo) const;
163
164        /* Not all virtual overloads of these methods are overridden in this class, so
165           bring the base class implementation in to avoid hiding the non-used ones. */
166        using Drawable::supports;
167        using Drawable::accept;
168
169        /** Return false, osg::ShapeDrawable does not support accept(AttributeFunctor&).*/
170        virtual bool supports(const AttributeFunctor&) const { return false; }
171
172        /** Return true, osg::ShapeDrawable does support accept(Drawable::ConstAttributeFunctor&).*/
173        virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
174
175        /** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has.*/
176        virtual void accept(Drawable::ConstAttributeFunctor& af) const;
177
178        /** Return true, osg::ShapeDrawable does support accept(PrimitiveFunctor&) .*/
179        virtual bool supports(const PrimitiveFunctor&) const { return true; }
180
181        /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has.*/
182        virtual void accept(PrimitiveFunctor& pf) const;
183
184        virtual BoundingBox computeBound() const;
185
186    protected:
187
188        ShapeDrawable& operator = (const ShapeDrawable&) { return *this;}
189
190        virtual ~ShapeDrawable();
191
192        Vec4 _color;
193
194        ref_ptr<TessellationHints> _tessellationHints;
195
196};
197
198
199}
200
201#endif
Note: See TracBrowser for help on using the browser.