vcglib/apps/nexus/patch.cpp

102 lines
2.6 KiB
C++
Raw Normal View History

2004-09-17 17:25:59 +02:00
#include "patch.h"
using namespace nxs;
Patch::Patch(Signature signature, Chunk *s,
unsigned short nvert, unsigned short nface):
start(s) {
Init(signature, nvert, nface);
}
void Patch::Init(Signature signature,
unsigned short nvert, unsigned short nface) {
nv = nvert;
nf = nface;
2004-09-30 02:27:42 +02:00
if(signature & NXS_FACES)
2004-09-17 17:25:59 +02:00
vstart = (float *)(((char *)start) + nf * sizeof(unsigned short) * 3);
2004-09-30 02:27:42 +02:00
else if(signature & NXS_STRIP)
2004-09-17 17:25:59 +02:00
vstart = (float *)(((char *)start) + nf * sizeof(unsigned short));
else
vstart = (float *)start;
//align memory
if(((int)vstart) & 0x2) vstart = (float *)(((char *)vstart) + 2);
cstart = nv * sizeof(float) * 3;
2004-09-30 02:27:42 +02:00
if(signature & NXS_COLORS)
nstart = cstart + nv * sizeof(unsigned int);
else
nstart = cstart;
2004-09-17 17:25:59 +02:00
2004-09-30 02:27:42 +02:00
if(signature & NXS_NORMALS_SHORT)
tstart = nstart + nv * sizeof(short) * 4;
else if(signature & NXS_NORMALS_FLOAT)
2004-09-17 17:25:59 +02:00
tstart = nstart + nv * sizeof(float) * 3;
else
tstart = nstart;
2004-09-30 02:27:42 +02:00
if(signature & NXS_TEXTURES_SHORT)
2004-09-17 17:25:59 +02:00
dstart = tstart + nv * sizeof(short) * 2;
2004-09-30 02:27:42 +02:00
else if(signature & NXS_TEXTURES_FLOAT)
2004-09-17 17:25:59 +02:00
dstart = tstart + nv * sizeof(float) * 2;
else
dstart = tstart;
}
unsigned int Patch::ChunkSize(Signature signature,
unsigned short nvert,
unsigned short nface) {
unsigned int size = ByteSize(signature, nvert, nface);
size = (size/sizeof(Chunk) + 1);
return size;
}
unsigned int Patch::ByteSize(Signature signature,
unsigned short nvert,
unsigned short nface) {
unsigned int size = 0;
2004-09-30 02:27:42 +02:00
if(signature & NXS_STRIP)
2004-09-17 17:25:59 +02:00
size += nface * sizeof(unsigned short);
2004-09-30 02:27:42 +02:00
else if(signature & NXS_FACES)
2004-09-17 17:25:59 +02:00
size += nface * 3 * sizeof(unsigned short);
//memory alignment
if(size & 0x2) size += 2;
size += nvert * sizeof(vcg::Point3f);
2004-09-30 02:27:42 +02:00
if(signature & NXS_COLORS)
2004-09-17 17:25:59 +02:00
size += nvert * sizeof(unsigned int);
2004-09-30 02:27:42 +02:00
if(signature & NXS_NORMALS_SHORT)
2004-09-17 17:25:59 +02:00
size += nvert * 4 * sizeof(short);
2004-09-30 02:27:42 +02:00
if(signature & NXS_NORMALS_FLOAT)
2004-09-17 17:25:59 +02:00
size += nvert * 3 * sizeof(float);
2004-09-30 02:27:42 +02:00
if(signature & NXS_TEXTURES_SHORT)
2004-09-17 17:25:59 +02:00
size += nvert * 2 * sizeof(short);
2004-09-30 02:27:42 +02:00
if(signature & NXS_TEXTURES_FLOAT)
2004-09-17 17:25:59 +02:00
size += nvert * 2 * sizeof(float);
2004-09-30 02:27:42 +02:00
if(signature & NXS_DATA8)
2004-09-17 17:25:59 +02:00
size += nvert * sizeof(char);
2004-09-30 02:27:42 +02:00
if(signature & NXS_DATA16)
2004-09-17 17:25:59 +02:00
size += nvert * 2 * sizeof(char);
2004-09-30 02:27:42 +02:00
if(signature & NXS_DATA32)
2004-09-17 17:25:59 +02:00
size += nvert * 4 * sizeof(char);
2004-09-30 02:27:42 +02:00
if(signature & NXS_DATA64)
2004-09-17 17:25:59 +02:00
size += nvert * 8 * sizeof(char);
//this condition should really rarely happen but helps save space
//during construction
if(size < nface * 3 * sizeof(unsigned int))
size = nface * 3 * sizeof(unsigned int);
return size;
}