+ // clear the visible surface and leaf flags arrays
+ memset(r_worldsurfacevisible, 0, model->num_surfaces);
+ memset(r_worldleafvisible, 0, model->brush.num_leafs);
+
+ r_worldnovis = false;
+
+ // if floating around in the void (no pvs data available, and no
+ // portals available), simply use all on-screen leafs.
+ if (!viewleaf || viewleaf->clusterindex < 0)
+ {
+ // no visibility method: (used when floating around in the void)
+ // simply cull each leaf to the frustum (view pyramid)
+ // similar to quake's RecursiveWorldNode but without cache misses
+ r_worldnovis = true;
+ for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
+ {
+ // if leaf is in current pvs and on the screen, mark its surfaces
+ if (!R_CullBox(leaf->mins, leaf->maxs))
+ {
+ renderstats.world_leafs++;
+ r_worldleafvisible[j] = true;
+ if (leaf->numleafsurfaces)
+ for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
+ r_worldsurfacevisible[*mark] = true;
+ }
+ }
+ }
+ // if the user prefers to disable portal culling (testing?), simply
+ // use all on-screen leafs that are in the pvs.
+ else if (!r_useportalculling.integer)
+ {
+ // pvs method:
+ // simply check if each leaf is in the Potentially Visible Set,
+ // and cull to frustum (view pyramid)
+ // similar to quake's RecursiveWorldNode but without cache misses
+ for (j = 0, leaf = model->brush.data_leafs;j < model->brush.num_leafs;j++, leaf++)
+ {
+ // if leaf is in current pvs and on the screen, mark its surfaces
+ if (CHECKPVSBIT(r_pvsbits, leaf->clusterindex) && !R_CullBox(leaf->mins, leaf->maxs))
+ {
+ renderstats.world_leafs++;
+ r_worldleafvisible[j] = true;
+ if (leaf->numleafsurfaces)
+ for (i = 0, mark = leaf->firstleafsurface;i < leaf->numleafsurfaces;i++, mark++)
+ r_worldsurfacevisible[*mark] = true;
+ }
+ }
+ }
+ // otherwise use a recursive portal flow, culling each portal to
+ // frustum and checking if the leaf the portal leads to is in the pvs
+ else