]> git.mxchange.org Git - simgear.git/blob - simgear/scene/model/PrimitiveCollector.hxx
Fixed a crash: the singleton needs to be instantiated the first time SGCommandMgr...
[simgear.git] / simgear / scene / model / PrimitiveCollector.hxx
1 // Copyright (C) 2008 - 2012  Mathias Froehlich - Mathias.Froehlich@web.de
2 //
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.
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 GNU
11 // Library General Public License for more details.
12 //
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.
16 //
17
18 #ifndef SIMGEAR_PRIMITIVE_COLLECTOR_HXX
19 #define SIMGEAR_PRIMITIVE_COLLECTOR_HXX
20
21 #include <osg/Matrix>
22 #include <osg/PrimitiveSet>
23
24 namespace simgear {
25
26 class PrimitiveCollector : public osg::PrimitiveFunctor {
27 public:
28     PrimitiveCollector();
29     virtual ~PrimitiveCollector();
30     
31     void swap(PrimitiveCollector& primitiveFunctor);
32
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);
39
40     virtual void drawArrays(GLenum mode, GLint first, GLsizei count);
41   
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);
47
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);
55     virtual void end();
56
57     void addVertex(const osg::Vec3d& v);
58     void addVertex(const osg::Vec4d& v);
59
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);
64
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;
69
70 private:
71     std::vector<osg::Vec3d> _vertices;
72     GLenum _mode;
73 };
74
75 }
76
77 #endif