- glTexEnvi(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_MODULATE);
-CHECKGLERROR
- glEnable(GL_TEXTURE_2D);
-CHECKGLERROR
- glDisableClientState(GL_TEXTURE_COORD_ARRAY);
-CHECKGLERROR
- }
- glDisableClientState(GL_COLOR_ARRAY);
-CHECKGLERROR
- glDisableClientState(GL_VERTEX_ARRAY);
-CHECKGLERROR
-
- glDisable(GL_BLEND);
-CHECKGLERROR
- glEnable(GL_DEPTH_TEST);
-CHECKGLERROR
- glDepthMask(true);
-CHECKGLERROR
- glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
-CHECKGLERROR
-}
-
-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 = *((long *)¢er) & 0x7FFFFF;
- i = min(i, (TRANSDEPTHRES - 1));
-#endif
- tri->next = buf_sorttranstri_list[i];
- buf_sorttranstri_list[i] = tri;
- k++;
- }
-
- //if (currentmesh + k > max_meshs || currenttriangle + k > max_batch || currentvertex + currenttransvertex > max_verts)
- // R_Mesh_Render();
-
- 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)
- {
- int numverts = transmesh->lastvert - transmesh->firstvert + 1;
- if (currentmesh >= max_meshs || currenttriangle + transmesh->triangles > max_batch || currentvertex + numverts > max_verts)
- R_Mesh_Render();
-
- memcpy(&buf_vertex[currentvertex], &buf_transvertex[transmesh->firstvert], numverts * sizeof(buf_vertex_t));
- memcpy(&buf_fcolor[currentvertex], &buf_transfcolor[transmesh->firstvert], numverts * sizeof(buf_fcolor_t));
- for (i = 0;i < backendunits && transmesh->textures[i];i++)
- memcpy(&buf_texcoord[i][currentvertex], &buf_transtexcoord[i][transmesh->firstvert], numverts * sizeof(buf_texcoord_t));
-
- mesh = &buf_mesh[currentmesh++];
- *mesh = *transmesh; // copy mesh properties
- mesh->firstvert = currentvertex;
- mesh->lastvert = currentvertex + numverts - 1;
- currentvertex += numverts;
- 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;
-}
-
-void R_Mesh_Draw(const rmeshinfo_t *m)
-{
- // these are static because gcc runs out of virtual registers otherwise
- static int i, j, overbright;
- static float *in, scaler;
- static float cr, cg, cb, ca;
- static buf_mesh_t *mesh;
- static buf_vertex_t *vert;
- static buf_fcolor_t *fcolor;
- static buf_texcoord_t *texcoord[MAX_TEXTUREUNITS];
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
- if (m->index == NULL
- || !m->numtriangles
- || m->vertex == NULL
- || !m->numverts)
- Host_Error("R_Mesh_Draw: no triangles or verts\n");
-
- // ignore meaningless alpha meshs
- if (!m->depthwrite && m->blendfunc1 == GL_SRC_ALPHA && (m->blendfunc2 == GL_ONE || m->blendfunc2 == GL_ONE_MINUS_SRC_ALPHA))
- {
- if (m->color)
- {
- for (i = 0, in = m->color + 3;i < m->numverts;i++, (int)in += m->colorstep)
- if (*in >= 0.01f)
- break;
- if (i == m->numverts)
- return;
- }
- else if (m->ca < 0.01f)
- return;
- }
-
- if (!backendactive)
- Sys_Error("R_Mesh_Draw: called when backend is not active\n");
-
- scaler = 1;
- if (m->blendfunc2 == GL_SRC_COLOR)
- {
- if (m->blendfunc1 == GL_DST_COLOR) // 2x modulate with framebuffer
- scaler *= 0.5f;
- }
- else
- {
- if (m->tex[0])