changed surface->mesh to surface->groupmesh and added num_firsttriangle and num_first...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Mar 2005 11:32:47 +0000 (11:32 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 28 Mar 2005 11:32:47 +0000 (11:32 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5130 d7cf8633-e32d-0410-b094-e92efae38249

gl_rsurf.c
model_brush.c
model_brush.h
model_shared.h
portals.c
pr_cmds.c

index f4e8c46..bc0047a 100644 (file)
@@ -306,17 +306,17 @@ static void RSurf_DeformVertices(const entity_render_t *ent, const texture_t *te
                VectorClear(forward);
                VectorClear(right);
                VectorSet(up, 0, 0, 1);
-               for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
+               for (j = 0;j < surface->num_vertices - 3;j += 4)
                {
                        VectorClear(center);
                        for (i = 0;i < 4;i++)
-                               VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
+                               VectorAdd(center, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
                        VectorScale(center, 0.25f, center);
                        // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
-                       Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
+                       Matrix4x4_FromVectors(&matrix1, (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex) + j*3, center);
                        Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
                        for (i = 0;i < 4;i++)
-                               Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
+                               Matrix4x4_Transform(&imatrix1, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (j+i)*3, v[i]);
                        forward[0] = modelorg[0] - center[0];
                        forward[1] = modelorg[1] - center[1];
                        VectorNormalize(forward);
@@ -332,29 +332,29 @@ static void RSurf_DeformVertices(const entity_render_t *ent, const texture_t *te
                Matrix4x4_Transform(&ent->inversematrix, r_viewright, right);
                Matrix4x4_Transform(&ent->inversematrix, r_viewup, up);
                // a single autosprite surface can contain multiple sprites...
-               for (j = 0;j < surface->mesh.num_vertices - 3;j += 4)
+               for (j = 0;j < surface->num_vertices - 3;j += 4)
                {
                        VectorClear(center);
                        for (i = 0;i < 4;i++)
-                               VectorAdd(center, surface->mesh.data_vertex3f + (j+i) * 3, center);
+                               VectorAdd(center, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (j+i) * 3, center);
                        VectorScale(center, 0.25f, center);
                        // FIXME: calculate vectors from triangle edges instead of using texture vectors as an easy way out?
-                       Matrix4x4_FromVectors(&matrix1, surface->mesh.data_normal3f + j*3, surface->mesh.data_svector3f + j*3, surface->mesh.data_tvector3f + j*3, center);
+                       Matrix4x4_FromVectors(&matrix1, (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex) + j*3, (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex) + j*3, center);
                        Matrix4x4_Invert_Simple(&imatrix1, &matrix1);
                        for (i = 0;i < 4;i++)
-                               Matrix4x4_Transform(&imatrix1, surface->mesh.data_vertex3f + (j+i)*3, v[i]);
+                               Matrix4x4_Transform(&imatrix1, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (j+i)*3, v[i]);
                        for (i = 0;i < 4;i++)
                                VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (i+j) * 3);
                }
        }
        else
-               memcpy(varray_vertex3f, surface->mesh.data_vertex3f, sizeof(float[3]) * surface->mesh.num_vertices);
+               memcpy(varray_vertex3f, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), sizeof(float[3]) * surface->num_vertices);
 }
 
 // any sort of deformvertices call is *VERY* rare, so this must be optimized
 // to skip deformvertices quickly!
 #if 1
-#define RSurf_GetVertexPointer(ent, texture, surface, modelorg) ((texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2)) ? (RSurf_DeformVertices(ent, texture, surface, modelorg), varray_vertex3f) : surface->mesh.data_vertex3f)
+#define RSurf_GetVertexPointer(ent, texture, surface, modelorg) ((texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2)) ? (RSurf_DeformVertices(ent, texture, surface, modelorg), varray_vertex3f) : (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex))
 #else
 static float *RSurf_GetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg)
 {
@@ -364,7 +364,7 @@ static float *RSurf_GetVertexPointer(const entity_render_t *ent, const texture_t
                return varray_vertex3f;
        }
        else
-               return surface->mesh.data_vertex3f;
+               return (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex);
 }
 #endif
 
@@ -436,11 +436,11 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                {
                        surface = texturesurfacelist[texturesurfaceindex];
                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
-                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                       R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : surface->mesh.data_lightmapcolor4f);
-                       R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
-                       GL_LockArrays(0, surface->mesh.num_vertices);
-                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                       R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
+                       R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+                       GL_LockArrays(0, surface->num_vertices);
+                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        GL_LockArrays(0, 0);
                }
                qglEnable(GL_CULL_FACE);
