-static void draw_mesh(struct mesh *mesh)
-{
- if(mesh->iarr) {
- g3d_draw_indexed(mesh->prim, mesh->varr, mesh->vcount, mesh->iarr, mesh->icount);
- } else {
- g3d_draw(mesh->prim, mesh->varr, mesh->vcount);
- }
-}
-
-static struct {
- struct g3d_vertex *varr;
- const float *xform;
-} zsort_cls;
-
-static int zsort_cmp(const void *aptr, const void *bptr)
-{
- const float *m = zsort_cls.xform;
-
- const struct g3d_vertex *va = (const struct g3d_vertex*)aptr;
- const struct g3d_vertex *vb = (const struct g3d_vertex*)bptr;
-
- float za = m[2] * va->x + m[6] * va->y + m[10] * va->z + m[14];
- float zb = m[2] * vb->x + m[6] * vb->y + m[10] * vb->z + m[14];
-
- ++va;
- ++vb;
-
- za += m[2] * va->x + m[6] * va->y + m[10] * va->z + m[14];
- zb += m[2] * vb->x + m[6] * vb->y + m[10] * vb->z + m[14];
-
- return za - zb;
-}
-
-static void zsort(struct mesh *m)
-{
- int nfaces = m->vcount / m->prim;
-
- zsort_cls.varr = m->varr;
- zsort_cls.xform = g3d_get_matrix(G3D_MODELVIEW, 0);
-
- qsort(m->varr, nfaces, m->prim * sizeof *m->varr, zsort_cmp);
-}
-