- cl = m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- if (fogenabled)
- {
- if (softwaretransform_complexity)
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorSubtract(outv, r_origin, diff);
- outc[0] = outc[1] = outc[2] = cl * (1 - exp(fogdensity/DotProduct(diff, diff)));
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- else
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- VectorCopy(v->v, outv);
- outv[3] = 1;
- VectorSubtract(outv, r_origin, diff);
- outc[0] = outc[1] = outc[2] = cl * (1 - exp(fogdensity/DotProduct(diff, diff)));
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- }
- else
- {
- if (softwaretransform_complexity)
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- outc[0] = outc[1] = outc[2] = cl;
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- else
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- VectorCopy(v->v, outv);
- outv[3] = 1;
- outc[0] = outc[1] = outc[2] = cl;
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- }
- }
- }
-#else
- int i;
- float diff[3], ifog;
- surfvertex_t *v;
- surfvert_t *sv;
- surfmesh_t *mesh;
- rmeshinfo_t m;
-
- memset(&m, 0, sizeof(m));
- if (currentrenderentity->effects & EF_ADDITIVE)
- {
- m.transparent = true;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- }
- else if (surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1)
- {
- m.transparent = true;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
- }
- else
- {
- m.transparent = false;
- m.blendfunc1 = GL_ONE;
- m.blendfunc2 = GL_ZERO;
- }
- m.vertex = &svert[0].v[0];
- m.vertexstep = sizeof(surfvert_t);
- m.tex[0] = R_GetTexture(surf->currenttexture->texture);
- m.texcoordstep[0] = sizeof(surfvertex_t);
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- m.index = mesh->index;
- m.texcoords[0] = &mesh->vertex->st[0];
- if (fogenabled)
- {
- m.color = &svert[0].c[0];
- m.colorstep = sizeof(surfvert_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- softwaretransform(v->v, sv->v);
- VectorSubtract(sv->v, r_origin, diff);
- ifog = 1 - exp(fogdensity/DotProduct(diff, diff));
- sv->c[0] = ifog;
- sv->c[1] = ifog;
- sv->c[2] = ifog;
- sv->c[3] = currentrenderentity->alpha;
- }
- }
- else
- {
- m.cr = m.cg = m.cb = 1;
- m.ca = currentrenderentity->alpha;
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- softwaretransform(v->v, sv->v);
- }
- R_Mesh_Draw(&m);
- }
-#endif
-}
-
-static void RSurfShader_Wall_Pass_Light(msurface_t *surf)
-{
-#if USEMESHBUFFER
- int i;
- surfvertex_t *v;
- float *outv, *outc, *outst, *outuv, cl, ca, diff[3], f;
- surfmesh_t *mesh;
- rmeshbufferinfo_t m;
-
- if (surf->dlightframe != r_framecount)
- return;
- if (currentrenderentity->effects & EF_FULLBRIGHT)
- return;
-
- memset(&m, 0, sizeof(m));
- if (currentrenderentity->effects & EF_ADDITIVE)
- {
- m.transparent = true;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- }
- else if (surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1)
- {
- m.transparent = true;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE_MINUS_SRC_ALPHA;
- }
- else
- {
- m.transparent = false;
- m.blendfunc1 = GL_ONE;
- m.blendfunc2 = GL_ZERO;
- }
- m.depthwrite = false;
- m.depthdisable = false;
- m.tex[0] = R_GetTexture(surf->currenttexture->texture);
- ca = currentrenderentity->alpha;
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- if (RSurf_LightCheck(surf->dlightbits, mesh))
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
-
- if (R_Mesh_Draw_GetBuffer(&m))
- {
- cl = m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0], outuv = m.texcoords[1];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2, outuv += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorClear(outc);
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- RSurf_LightSeparate(surf->dlightbits, m.numverts, m.vertex, m.color);
- if (fogenabled)
- {
- for (i = 0, outv = m.vertex, outc = m.color;i < m.numverts;i++, outv += 4, outc += 4)
- {
- VectorSubtract(outv, r_origin, diff);
- f = cl * (1 - exp(fogdensity/DotProduct(diff, diff)));
- VectorScale(outc, f, outc);
- }
- }
- else if (cl != 1)
- for (i = 0, outc = m.color;i < m.numverts;i++, outc += 4)
- VectorScale(outc, cl, outc);
- }
- }
- }
-#else
- int i;
- float diff[3], ifog;
- surfvertex_t *v;
- surfvert_t *sv;
- surfmesh_t *mesh;
- rmeshinfo_t m;
-
- memset(&m, 0, sizeof(m));
- if (currentrenderentity->effects & EF_ADDITIVE)
- m.transparent = true;
- else if (surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1)
- m.transparent = true;
- else
- m.transparent = false;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- m.vertex = &svert[0].v[0];
- m.vertexstep = sizeof(surfvert_t);
- m.color = &svert[0].c[0];
- m.colorstep = sizeof(surfvert_t);
- m.tex[0] = R_GetTexture(surf->currenttexture->texture);
- m.texcoordstep[0] = sizeof(surfvertex_t);
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- m.index = mesh->index;
- m.texcoords[0] = &mesh->vertex->st[0];
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- softwaretransform(v->v, sv->v);
- sv->c[0] = 0;
- sv->c[1] = 0;
- sv->c[2] = 0;
- sv->c[3] = currentrenderentity->alpha;
- }
- if (RSurf_Light(surf->dlightbits, m.numverts))
- {
- if (fogenabled)
- {
- for (i = 0, sv = svert;i < m.numverts;i++, sv++)
- {
- VectorSubtract(sv->v, r_origin, diff);
- ifog = 1 - exp(fogdensity/DotProduct(diff, diff));
- sv->c[0] *= ifog;
- sv->c[1] *= ifog;
- sv->c[2] *= ifog;
- }
- }
- R_Mesh_Draw(&m);
- }
- }
-#endif
-}
-
-static void RSurfShader_Wall_Pass_Glow(msurface_t *surf)
-{
-#if USEMESHBUFFER
- int i;
- surfvertex_t *v;
- float *outv, *outc, *outst, cl, ca, diff[3];
- surfmesh_t *mesh;
- rmeshbufferinfo_t m;
- memset(&m, 0, sizeof(m));
- m.transparent = currentrenderentity->effects & EF_ADDITIVE || surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- m.tex[0] = R_GetTexture(surf->currenttexture->glowtexture);
- ca = currentrenderentity->alpha;
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
-
- if (R_Mesh_Draw_GetBuffer(&m))
- {
- cl = m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- if (fogenabled)
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorSubtract(outv, r_origin, diff);
- outc[0] = outc[1] = outc[2] = cl * (1 - exp(fogdensity/DotProduct(diff, diff)));
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- else
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- outc[0] = outc[1] = outc[2] = cl;
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- }
- }
-#else
- int i;
- float diff[3], ifog;
- surfvertex_t *v;
- surfvert_t *sv;
- surfmesh_t *mesh;
- rmeshinfo_t m;
-
- memset(&m, 0, sizeof(m));
- m.transparent = currentrenderentity->effects & EF_ADDITIVE || surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- m.cr = 1;
- m.cg = 1;
- m.cb = 1;
- m.ca = currentrenderentity->alpha;
- m.tex[0] = R_GetTexture(surf->currenttexture->glowtexture);
- m.texcoordstep[0] = sizeof(surfvertex_t);
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- m.index = mesh->index;
- m.texcoords[0] = &mesh->vertex->st[0];
- if (fogenabled)
- {
- m.color = &svert[0].c[0];
- m.colorstep = sizeof(surfvert_t);
- if (softwaretransform_complexity)
- {
- m.vertex = &svert[0].v[0];
- m.vertexstep = sizeof(surfvert_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- softwaretransform(v->v, sv->v);
- VectorSubtract(sv->v, r_origin, diff);
- ifog = 1 - exp(fogdensity/DotProduct(diff, diff));
- sv->c[0] = m.cr * ifog;
- sv->c[1] = m.cg * ifog;
- sv->c[2] = m.cb * ifog;
- sv->c[3] = m.ca;
- }
- }
- else
- {
- m.vertex = &mesh->vertex->v[0];
- m.vertexstep = sizeof(surfvertex_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- VectorSubtract(v->v, r_origin, diff);
- ifog = 1 - exp(fogdensity/DotProduct(diff, diff));
- sv->c[0] = m.cr * ifog;
- sv->c[1] = m.cg * ifog;
- sv->c[2] = m.cb * ifog;
- sv->c[3] = m.ca;
- }
- }
- }
- else
- {
- if (softwaretransform_complexity)
- {
- m.vertex = &svert[0].v[0];
- m.vertexstep = sizeof(surfvert_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- softwaretransform(v->v, sv->v);
- }
- else
- {
- m.vertex = &mesh->vertex->v[0];
- m.vertexstep = sizeof(surfvertex_t);
- }
- }
- R_Mesh_Draw(&m);
- }
-#endif
-}
-
-static void RSurfShader_Wall_Pass_Fog(msurface_t *surf)
-{
-#if USEMESHBUFFER
- int i;
- surfvertex_t *v;
- float *outv, *outc, *outst, cl, ca, diff[3], f;
- surfmesh_t *mesh;
- rmeshbufferinfo_t m;
- memset(&m, 0, sizeof(m));
- m.transparent = currentrenderentity->effects & EF_ADDITIVE || surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- ca = currentrenderentity->alpha;
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
-
- if (R_Mesh_Draw_GetBuffer(&m))
- {
- cl = m.colorscale;
- memcpy(m.index, mesh->index, m.numtriangles * sizeof(int[3]));
- if (softwaretransform_complexity)
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- softwaretransform(v->v, outv);
- outv[3] = 1;
- VectorSubtract(outv, r_origin, diff);
- f = cl * exp(fogdensity/DotProduct(diff, diff));
- VectorScale(fogcolor, f, outc);
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- else
- {
- for (i = 0, v = mesh->vertex, outv = m.vertex, outc = m.color, outst = m.texcoords[0];i < m.numverts;i++, v++, outv += 4, outc += 4, outst += 2)
- {
- VectorCopy(v->v, outv);
- outv[3] = 1;
- VectorSubtract(outv, r_origin, diff);
- VectorSubtract(outv, r_origin, diff);
- f = cl * exp(fogdensity/DotProduct(diff, diff));
- VectorScale(fogcolor, f, outc);
- outc[3] = ca;
- outst[0] = v->st[0];
- outst[1] = v->st[1];
- }
- }
- }
- }
-#else
- int i;
- surfvertex_t *v;
- surfvert_t *sv;
- rmeshinfo_t m;
- surfmesh_t *mesh;
- vec3_t diff;
-
- memset(&m, 0, sizeof(m));
- m.transparent = currentrenderentity->effects & EF_ADDITIVE || surf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1;
- m.blendfunc1 = GL_SRC_ALPHA;
- m.blendfunc2 = GL_ONE;
- m.color = &svert[0].c[0];
- m.colorstep = sizeof(surfvert_t);
- m.tex[0] = R_GetTexture(surf->currenttexture->fogtexture);
- m.texcoordstep[0] = sizeof(surfvertex_t);
- for (mesh = surf->mesh;mesh;mesh = mesh->chain)
- {
- m.numtriangles = mesh->numtriangles;
- m.numverts = mesh->numverts;
- m.index = mesh->index;
- m.texcoords[0] = &mesh->vertex->st[0];
- if (softwaretransform_complexity)
- {
- m.vertex = &svert[0].v[0];
- m.vertexstep = sizeof(surfvert_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- softwaretransform(v->v, sv->v);
- VectorSubtract(sv->v, r_origin, diff);
- sv->c[0] = fogcolor[0];
- sv->c[1] = fogcolor[1];
- sv->c[2] = fogcolor[2];
- sv->c[3] = currentrenderentity->alpha * exp(fogdensity/DotProduct(diff,diff));
- }
- }
- else
- {
- m.vertex = &mesh->vertex->v[0];
- m.vertexstep = sizeof(surfvertex_t);
- for (i = 0, sv = svert, v = mesh->vertex;i < m.numverts;i++, sv++, v++)
- {
- VectorSubtract(v->v, r_origin, diff);
- sv->c[0] = fogcolor[0];
- sv->c[1] = fogcolor[1];
- sv->c[2] = fogcolor[2];
- sv->c[3] = currentrenderentity->alpha * exp(fogdensity/DotProduct(diff,diff));
- }
- }
- R_Mesh_Draw(&m);
- }
-#endif
-}
-
-static void RSurfShader_Wall_Fullbright(msurface_t *firstsurf)
-{
- msurface_t *surf;
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseFullbright(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
-}
-
-static void RSurfShader_Wall_Vertex(msurface_t *firstsurf)
-{
- msurface_t *surf;
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseVertex(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
-}
-
-static void RSurfShader_Wall_Lightmap(msurface_t *firstsurf)
-{
- msurface_t *surf;
- if (r_vertexsurfaces.integer)
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseVertex(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- else if (r_multitexture.integer)
- {
- if (r_dlightmap.integer)
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseMTex(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- else
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseMTex(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->dlightframe == r_framecount)
- RSurfShader_Wall_Pass_Light(surf);
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- }
- else if (firstsurf->currenttexture->fogtexture != NULL || currentrenderentity->alpha != 1 || currentrenderentity->effects & EF_ADDITIVE)
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseVertex(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- else
- {
- if (r_dlightmap.integer)
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseTexture(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_BaseLightmap(surf);
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- else
- {
- for (surf = firstsurf;surf;surf = surf->chain)
- {
- c_brush_polys++;
- RSurfShader_Wall_Pass_BaseTexture(surf);
- }
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_BaseLightmap(surf);
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->dlightframe == r_framecount)
- RSurfShader_Wall_Pass_Light(surf);
- for (surf = firstsurf;surf;surf = surf->chain)
- if (surf->currenttexture->glowtexture)
- RSurfShader_Wall_Pass_Glow(surf);
- if (fogenabled)
- for (surf = firstsurf;surf;surf = surf->chain)
- RSurfShader_Wall_Pass_Fog(surf);
- }
- }
-}
-
-/*
-=============================================================
-
- WORLD MODEL
-
-=============================================================
-*/
-
-static void R_SolidWorldNode (void)
-{
- if (r_viewleaf->contents != CONTENTS_SOLID)
- {
- int portalstack;
- mportal_t *p, *pstack[8192];
- msurface_t *surf, **mark, **endmark;
- mleaf_t *leaf;
- // LordHavoc: portal-passage worldnode; follows portals leading
- // outward from viewleaf, if a portal leads offscreen it is not
- // followed, in indoor maps this can often cull a great deal of
- // geometry away when pvs data is not present (useful with pvs as well)
-
- leaf = r_viewleaf;
- leaf->worldnodeframe = r_framecount;
- portalstack = 0;
- loc0:
- c_leafs++;
-
- leaf->visframe = r_framecount;
-
- if (leaf->nummarksurfaces)
- {
- mark = leaf->firstmarksurface;
- endmark = mark + leaf->nummarksurfaces;
- do
- {
- surf = *mark++;
- // make sure surfaces are only processed once
- if (surf->worldnodeframe == r_framecount)
- continue;
- surf->worldnodeframe = r_framecount;
- if (PlaneDist(r_origin, surf->plane) < surf->plane->dist)
- {
- if (surf->flags & SURF_PLANEBACK)
- surf->visframe = r_framecount;
- }
- else
- {
- if (!(surf->flags & SURF_PLANEBACK))
- surf->visframe = r_framecount;
- }
- }
- while (mark < endmark);
- }
-
- // follow portals into other leafs
- p = leaf->portals;
- for (;p;p = p->next)
- {
- if (DotProduct(r_origin, p->plane.normal) < p->plane.dist)
- {
- leaf = p->past;
- if (leaf->worldnodeframe != r_framecount)
- {
- leaf->worldnodeframe = r_framecount;
- if (leaf->contents != CONTENTS_SOLID)
- {
- if (R_NotCulledBox(leaf->mins, leaf->maxs))
- {
- p->visframe = r_framecount;
- pstack[portalstack++] = p;
- goto loc0;
-
- loc1:
- p = pstack[--portalstack];
- }
- }
- }
- }
- }
-
- if (portalstack)
- goto loc1;
- }
- else
- {
- mnode_t *nodestack[8192], *node = cl.worldmodel->nodes;
- int nodestackpos = 0;
- // LordHavoc: recursive descending worldnode; if portals are not
- // available, this is a good last resort, can cull large amounts of
- // geometry, but is more time consuming than portal-passage and renders
- // things behind walls
-
-loc2:
- if (R_NotCulledBox(node->mins, node->maxs))
- {
- if (node->numsurfaces)
- {
- msurface_t *surf = cl.worldmodel->surfaces + node->firstsurface, *surfend = surf + node->numsurfaces;
- if (PlaneDiff (r_origin, node->plane) < 0)
- {
- for (;surf < surfend;surf++)
- {
- if (surf->flags & SURF_PLANEBACK)
- surf->visframe = r_framecount;
- }
- }
- else
- {
- for (;surf < surfend;surf++)
- {
- if (!(surf->flags & SURF_PLANEBACK))
- surf->visframe = r_framecount;
- }
- }
- }
-
- // recurse down the children
- if (node->children[0]->contents >= 0)
- {
- if (node->children[1]->contents >= 0)
- {
- if (nodestackpos < 8192)
- nodestack[nodestackpos++] = node->children[1];
- node = node->children[0];
- goto loc2;
- }
- else
- ((mleaf_t *)node->children[1])->visframe = r_framecount;
- node = node->children[0];
- goto loc2;
- }
- else
- {
- ((mleaf_t *)node->children[0])->visframe = r_framecount;
- if (node->children[1]->contents >= 0)
- {
- node = node->children[1];
- goto loc2;
- }
- else if (nodestackpos > 0)
- {
- ((mleaf_t *)node->children[1])->visframe = r_framecount;
- node = nodestack[--nodestackpos];
- goto loc2;
- }