1 // Copyright (C) 2008 - 2012 Mathias Froehlich - Mathias.Froehlich@web.de
3 // This library is free software; you can redistribute it and/or
4 // modify it under the terms of the GNU Library General Public
5 // License as published by the Free Software Foundation; either
6 // version 2 of the License, or (at your option) any later version.
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 GNU
11 // Library General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program; if not, write to the Free Software
15 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18 #ifndef SIMGEAR_PRIMITIVE_COLLECTOR_HXX
19 #define SIMGEAR_PRIMITIVE_COLLECTOR_HXX
22 #include <osg/PrimitiveSet>
26 class PrimitiveCollector : public osg::PrimitiveFunctor {
29 virtual ~PrimitiveCollector();
31 void swap(PrimitiveCollector& primitiveFunctor);
33 virtual void setVertexArray(unsigned int count, const osg::Vec2* vertices);
34 virtual void setVertexArray(unsigned int count, const osg::Vec3* vertices);
35 virtual void setVertexArray(unsigned int count, const osg::Vec4* vertices);
36 virtual void setVertexArray(unsigned int count, const osg::Vec2d* vertices);
37 virtual void setVertexArray(unsigned int count, const osg::Vec3d* vertices);
38 virtual void setVertexArray(unsigned int count, const osg::Vec4d* vertices);
40 virtual void drawArrays(GLenum mode, GLint first, GLsizei count);
42 template<typename index_type>
43 void drawElementsTemplate(GLenum mode, GLsizei count, const index_type* indices);
44 virtual void drawElements(GLenum mode, GLsizei count, const GLubyte* indices);
45 virtual void drawElements(GLenum mode, GLsizei count, const GLushort* indices);
46 virtual void drawElements(GLenum mode, GLsizei count, const GLuint* indices);
48 virtual void begin(GLenum mode);
49 virtual void vertex(const osg::Vec2& v);
50 virtual void vertex(const osg::Vec3& v);
51 virtual void vertex(const osg::Vec4& v);
52 virtual void vertex(float x, float y);
53 virtual void vertex(float x, float y, float z);
54 virtual void vertex(float x, float y, float z, float w);
57 void addVertex(const osg::Vec3d& v);
58 void addVertex(const osg::Vec4d& v);
60 void addPoint(unsigned i1);
61 void addLine(unsigned i1, unsigned i2);
62 void addTriangle(unsigned i1, unsigned i2, unsigned i3);
63 void addQuad(unsigned i1, unsigned i2, unsigned i3, unsigned i4);
65 /// The callback functions that are called on an apropriate primitive
66 virtual void addPoint(const osg::Vec3d& v1) = 0;
67 virtual void addLine(const osg::Vec3d& v1, const osg::Vec3d& v2) = 0;
68 virtual void addTriangle(const osg::Vec3d& v1, const osg::Vec3d& v2, const osg::Vec3d& v3) = 0;
71 std::vector<osg::Vec3d> _vertices;