@@ -491,9 +491,9 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                        for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
-                               R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
-                               GL_LockArrays(0, surface->mesh.num_vertices);
-                               R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                               R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+                               GL_LockArrays(0, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
@@ -525,10 +525,10 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                {
                        surface = texturesurfacelist[texturesurfaceindex];
                        R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
-                       GL_LockArrays(0, surface->mesh.num_vertices);
-                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                       GL_LockArrays(0, surface->num_vertices);
+                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        GL_LockArrays(0, 0);
                }
 
@@ -579,15 +579,15 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_VertexPointer(vertex3f);
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                        if (surface->lightmaptexture)
                                        {
                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
                                                if (fogallpasses)
                                                {
                                                        R_Mesh_ColorPointer(varray_color4f);
-                                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                        {
                                                                VectorSubtract(v, modelorg, diff);
                                                                f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -607,18 +607,18 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        {
                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                R_Mesh_ColorPointer(varray_color4f);
-                                               if (surface->mesh.data_lightmapcolor4f)
+                                               if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
                                                {
-                                                       for (i = 0, c = varray_color4f;i < surface->mesh.num_vertices;i++, c += 4)
+                                                       for (i = 0, c = varray_color4f;i < surface->num_vertices;i++, c += 4)
                                                        {
-                                                               c[0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
-                                                               c[1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
-                                                               c[2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
-                                                               c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                               c[0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
+                                                               c[1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
+                                                               c[2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
+                                                               c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                        }
                                                        if (fogallpasses)
                                                        {
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -632,8 +632,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        GL_Color(0, 0, 0, a);
                                                }
                                        }
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -674,17 +674,17 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                surface = texturesurfacelist[texturesurfaceindex];
                                                vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                                R_Mesh_VertexPointer(vertex3f);
-                                               R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                               R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        c[0] = 0;
                                                        c[1] = 0;
                                                        c[2] = 0;
-                                                       if (surface->mesh.data_lightmapcolor4f)
-                                                               VectorCopy(surface->mesh.data_lightmapcolor4f + i*4, c);
+                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
+                                                               VectorCopy((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) + i*4, c);
                                                        else if (surface->lightmapinfo)
                                                        {
-                                                               const qbyte *lm = surface->lightmapinfo->samples + surface->mesh.data_lightmapoffsets[i];
+                                                               const qbyte *lm = surface->lightmapinfo->samples + (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i];
                                                                float scale = d_lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f);
                                                                VectorMA(c, scale, lm, c);
                                                                if (surface->lightmapinfo->styles[1] != 255)
@@ -716,13 +716,13 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                                f = 1 - exp(fogdensity/DotProduct(diff, diff));
                                                                VectorScale(c, f, c);
                                                        }
-                                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
-                                                               c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                               c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                        else
                                                                c[3] = a;
                                                }
-                                               GL_LockArrays(0, surface->mesh.num_vertices);
-                                               R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                               GL_LockArrays(0, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                GL_LockArrays(0, 0);
                                        }
                                }
@@ -735,24 +735,24 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        surface = texturesurfacelist[texturesurfaceindex];
                                                        vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                                        R_Mesh_VertexPointer(vertex3f);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
                                                                        c[0] = r * f;
                                                                        c[1] = g * f;
                                                                        c[2] = b * f;
-                                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                                       c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                                }
                                                        }
                                                        else
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -762,8 +762,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                                        c[3] = a;
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -774,16 +774,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        surface = texturesurfacelist[texturesurfaceindex];
                                                        vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                                        R_Mesh_VertexPointer(vertex3f);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        c[0] = r;
                                                                        c[1] = g;
                                                                        c[2] = b;
-                                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                                       c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                                }
                                                        }
                                                        else
@@ -791,8 +791,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                                R_Mesh_ColorPointer(NULL);
                                                                GL_Color(r, g, b, a);
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -815,9 +815,9 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -832,8 +832,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -863,8 +863,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
                                                        RSurf_DeformVertices(ent, texture, surface, modelorg);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -873,10 +873,10 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        else //if (r == 1 && g == 1 && b == 1)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
-                                                               R_Mesh_ColorPointer(surface->mesh.data_lightmapcolor4f);
+                                                               R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -886,8 +886,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
                                                        RSurf_DeformVertices(ent, texture, surface, modelorg);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -897,16 +897,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0;i < surface->mesh.num_vertices;i++)
+                                                               for (i = 0;i < surface->num_vertices;i++)
                                                                {
-                                                                       varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
-                                                                       varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
-                                                                       varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
-                                                                       varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
+                                                                       varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
+                                                                       varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
+                                                                       varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
+                                                                       varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -926,11 +926,11 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
-                                                       qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), surface->mesh.data_vertex3f);
+                                                       qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
                                                        qglClientActiveTexture(GL_TEXTURE0_ARB);
-                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->mesh.data_texcoordlightmap2f);
+                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
                                                        qglClientActiveTexture(GL_TEXTURE1_ARB);
-                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->mesh.data_texcoordtexture2f);
+                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -941,19 +941,19 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                                qglEnableClientState(GL_COLOR_ARRAY);
-                                                               qglColorPointer(4, GL_FLOAT, sizeof(float[4]), surface->mesh.data_lightmapcolor4f);
+                                                               qglColorPointer(4, GL_FLOAT, sizeof(float[4]), (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
                                                        }
-                                                       qglLockArraysEXT(0, surface->mesh.num_vertices);
-                                                       qglDrawRangeElements(GL_TRIANGLES, 0, surface->mesh.num_vertices, surface->mesh.num_triangles * 3, GL_UNSIGNED_INT, surface->mesh.data_element3i);
+                                                       qglLockArraysEXT(0, surface->num_vertices);
+                                                       qglDrawRangeElements(GL_TRIANGLES, 0, surface->num_vertices, surface->num_triangles * 3, GL_UNSIGNED_INT, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        qglUnlockArraysEXT();
                                                }
 #else
                                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
-                                                       R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
+                                                       R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -962,10 +962,10 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        else //if (r == 1 && g == 1 && b == 1)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
-                                                               R_Mesh_ColorPointer(surface->mesh.data_lightmapcolor4f);
+                                                               R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
 #endif
@@ -975,9 +975,9 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
-                                                       R_Mesh_VertexPointer(surface->mesh.data_vertex3f);
-                                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                                       R_Mesh_TexCoordPointer(1, 2, surface->mesh.data_texcoordtexture2f);
+                                                       R_Mesh_VertexPointer((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -987,16 +987,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0;i < surface->mesh.num_vertices;i++)
+                                                               for (i = 0;i < surface->num_vertices;i++)
                                                                {
-                                                                       varray_color4f[i*4+0] = surface->mesh.data_lightmapcolor4f[i*4+0] * r;
-                                                                       varray_color4f[i*4+1] = surface->mesh.data_lightmapcolor4f[i*4+1] * g;
-                                                                       varray_color4f[i*4+2] = surface->mesh.data_lightmapcolor4f[i*4+2] * b;
-                                                                       varray_color4f[i*4+3] = surface->mesh.data_lightmapcolor4f[i*4+3];
+                                                                       varray_color4f[i*4+0] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+0] * r;
+                                                                       varray_color4f[i*4+1] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+1] * g;
+                                                                       varray_color4f[i*4+2] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+2] * b;
+                                                                       varray_color4f[i*4+3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3];
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                                       GL_LockArrays(0, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -1015,10 +1015,10 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
                                        R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordlightmap2f);
-                                       R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : surface->mesh.data_lightmapcolor4f);
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                       R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1036,9 +1036,9 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                {
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1070,8 +1070,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                surface = texturesurfacelist[texturesurfaceindex];
                                vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                R_Mesh_VertexPointer(vertex3f);
-                               R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                               R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                {
                                        c[0] = r;
                                        c[1] = g;
@@ -1082,13 +1082,13 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                f = 1 - exp(fogdensity/DotProduct(diff, diff));
                                                VectorScale(c, f, c);
                                        }
-                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
-                                               c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                               c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                        else
                                                c[3] = a;
                                }
