RE: [Plib-devel] proposal for PLIB 1.3 ssg load hints
Brought to you by:
sjbaker
From: Dave M. <Dav...@dy...> - 2000-04-06 18:01:40
|
Steve wrote: > I wonder if it would be better to do this with a callback > function though. Under that scheme, if the application > installs a 'Leaf node creation callback', then the loader > will call the callback with the lists of vertices, colours, > normals, etc - and the application would then create the > node, populate the various fields (or not if it didn't > want them) and return the address of the ssgEntity it > finally decided to create back to the loader. > yes. very flexible. here is some code... class ssgLoadLeafData { public: ssgLoadLeafData () ; ~ssgLoadLeafData () ; const char* name ; //node name GLenum gltype ; ssgVertexArray *vl ; ssgNormalArray *nl ; ssgTexCoordArray *tl ; ssgColourArray *cl ; ssgSimpleState *st ; } ; typedef ssgEntity* (*ssgLoadLeafCallback)( ssgLoadLeafData* data ) ; static ssgLoadLeafCallback load_leaf_cb = default_load_leaf ; the loader would do something like this: ssgLoadLeafData* data = new ssgLoadLeafData; //initialize leaf data from file data ssgEntity* ent = (*load_leaf_cb)( data ) ; if ( ent == NULL ) delete data ; else current_branch->addKid ( ent ) ; the default callback would be: ssgEntity* default_load_leaf ( ssgLoadLeafData* data ) { ssgVtxTable *vtab = new ssgVtxTable ( data->gltype, data->vl, data->nl, data->tl, data->cl ) ; if ( data->st ) vtab -> setState ( data->st ) ; vtab -> setName ( data->name ) ; return vtab ; } -- Dave McClurg |