1 | #include "GeoSubMesh.h"
|
---|
2 |
|
---|
3 | using namespace Geometry;
|
---|
4 |
|
---|
5 | //---------------------------------------------------------------------------
|
---|
6 | // Constructor.
|
---|
7 | //---------------------------------------------------------------------------
|
---|
8 | SubMesh::SubMesh():
|
---|
9 | mIndex(0),
|
---|
10 | mVertexBuffer(0),
|
---|
11 | mIndexCount(0),
|
---|
12 | mSharedVertexBuffer(false),
|
---|
13 | mStrip(0),
|
---|
14 | mStripCount(0),
|
---|
15 | mType(GEO_TRIANGLE_LIST)
|
---|
16 | {
|
---|
17 | strcpy(mName,"");
|
---|
18 | strcpy(mMaterialName,"");
|
---|
19 | }
|
---|
20 |
|
---|
21 | //---------------------------------------------------------------------------
|
---|
22 | // Destroyer.
|
---|
23 | //---------------------------------------------------------------------------
|
---|
24 | SubMesh::~SubMesh()
|
---|
25 | {
|
---|
26 | delete [] mIndex;
|
---|
27 |
|
---|
28 | if (!mSharedVertexBuffer)
|
---|
29 | {
|
---|
30 | delete mVertexBuffer;
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | //---------------------------------------------------------------------------
|
---|
35 | // Load data from a serializer.
|
---|
36 | //---------------------------------------------------------------------------
|
---|
37 | void SubMesh::Load(Serializer &s)
|
---|
38 | {
|
---|
39 | // Clear Data.
|
---|
40 | delete [] mIndex;
|
---|
41 |
|
---|
42 | mIndex = 0;
|
---|
43 |
|
---|
44 | if (!mSharedVertexBuffer)
|
---|
45 | {
|
---|
46 | delete mVertexBuffer;
|
---|
47 |
|
---|
48 | mVertexBuffer = 0;
|
---|
49 | }
|
---|
50 |
|
---|
51 | mIndexCount = 0;
|
---|
52 |
|
---|
53 | // Load Data from Serializer.
|
---|
54 | s.ReadArray(&mSharedVertexBuffer, 1);
|
---|
55 |
|
---|
56 | if (mSharedVertexBuffer)
|
---|
57 | {
|
---|
58 | mVertexBuffer = 0;
|
---|
59 | }
|
---|
60 | else
|
---|
61 | {
|
---|
62 | mVertexBuffer = new VertexBuffer();
|
---|
63 |
|
---|
64 | mVertexBuffer->Load(s);
|
---|
65 | }
|
---|
66 |
|
---|
67 | s.ReadArray(&mIndexCount, 1);
|
---|
68 |
|
---|
69 | mIndex = new Index[mIndexCount];
|
---|
70 |
|
---|
71 | s.ReadArray(mIndex, mIndexCount);
|
---|
72 | }
|
---|
73 |
|
---|
74 | //---------------------------------------------------------------------------
|
---|
75 | // Save data to a serializer.
|
---|
76 | //---------------------------------------------------------------------------
|
---|
77 | void SubMesh::Save(Serializer &s)
|
---|
78 | {
|
---|
79 | s.WriteArray(&mSharedVertexBuffer, 1);
|
---|
80 |
|
---|
81 | if (!mSharedVertexBuffer)
|
---|
82 | {
|
---|
83 | mVertexBuffer->Save(s);
|
---|
84 | }
|
---|
85 |
|
---|
86 | s.WriteArray(&mIndexCount, 1);
|
---|
87 | s.WriteArray(mIndex, mIndexCount);
|
---|
88 | }
|
---|
89 |
|
---|