-                               GL_LockArrays(0, surface->mesh.num_vertices);
-                               R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                               GL_LockArrays(0, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1104,9 +1104,9 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                        {
                                surface = texturesurfacelist[texturesurfaceindex];
                                R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                               R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoorddetail2f);
-                               GL_LockArrays(0, surface->mesh.num_vertices);
-                               R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                               R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoorddetail2f + 2 * surface->num_firstvertex));
+                               GL_LockArrays(0, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1133,23 +1133,23 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_VertexPointer(vertex3f);
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                        R_Mesh_ColorPointer(varray_color4f);
-                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                        {
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        VectorSubtract(v, modelorg, diff);
                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
                                                        c[0] = f * r;
                                                        c[1] = f * g;
                                                        c[2] = f * b;
-                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                       c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                }
                                        }
                                        else
                                        {
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        VectorSubtract(v, modelorg, diff);
                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -1159,8 +1159,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        c[3] = a;
                                                }
                                        }
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1171,16 +1171,16 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        surface = texturesurfacelist[texturesurfaceindex];
                                        vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                        R_Mesh_VertexPointer(vertex3f);
-                                       R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
-                                       if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                        {
                                                R_Mesh_ColorPointer(varray_color4f);
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        c[0] = r;
                                                        c[1] = g;
                                                        c[2] = b;
-                                                       c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * a;
+                                                       c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * a;
                                                }
                                        }
                                        else
@@ -1188,8 +1188,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                R_Mesh_ColorPointer(NULL);
                                                GL_Color(r, g, b, a);
                                        }
-                                       GL_LockArrays(0, surface->mesh.num_vertices);
-                                       R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       GL_LockArrays(0, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1226,24 +1226,24 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                surface = texturesurfacelist[texturesurfaceindex];
                                vertex3f = RSurf_GetVertexPointer(ent, texture, surface, modelorg);
                                R_Mesh_VertexPointer(vertex3f);
-                               R_Mesh_TexCoordPointer(0, 2, surface->mesh.data_texcoordtexture2f);
+                               R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
                                R_Mesh_ColorPointer(varray_color4f);
-                               //RSurf_FogPassColors_Vertex3f_Color4f(surface->mesh.data_vertex3f, varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->mesh.num_vertices, modelorg);
-                               if (surface->mesh.data_lightmapcolor4f && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                               //RSurf_FogPassColors_Vertex3f_Color4f((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), varray_color4f, fogcolor[0], fogcolor[1], fogcolor[2], texture->currentalpha, 1, surface->num_vertices, modelorg);
+                               if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                {
-                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
                                                VectorSubtract(v, modelorg, diff);
                                                f = exp(fogdensity/DotProduct(diff, diff));
                                                c[0] = r;
                                                c[1] = g;
                                                c[2] = b;
-                                               c[3] = surface->mesh.data_lightmapcolor4f[i*4+3] * f * a;
+                                               c[3] = (surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex)[i*4+3] * f * a;
                                        }
                                }
                                else
                                {
-                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->mesh.num_vertices;i++, v += 3, c += 4)
+                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
                                                VectorSubtract(v, modelorg, diff);
                                                f = exp(fogdensity/DotProduct(diff, diff));
@@ -1253,8 +1253,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                c[3] = f * a;
                                        }
                                }
