+ surface = batchsurfacelist[l];
+ RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
+ for (m = surface->num_firsttriangle, mend = m + surface->num_triangles;m < mend;m++)
+ {
+ if (trispvs)
+ {
+ if (!CHECKPVSBIT(trispvs, m))
+ {
+ usebufferobject = false;
+ continue;
+ }
+ }
+ else if (culltriangles)
+ {
+ if (r_shadow_frontsidecasting.integer && !PointInfrontOfTriangle(rsurface.entitylightorigin, rsurface.vertex3f + element3i[m*3+0]*3, rsurface.vertex3f + element3i[m*3+1]*3, rsurface.vertex3f + element3i[m*3+2]*3))
+ {
+ usebufferobject = false;
+ continue;
+ }
+ }
+ if (batchnumtriangles >= BATCHSIZE)
+ {
+ r_refdef.stats.lights_lighttriangles += batchnumtriangles;
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ // use the element buffer if all triangles are consecutive
+ if (m == batchfirsttriangle + batchnumtriangles)
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchfirsttriangle, batchnumtriangles, ent->model->surfmesh.data_element3i, ent->model->surfmesh.data_element3s, ent->model->surfmesh.ebo3i, ent->model->surfmesh.ebo3s);
+ else
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, 0, batchnumtriangles, batchelements, NULL, 0, 0);
+ usebufferobject = true;
+ batchnumtriangles = 0;
+ batchfirsttriangle = m;
+ }
+ batchelements[batchnumtriangles*3+0] = element3i[m*3+0];
+ batchelements[batchnumtriangles*3+1] = element3i[m*3+1];
+ batchelements[batchnumtriangles*3+2] = element3i[m*3+2];
+ batchnumtriangles++;
+ }
+ }
+ if (batchnumtriangles > 0)
+ {
+ r_refdef.stats.lights_lighttriangles += batchnumtriangles;
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ // use the element buffer if all triangles are consecutive
+ if (m == batchfirsttriangle + batchnumtriangles)
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchfirsttriangle, batchnumtriangles, ent->model->surfmesh.data_element3i, ent->model->surfmesh.data_element3s, ent->model->surfmesh.ebo3i, ent->model->surfmesh.ebo3s);