compute total geom verts more efficiently

This commit is contained in:
cxgeorge 2002-04-30 00:53:01 +00:00
parent 31c4671e67
commit 5f75d73f3a
3 changed files with 40 additions and 21 deletions

View File

@ -138,6 +138,10 @@ get_texcoords_index() const {
INLINE void Geom::
set_num_prims(int num) {
_numprims = num;
if (!uses_components()) {
// except for strips & fans with the length arrays, total verts will be simply this
_num_vertices = _numprims*get_num_vertices_per_prim();
}
make_dirty();
}
@ -151,6 +155,30 @@ get_num_prims(void) const {
return _numprims;
}
////////////////////////////////////////////////////////////////////
// Function: Geom::get_num_vertices
// Access: Public
// Description: Returns the number of vertices required by all all
// the prims in the Geom.
////////////////////////////////////////////////////////////////////
INLINE int Geom::
get_num_vertices() const {
return _num_vertices;
}
INLINE int PTA_int_arraysum(const PTA_int &lengths) {
assert(lengths.size()>0);
int *pLen=&lengths[0];
int *pArrayEnd=pLen+lengths.size();
int nVerts = 0;
for (;pLen<pArrayEnd;pLen++) {
nVerts += *pLen;
}
return nVerts;
}
////////////////////////////////////////////////////////////////////
// Function: Geom::set_lengths
// Access: Public
@ -163,6 +191,7 @@ get_num_prims(void) const {
INLINE void Geom::
set_lengths(const PTA_int &lengths) {
_primlengths = lengths;
_num_vertices = PTA_int_arraysum(lengths);
make_dirty();
}

View File

@ -187,6 +187,7 @@ operator = (const Geom &copy) {
_tindex = copy._tindex;
_numprims = copy._numprims;
_num_vertices = copy._num_vertices;
_primlengths = copy._primlengths;
for (int i = 0; i < num_GeomAttrTypes; i++) {
_bind[i] = copy._bind[i];
@ -355,26 +356,6 @@ is_dynamic() const {
return (_vindex != (ushort*)0L);
}
////////////////////////////////////////////////////////////////////
// Function: Geom::get_num_vertices
// Access: Public
// Description: Returns the number of vertices required by all all
// the prims in the Geom.
////////////////////////////////////////////////////////////////////
int Geom::
get_num_vertices() const {
if (!uses_components()) {
return get_num_vertices_per_prim() * get_num_prims();
}
int total = 0;
for (int i = 0; i < get_num_prims(); i++) {
total += _primlengths[i];
}
return total;
}
////////////////////////////////////////////////////////////////////
// Function: Geom::explode
// Access: Public, Virtual
@ -707,8 +688,17 @@ fillin(DatagramIterator& scan, BamReader* manager) {
READ_PTA(manager, scan, IPD_ushort::read_datagram, _tindex)
_numprims = scan.get_uint16();
// is there any point in doing this for uses_components()==false?
READ_PTA(manager, scan, IPD_int::read_datagram, _primlengths)
if (uses_components()) {
_num_vertices = PTA_int_arraysum(_primlengths);
} else {
// except for strips & fans with the length arrays, total verts will be simply this
_num_vertices = _numprims*get_num_vertices_per_prim();
}
//Write out the bindings for vertices, normals,
//colors and texture coordinates
for(i = 0; i < num_GeomAttrTypes; i++) {

View File

@ -246,7 +246,7 @@ protected:
PTA_ushort _cindex;
PTA_ushort _tindex;
int _numprims;
int _numprims,_num_vertices;
PTA_int _primlengths;
enum GeomBindType _bind[num_GeomAttrTypes];