-                               GL_LockArrays(0, surface->mesh.num_vertices);
-                               R_Mesh_Draw(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                               GL_LockArrays(0, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1358,7 +1358,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                f = t->currentmaterialflags & flagsmask;
                                texture = t->currentframe;
                        }
-                       if (f && surface->mesh.num_triangles)
+                       if (f && surface->num_triangles)
                        {
                                // if lightmap parameters changed, rebuild lightmap texture
                                if (surface->cached_dlight && surface->lightmapinfo->samples)
@@ -1388,7 +1388,7 @@ void R_DrawSurfaces(entity_render_t *ent, qboolean skysurfaces)
                                f = t->currentmaterialflags & flagsmask;
                                texture = t->currentframe;
                        }
-                       if (f && surface->mesh.num_triangles)
+                       if (f && surface->num_triangles)
                        {
                                // if lightmap parameters changed, rebuild lightmap texture
                                if (surface->cached_dlight && surface->lightmapinfo->samples)
@@ -1670,7 +1670,7 @@ void R_Q1BSP_GetLightInfo(entity_render_t *ent, vec3_t relativelightorigin, floa
                                                if (BoxesOverlap(lightmins, lightmaxs, surface->mins, surface->maxs))
                                                if ((surface->texture->currentmaterialflags & (MATERIALFLAG_WALL | MATERIALFLAG_NODRAW | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
                                                {
-                                                       for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->mesh.num_triangles;triangleindex++, t++, e += 3)
+                                                       for (triangleindex = 0, t = surface->num_firstshadowmeshtriangle, e = model->brush.shadowmesh->element3i + t * 3;triangleindex < surface->num_triangles;triangleindex++, t++, e += 3)
                                                        {
                                                                v[0] = model->brush.shadowmesh->vertex3f + e[0] * 3;
                                                                v[1] = model->brush.shadowmesh->vertex3f + e[1] * 3;
@@ -1719,7 +1719,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                                continue;
                        if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                                continue;
-                       R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->mesh.num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
+                       R_Shadow_MarkVolumeFromBox(surface->num_firstshadowmeshtriangle, surface->num_triangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, relativelightorigin, lightmins, lightmaxs, surface->mins, surface->maxs);
                }
                R_Shadow_VolumeFromList(model->brush.shadowmesh->numverts, model->brush.shadowmesh->numtriangles, model->brush.shadowmesh->vertex3f, model->brush.shadowmesh->element3i, model->brush.shadowmesh->neighbor3i, relativelightorigin, lightradius + model->radius + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
        }
@@ -1739,14 +1739,14 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
                for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
                {
                        surface = model->brush.data_surfaces + surfacelist[surfacelistindex];
-                       if (surface->texture->basematerialflags & MATERIALFLAG_NODRAW || !surface->mesh.num_triangles)
+                       if (surface->texture->basematerialflags & MATERIALFLAG_NODRAW || !surface->num_triangles)
                                continue;
                        if (r_shadow_compilingrtlight)
                        {
                                // if compiling an rtlight, capture the mesh
                                t = surface->texture;
                                if ((t->basematerialflags & (MATERIALFLAG_WALL | MATERIALFLAG_TRANSPARENT)) == MATERIALFLAG_WALL)
-                                       Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, surface->mesh.num_triangles, surface->mesh.data_element3i);
+                                       Mod_ShadowMesh_AddMesh(r_shadow_mempool, r_shadow_compilingrtlight->static_meshchain_light, surface->texture->skin.base, surface->texture->skin.gloss, surface->texture->skin.nmap, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex), surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        }
                        else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
                        {
@@ -1756,7 +1756,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
                                {
                                        if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                                                qglDisable(GL_CULL_FACE);
-                                       R_Shadow_RenderLighting(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_element3i, surface->mesh.data_vertex3f, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f, surface->mesh.data_texcoordtexture2f, relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
+                                       R_Shadow_RenderLighting(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex), relativelightorigin, relativeeyeorigin, lightcolor, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, t->skin.base, t->skin.nmap, t->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
                                        if (surface->texture->textureflags & Q3TEXTUREFLAG_TWOSIDED)
                                                qglEnable(GL_CULL_FACE);
                                }
index 835098e..134c151 100644 (file)
@@ -220,12 +220,12 @@ static void Mod_Q1BSP_FindNonSolidLocation_r_Leaf(findnonsolidlocationinfo_t *in
                surface = info->model->brush.data_surfaces + *mark;
                if (surface->texture->supercontents & SUPERCONTENTS_SOLID)
                {
-                       for (k = 0;k < surface->mesh.num_triangles;k++)
+                       for (k = 0;k < surface->num_triangles;k++)
                        {
-                               tri = surface->mesh.data_element3i + k * 3;
-                               VectorCopy((surface->mesh.data_vertex3f + tri[0] * 3), vert[0]);
-                               VectorCopy((surface->mesh.data_vertex3f + tri[1] * 3), vert[1]);
-                               VectorCopy((surface->mesh.data_vertex3f + tri[2] * 3), vert[2]);
+                               tri = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle) + k * 3;
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + tri[0] * 3), vert[0]);
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + tri[1] * 3), vert[1]);
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + tri[2] * 3), vert[2]);
                                VectorSubtract(vert[1], vert[0], edge[0]);
                                VectorSubtract(vert[2], vert[1], edge[1]);
                                CrossProduct(edge[1], edge[0], facenormal);
@@ -1736,7 +1736,7 @@ static void Mod_Q1BSP_GenerateWarpMesh(msurface_t *surface)
 
        subdivpolytriangles = 0;
        subdivpolyverts = 0;
-       SubdividePolygon(surface->mesh.num_vertices, surface->mesh.data_vertex3f);
+       SubdividePolygon(surface->num_vertices, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
        if (subdivpolytriangles < 1)
                Host_Error("Mod_Q1BSP_GenerateWarpMesh: no triangles?\n");
 
@@ -1817,61 +1817,53 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                //      surface->flags |= SURF_PLANEBACK;
                //surface->plane = loadmodel->brush.data_planes + planenum;
 
-               surface->mesh.num_vertices = numedges;
-               surface->mesh.num_triangles = numedges - 2;
-               surface->mesh.data_vertex3f = loadmodel->meshlist[0]->data_vertex3f + totalverts * 3;
-               surface->mesh.data_texcoordtexture2f = loadmodel->meshlist[0]->data_texcoordtexture2f + totalverts * 2;
-               surface->mesh.data_texcoordlightmap2f = loadmodel->meshlist[0]->data_texcoordlightmap2f + totalverts * 2;
-               surface->mesh.data_texcoorddetail2f = loadmodel->meshlist[0]->data_texcoorddetail2f + totalverts * 2;
-               surface->mesh.data_svector3f = loadmodel->meshlist[0]->data_svector3f + totalverts * 3;
-               surface->mesh.data_tvector3f = loadmodel->meshlist[0]->data_tvector3f + totalverts * 3;
-               surface->mesh.data_normal3f = loadmodel->meshlist[0]->data_normal3f + totalverts * 3;
-               surface->mesh.data_lightmapoffsets = loadmodel->meshlist[0]->data_lightmapoffsets + totalverts;
-               surface->mesh.data_element3i = loadmodel->meshlist[0]->data_element3i + totaltris * 3;
-               surface->mesh.data_neighbor3i = loadmodel->meshlist[0]->data_neighbor3i + totaltris * 3;
+               surface->groupmesh = loadmodel->meshlist[0];
+               surface->num_firstvertex = totalverts;
+               surface->num_vertices = numedges;
+               surface->num_firsttriangle = totaltris;
+               surface->num_triangles = numedges - 2;
                totalverts += numedges;
                totaltris += numedges - 2;
 
                // convert edges back to a normal polygon
-               for (i = 0;i < surface->mesh.num_vertices;i++)
+               for (i = 0;i < surface->num_vertices;i++)
                {
                        int lindex = loadmodel->brushq1.surfedges[firstedge + i];
                        float s, t;
                        if (lindex > 0)
-                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[lindex].v[0]].position, surface->mesh.data_vertex3f + i * 3);
+                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[lindex].v[0]].position, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
                        else
-                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, surface->mesh.data_vertex3f + i * 3);
-                       s = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
-                       t = DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
-                       surface->mesh.data_texcoordtexture2f[i * 2 + 0] = s / surface->texture->width;
-                       surface->mesh.data_texcoordtexture2f[i * 2 + 1] = t / surface->texture->height;
-                       surface->mesh.data_texcoorddetail2f[i * 2 + 0] = s * (1.0f / 16.0f);
-                       surface->mesh.data_texcoorddetail2f[i * 2 + 1] = t * (1.0f / 16.0f);
-                       surface->mesh.data_texcoordlightmap2f[i * 2 + 0] = 0;
-                       surface->mesh.data_texcoordlightmap2f[i * 2 + 1] = 0;
-                       surface->mesh.data_lightmapoffsets[i] = 0;
+                               VectorCopy(loadmodel->brushq1.vertexes[loadmodel->brushq1.edges[-lindex].v[1]].position, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3);
+                       s = DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+                       t = DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
+                       (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 0] = s / surface->texture->width;
+                       (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex)[i * 2 + 1] = t / surface->texture->height;
+                       (surface->groupmesh->data_texcoorddetail2f + 2 * surface->num_firstvertex)[i * 2 + 0] = s * (1.0f / 16.0f);
+                       (surface->groupmesh->data_texcoorddetail2f + 2 * surface->num_firstvertex)[i * 2 + 1] = t * (1.0f / 16.0f);
+                       (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = 0;
+                       (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = 0;
+                       (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i] = 0;
                }
 
-               for (i = 0;i < surface->mesh.num_triangles;i++)
+               for (i = 0;i < surface->num_triangles;i++)
                {
-                       surface->mesh.data_element3i[i * 3 + 0] = 0;
-                       surface->mesh.data_element3i[i * 3 + 1] = i + 1;
-                       surface->mesh.data_element3i[i * 3 + 2] = i + 2;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 0] = 0;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 1] = i + 1;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 2] = i + 2;
                }
 
                // compile additional data about the surface geometry
