root/OpenSceneGraph/trunk/include/osg/Geometry @ 13557

Revision 13557, 14.7 kB (checked in by robert, 3 hours ago)

Fixed rendering of Popups

  • 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_GEOMETRY
15#define OSG_GEOMETRY 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
26class OSG_EXPORT Geometry : public Drawable
27{
28    public:
29
30        Geometry();
31
32        /** Copy constructor using CopyOp to manage deep vs shallow copy. */
33        Geometry(const Geometry& geometry,const CopyOp& copyop=CopyOp::SHALLOW_COPY);
34
35        virtual Object* cloneType() const { return new Geometry(); }
36        virtual Object* clone(const CopyOp& copyop) const { return new Geometry(*this,copyop); }
37        virtual bool isSameKindAs(const Object* obj) const { return dynamic_cast<const Geometry*>(obj)!=NULL; }
38        virtual const char* libraryName() const { return "osg"; }
39        virtual const char* className() const { return "Geometry"; }
40
41        virtual Geometry* asGeometry() { return this; }
42        virtual const Geometry* asGeometry() const { return this; }
43
44        bool empty() const;
45
46        typedef std::vector< osg::ref_ptr<osg::Array> >  ArrayList;
47
48        void setVertexArray(Array* array);
49        Array* getVertexArray() { return _vertexArray.get(); }
50        const Array* getVertexArray() const  { return _vertexArray.get(); }
51
52
53        void setNormalArray(Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
54        Array* getNormalArray() { return _normalArray.get(); }
55        const Array* getNormalArray() const { return _normalArray.get(); }
56
57
58
59        void setColorArray(Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
60        Array* getColorArray() { return _colorArray.get(); }
61        const Array* getColorArray() const { return _colorArray.get(); }
62
63
64
65        void setSecondaryColorArray(Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
66        Array* getSecondaryColorArray() { return _secondaryColorArray.get(); }
67        const Array* getSecondaryColorArray() const  { return _secondaryColorArray.get(); }
68
69
70        void setFogCoordArray(Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
71        Array* getFogCoordArray() { return _fogCoordArray.get(); }
72        const Array* getFogCoordArray() const { return _fogCoordArray.get(); }
73
74
75        void setTexCoordArray(unsigned int unit,Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
76        Array* getTexCoordArray(unsigned int unit);
77        const Array* getTexCoordArray(unsigned int unit) const;
78
79        unsigned int getNumTexCoordArrays() const {  return static_cast<unsigned int>(_texCoordList.size()); }
80        ArrayList& getTexCoordArrayList() { return _texCoordList; }
81        const ArrayList& getTexCoordArrayList() const { return _texCoordList; }
82
83
84
85        void setVertexAttribArray(unsigned int index, Array* array, osg::Array::Binding binding=osg::Array::BIND_UNDEFINED);
86        Array *getVertexAttribArray(unsigned int index);
87        const Array *getVertexAttribArray(unsigned int index) const;
88
89
90        unsigned int getNumVertexAttribArrays() const { return static_cast<unsigned int>(_vertexAttribList.size()); }
91        ArrayList& getVertexAttribArrayList() { return _vertexAttribList; }
92        const ArrayList& getVertexAttribArrayList() const { return _vertexAttribList; }
93
94
95
96        typedef std::vector< ref_ptr<PrimitiveSet> > PrimitiveSetList;
97
98        void setPrimitiveSetList(const PrimitiveSetList& primitives);
99
100        PrimitiveSetList& getPrimitiveSetList() { return _primitives; }
101        const PrimitiveSetList& getPrimitiveSetList() const { return _primitives; }
102
103        unsigned int getNumPrimitiveSets() const { return static_cast<unsigned int>(_primitives.size()); }
104        PrimitiveSet* getPrimitiveSet(unsigned int pos) { return _primitives[pos].get(); }
105        const PrimitiveSet* getPrimitiveSet(unsigned int pos) const { return _primitives[pos].get(); }
106
107        /** Add a primitive set to the geometry. */
108        bool addPrimitiveSet(PrimitiveSet* primitiveset);
109
110        /** Set a primitive set to the specified position in geometry's primitive set list. */
111        bool setPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
112
113        /** Insert a primitive set to the specified position in geometry's primitive set list. */
114        bool insertPrimitiveSet(unsigned int i,PrimitiveSet* primitiveset);
115
116        /** Remove primitive set(s) from the specified position in geometry's primitive set list. */
117        bool removePrimitiveSet(unsigned int i,unsigned int numElementsToRemove=1);
118
119        /** Get the index number of a primitive set, return a value between
120          * 0 and getNumPrimitiveSet()-1 if found, if not found then return getNumPrimitiveSet().
121          * When checking for a valid find value use if ((value=geometry->getPrimitiveSetIndex(primitive))!=geometry.getNumPrimitiveSet())
122        */
123        unsigned int getPrimitiveSetIndex(const PrimitiveSet* primitiveset) const;
124
125
126        /** return true if any arrays are shared.*/
127        bool containsSharedArrays() const;
128
129        /** duplicate any shared arrays.*/
130        void duplicateSharedArrays();
131
132
133        /** When set to true, ignore the setUseDisplayList() settings, and hints to the drawImplementation
134            method to use OpenGL vertex buffer objects for rendering.*/
135        virtual void setUseVertexBufferObjects(bool flag);
136
137        /** Force a recompile on next draw() of any OpenGL display list associated with this geoset.*/
138        virtual void dirtyDisplayList();
139
140
141        /** Resize any per context GLObject buffers to specified size. */
142        virtual void resizeGLObjectBuffers(unsigned int maxSize);
143
144        /** If State is non-zero, this function releases OpenGL objects for
145          * the specified graphics context. Otherwise, releases OpenGL objects
146          * for all graphics contexts. */
147        virtual void releaseGLObjects(State* state=0) const;
148
149        bool getArrayList(ArrayList& arrayList) const;
150
151        typedef std::vector<osg::DrawElements*>  DrawElementsList;
152        bool getDrawElementsList(DrawElementsList& drawElementsList) const;
153
154        osg::VertexBufferObject* getOrCreateVertexBufferObject();
155        osg::ElementBufferObject* getOrCreateElementBufferObject();
156
157
158        /** Return the estimated size of GLObjects (display lists/vertex buffer objects) that are associated with this drawable.
159          * This size is used a hint for reuse of deleted display lists/vertex buffer objects. */
160        virtual unsigned int getGLObjectSizeHint() const;
161
162        /** Immediately compile this \c Drawable into an OpenGL Display List/VertexBufferObjects.
163          * @note Operation is ignored if \c _useDisplayList is \c false or VertexBufferObjects are not used.
164        */
165        virtual void compileGLObjects(RenderInfo& renderInfo) const;
166
167        /** Draw Geometry directly ignoring an OpenGL display list which could be attached.
168          * This is the internal draw method which does the drawing itself,
169          * and is the method to override when deriving from Geometry for user-drawn objects.
170        */
171        virtual void drawImplementation(RenderInfo& renderInfo) const;
172
173        /** Return true, osg::Geometry does support accept(Drawable::AttributeFunctor&). */
174        virtual bool supports(const Drawable::AttributeFunctor&) const { return true; }
175
176        /** Accept an Drawable::AttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
177        virtual void accept(Drawable::AttributeFunctor& af);
178
179        /** Return true, osg::Geometry does support accept(Drawable::ConstAttributeFunctor&). */
180        virtual bool supports(const Drawable::ConstAttributeFunctor&) const { return true; }
181
182        /** Accept a Drawable::ConstAttributeFunctor and call its methods to tell it about the internal attributes that this Drawable has. */
183        virtual void accept(Drawable::ConstAttributeFunctor& af) const;
184
185        /** Return true, osg::Geometry does support accept(PrimitiveFunctor&). */
186        virtual bool supports(const PrimitiveFunctor&) const { return true; }
187
188        /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
189        virtual void accept(PrimitiveFunctor& pf) const;
190
191        /** Return true, osg::Geometry does support accept(PrimitiveIndexFunctor&). */
192        virtual bool supports(const PrimitiveIndexFunctor&) const { return true; }
193
194        /** Accept a PrimitiveFunctor and call its methods to tell it about the internal primitives that this Drawable has. */
195        virtual void accept(PrimitiveIndexFunctor& pf) const;
196
197
198    protected:
199
200        Geometry& operator = (const Geometry&) { return *this;}
201
202        virtual ~Geometry();
203
204
205        void addVertexBufferObjectIfRequired(osg::Array* array);
206        void addElementBufferObjectIfRequired(osg::PrimitiveSet* primitiveSet);
207
208
209        PrimitiveSetList                _primitives;
210        osg::ref_ptr<Array>             _vertexArray;
211        osg::ref_ptr<Array>             _normalArray;
212        osg::ref_ptr<Array>             _colorArray;
213        osg::ref_ptr<Array>             _secondaryColorArray;
214        osg::ref_ptr<Array>             _fogCoordArray;
215        ArrayList                       _texCoordList;
216        ArrayList                       _vertexAttribList;
217
218        bool                            _containsDeprecatedData;
219
220    public:
221
222
223        /** Return true if the deprecated use array indicies or BIND_PER_PRIMITIVE binding has been assigned to arrays.*/
224        bool containsDeprecatedData() const { return  _containsDeprecatedData; }
225
226        /** fallback for deprecated functionality. Return true if the Geometry contains any array indices or BIND_PER_PRIMITIVE arrays. */
227        bool checkForDeprecatedData();
228
229        /** fallback for deprecated functionality. Removes any array indices and BIND_PER_PRIMITIVE arrays.*/
230        void fixDeprecatedData();
231
232        /** Same values as Array::Binding.*/
233        enum AttributeBinding
234        {
235            BIND_OFF=0,
236            BIND_OVERALL=1,
237            BIND_PER_PRIMITIVE_SET=2,
238            BIND_PER_VERTEX=4
239        };
240
241        /** deprecated, use array->setBinding(..). */
242        void setNormalBinding(AttributeBinding ab);
243        AttributeBinding getNormalBinding() const;
244
245        /** deprecated, use array->setBinding(..). */
246        void setColorBinding(AttributeBinding ab);
247        AttributeBinding getColorBinding() const;
248
249        /** deprecated, use array->setBinding(..). */
250        void setSecondaryColorBinding(AttributeBinding ab);
251        AttributeBinding getSecondaryColorBinding() const;
252
253        /** deprecated, use array->setBinding(..). */
254        void setFogCoordBinding(AttributeBinding ab);
255        AttributeBinding getFogCoordBinding() const;
256
257        /** deprecated, use array->setBinding(..). */
258        void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
259        AttributeBinding getVertexAttribBinding(unsigned int index) const;
260
261        /** deprecated, use array->setNormalize(..). */
262        void setVertexAttribNormalize(unsigned int index,GLboolean norm);
263        GLboolean getVertexAttribNormalize(unsigned int index) const;
264};
265
266/** Convenience function to be used for creating quad geometry with texture coords.
267  * Tex coords go from left bottom (l,b) to right top (r,t).
268*/
269extern OSG_EXPORT Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float l, float b, float r, float t);
270
271/** Convenience function to be used for creating quad geometry with texture coords.
272  * Tex coords go from bottom left (0,0) to top right (s,t).
273*/
274inline Geometry* createTexturedQuadGeometry(const Vec3& corner,const Vec3& widthVec,const Vec3& heightVec, float s=1.0f, float t=1.0f)
275{
276    return createTexturedQuadGeometry(corner,widthVec,heightVec, 0.0f, 0.0f, s, t);
277}
278
279} // namespace osg
280
281
282#include <osg/Notify>
283
284/** Contains deprecated features of namespace osg. */
285namespace deprecated_osg {
286
287/** Geometry class contaning deprecated features.
288  * Please note this class is \b not "exported" (OSG_EXPORT) to avoid issues with MSVC, when compiling plugins.
289*/
290class OSG_EXPORT Geometry : public osg::Geometry
291{
292    public:
293        Geometry() : osg::Geometry() {}
294        Geometry(const Geometry& geometry,const osg::CopyOp& copyop=osg::CopyOp::SHALLOW_COPY) : osg::Geometry(geometry, copyop) {}
295
296        /** Same values as Array::Binding.*/
297        enum AttributeBinding
298        {
299            BIND_OFF=0,
300            BIND_OVERALL=1,
301            BIND_PER_PRIMITIVE_SET=2,
302            BIND_PER_PRIMITIVE=3,
303            BIND_PER_VERTEX=4
304        };
305
306        void setNormalBinding(AttributeBinding ab);
307        AttributeBinding getNormalBinding() const;
308
309        void setColorBinding(AttributeBinding ab);
310        AttributeBinding getColorBinding() const;
311
312        void setSecondaryColorBinding(AttributeBinding ab);
313        AttributeBinding getSecondaryColorBinding() const;
314
315        void setFogCoordBinding(AttributeBinding ab);
316        AttributeBinding getFogCoordBinding() const;
317
318        void setVertexAttribBinding(unsigned int index,AttributeBinding ab);
319        AttributeBinding getVertexAttribBinding(unsigned int index) const;
320
321        void setVertexAttribNormalize(unsigned int index,GLboolean norm);
322        GLboolean getVertexAttribNormalize(unsigned int index) const;
323
324        void setVertexIndices(osg::IndexArray* array);
325        const osg::IndexArray* getVertexIndices() const;
326
327        void setNormalIndices(osg::IndexArray* array);
328        const osg::IndexArray* getNormalIndices() const;
329
330        void setColorIndices(osg::IndexArray* array);
331        const osg::IndexArray* getColorIndices() const;
332
333        void setSecondaryColorIndices(osg::IndexArray* array);
334        const osg::IndexArray* getSecondaryColorIndices() const;
335
336        void setFogCoordIndices(osg::IndexArray* array);
337        const osg::IndexArray* getFogCoordIndices() const;
338
339        void setTexCoordIndices(unsigned int unit,osg::IndexArray* array);
340        const osg::IndexArray* getTexCoordIndices(unsigned int unit) const;
341
342        void setVertexAttribIndices(unsigned int index,osg::IndexArray* array);
343        const osg::IndexArray* getVertexAttribIndices(unsigned int index) const;
344
345};
346
347} // namespace deprecated_osg
348
349#endif
Note: See TracBrowser for help on using the browser.