[138] | 1 | #include "GeoVertexBuffer.h"
|
---|
| 2 |
|
---|
| 3 | using namespace Geometry;
|
---|
| 4 |
|
---|
| 5 | //---------------------------------------------------------------------
|
---|
| 6 | VertexBuffer::~VertexBuffer()
|
---|
| 7 | {
|
---|
| 8 | delete[] mPosition;
|
---|
| 9 | delete[] mNormal;
|
---|
| 10 | delete[] mTexCoords;
|
---|
| 11 | }
|
---|
| 12 |
|
---|
| 13 | //---------------------------------------------------------------------
|
---|
| 14 | void VertexBuffer::Save(Serializer &s)
|
---|
| 15 | {
|
---|
| 16 | s.WriteArray(&mVertexInfo,1);
|
---|
| 17 | s.WriteArray(&mVertexCount,1);
|
---|
| 18 | if (mVertexInfo & VERTEX_POSITION)
|
---|
| 19 | {
|
---|
| 20 | s.WriteArray(mPosition, mVertexCount);
|
---|
| 21 | }
|
---|
| 22 | if (mVertexInfo & VERTEX_NORMAL)
|
---|
| 23 | {
|
---|
| 24 | s.WriteArray(mNormal, mVertexCount);
|
---|
| 25 | }
|
---|
| 26 | if (mVertexInfo & VERTEX_TEXCOORDS)
|
---|
| 27 | {
|
---|
| 28 | s.WriteArray(mTexCoords, mVertexCount);
|
---|
| 29 | }
|
---|
| 30 | }
|
---|
| 31 |
|
---|
| 32 | //---------------------------------------------------------------------
|
---|
| 33 | void VertexBuffer::Load(Serializer &s)
|
---|
| 34 | {
|
---|
| 35 | //Clear data
|
---|
| 36 | delete[] mPosition; mPosition = 0;
|
---|
| 37 | delete[] mNormal; mNormal = 0;
|
---|
| 38 | delete[] mTexCoords; mTexCoords = 0;
|
---|
| 39 |
|
---|
| 40 | s.ReadArray(&mVertexInfo,1);
|
---|
| 41 | s.ReadArray(&mVertexCount,1);
|
---|
| 42 | if (mVertexInfo & VERTEX_POSITION)
|
---|
| 43 | {
|
---|
| 44 | mPosition = new Vector3[mVertexCount];
|
---|
| 45 | s.ReadArray(mPosition, mVertexCount);
|
---|
| 46 | }
|
---|
| 47 | if (mVertexInfo & VERTEX_NORMAL)
|
---|
| 48 | {
|
---|
| 49 | mNormal = new Vector3[mVertexCount];
|
---|
| 50 | s.ReadArray(mNormal, mVertexCount);
|
---|
| 51 | }
|
---|
| 52 | if (mVertexInfo & VERTEX_TEXCOORDS)
|
---|
| 53 | {
|
---|
| 54 | mTexCoords = new Vector2[mVertexCount];
|
---|
| 55 | s.ReadArray(mTexCoords, mVertexCount);
|
---|
| 56 | }
|
---|
| 57 | }
|
---|
| 58 |
|
---|
| 59 | //---------------------------------------------------------------------
|
---|
| 60 | VertexBuffer *VertexBuffer::Clone() const
|
---|
| 61 | {
|
---|
| 62 | VertexBuffer *vnew = new VertexBuffer();
|
---|
| 63 | vnew->mVertexInfo = mVertexInfo;
|
---|
| 64 | vnew->mVertexCount = mVertexCount;
|
---|
| 65 | vnew->mPosition = new Vector3[mVertexCount];
|
---|
| 66 | vnew->mNormal = new Vector3[mVertexCount];
|
---|
| 67 | vnew->mTexCoords = new Vector2[mVertexCount];
|
---|
| 68 |
|
---|
| 69 | memcpy(vnew->mPosition, mPosition, mVertexCount*sizeof(Vector3));
|
---|
| 70 | memcpy(vnew->mNormal, mNormal, mVertexCount*sizeof(Vector3));
|
---|
| 71 | memcpy(vnew->mTexCoords, mTexCoords, mVertexCount*sizeof(Vector2));
|
---|
| 72 | return vnew;
|
---|
| 73 | } |
---|