+surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors)
+{
+ surfmesh_t *mesh;
+ qbyte *data;
+ mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + 3 + (neighbors ? 3 : 0)) * sizeof(int));
+ mesh->num_vertices = numvertices;
+ mesh->num_triangles = numtriangles;
+ data = (qbyte *)(mesh + 1);
+ if (mesh->num_vertices)
+ {
+ mesh->data_vertex3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_svector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_tvector3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_normal3f = (float *)data, data += sizeof(float[3]) * mesh->num_vertices;
+ mesh->data_texcoordtexture2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ mesh->data_texcoordlightmap2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ if (detailtexcoords)
+ mesh->data_texcoorddetail2f = (float *)data, data += sizeof(float[2]) * mesh->num_vertices;
+ if (vertexcolors)
+ mesh->data_lightmapcolor4f = (float *)data, data += sizeof(float[4]) * mesh->num_vertices;
+ if (lightmapoffsets)
+ mesh->data_lightmapoffsets = (int *)data, data += sizeof(int) * mesh->num_vertices;
+ }
+ if (mesh->num_triangles)
+ {
+ mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+ mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+ if (neighbors)
+ mesh->data_neighbor3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+ }
+ return mesh;
+}
+