1 /*
2  Copyright (C) 2010-2014 Kristian Duske
3 
4  This file is part of TrenchBroom.
5 
6  TrenchBroom is free software: you can redistribute it and/or modify
7  it under the terms of the GNU General Public License as published by
8  the Free Software Foundation, either version 3 of the License, or
9  (at your option) any later version.
10 
11  TrenchBroom is distributed in the hope that it will be useful,
12  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  GNU General Public License for more details.
15 
16  You should have received a copy of the GNU General Public License
17  along with TrenchBroom. If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef TrenchBroom_VertexSpec
21 #define TrenchBroom_VertexSpec
22 
23 #include "Vec.h"
24 #include "Renderer/GL.h"
25 #include "Renderer/AttributeSpec.h"
26 #include "Renderer/Vertex.h"
27 
28 #include <vector>
29 
30 namespace TrenchBroom {
31     namespace Renderer {
32         template <typename _A1>
33         class VertexSpec1 {
34         public:
35             typedef _A1 A1;
36             typedef Vertex1<_A1> Vertex;
37             static const size_t Size;
38         public:
setup(const size_t baseOffset)39             static void setup(const size_t baseOffset) {
40                 _A1::setup(0, Size, baseOffset);
41             }
42 
cleanup()43             static void cleanup() {
44                 _A1::cleanup(0);
45             }
46         private:
47             VertexSpec1();
48         };
49 
50         template <typename A1>
51         const size_t VertexSpec1<A1>::Size = sizeof(VertexSpec1<A1>::Vertex);
52 
53         template <typename _A1, typename _A2>
54         class VertexSpec2 {
55         public:
56             typedef _A1 A1;
57             typedef _A2 A2;
58             typedef Vertex2<_A1, _A2> Vertex;
59             static const size_t Size;
60         public:
setup(const size_t baseOffset)61             static void setup(const size_t baseOffset) {
62                 _A1::setup(0, Size, baseOffset);
63                 _A2::setup(1, Size, baseOffset + _A1::Size);
64             }
65 
cleanup()66             static void cleanup() {
67                 _A2::cleanup(1);
68                 _A1::cleanup(0);
69             }
70         private:
71             VertexSpec2();
72         };
73 
74         template <typename A1, typename A2>
75         const size_t VertexSpec2<A1, A2>::Size = sizeof(VertexSpec2<A1, A2>::Vertex);
76 
77         template <typename _A1, typename _A2, typename _A3>
78         class VertexSpec3 {
79         public:
80             typedef _A1 A1;
81             typedef _A2 A2;
82             typedef _A3 A3;
83             typedef Vertex3<_A1, _A2, _A3> Vertex;
84             static const size_t Size;
85         public:
setup(const size_t baseOffset)86             static void setup(const size_t baseOffset) {
87                 _A1::setup(0, Size, baseOffset);
88                 _A2::setup(1, Size, baseOffset + _A1::Size);
89                 _A3::setup(2, Size, baseOffset + _A1::Size + _A2::Size);
90             }
91 
cleanup()92             static void cleanup() {
93                 _A3::cleanup(2);
94                 _A2::cleanup(1);
95                 _A1::cleanup(0);
96             }
97         private:
98             VertexSpec3();
99         };
100 
101         template <typename A1, typename A2, typename A3>
102         const size_t VertexSpec3<A1, A2, A3>::Size = sizeof(VertexSpec3<A1, A2, A3>::Vertex);
103 
104         template <typename _A1, typename _A2, typename _A3, typename _A4>
105         class VertexSpec4 {
106         public:
107             typedef _A1 A1;
108             typedef _A2 A2;
109             typedef _A3 A3;
110             typedef _A4 A4;
111             typedef Vertex4<_A1, _A2, _A3, _A4> Vertex;
112             static const size_t Size;
113         public:
setup(const size_t baseOffset)114             static void setup(const size_t baseOffset) {
115                 _A1::setup(0, Size, baseOffset);
116                 _A2::setup(1, Size, baseOffset + _A1::Size);
117                 _A3::setup(2, Size, baseOffset + _A1::Size + _A2::Size);
118                 _A4::setup(3, Size, baseOffset + _A1::Size + _A2::Size + _A3::Size);
119             }
120 
cleanup()121             static void cleanup() {
122                 _A4::cleanup(3);
123                 _A3::cleanup(2);
124                 _A2::cleanup(1);
125                 _A1::cleanup(0);
126             }
127         private:
128             VertexSpec4();
129         };
130 
131         template <typename A1, typename A2, typename A3, typename A4>
132         const size_t VertexSpec4<A1, A2, A3, A4>::Size = sizeof(VertexSpec4<A1, A2, A3, A4>::Vertex);
133 
134         template <typename _A1, typename _A2, typename _A3, typename _A4, typename _A5>
135         class VertexSpec5 {
136         public:
137             typedef _A1 A1;
138             typedef _A2 A2;
139             typedef _A3 A3;
140             typedef _A4 A4;
141             typedef _A5 A5;
142             typedef Vertex5<_A1, _A2, _A3, _A4, _A5> Vertex;
143             static const size_t Size;
144         public:
setup(const size_t baseOffset)145             static void setup(const size_t baseOffset) {
146                 _A1::setup(0, Size, baseOffset);
147                 _A2::setup(1, Size, baseOffset + _A1::Size);
148                 _A3::setup(2, Size, baseOffset + _A1::Size + _A2::Size);
149                 _A4::setup(3, Size, baseOffset + _A1::Size + _A2::Size + _A3::Size);
150                 _A5::setup(4, Size, baseOffset + _A1::Size + _A2::Size + _A3::Size + _A4::Size);
151             }
152 
cleanup()153             static void cleanup() {
154                 _A5::cleanup(4);
155                 _A4::cleanup(3);
156                 _A3::cleanup(2);
157                 _A2::cleanup(1);
158                 _A1::cleanup(0);
159             }
160         private:
161             VertexSpec5();
162         };
163 
164         template <typename A1, typename A2, typename A3, typename A4, typename A5>
165         const size_t VertexSpec5<A1, A2, A3, A4, A5>::Size = sizeof(VertexSpec5<A1, A2, A3, A4, A5>::Vertex);
166 
167         namespace VertexSpecs {
168             typedef VertexSpec1<AttributeSpecs::P2> P2;
169             typedef VertexSpec2<AttributeSpecs::P2, AttributeSpecs::C4> P2C4;
170             typedef VertexSpec2<AttributeSpecs::P2, AttributeSpecs::T02> P2T2;
171             typedef VertexSpec3<AttributeSpecs::P2, AttributeSpecs::T02, AttributeSpecs::C4> P2T2C4;
172             typedef VertexSpec1<AttributeSpecs::P3> P3;
173             typedef VertexSpec2<AttributeSpecs::P3, AttributeSpecs::C4> P3C4;
174             typedef VertexSpec2<AttributeSpecs::P3, AttributeSpecs::T02> P3T2;
175             typedef VertexSpec2<AttributeSpecs::P3, AttributeSpecs::N> P3N;
176             typedef VertexSpec3<AttributeSpecs::P3, AttributeSpecs::N, AttributeSpecs::C4> P3NC4;
177             typedef VertexSpec3<AttributeSpecs::P3, AttributeSpecs::T02, AttributeSpecs::C4> P3T2C4;
178             typedef VertexSpec3<AttributeSpecs::P3, AttributeSpecs::N, AttributeSpecs::T02> P3NT2;
179         }
180     }
181 }
182 
183 #endif /* defined(TrenchBroom_VertexSpec) */
184