[774] | 1 | #include "GeoVertexBuffer.h"
|
---|
| 2 |
|
---|
| 3 | using namespace Geometry;
|
---|
| 4 |
|
---|
[1009] | 5 | //---------------------------------------------------------------------------
|
---|
| 6 | // Destroyer.
|
---|
| 7 | //---------------------------------------------------------------------------
|
---|
[774] | 8 | VertexBuffer::~VertexBuffer()
|
---|
| 9 | {
|
---|
[1009] | 10 | delete [] mPosition;
|
---|
| 11 | delete [] mNormal;
|
---|
| 12 | delete [] mTexCoords;
|
---|
[774] | 13 | }
|
---|
| 14 |
|
---|
[1009] | 15 | //---------------------------------------------------------------------------
|
---|
| 16 | // Save to a serializer.
|
---|
| 17 | //---------------------------------------------------------------------------
|
---|
[774] | 18 | void VertexBuffer::Save(Serializer &s)
|
---|
| 19 | {
|
---|
[1009] | 20 | s.WriteArray(&mVertexInfo, 1);
|
---|
| 21 | s.WriteArray(&mVertexCount, 1);
|
---|
| 22 |
|
---|
[774] | 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 |
|
---|
[1009] | 37 | //---------------------------------------------------------------------------
|
---|
| 38 | // Loads from a serializer.
|
---|
| 39 | //---------------------------------------------------------------------------
|
---|
[774] | 40 | void VertexBuffer::Load(Serializer &s)
|
---|
| 41 | {
|
---|
[1009] | 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;
|
---|
[774] | 54 |
|
---|
| 55 | s.ReadArray(&mVertexInfo,1);
|
---|
| 56 | s.ReadArray(&mVertexCount,1);
|
---|
[1009] | 57 |
|
---|
[774] | 58 | if (mVertexInfo & VERTEX_POSITION)
|
---|
| 59 | {
|
---|
[1009] | 60 | mPosition = new Vector3[mVertexCount];
|
---|
| 61 |
|
---|
[774] | 62 | s.ReadArray(mPosition, mVertexCount);
|
---|
| 63 | }
|
---|
[1009] | 64 |
|
---|
[774] | 65 | if (mVertexInfo & VERTEX_NORMAL)
|
---|
| 66 | {
|
---|
[1009] | 67 | mNormal = new Vector3[mVertexCount];
|
---|
| 68 |
|
---|
[774] | 69 | s.ReadArray(mNormal, mVertexCount);
|
---|
| 70 | }
|
---|
[1009] | 71 |
|
---|
[774] | 72 | if (mVertexInfo & VERTEX_TEXCOORDS)
|
---|
| 73 | {
|
---|
[1009] | 74 | mTexCoords = new Vector2[mVertexCount];
|
---|
| 75 |
|
---|
[774] | 76 | s.ReadArray(mTexCoords, mVertexCount);
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 |
|
---|
[1009] | 80 | //---------------------------------------------------------------------------
|
---|
| 81 | // Copy contents of vertex buffer to another.
|
---|
| 82 | //---------------------------------------------------------------------------
|
---|
[774] | 83 | VertexBuffer *VertexBuffer::Clone() const
|
---|
| 84 | {
|
---|
[1009] | 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];
|
---|
[774] | 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));
|
---|
[1009] | 95 |
|
---|
| 96 | return vnew;
|
---|
| 97 | }
|
---|
| 98 |
|
---|