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(mMaterialName,"");
|
---|
18 | }
|
---|
19 |
|
---|
20 | //---------------------------------------------------------------------------
|
---|
21 | // Destroyer.
|
---|
22 | //---------------------------------------------------------------------------
|
---|
23 | SubMesh::~SubMesh()
|
---|
24 | {
|
---|
25 | delete [] mIndex;
|
---|
26 |
|
---|
27 | if (!mSharedVertexBuffer)
|
---|
28 | {
|
---|
29 | delete mVertexBuffer;
|
---|
30 | }
|
---|
31 | }
|
---|
32 |
|
---|
33 | //---------------------------------------------------------------------------
|
---|
34 | // Load data from a serializer.
|
---|
35 | //---------------------------------------------------------------------------
|
---|
36 | void SubMesh::Load(Serializer &s)
|
---|
37 | {
|
---|
38 | // Clear Data.
|
---|
39 | delete [] mIndex;
|
---|
40 |
|
---|
41 | mIndex = 0;
|
---|
42 |
|
---|
43 | if (!mSharedVertexBuffer)
|
---|
44 | {
|
---|
45 | delete mVertexBuffer;
|
---|
46 |
|
---|
47 | mVertexBuffer = 0;
|
---|
48 | }
|
---|
49 |
|
---|
50 | mIndexCount = 0;
|
---|
51 |
|
---|
52 | // Load Data from Serializer.
|
---|
53 | s.ReadArray(&mSharedVertexBuffer, 1);
|
---|
54 |
|
---|
55 | if (mSharedVertexBuffer)
|
---|
56 | {
|
---|
57 | mVertexBuffer = 0;
|
---|
58 | }
|
---|
59 | else
|
---|
60 | {
|
---|
61 | mVertexBuffer = new VertexBuffer();
|
---|
62 |
|
---|
63 | mVertexBuffer->Load(s);
|
---|
64 | }
|
---|
65 |
|
---|
66 | s.ReadArray(&mIndexCount, 1);
|
---|
67 |
|
---|
68 | mIndex = new Index[mIndexCount];
|
---|
69 |
|
---|
70 | s.ReadArray(mIndex, mIndexCount);
|
---|
71 | }
|
---|
72 |
|
---|
73 | //---------------------------------------------------------------------------
|
---|
74 | // Save data to a serializer.
|
---|
75 | //---------------------------------------------------------------------------
|
---|
76 | void SubMesh::Save(Serializer &s)
|
---|
77 | {
|
---|
78 | s.WriteArray(&mSharedVertexBuffer, 1);
|
---|
79 |
|
---|
80 | if (!mSharedVertexBuffer)
|
---|
81 | {
|
---|
82 | mVertexBuffer->Save(s);
|
---|
83 | }
|
---|
84 |
|
---|
85 | s.WriteArray(&mIndexCount, 1);
|
---|
86 | s.WriteArray(mIndex, mIndexCount);
|
---|
87 | }
|
---|
88 |
|
---|