-               Mod_BuildTriangleNeighbors(surface->mesh.data_neighbor3i, surface->mesh.data_element3i, surface->mesh.num_triangles);
-               Mod_BuildTextureVectorsAndNormals(surface->mesh.num_vertices, surface->mesh.num_triangles, surface->mesh.data_vertex3f, surface->mesh.data_texcoordtexture2f, surface->mesh.data_element3i, surface->mesh.data_svector3f, surface->mesh.data_tvector3f, surface->mesh.data_normal3f);
-               BoxFromPoints(surface->mins, surface->maxs, surface->mesh.num_vertices, surface->mesh.data_vertex3f);
+               Mod_BuildTextureVectorsAndNormals(surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex), (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), (surface->groupmesh->data_svector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_tvector3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_normal3f + 3 * surface->num_firstvertex));
+               BoxFromPoints(surface->mins, surface->maxs, surface->num_vertices, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
 
                // generate surface extents information
-               texmins[0] = texmaxs[0] = DotProduct(surface->mesh.data_vertex3f, surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
-               texmins[1] = texmaxs[1] = DotProduct(surface->mesh.data_vertex3f, surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
-               for (i = 1;i < surface->mesh.num_vertices;i++)
+               texmins[0] = texmaxs[0] = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3];
+               texmins[1] = texmaxs[1] = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3];
+               for (i = 1;i < surface->num_vertices;i++)
                {
                        for (j = 0;j < 2;j++)
                        {
-                               val = DotProduct(surface->mesh.data_vertex3f + i * 3, surface->lightmapinfo->texinfo->vecs[j]) + surface->lightmapinfo->texinfo->vecs[j][3];
+                               val = DotProduct((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3, surface->lightmapinfo->texinfo->vecs[j]) + surface->lightmapinfo->texinfo->vecs[j][3];
                                texmins[j] = min(texmins[j], val);
                                texmaxs[j] = max(texmaxs[j], val);
                        }
@@ -1937,16 +1929,16 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
                        uscale = (uscale - ubase) / ssize;
                        vscale = (vscale - vbase) / tsize;
 
-                       for (i = 0;i < surface->mesh.num_vertices;i++)
+                       for (i = 0;i < surface->num_vertices;i++)
                        {
-                               u = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
-                               v = ((DotProduct((surface->mesh.data_vertex3f + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
-                               surface->mesh.data_texcoordlightmap2f[i * 2 + 0] = u * uscale + ubase;
-                               surface->mesh.data_texcoordlightmap2f[i * 2 + 1] = v * vscale + vbase;
+                               u = ((DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[0]) + surface->lightmapinfo->texinfo->vecs[0][3]) + 8 - surface->lightmapinfo->texturemins[0]) * (1.0 / 16.0);
+                               v = ((DotProduct(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + i * 3), surface->lightmapinfo->texinfo->vecs[1]) + surface->lightmapinfo->texinfo->vecs[1][3]) + 8 - surface->lightmapinfo->texturemins[1]) * (1.0 / 16.0);
+                               (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 0] = u * uscale + ubase;
+                               (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex)[i * 2 + 1] = v * vscale + vbase;
                                // LordHavoc: calc lightmap data offset for vertex lighting to use
                                iu = (int) u;
                                iv = (int) v;
-                               surface->mesh.data_lightmapoffsets[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
+                               (surface->groupmesh->data_lightmapoffsets + surface->num_firstvertex)[i] = (bound(0, iv, tmax) * ssize + bound(0, iu, smax)) * 3;
                        }
                }
        }
@@ -2974,11 +2966,11 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
        for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
        {
                surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
-               numshadowmeshtriangles += surface->mesh.num_triangles;
+               numshadowmeshtriangles += surface->num_triangles;
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
        for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
-               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.data_element3i);
+               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
        Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
 
@@ -3083,7 +3075,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
                                if (surface->texture->basematerialflags & MATERIALFLAG_SKY)
                                        mod->DrawSky = R_Q1BSP_DrawSky;
                                // calculate bounding shapes
-                               for (k = 0, vec = surface->mesh.data_vertex3f;k < surface->mesh.num_vertices;k++, vec += 3)
+                               for (k = 0, vec = (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex);k < surface->num_vertices;k++, vec += 3)
                                {
                                        if (mod->normalmins[0] > vec[0]) mod->normalmins[0] = vec[0];
                                        if (mod->normalmins[1] > vec[1]) mod->normalmins[1] = vec[1];
@@ -4239,12 +4231,12 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                // don't render it
                                continue;
                        }
-                       out->mesh.num_vertices = numvertices;
-                       out->mesh.num_triangles = numtriangles;
-                       if (meshvertices + out->mesh.num_vertices > 65536)
+                       out->num_vertices = numvertices;
+                       out->num_triangles = numtriangles;
+                       if (meshvertices + out->num_vertices > 65536)
                                break;
-                       meshvertices += out->mesh.num_vertices;
-                       meshtriangles += out->mesh.num_triangles;
+                       meshvertices += out->num_vertices;
+                       meshtriangles += out->num_triangles;
                }
 
                i = oldi;
@@ -4253,44 +4245,38 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                mesh = tempmeshlist[meshnum] = Mod_AllocSurfMesh(loadmodel->mempool, meshvertices, meshtriangles, false, false, true);
                meshvertices = 0;
                meshtriangles = 0;
-               for (;i < count && meshvertices + out->mesh.num_vertices <= mesh->num_vertices;i++, in++, out++)
+               for (;i < count && meshvertices + out->num_vertices <= mesh->num_vertices;i++, in++, out++)
                {
-                       if (out->mesh.num_vertices < 3 || out->mesh.num_triangles < 1)
+                       if (out->num_vertices < 3 || out->num_triangles < 1)
                                continue;
 
                        type = LittleLong(in->type);
                        firstvertex = LittleLong(in->firstvertex);
                        firstelement = LittleLong(in->firstelement);
-                       out->mesh.data_vertex3f = mesh->data_vertex3f + meshvertices * 3;
-                       out->mesh.data_svector3f = mesh->data_svector3f + meshvertices * 3;
-                       out->mesh.data_tvector3f = mesh->data_tvector3f + meshvertices * 3;
-                       out->mesh.data_normal3f = mesh->data_normal3f + meshvertices * 3;
-                       out->mesh.data_texcoordtexture2f = mesh->data_texcoordtexture2f + meshvertices * 2;
-                       out->mesh.data_texcoordlightmap2f = mesh->data_texcoordlightmap2f + meshvertices * 2;
-                       out->mesh.data_lightmapcolor4f = mesh->data_lightmapcolor4f + meshvertices * 4;
-                       out->mesh.data_element3i = mesh->data_element3i + meshtriangles * 3;
-                       out->mesh.data_neighbor3i = mesh->data_neighbor3i + meshtriangles * 3;
+                       out->groupmesh = mesh;
+                       out->num_firstvertex = meshvertices;
+                       out->num_firsttriangle = meshtriangles;
                        switch(type)
                        {
                        case Q3FACETYPE_POLYGON:
                        case Q3FACETYPE_MESH:
                                // no processing necessary
-                               for (j = 0;j < out->mesh.num_vertices;j++)
+                               for (j = 0;j < out->num_vertices;j++)
                                {
-                                       out->mesh.data_vertex3f[j * 3 + 0] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 0];
-                                       out->mesh.data_vertex3f[j * 3 + 1] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 1];
-                                       out->mesh.data_vertex3f[j * 3 + 2] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 2];
-                                       out->mesh.data_texcoordtexture2f[j * 2 + 0] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 0];
-                                       out->mesh.data_texcoordtexture2f[j * 2 + 1] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 1];
-                                       out->mesh.data_texcoordlightmap2f[j * 2 + 0] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 0];
-                                       out->mesh.data_texcoordlightmap2f[j * 2 + 1] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 1];
-                                       out->mesh.data_lightmapcolor4f[j * 4 + 0] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 0];
-                                       out->mesh.data_lightmapcolor4f[j * 4 + 1] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 1];
-                                       out->mesh.data_lightmapcolor4f[j * 4 + 2] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 2];
-                                       out->mesh.data_lightmapcolor4f[j * 4 + 3] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 3];
+                                       (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 0] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 0];
+                                       (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 1] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 1];
+                                       (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex)[j * 3 + 2] = loadmodel->brushq3.data_vertex3f[(firstvertex + j) * 3 + 2];
+                                       (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 0];
+                                       (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordtexture2f[(firstvertex + j) * 2 + 1];
+                                       (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 0] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 0];
+                                       (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex)[j * 2 + 1] = loadmodel->brushq3.data_texcoordlightmap2f[(firstvertex + j) * 2 + 1];
+                                       (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 0] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 0];
+                                       (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 1] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 1];
+                                       (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 2] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 2];
+                                       (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 3] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 3];
                                }
