1 | #include "GeoVertexBuffer.h"
|
---|
2 |
|
---|
3 | using namespace Geometry;
|
---|
4 |
|
---|
5 | //---------------------------------------------------------------------------
|
---|
6 | // Destroyer.
|
---|
7 | //---------------------------------------------------------------------------
|
---|
8 | VertexBuffer::~VertexBuffer()
|
---|
9 | {
|
---|
10 | delete [] mPosition;
|
---|
11 | delete [] mNormal;
|
---|
12 | delete [] mTexCoords;
|
---|
13 | }
|
---|
14 |
|
---|
15 | //---------------------------------------------------------------------------
|
---|
16 | // Save to a serializer.
|
---|
17 | //---------------------------------------------------------------------------
|
---|
18 | void VertexBuffer::Save(Serializer &s)
|
---|
19 | {
|
---|
20 | s.WriteArray(&mVertexInfo, 1);
|
---|
21 | s.WriteArray(&mVertexCount, 1);
|
---|
22 |
|
---|
23 | if (mVertexInfo & VERTEX_POSITION)
|
---|
24 | {
|
---|
25 | s.WriteArray(mPosition, mVertexCount);
|
---|
26 | }
|
---|
27 | if (mVertexInfo & VERTEX_NORMAL)
|
---|
28 | {
|
---|
29 | s.WriteArray(mNormal, mVertexCount);
|
---|
30 | }
|
---|
31 | if (mVertexInfo & VERTEX_TEXCOORDS)
|
---|
32 | {
|
---|
33 | s.WriteArray(mTexCoords, mVertexCount);
|
---|
34 | }
|
---|
35 | }
|
---|
36 |
|
---|
37 | //---------------------------------------------------------------------------
|
---|
38 | // Loads from a serializer.
|
---|
39 | //---------------------------------------------------------------------------
|
---|
40 | void VertexBuffer::Load(Serializer &s)
|
---|
41 | {
|
---|
42 | // Clear data.
|
---|
43 | delete [] mPosition;
|
---|
44 |
|
---|
45 | mPosition = 0;
|
---|
46 |
|
---|
47 | delete [] mNormal;
|
---|
48 |
|
---|
49 | mNormal = 0;
|
---|
50 |
|
---|
51 | delete [] mTexCoords;
|
---|
52 |
|
---|
53 | mTexCoords = 0;
|
---|
54 |
|
---|
55 | s.ReadArray(&mVertexInfo,1);
|
---|
56 | s.ReadArray(&mVertexCount,1);
|
---|
57 |
|
---|
58 | if (mVertexInfo & VERTEX_POSITION)
|
---|
59 | {
|
---|
60 | mPosition = new Vector3[mVertexCount];
|
---|
61 |
|
---|
62 | s.ReadArray(mPosition, mVertexCount);
|
---|
63 | }
|
---|
64 |
|
---|
65 | if (mVertexInfo & VERTEX_NORMAL)
|
---|
66 | {
|
---|
67 | mNormal = new Vector3[mVertexCount];
|
---|
68 |
|
---|
69 | s.ReadArray(mNormal, mVertexCount);
|
---|
70 | }
|
---|
71 |
|
---|
72 | if (mVertexInfo & VERTEX_TEXCOORDS)
|
---|
73 | {
|
---|
74 | mTexCoords = new Vector2[mVertexCount];
|
---|
75 |
|
---|
76 | s.ReadArray(mTexCoords, mVertexCount);
|
---|
77 | }
|
---|
78 | }
|
---|
79 |
|
---|
80 | //---------------------------------------------------------------------------
|
---|
81 | // Copy contents of vertex buffer to another.
|
---|
82 | //---------------------------------------------------------------------------
|
---|
83 | VertexBuffer *VertexBuffer::Clone() const
|
---|
84 | {
|
---|
85 | VertexBuffer *vnew = new VertexBuffer();
|
---|
86 | vnew->mVertexInfo = mVertexInfo;
|
---|
87 | vnew->mVertexCount = mVertexCount;
|
---|
88 | vnew->mPosition = new Vector3[mVertexCount];
|
---|
89 | vnew->mNormal = new Vector3[mVertexCount];
|
---|
90 | vnew->mTexCoords = new Vector2[mVertexCount];
|
---|
91 |
|
---|
92 | memcpy(vnew->mPosition, mPosition, mVertexCount*sizeof(Vector3));
|
---|
93 | memcpy(vnew->mNormal, mNormal, mVertexCount*sizeof(Vector3));
|
---|
94 | memcpy(vnew->mTexCoords, mTexCoords, mVertexCount*sizeof(Vector2));
|
---|
95 |
|
---|
96 | return vnew;
|
---|
97 | }
|
---|
98 |
|
---|