+ surface = texturesurfacelist[i];
+ for (j = i + 1, surface2 = surface + 1;j < texturenumsurfaces;j++, surface2++)
+ if (texturesurfacelist[j] != surface2)
+ break;
+ surface2 = texturesurfacelist[j-1];
+ numvertices = surface2->num_firstvertex + surface2->num_vertices - surface->num_firstvertex;
+ numtriangles = surface2->num_firsttriangle + surface2->num_triangles - surface->num_firsttriangle;
+ GL_LockArrays(surface->num_firstvertex, numvertices);
+ R_Mesh_Draw(surface->num_firstvertex, numvertices, numtriangles, (rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
+ }
+ }
+ else
+ {
+ for (i = 0;i < texturenumsurfaces;i++)
+ {
+ surface = texturesurfacelist[i];
+ GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+ R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
+ }
+ }
+}
+
+static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurface_t **texturesurfacelist, int lightmaptexunit, int deluxemaptexunit)
+{
+ int i;
+ int j;
+ const msurface_t *surface = texturesurfacelist[0];
+ const msurface_t *surface2;
+ int firstvertex;
+ int endvertex;
+ int numvertices;
+ int numtriangles;
+ // TODO: lock all array ranges before render, rather than on each surface
+ if (texturenumsurfaces == 1)
+ {
+ R_Mesh_TexBind(lightmaptexunit, R_GetTexture(surface->lightmaptexture));
+ if (deluxemaptexunit >= 0)
+ R_Mesh_TexBind(deluxemaptexunit, R_GetTexture(surface->deluxemaptexture));
+ GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+ R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle));
+ }
+ else if (r_batchmode.integer == 2)
+ {
+ #define MAXBATCHTRIANGLES 4096
+ int batchtriangles = 0;
+ int batchelements[MAXBATCHTRIANGLES*3];
+ for (i = 0;i < texturenumsurfaces;i = j)
+ {
+ surface = texturesurfacelist[i];
+ R_Mesh_TexBind(lightmaptexunit, R_GetTexture(surface->lightmaptexture));
+ if (deluxemaptexunit >= 0)
+ R_Mesh_TexBind(deluxemaptexunit, R_GetTexture(surface->deluxemaptexture));
+ j = i + 1;
+ if (surface->num_triangles > MAXBATCHTRIANGLES)