-                               for (j = 0;j < out->mesh.num_triangles*3;j++)
-                                       out->mesh.data_element3i[j] = loadmodel->brushq3.data_element3i[firstelement + j];
+                               for (j = 0;j < out->num_triangles*3;j++)
+                                       (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = loadmodel->brushq3.data_element3i[firstelement + j];
                                break;
                        case Q3FACETYPE_PATCH:
                                patchsize[0] = LittleLong(in->specific.patch.patchsize[0]);
@@ -4323,18 +4309,18 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                type = Q3FACETYPE_MESH;
                                // generate geometry
                                // (note: normals are skipped because they get recalculated)
-                               Q3PatchTesselateFloat(3, sizeof(float[3]), out->mesh.data_vertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
-                               Q3PatchTesselateFloat(2, sizeof(float[2]), out->mesh.data_texcoordtexture2f, patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordtexture2f, xtess, ytess);
-                               Q3PatchTesselateFloat(2, sizeof(float[2]), out->mesh.data_texcoordlightmap2f, patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordlightmap2f, xtess, ytess);
-                               Q3PatchTesselateFloat(4, sizeof(float[4]), out->mesh.data_lightmapcolor4f, patchsize[0], patchsize[1], sizeof(float[4]), originalcolor4f, xtess, ytess);
-                               Q3PatchTriangleElements(out->mesh.data_element3i, finalwidth, finalheight);
-                               out->mesh.num_triangles = Mod_RemoveDegenerateTriangles(out->mesh.num_triangles, out->mesh.data_element3i, out->mesh.data_element3i, out->mesh.data_vertex3f);
+                               Q3PatchTesselateFloat(3, sizeof(float[3]), (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
+                               Q3PatchTesselateFloat(2, sizeof(float[2]), (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordtexture2f, xtess, ytess);
+                               Q3PatchTesselateFloat(2, sizeof(float[2]), (out->groupmesh->data_texcoordlightmap2f + 2 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[2]), originaltexcoordlightmap2f, xtess, ytess);
+                               Q3PatchTesselateFloat(4, sizeof(float[4]), (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex), patchsize[0], patchsize[1], sizeof(float[4]), originalcolor4f, xtess, ytess);
+                               Q3PatchTriangleElements((out->groupmesh->data_element3i + 3 * out->num_firsttriangle), finalwidth, finalheight);
+                               out->num_triangles = Mod_RemoveDegenerateTriangles(out->num_triangles, (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex));
                                if (developer.integer >= 2)
                                {
-                                       if (out->mesh.num_triangles < finaltriangles)
-                                               Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve subdivided to %i vertices / %i triangles, %i degenerate triangles removed (leaving %i)\n", patchsize[0], patchsize[1], out->mesh.num_vertices, finaltriangles, finaltriangles - out->mesh.num_triangles, out->mesh.num_triangles);
+                                       if (out->num_triangles < finaltriangles)
+                                               Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve subdivided to %i vertices / %i triangles, %i degenerate triangles removed (leaving %i)\n", patchsize[0], patchsize[1], out->num_vertices, finaltriangles, finaltriangles - out->num_triangles, out->num_triangles);
                                        else
-                                               Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve subdivided to %i vertices / %i triangles\n", patchsize[0], patchsize[1], out->mesh.num_vertices, out->mesh.num_triangles);
+                                               Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve subdivided to %i vertices / %i triangles\n", patchsize[0], patchsize[1], out->num_vertices, out->num_triangles);
                                }
                                // q3map does not put in collision brushes for curves... ugh
                                // build the lower quality collision geometry
@@ -4366,46 +4352,44 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
                                Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight);
 
-                               //Mod_SnapVertices(3, out->mesh.num_vertices, out->mesh.data_vertex3f, 0.25);
+                               //Mod_SnapVertices(3, out->num_vertices, (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), 0.25);
                                Mod_SnapVertices(3, out->num_collisionvertices, out->data_collisionvertex3f, 1);
 
-                               oldnumtriangles = out->mesh.num_triangles;
+                               oldnumtriangles = out->num_triangles;
                                oldnumtriangles2 = out->num_collisiontriangles;
                                out->num_collisiontriangles = Mod_RemoveDegenerateTriangles(out->num_collisiontriangles, out->data_collisionelement3i, out->data_collisionelement3i, out->data_collisionvertex3f);
                                if (developer.integer)
-                                       Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve became %i:%i vertices / %i:%i triangles (%i:%i degenerate)\n", patchsize[0], patchsize[1], out->mesh.num_vertices, out->num_collisionvertices, oldnumtriangles, oldnumtriangles2, oldnumtriangles - out->mesh.num_triangles, oldnumtriangles2 - out->num_collisiontriangles);
+                                       Con_Printf("Mod_Q3BSP_LoadFaces: %ix%i curve became %i:%i vertices / %i:%i triangles (%i:%i degenerate)\n", patchsize[0], patchsize[1], out->num_vertices, out->num_collisionvertices, oldnumtriangles, oldnumtriangles2, oldnumtriangles - out->num_triangles, oldnumtriangles2 - out->num_collisiontriangles);
                                break;
                        default:
                                break;
                        }
-                       meshvertices += out->mesh.num_vertices;
-                       meshtriangles += out->mesh.num_triangles;
-                       for (j = 0, invalidelements = 0;j < out->mesh.num_triangles * 3;j++)
-                               if (out->mesh.data_element3i[j] < 0 || out->mesh.data_element3i[j] >= out->mesh.num_vertices)
+                       meshvertices += out->num_vertices;
+                       meshtriangles += out->num_triangles;
+                       for (j = 0, invalidelements = 0;j < out->num_triangles * 3;j++)
+                               if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < 0 || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_vertices)
                                        invalidelements++;
                        if (invalidelements)
                        {
-                               Con_Printf("Mod_Q3BSP_LoadFaces: Warning: face #%i has %i invalid elements, type = %i, texture->name = \"%s\", texture->surfaceflags = %i, firstvertex = %i, numvertices = %i, firstelement = %i, numelements = %i, elements list:\n", i, invalidelements, type, out->texture->name, out->texture->surfaceflags, firstvertex, out->mesh.num_vertices, firstelement, out->mesh.num_triangles * 3);
-                               for (j = 0;j < out->mesh.num_triangles * 3;j++)
+                               Con_Printf("Mod_Q3BSP_LoadFaces: Warning: face #%i has %i invalid elements, type = %i, texture->name = \"%s\", texture->surfaceflags = %i, firstvertex = %i, numvertices = %i, firstelement = %i, numelements = %i, elements list:\n", i, invalidelements, type, out->texture->name, out->texture->surfaceflags, firstvertex, out->num_vertices, firstelement, out->num_triangles * 3);
+                               for (j = 0;j < out->num_triangles * 3;j++)
                                {
-                                       Con_Printf(" %i", out->mesh.data_element3i[j]);
-                                       if (out->mesh.data_element3i[j] < 0 || out->mesh.data_element3i[j] >= out->mesh.num_vertices)
-                                               out->mesh.data_element3i[j] = 0;
+                                       Con_Printf(" %i", (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j]);
+                                       if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < 0 || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_vertices)
+                                               (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = 0;
                                }
                                Con_Print("\n");
                        }
-                       // for shadow volumes
-                       Mod_BuildTriangleNeighbors(out->mesh.data_neighbor3i, out->mesh.data_element3i, out->mesh.num_triangles);
                        // for per pixel lighting
-                       Mod_BuildTextureVectorsAndNormals(out->mesh.num_vertices, out->mesh.num_triangles, out->mesh.data_vertex3f, out->mesh.data_texcoordtexture2f, out->mesh.data_element3i, out->mesh.data_svector3f, out->mesh.data_tvector3f, out->mesh.data_normal3f);
+                       Mod_BuildTextureVectorsAndNormals(out->num_vertices, out->num_triangles, (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), (out->groupmesh->data_texcoordtexture2f + 2 * out->num_firstvertex), (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), (out->groupmesh->data_svector3f + 3 * out->num_firstvertex), (out->groupmesh->data_tvector3f + 3 * out->num_firstvertex), (out->groupmesh->data_normal3f + 3 * out->num_firstvertex));
                        // calculate a bounding box
                        VectorClear(out->mins);
                        VectorClear(out->maxs);
-                       if (out->mesh.num_vertices)
+                       if (out->num_vertices)
                        {
-                               VectorCopy(out->mesh.data_vertex3f, out->mins);
-                               VectorCopy(out->mesh.data_vertex3f, out->maxs);
-                               for (j = 1, v = out->mesh.data_vertex3f + 3;j < out->mesh.num_vertices;j++, v += 3)
+                               VectorCopy((out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), out->mins);
+                               VectorCopy((out->groupmesh->data_vertex3f + 3 * out->num_firstvertex), out->maxs);
+                               for (j = 1, v = (out->groupmesh->data_vertex3f + 3 * out->num_firstvertex) + 3;j < out->num_vertices;j++, v += 3)
                                {
                                        out->mins[0] = min(out->mins[0], v[0]);
                                        out->maxs[0] = max(out->maxs[0], v[0]);
@@ -5458,11 +5442,11 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
        for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
        {
                surface->num_firstshadowmeshtriangle = numshadowmeshtriangles;
-               numshadowmeshtriangles += surface->mesh.num_triangles;
+               numshadowmeshtriangles += surface->num_triangles;
        }
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Begin(loadmodel->mempool, numshadowmeshtriangles * 3, numshadowmeshtriangles, NULL, NULL, NULL, false, false, true);
        for (j = 0, surface = loadmodel->brush.data_surfaces;j < loadmodel->brush.num_surfaces;j++, surface++)
-               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->mesh.data_vertex3f, NULL, NULL, NULL, NULL, surface->mesh.num_triangles, surface->mesh.data_element3i);
+               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
        loadmodel->brush.shadowmesh = Mod_ShadowMesh_Finish(loadmodel->mempool, loadmodel->brush.shadowmesh, false, true);
        Mod_BuildTriangleNeighbors(loadmodel->brush.shadowmesh->neighbor3i, loadmodel->brush.shadowmesh->element3i, loadmodel->brush.shadowmesh->numtriangles);
 
index 4613346..0f2aade 100644 (file)
@@ -175,21 +175,26 @@ typedef struct msurface_s
        texture_t *texture;
        // the lightmap texture fragment to use on the rendering mesh
        rtexture_t *lightmaptexture;
-       // if lightmap settings changed, this forces update
-       int cached_dlight; // q1bsp
-       // mesh for rendering
-       surfmesh_t mesh;
-
-       int num_collisiontriangles;
-       int *data_collisionelement3i;
-       int num_collisionvertices;
-       float *data_collisionvertex3f;
-
-       // index into model->brush.shadowmesh
-       int num_firstshadowmeshtriangle;
-
-       msurface_lightmapinfo_t *lightmapinfo;
 
+       // this surface is part of this mesh
+       surfmesh_t *groupmesh;
+       int num_triangles; // number of triangles in the mesh
+       int num_firsttriangle; // first triangle in the mesh (index into groupmesh)
+       int num_vertices; // number of vertices in the mesh
+       int num_firstvertex; // first vertex in the mesh (index into groupmesh)
+
+       // shadow volume building information
+       int num_firstshadowmeshtriangle; // index into model->brush.shadowmesh
+
+       // lightmaptexture rebuild information not used in q3bsp
+       int cached_dlight; // q1bsp // forces rebuild of lightmaptexture
+       msurface_lightmapinfo_t *lightmapinfo; // q1bsp
+
+       // mesh information for collisions (only used by q3bsp curves)
+       int num_collisiontriangles; // q3bsp
+       int *data_collisionelement3i; // q3bsp
+       int num_collisionvertices; // q3bsp
+       float *data_collisionvertex3f; // q3bsp
        struct q3deffect_s *effect; // q3bsp
        // FIXME: collisionmarkframe should be kept in a separate array
        int collisionmarkframe; // q3bsp // don't collide twice in one trace
index c540460..08925d8 100644 (file)
@@ -73,7 +73,8 @@ typedef struct overridetagnameset_s
 }
 overridetagnameset_t;
 
-// LordHavoc: replaces glpoly, triangle mesh
+// used for mesh lists in q1bsp/q3bsp map models
+// (the surfaces reference portions of these meshes)
 typedef struct surfmesh_s
 {
        int num_triangles; // number of triangles in the mesh
index 89eac51..8e76acb 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -345,11 +345,11 @@ void Portal_RecursiveFlow_ExactLeafFaces(portalrecursioninfo_t *info, int *mark,
                {
                        // FIXME?  this assumes q1bsp polygon surfaces
                        surface = info->model->brush.data_surfaces + *mark;
-                       for (j = 0, elements = surface->mesh.data_element3i;j < surface->mesh.num_triangles;j++, elements += 3)
+                       for (j = 0, elements = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);j < surface->num_triangles;j++, elements += 3)
                        {
-                               VectorCopy((surface->mesh.data_vertex3f + elements[0] * 3), trianglepoints[0]);
-                               VectorCopy((surface->mesh.data_vertex3f + elements[1] * 3), trianglepoints[1]);
-                               VectorCopy((surface->mesh.data_vertex3f + elements[2] * 3), trianglepoints[2]);
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + elements[0] * 3), trianglepoints[0]);
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + elements[1] * 3), trianglepoints[1]);
+                               VectorCopy(((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + elements[2] * 3), trianglepoints[2]);
                                if (PointInfrontOfTriangle(info->eye, trianglepoints[0], trianglepoints[1], trianglepoints[2]))
                                {
                                        trimins[0] = min(trianglepoints[0][0], min(trianglepoints[1][0], trianglepoints[2][0]));
@@ -363,7 +363,7 @@ void Portal_RecursiveFlow_ExactLeafFaces(portalrecursioninfo_t *info, int *mark,
                                                        break;
                                }
                        }
-                       if (j == surface->mesh.num_triangles)
+                       if (j == surface->num_triangles)
                                continue;
                        info->surfacemark[*mark] = true;
                }
index 15e902b..82737bf 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -2606,13 +2606,13 @@ static void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
        float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
        bestdist = 1000000000;
        VectorCopy(p, out);
-       for (i = 0;i < surface->mesh.num_triangles;i++)
+       for (i = 0;i < surface->num_triangles;i++)
        {
                // clip original point to each triangle of the surface and find the
                // triangle that is closest
-               v[0] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 0] * 3;
-               v[1] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 1] * 3;
-               v[2] = surface->mesh.data_vertex3f + surface->mesh.data_element3i[i * 3 + 2] * 3;
+               v[0] = (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 0] * 3;
+               v[1] = (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 1] * 3;
+               v[2] = (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 2] * 3;
                TriangleNormal(v[0], v[1], v[2], facenormal);
                VectorNormalize(facenormal);
                offsetdist = DotProduct(v[0], facenormal) - DotProduct(p, facenormal);
