diff options
author | rodri <rgl@antares-labs.eu> | 2024-02-01 23:35:25 +0000 |
---|---|---|
committer | rodri <rgl@antares-labs.eu> | 2024-02-01 23:35:25 +0000 |
commit | f2e5828b91c56c2fc0247c5feb5a7215ec4529cc (patch) | |
tree | 9bd115d9079951837002eba859a7223d956906cd | |
parent | 5a97a65584a9bdd97cd3399beff59c5ea5d9d4a9 (diff) | |
download | libgraphics-f2e5828b91c56c2fc0247c5feb5a7215ec4529cc.tar.gz libgraphics-f2e5828b91c56c2fc0247c5feb5a7215ec4529cc.tar.bz2 libgraphics-f2e5828b91c56c2fc0247c5feb5a7215ec4529cc.zip |
only create existing indices during quad triangulation.
-rw-r--r-- | render.c | 56 |
1 files changed, 32 insertions, 24 deletions
@@ -39,19 +39,23 @@ triangulate(OBJElem **newe, OBJElem *e) newidxtab->indices[1] = idxtab->indices[1]; newidxtab->indices[2] = idxtab->indices[2]; idxtab = &e->indextab[OBJVTexture]; - newidxtab = &newe[0]->indextab[OBJVTexture]; - newidxtab->nindex = 3; - newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); - newidxtab->indices[0] = idxtab->indices[0]; - newidxtab->indices[1] = idxtab->indices[1]; - newidxtab->indices[2] = idxtab->indices[2]; + if(idxtab->nindex > 0){ + newidxtab = &newe[0]->indextab[OBJVTexture]; + newidxtab->nindex = 3; + newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); + newidxtab->indices[0] = idxtab->indices[0]; + newidxtab->indices[1] = idxtab->indices[1]; + newidxtab->indices[2] = idxtab->indices[2]; + } idxtab = &e->indextab[OBJVNormal]; - newidxtab = &newe[0]->indextab[OBJVNormal]; - newidxtab->nindex = 3; - newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); - newidxtab->indices[0] = idxtab->indices[0]; - newidxtab->indices[1] = idxtab->indices[1]; - newidxtab->indices[2] = idxtab->indices[2]; + if(idxtab->nindex > 0){ + newidxtab = &newe[0]->indextab[OBJVNormal]; + newidxtab->nindex = 3; + newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); + newidxtab->indices[0] = idxtab->indices[0]; + newidxtab->indices[1] = idxtab->indices[1]; + newidxtab->indices[2] = idxtab->indices[2]; + } idxtab = &e->indextab[OBJVGeometric]; newe[1] = emalloc(sizeof *newe[1]); @@ -63,19 +67,23 @@ triangulate(OBJElem **newe, OBJElem *e) newidxtab->indices[1] = idxtab->indices[2]; newidxtab->indices[2] = idxtab->indices[3]; idxtab = &e->indextab[OBJVTexture]; - newidxtab = &newe[1]->indextab[OBJVTexture]; - newidxtab->nindex = 3; - newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); - newidxtab->indices[0] = idxtab->indices[0]; - newidxtab->indices[1] = idxtab->indices[2]; - newidxtab->indices[2] = idxtab->indices[3]; + if(idxtab->nindex > 0){ + newidxtab = &newe[1]->indextab[OBJVTexture]; + newidxtab->nindex = 3; + newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); + newidxtab->indices[0] = idxtab->indices[0]; + newidxtab->indices[1] = idxtab->indices[2]; + newidxtab->indices[2] = idxtab->indices[3]; + } idxtab = &e->indextab[OBJVNormal]; - newidxtab = &newe[1]->indextab[OBJVNormal]; - newidxtab->nindex = 3; - newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); - newidxtab->indices[0] = idxtab->indices[0]; - newidxtab->indices[1] = idxtab->indices[2]; - newidxtab->indices[2] = idxtab->indices[3]; + if(idxtab->nindex > 0){ + newidxtab = &newe[1]->indextab[OBJVNormal]; + newidxtab->nindex = 3; + newidxtab->indices = emalloc(newidxtab->nindex*sizeof(*newidxtab->indices)); + newidxtab->indices[0] = idxtab->indices[0]; + newidxtab->indices[1] = idxtab->indices[2]; + newidxtab->indices[2] = idxtab->indices[3]; + } return 2; } |