-static struct material *add_material(struct level *lvl, struct material *mtl)
-{
- int i, newsz;
- struct material *tmp;
-
- for(i=0; i<lvl->num_mtls; i++) {
- if(memcmp(lvl->mtls + i, mtl, sizeof *mtl) == 0) {
- return lvl->mtls + i;
- }
- }
-
- if(lvl->num_mtls >= lvl->max_mtls) {
- newsz = lvl->max_mtls ? lvl->max_mtls * 2 : 16;
- if(!(tmp = realloc(lvl->mtls, newsz * sizeof *lvl->mtls))) {
- fprintf(stderr, "add_material: failed to resize materials array to %d\n", newsz);
- return 0;
- }
- lvl->mtls = tmp;
- lvl->max_mtls = newsz;
- }
- lvl->mtls[lvl->num_mtls] = *mtl;
-
- return lvl->mtls + lvl->num_mtls++;
-}
-
-static int append_polygons(struct bvhnode *bnode, struct triangle *faces, int num_faces, struct material *mtl)