1 // vertexbuf.h
2 //
3 // Copyright (C) 2001, Chris Laurel
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 
10 #ifndef _VERTEXBUF_H_
11 #define _VERTEXBUF_H_
12 
13 #include <celutil/basictypes.h>
14 #include <celutil/color.h>
15 #include <celmath/vecmath.h>
16 #include <celmath/aabox.h>
17 
18 
19 class VertexBuffer
20 {
21  public:
22     enum {
23         VertexNormal   = 0x01,
24         VertexColor    = 0x02,
25         VertexColor0   = 0x02,
26         VertexColor1   = 0x04,
27         TexCoord0      = 0x08,
28         TexCoord1      = 0x10,
29     };
30 
31     class Vertex
32     {
33     public:
34         Point3f point;
35         Vec3f normal;
36         Color color;
37         Point2f texCoords[2];
38     };
39 
40     union VertexPart
41     {
42         float f;
43         unsigned char c[4];
44     };
45 
46  public:
47     VertexList(uint32 _parts, uint32 initialVertexPoolSize = 0);
48     ~VertexList();
49 
50     void addVertex(const Vertex& v);
51 
52     Color getDiffuseColor() const;
53     void setDiffuseColor(Color);
54 
55     void render();
56 
57     AxisAlignedBox getBoundingBox() const;
58     void transform(Vec3f translation, float scale);
59 
60  private:
61     uint32 parts;
62     uint32 vertexSize;
63 
64     uint32 nVertices;
65     uint32 maxVertices;
66     VertexPart* vertices;
67 
68     Color diffuseColor;
69 
70     AxisAlignedBox bbox;
71 };
72 
73 #endif // _VERTEXBUF_H_
74