Polygons in pfGeoSets

New Message Reply Date view Thread view Subject view Author view

Swaminathan N. (swami++at++evl.eecs.uic.edu)
Wed, 28 Aug 1996 18:47:05 -0500 (CDT)


Hi, I'm trying to create a geoset using indexed polygons. The code seems
to work for small numbers of primitives, but doesnt for larger numbers.
>From pfPrint I gather that the number of primitives and the strip lengths
are fine. However I get much more vertices than
striplength[i]*numberOfPrimitives. For instance if there are 800
primitive triangles, I get 3669 coordIndexes, 1269 more than 2400 which I'm
supposed to get. I've been working on the assumption that I've screwed up
my memory allocation somewhere, but I've looked and looked. Maybe it's
something obvious. I'd like to know if this is indeed the way to
create indexed polygons. Anyway here's relevant piece of code. Thanks
Swami

static void *
memdup(void *mem, size_t bytes) {
  void *data = pfMalloc(bytes, pfGetSharedArena());
  memcpy(data, mem, bytes);
  return data;
}

// QvIndexedFaceSet is a class that has data members
// c.values: an array of pfVec3, pfMalloced
// coordIndex.values: an array containing the coordinate indices with -1 as
// end of face markers, pfMalloced
void
QvIndexedFaceSet::makegset() {
  QvCoordinate *c = NULL;
  if (coord.value) c = (QvCoordinate *)(coord.value);
  //coord.value holds the coordinate values as a pfVec3 *

  int numVerts = 0, numPrims = 0, numIndex = 0;
  int length[1024];
  ushort *icoord;
  pfGeoSet *g = new pfGeoSet;

  icoord = (ushort *)malloc(sizeof(ushort) * coordIndex.num);
  // get rid of the -1 which are end of face markers
  // coordIndex.num is the number of indices in total
  for (int i=0; i<coordIndex.num; i++) {
    if (coordIndex.get1Value(i) == -1 || i == coordIndex.num) {
      length[numPrims++] = numVerts; // length contains the polygon size
      numVerts = 0;
    }
    else {
      // icoord contains the coord indices without the -1's
      icoord[numIndex++] = coordIndex.get1Value(i);
      numVerts++;
    }
  }

  g->setNumPrims(numPrims);
  g->setPrimLengths((int *)memdup(length,sizeof(int)*numPrims));
  g->setPrimType(PFGS_POLYS);
  g->setAttr(PFGS_COORD3, PFGS_PER_VERTEX,
             memdup(c->point.values,sizeof(pfVec3)*c->point.num),
             (ushort *)memdup(icoord, sizeof(ushort)*numIndex));

}

// pfPrint output
GeoSet: 0x180b7600 {
  Primitive: PFGS_POLYS, INDEXED, pfPrims=800, glPrims=800, verts=2400
    Attribute Bindings:
        PFGS_COLOR4=PFGS_OFF PFGS_NORMAL3=PFGS_OFF PFGS_TEXCOORD2=PFGS_OFF
  Attribute List Pointers:
    PFGS_COORD3: 0x18102c90
    PFGS_COLOR4: 0x0
    PFGS_NORMAL3: 0x0
    PFGS_TEXCOORD2: 0x0
  Attribute Index List Pointers:
    PFGS_COLOR4: 0x0
    PFGS_NORMAL3: 0x0
    PFGS_TEXCOORD2: 0x0
    PFGS_COORD3: 0x18103fc0
  Strip Lengths: eight hundred 3's follow here
  
3669 "Coord Index:" follow here
}

=======================================================================
List Archives, FAQ, FTP: http://www.sgi.com/Technology/Performer/
            Submissions: info-performer++at++sgi.com
        Admin. requests: info-performer-request++at++sgi.com


New Message Reply Date view Thread view Subject view Author view

This archive was generated by hypermail 2.0b2 on Mon Aug 10 1998 - 17:53:26 PDT

This message has been cleansed for anti-spam protection. Replace '++at++' in any mail addresses with the '@' symbol.