- R_Mesh_Start();
-}
-
-void R_Mesh_AddTransparent(void)
-{
- int i, j, k, *index;
- float viewdistcompare, centerscaler, dist1, dist2, dist3, center, maxdist;
- buf_vertex_t *vert1, *vert2, *vert3;
- buf_transtri_t *tri;
- buf_mesh_t *mesh, *transmesh;
-
- if (!currenttransmesh)
- return;
-
- // convert index data to transtris for sorting
- for (j = 0;j < currenttransmesh;j++)
- {
- mesh = buf_transmesh + j;
- k = mesh->firsttriangle;
- index = &buf_transtri[k].index[0];
- for (i = 0;i < mesh->triangles;i++)
- {
- tri = &buf_sorttranstri[k++];
- tri->mesh = mesh;
- tri->index[0] = *index++;
- tri->index[1] = *index++;
- tri->index[2] = *index++;
- }
- }
-
- // map farclip to 0-4095 list range
- centerscaler = (TRANSDEPTHRES / r_farclip) * (1.0f / 3.0f);
- viewdistcompare = viewdist + 4.0f;
-
- memset(buf_sorttranstri_list, 0, TRANSDEPTHRES * sizeof(buf_transtri_t *));
-
- k = 0;
- for (j = 0;j < currenttranstriangle;j++)
- {
- tri = &buf_sorttranstri[j];
- i = tri->mesh->firstvert;
-
- vert1 = &buf_transvertex[tri->index[0] + i];
- vert2 = &buf_transvertex[tri->index[1] + i];
- vert3 = &buf_transvertex[tri->index[2] + i];
-
- dist1 = DotProduct(vert1->v, vpn);
- dist2 = DotProduct(vert2->v, vpn);
- dist3 = DotProduct(vert3->v, vpn);
-
- maxdist = max(dist1, max(dist2, dist3));
- if (maxdist < viewdistcompare)
- continue;
-
- center = (dist1 + dist2 + dist3) * centerscaler - viewdist;
-#if SLOWMATH
- i = (int) center;
- i = bound(0, i, (TRANSDEPTHRES - 1));
-#else
- if (center < 0.0f)
- center = 0.0f;
- center += 8388608.0f;
- i = *((int *)¢er) & 0x7FFFFF;
- i = min(i, (TRANSDEPTHRES - 1));
-#endif
- tri->next = buf_sorttranstri_list[i];
- buf_sorttranstri_list[i] = tri;
- k++;
- }
-
- for (i = 0;i < currenttransmesh;i++)
- buf_transmesh[i].transchain = NULL;
- transmesh = NULL;
- for (j = 0;j < TRANSDEPTHRES;j++)
- {
- if ((tri = buf_sorttranstri_list[j]))
- {
- for (;tri;tri = tri->next)
- {
- if (!tri->mesh->transchain)
- {
- tri->mesh->chain = transmesh;
- transmesh = tri->mesh;
- }
- tri->meshsortchain = tri->mesh->transchain;
- tri->mesh->transchain = tri;
- }
- }
- }
-
- for (;transmesh;transmesh = transmesh->chain)
- {
- if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currentvertex + transmesh->verts > max_verts)
- R_Mesh_Render();
-
- mesh = &buf_mesh[currentmesh++];
- *mesh = *transmesh; // copy mesh properties
-
- mesh->firstvert = currentvertex;
- memcpy(&buf_vertex[currentvertex], &buf_transvertex[transmesh->firstvert], transmesh->verts * sizeof(buf_vertex_t));
- memcpy(&buf_fcolor[currentvertex], &buf_transfcolor[transmesh->firstvert], transmesh->verts * sizeof(buf_fcolor_t));
- for (i = 0;i < backendunits && transmesh->textures[i];i++)
- memcpy(&buf_texcoord[i][currentvertex], &buf_transtexcoord[i][transmesh->firstvert], transmesh->verts * sizeof(buf_texcoord_t));
- currentvertex += mesh->verts;
-
- mesh->firsttriangle = currenttriangle;
- for (tri = transmesh->transchain;tri;tri = tri->meshsortchain)
- {
- buf_tri[currenttriangle].index[0] = tri->index[0];
- buf_tri[currenttriangle].index[1] = tri->index[1];
- buf_tri[currenttriangle].index[2] = tri->index[2];
- currenttriangle++;
- }
- mesh->triangles = currenttriangle - mesh->firsttriangle;
- }
-
- currenttransmesh = 0;
- currenttranstriangle = 0;
- currenttransvertex = 0;