+ {
+ // use the bufferobject if all triangles are accepted
+ usebufferobject = true;
+ batchnumtriangles = 0;
+ // note: this only accepts consecutive surfaces because
+ // non-consecutive surfaces often have extreme vertex
+ // ranges (due to large numbers of surfaces omitted
+ // between them)
+ surface = batchsurfacelist[k];
+ for (l = k;l < batchnumsurfaces && surface == batchsurfacelist[l] && tex == surface->texture;l++, surface++)
+ {
+ RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
+ for (m = surface->num_firsttriangle, mend = m + surface->num_triangles;m < mend;m++)
+ {
+ if (culltriangles)
+ {
+ if (trispvs)
+ {
+ if (!CHECKPVSBIT(trispvs, m))
+ {
+ usebufferobject = false;
+ continue;
+ }
+ }
+ else
+ {
+ 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;
+ }
+ }
+ }
+ 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++;
+ r_refdef.stats.lights_lighttriangles++;
+ if (batchnumtriangles >= BATCHSIZE)
+ {
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, 0, 0);
+ batchnumtriangles = 0;
+ usebufferobject = false;
+ }
+ }
+ r_refdef.stats.lights_lighttriangles += batchsurfacelist[l]->num_triangles;
+ }
+ if (batchnumtriangles > 0)
+ {
+ Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
+ if (usebufferobject)
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, ent->model->surfmesh.ebo, sizeof(int[3]) * batchsurfacelist[k]->num_firsttriangle);
+ else
+ R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, 0, 0);
+ }
+ }