@@ -2663,7 +2663,7 @@ void PF_getsurfacenumpoints(void)
        }
 
        // note: this (incorrectly) assumes it is a simple polygon
-       G_FLOAT(OFS_RETURN) = surface->mesh.num_vertices;
+       G_FLOAT(OFS_RETURN) = surface->num_vertices;
 }
 //PF_getsurfacepoint,     // #435 vector(entity e, float s, float n) getsurfacepoint = #435;
 void PF_getsurfacepoint(void)
@@ -2679,10 +2679,10 @@ void PF_getsurfacepoint(void)
                return;
        // note: this (incorrectly) assumes it is a simple polygon
        pointnum = G_FLOAT(OFS_PARM2);
-       if (pointnum < 0 || pointnum >= surface->mesh.num_vertices)
+       if (pointnum < 0 || pointnum >= surface->num_vertices)
                return;
        // FIXME: implement rotation/scaling
-       VectorAdd(&surface->mesh.data_vertex3f[pointnum * 3], ed->v->origin, G_VECTOR(OFS_RETURN));
+       VectorAdd(&(surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex)[pointnum * 3], ed->v->origin, G_VECTOR(OFS_RETURN));
 }
 //PF_getsurfacenormal,    // #436 vector(entity e, float s) getsurfacenormal = #436;
 void PF_getsurfacenormal(void)
@@ -2696,7 +2696,7 @@ void PF_getsurfacenormal(void)
        // note: this (incorrectly) assumes it is a simple polygon
        // note: this only returns the first triangle, so it doesn't work very
        // well for curved surfaces or arbitrary meshes
-       TriangleNormal(surface->mesh.data_vertex3f, surface->mesh.data_vertex3f + 3, surface->mesh.data_vertex3f + 6, normal);
+       TriangleNormal((surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 3, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex) + 6, normal);
        VectorNormalize(normal);
        VectorCopy(normal, G_VECTOR(OFS_RETURN));
 }