1 #ifndef AWFUL_SCENEGRAPH_VTXARRAY_H_
2 #define AWFUL_SCENEGRAPH_VTXARRAY_H_
12 This template based vertex buffer is simple, efficient, very flexible and easy to extend. Me like.
13 It will be a little less clean when it comes to serialization and language bindings however.
14 For language bindings with swig, specific instances will have to be defined.
15 Same thing with serialization.
18 old notes from jerky, probably partially obsolete:
20 0. Just do a quick and dirty, plain vertex array implementation, implementing
21 operator[] to access vertices, as well as points 1 and 3 below.
23 Later (= someday = when I feel like doing it) implement VBO support (points 2, 4 and 5 below)
25 1. Define vertex attributes (order + type) - All float as it seems the only properly supported
28 2. Make a mmap function (then access vertices with operator[])
30 3. A "select" or "activate" or "configure" function that makes it the current vertex array (binds the VBO
31 and setup the vertex arrays)
33 4. uses only vbos for now. It will be possible to add some transparent fallback to regular vertex arrays
34 later if needed (VBO is going to be part of the core starting with opengl 1.5, so
35 it will probably always be available anyway)
37 5. more to come as I progress and read the VBO docs
43 class VtxArray
: public RefCounted
46 virtual void disableStates() const = 0;
47 virtual void enableStates() const = 0;
48 virtual void bind() const = 0;
53 // Note: the classes used to represent these types must not be padded.
60 static void DisableState()
62 glDisableClientState( GL_VERTEX_ARRAY
);
65 static void EnableState()
67 glEnableClientState( GL_VERTEX_ARRAY
);
70 static void Bind( const type
* pArray_
, int Stride_
)
72 glVertexPointer( 3, GL_FLOAT
, Stride_
, pArray_
);
81 static void DisableState()
83 glDisableClientState( GL_NORMAL_ARRAY
);
86 static void EnableState()
88 glEnableClientState( GL_NORMAL_ARRAY
);
91 static void Bind( const type
* pArray_
, int Stride_
)
93 glNormalPointer( GL_FLOAT
, Stride_
, pArray_
);
100 typedef RGBColInt type
;
102 static void DisableState()
104 glDisableClientState( GL_COLOR_ARRAY
);
107 static void EnableState()
109 glEnableClientState( GL_COLOR_ARRAY
);
112 static void Bind( const type
* pArray_
, int Stride_
)
114 glColorPointer( 4, GL_UNSIGNED_BYTE
, Stride_
, pArray_
);
123 static void DisableState()
125 glDisableClientState( GL_TEXTURE_COORD_ARRAY
);
128 static void EnableState()
130 glEnableClientState( GL_TEXTURE_COORD_ARRAY
);
133 static void Bind( const type
* pArray_
, int Stride_
)
135 glTexCoordPointer( 2, GL_FLOAT
, Stride_
, pArray_
);
140 template< class A1
, class A2
= void, class A3
= void, class A4
= void > class Vertex
143 typename
A1::type a1
;
144 typename
A2::type a2
;
145 typename
A3::type a3
;
146 typename
A4::type a4
;
149 template< class A1
, class A2
, class A3
> class Vertex
< A1
, A2
, A3
>
152 typename
A1::type a1
;
153 typename
A2::type a2
;
154 typename
A3::type a3
;
157 template< class A1
, class A2
> class Vertex
< A1
, A2
>
160 typename
A1::type a1
;
161 typename
A2::type a2
;
164 template< class A1
> class Vertex
< A1
>
167 typename
A1::type a1
;
170 template< class A1
, class A2
= void, class A3
= void, class A4
= void >
171 class VertexArray
: public VtxArray
, public std::vector
< Vertex
< A1
, A2
, A3
, A4
> >
174 typedef Vertex
< A1
, A2
, A3
, A4
> vertex_type
;
176 VertexArray( typename
std::vector
< Vertex
< A1
, A2
, A3
, A4
> >::size_type Size_
) :
177 std::vector
< Vertex
< A1
, A2
, A3
, A4
> >( Size_
)
181 virtual void disableStates() const
189 virtual void enableStates() const
197 virtual void bind() const
199 const typename
A1::type
* pA1Array
= &( *this )[0].a1
;
200 A1::Bind( pA1Array
, sizeof( vertex_type
) );
201 const typename
A2::type
* pA2Array
= &( *this )[0].a2
;
202 A2::Bind( pA2Array
, sizeof( vertex_type
) );
203 const typename
A3::type
* pA3Array
= &( *this )[0].a3
;
204 A3::Bind( pA3Array
, sizeof( vertex_type
) );
205 const typename
A4::type
* pA4Array
= &( *this )[0].a4
;
206 A4::Bind( pA4Array
, sizeof( vertex_type
) );
210 template< class A1
, class A2
, class A3
>
211 class VertexArray
< A1
, A2
, A3
> : public VtxArray
, public std::vector
< Vertex
< A1
, A2
, A3
> >
214 typedef Vertex
< A1
, A2
, A3
> vertex_type
;
216 VertexArray( typename
std::vector
< Vertex
< A1
, A2
, A3
> >::size_type Size_
) :
217 std::vector
< Vertex
< A1
, A2
, A3
> >( Size_
)
221 virtual void disableStates() const
228 virtual void enableStates() const
235 virtual void bind() const
237 const typename
A1::type
* pA1Array
= &( *this )[0].a1
;
238 A1::Bind( pA1Array
, sizeof( vertex_type
) );
239 const typename
A2::type
* pA2Array
= &( *this )[0].a2
;
240 A2::Bind( pA2Array
, sizeof( vertex_type
) );
241 const typename
A3::type
* pA3Array
= &( *this )[0].a3
;
242 A3::Bind( pA3Array
, sizeof( vertex_type
) );
246 template< class A1
, class A2
>
247 class VertexArray
< A1
, A2
> : public VtxArray
, public std::vector
< Vertex
< A1
, A2
> >
250 typedef Vertex
< A1
, A2
> vertex_type
;
252 VertexArray( typename
std::vector
< Vertex
< A1
, A2
> >::size_type Size_
) :
253 std::vector
< Vertex
< A1
, A2
> >( Size_
)
257 virtual void disableStates() const
263 virtual void enableStates() const
269 virtual void bind() const
271 const typename
A1::type
* pA1Array
= &( *this )[0].a1
;
272 A1::Bind( pA1Array
, sizeof( vertex_type
) );
273 const typename
A2::type
* pA2Array
= &( *this )[0].a2
;
274 A2::Bind( pA2Array
, sizeof( vertex_type
) );
279 class VertexArray
< A1
> : public VtxArray
, public std::vector
< Vertex
< A1
> >
282 typedef Vertex
< A1
> vertex_type
;
284 VertexArray( typename
std::vector
< Vertex
< A1
> >::size_type Size_
) :
285 std::vector
< Vertex
< A1
> >( Size_
)
289 virtual void disableStates() const
294 virtual void enableStates() const
299 virtual void bind() const
301 const typename
A1::type
* pA1Array
= &( *this )[0].a1
;
302 A1::Bind( pA1Array
, sizeof( vertex_type
) );