optimized surface rendering to surface->groupmesh->data_* array pointers directly...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 4 Apr 2005 16:01:17 +0000 (16:01 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 4 Apr 2005 16:01:17 +0000 (16:01 +0000)
fixed stupid bug in q1bsp texture loading which was making all missing textures invisible
changed portal generation to not break when a portal is clipped away, this fixes a crash at render time with bogus portals
changed r_drawportals to only draw portals surrounding the visible leafs (speed gain, but also useful for debugging vis glitches)

git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@5153 d7cf8633-e32d-0410-b094-e92efae38249

12 files changed:
curves.c
curves.h
gl_models.c
gl_rsurf.c
model_alias.c
model_brush.c
model_shared.c
model_shared.h
portals.c
pr_cmds.c
r_shadow.c
r_shadow.h

index de4e89c..f0b8b29 100644 (file)
--- a/curves.c
+++ b/curves.c
@@ -167,13 +167,13 @@ int Q3PatchTesselationOnY(int patchwidth, int patchheight, int components, const
 // (such as those produced by Q3PatchTesselate)
 // (note: width and height are the actual vertex size, this produces
 //  (width-1)*(height-1)*2 triangles, 3 elements each)
-void Q3PatchTriangleElements(int *elements, int width, int height)
+void Q3PatchTriangleElements(int *elements, int width, int height, int firstvertex)
 {
        int x, y, row0, row1;
        for (y = 0;y < height - 1;y++)
        {
-               row0 = (y + 0) * width;
-               row1 = (y + 1) * width;
+               row0 = firstvertex + (y + 0) * width;
+               row1 = firstvertex + (y + 1) * width;
                for (x = 0;x < width - 1;x++)
                {
                        *elements++ = row0;
index 48d0121..af9ba15 100644 (file)
--- a/curves.h
+++ b/curves.h
@@ -14,7 +14,7 @@ int Q3PatchTesselationOnY(int patchwidth, int patchheight, int components, const
 // (such as those produced by Q3PatchTesselate)
 // (note: width and height are the actual vertex size, this produces
 //  (width-1)*(height-1)*2 triangles, 3 elements each)
-void Q3PatchTriangleElements(int *elements, int width, int height);
+void Q3PatchTriangleElements(int *elements, int width, int height, int firstvertex);
 
 #endif
 
index f663486..d416dd0 100644 (file)
@@ -142,7 +142,7 @@ static void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                if (normal3f == NULL)
                {
                        normal3f = varray_normal3f;
-                       Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
+                       Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
                }
                R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
        }
@@ -179,7 +179,7 @@ static void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                        if (normal3f == NULL)
                        {
                                normal3f = varray_normal3f;
-                               Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
+                               Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
                        }
                        R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
                }
@@ -207,7 +207,7 @@ static void R_DrawAliasModelCallback (const void *calldata1, int calldata2)
                        if (normal3f == NULL)
                        {
                                normal3f = varray_normal3f;
-                               Mod_BuildNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
+                               Mod_BuildNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_element3i, normal3f);
                        }
                        R_LightModel_CalcVertexColors(ambientcolor4f, diffusecolor, diffusenormal, mesh->num_vertices, vertex3f, normal3f, varray_color4f);
                }
@@ -384,16 +384,16 @@ void R_Model_Alias_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, v
                        tvector3f = varray_tvector3f;
                        normal3f = varray_normal3f;
                        Mod_Alias_GetMesh_Vertex3f(ent->model, ent->frameblend, mesh, vertex3f);
-                       Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
+                       Mod_BuildTextureVectorsAndNormals(0, mesh->num_vertices, mesh->num_triangles, vertex3f, mesh->data_texcoord2f, mesh->data_element3i, svector3f, tvector3f, normal3f);
                }
                c_alias_polys += mesh->num_triangles;
-               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorbase, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, (ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged, texture->skin.nmap, texture->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
+               R_Shadow_RenderLighting(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorbase, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, (ent->colormap >= 0 || !texture->skin.merged) ? texture->skin.base : texture->skin.merged, texture->skin.nmap, texture->skin.gloss, lightcubemap, ambientscale, diffusescale, specularscale);
                if (ent->colormap >= 0)
                {
                        if (texture->skin.pants && VectorLength2(lightcolorpants) >= 0.001)
-                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorpants, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.pants, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0);
+                               R_Shadow_RenderLighting(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorpants, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.pants, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0);
                        if (texture->skin.shirt && VectorLength2(lightcolorshirt) >= 0.001)
-                               R_Shadow_RenderLighting(mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorshirt, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.shirt, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0);
+                               R_Shadow_RenderLighting(0, mesh->num_vertices, mesh->num_triangles, mesh->data_element3i, vertex3f, svector3f, tvector3f, normal3f, mesh->data_texcoord2f, relativelightorigin, relativeeyeorigin, lightcolorshirt, matrix_modeltolight, matrix_modeltoattenuationxyz, matrix_modeltoattenuationz, texture->skin.shirt, texture->skin.nmap, NULL, lightcubemap, ambientscale, diffusescale, 0);
                }
        }
 }
index 85db63d..a9a4f78 100644 (file)
@@ -323,7 +323,7 @@ static void RSurf_DeformVertices(const entity_render_t *ent, const texture_t *te
                        right[0] = forward[1];
                        right[1] = -forward[0];
                        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);
+                               VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (surface->num_firstvertex+i+j) * 3);
                }
        }
        else if (texture->textureflags & Q3TEXTUREFLAG_AUTOSPRITE)
@@ -344,17 +344,17 @@ static void RSurf_DeformVertices(const entity_render_t *ent, const texture_t *te
                        for (i = 0;i < 4;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);
+                               VectorMAMAMAM(1, center, v[i][0], forward, v[i][1], right, v[i][2], up, varray_vertex3f + (surface->num_firstvertex+i+j) * 3);
                }
        }
        else
-               memcpy(varray_vertex3f, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), sizeof(float[3]) * surface->num_vertices);
+               memcpy((varray_vertex3f + 3 * surface->num_firstvertex), (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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex))
+#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)
 #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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex);
+               return surface->groupmesh->data_vertex3f;
 }
 #endif
 
@@ -417,6 +417,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
        qboolean dofogpass;
        qboolean fogallpasses;
        qboolean waterscrolling;
+       surfmesh_t *groupmesh;
+       rtexture_t *lightmaptexture;
        rmeshstate_t m;
        texture = texture->currentframe;
        if (texture->currentmaterialflags & MATERIALFLAG_NODRAW)
@@ -436,11 +438,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->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(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                       R_Mesh_ColorPointer(surface->lightmaptexture ? NULL : surface->groupmesh->data_lightmapcolor4f);
+                       R_Mesh_VertexPointer(surface->groupmesh->data_vertex3f);
+                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        GL_LockArrays(0, 0);
                }
                qglEnable(GL_CULL_FACE);
@@ -491,9 +493,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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
-                               GL_LockArrays(0, surface->num_vertices);
-                               R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                               R_Mesh_VertexPointer(surface->groupmesh->data_vertex3f);
+                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_firstvertex, 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 +527,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->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(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
+                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        GL_LockArrays(0, 0);
                }
 
@@ -579,15 +581,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->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
-                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
                                        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->num_vertices;i++, v += 3, c += 4)
+                                                       for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                        {
                                                                VectorSubtract(v, modelorg, diff);
                                                                f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -607,9 +609,9 @@ 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->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
+                                               if (!surface->lightmaptexture)
                                                {
-                                                       for (i = 0, c = varray_color4f;i < surface->num_vertices;i++, c += 4)
+                                                       for (i = 0, c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, c += 4)
                                                        {
                                                                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;
@@ -618,7 +620,7 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        }
                                                        if (fogallpasses)
                                                        {
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -632,8 +634,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        GL_Color(0, 0, 0, a);
                                                }
                                        }
-                                       GL_LockArrays(0, surface->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -674,15 +676,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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        c[0] = 0;
                                                        c[1] = 0;
                                                        c[2] = 0;
-                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex))
+                                                       if (!surface->lightmapinfo)
                                                                VectorCopy((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) + i*4, c);
-                                                       else if (surface->lightmapinfo)
+                                                       else //if (surface->lightmapinfo)
                                                        {
                                                                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);
@@ -716,13 +718,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->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                       if (!surface->lightmapinfo && (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->num_vertices);
-                                               R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                GL_LockArrays(0, 0);
                                        }
                                }
@@ -735,11 +737,11 @@ 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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                                       if (!surface->lightmapinfo && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -752,7 +754,7 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        else
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        VectorSubtract(v, modelorg, diff);
                                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -762,8 +764,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                                        c[3] = a;
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -774,11 +776,11 @@ 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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                                       if (!surface->lightmaptexture && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                                        {
                                                                R_Mesh_ColorPointer(varray_color4f);
-                                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                                {
                                                                        c[0] = r;
                                                                        c[1] = g;
@@ -791,8 +793,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->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -815,9 +817,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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                       GL_LockArrays(0, surface->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -832,8 +834,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->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -863,8 +865,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->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
-                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -873,10 +875,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->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
+                                                               R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
                                                        }
-                                                       GL_LockArrays(0, surface->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -886,8 +888,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->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
-                                                       R_Mesh_TexCoordPointer(1, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -897,16 +899,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->num_vertices;i++)
+                                                               for (i = 0, c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, c += 4)
                                                                {
-                                                                       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];
+                                                                       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];
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -926,11 +928,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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
+                                                       qglVertexPointer(3, GL_FLOAT, sizeof(float[3]), surface->groupmesh->data_vertex3f);
                                                        qglClientActiveTexture(GL_TEXTURE0_ARB);
-                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordlightmap2f + 2 * surface->num_firstvertex));
+                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->groupmesh->data_texcoordlightmap2f);
                                                        qglClientActiveTexture(GL_TEXTURE1_ARB);
-                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                                       qglTexCoordPointer(2, GL_FLOAT, sizeof(float[2]), surface->groupmesh->data_texcoordtexture2f);
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -941,31 +943,43 @@ 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->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
+                                                               qglColorPointer(4, GL_FLOAT, sizeof(float[4]), surface->groupmesh->data_lightmapcolor4f);
                                                        }
                                                        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));
+                                                       qglDrawRangeElements(GL_TRIANGLES, surface->num_firstvertex, surface->num_firstvertex + surface->num_vertices, surface->num_triangles * 3, GL_UNSIGNED_INT, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        qglUnlockArraysEXT();
                                                }
 #else
+                                               groupmesh = NULL;
+                                               lightmaptexture = NULL;
                                                for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
                                                {
                                                        surface = texturesurfacelist[texturesurfaceindex];
-                                                       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)
+                                                       if (groupmesh != surface->groupmesh)
                                                        {
-                                                               R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
-                                                               R_Mesh_ColorPointer(NULL);
+                                                               groupmesh = surface->groupmesh;
+                                                               R_Mesh_VertexPointer(groupmesh->data_vertex3f);
+                                                               R_Mesh_TexCoordPointer(0, 2, groupmesh->data_texcoordlightmap2f);
+                                                               R_Mesh_TexCoordPointer(1, 2, groupmesh->data_texcoordtexture2f);
+                                                               if (!lightmaptexture)
+                                                                       R_Mesh_ColorPointer(groupmesh->data_lightmapcolor4f);
                                                        }
-                                                       else //if (r == 1 && g == 1 && b == 1)
+                                                       if (lightmaptexture != surface->lightmaptexture)
                                                        {
-                                                               R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
-                                                               R_Mesh_ColorPointer((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex));
+                                                               lightmaptexture = surface->lightmaptexture;
+                                                               if (lightmaptexture)
+                                                               {
+                                                                       R_Mesh_TexBind(0, R_GetTexture(lightmaptexture));
+                                                                       R_Mesh_ColorPointer(NULL);
+                                                               }
+                                                               else //if (r == 1 && g == 1 && b == 1)
+                                                               {
+                                                                       R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
+                                                                       R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
+                                                               }
                                                        }
-                                                       GL_LockArrays(0, surface->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
 #endif
@@ -975,9 +989,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->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));
+                                                       R_Mesh_VertexPointer(surface->groupmesh->data_vertex3f);
+                                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                                       R_Mesh_TexCoordPointer(1, 2, surface->groupmesh->data_texcoordtexture2f);
                                                        if (surface->lightmaptexture)
                                                        {
                                                                R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
@@ -987,16 +1001,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->num_vertices;i++)
+                                                               for (i = 0, c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, c += 4)
                                                                {
-                                                                       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];
+                                                                       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];
                                                                }
                                                        }
-                                                       GL_LockArrays(0, surface->num_vertices);
-                                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                                        GL_LockArrays(0, 0);
                                                }
                                        }
@@ -1010,16 +1024,62 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                GL_Color(1, 1, 1, 1);
                                memset(&m, 0, sizeof(m));
                                R_Mesh_State(&m);
-                               for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                               if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
                                {
-                                       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->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(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
-                                       GL_LockArrays(0, 0);
+                                       R_Mesh_VertexPointer(varray_vertex3f);
+                                       for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                                       {
+                                               surface = texturesurfacelist[texturesurfaceindex];
+                                               RSurf_DeformVertices(ent, texture, surface, modelorg);
+                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordlightmap2f);
+                                               if (surface->lightmaptexture)
+                                               {
+                                                       R_Mesh_TexBind(0, R_GetTexture(surface->lightmaptexture));
+                                                       R_Mesh_ColorPointer(NULL);
+                                               }
+                                               else //if (r == 1 && g == 1 && b == 1)
+                                               {
+                                                       R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
+                                                       R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
+                                               }
+                                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                               GL_LockArrays(0, 0);
+                                       }
+                               }
+                               else
+                               {
+                                       groupmesh = NULL;
+                                       lightmaptexture = NULL;
+                                       for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                                       {
+                                               surface = texturesurfacelist[texturesurfaceindex];
+                                               if (groupmesh != surface->groupmesh)
+                                               {
+                                                       groupmesh = surface->groupmesh;
+                                                       R_Mesh_VertexPointer(groupmesh->data_vertex3f);
+                                                       R_Mesh_TexCoordPointer(0, 2, groupmesh->data_texcoordlightmap2f);
+                                                       if (!lightmaptexture)
+                                                               R_Mesh_ColorPointer(groupmesh->data_lightmapcolor4f);
+                                               }
+                                               if (lightmaptexture != surface->lightmaptexture)
+                                               {
+                                                       lightmaptexture = surface->lightmaptexture;
+                                                       if (lightmaptexture)
+                                                       {
+                                                               R_Mesh_TexBind(0, R_GetTexture(lightmaptexture));
+                                                               R_Mesh_ColorPointer(NULL);
+                                                       }
+                                                       else //if (r == 1 && g == 1 && b == 1)
+                                                       {
+                                                               R_Mesh_TexBind(0, R_GetTexture(r_texture_white));
+                                                               R_Mesh_ColorPointer(surface->groupmesh->data_lightmapcolor4f);
+                                                       }
+                                               }
+                                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                               GL_LockArrays(0, 0);
+                                       }
                                }
                        }
                        if (dobase)
@@ -1032,14 +1092,35 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                if (waterscrolling)
                                        m.texmatrix[0] = r_surf_waterscrollmatrix;
                                R_Mesh_State(&m);
-                               for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                               if (texture->textureflags & (Q3TEXTUREFLAG_AUTOSPRITE | Q3TEXTUREFLAG_AUTOSPRITE2))
                                {
-                                       surface = texturesurfacelist[texturesurfaceindex];
-                                       R_Mesh_VertexPointer(RSurf_GetVertexPointer(ent, texture, surface, modelorg));
-                                       R_Mesh_TexCoordPointer(0, 2, (surface->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                       GL_LockArrays(0, surface->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
-                                       GL_LockArrays(0, 0);
+                                       R_Mesh_VertexPointer(varray_vertex3f);
+                                       for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                                       {
+                                               surface = texturesurfacelist[texturesurfaceindex];
+                                               RSurf_DeformVertices(ent, texture, surface, modelorg);
+                                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                               GL_LockArrays(0, 0);
+                                       }
+                               }
+                               else
+                               {
+                                       groupmesh = NULL;
+                                       for (texturesurfaceindex = 0;texturesurfaceindex < texturenumsurfaces;texturesurfaceindex++)
+                                       {
+                                               surface = texturesurfacelist[texturesurfaceindex];
+                                               if (groupmesh != surface->groupmesh)
+                                               {
+                                                       groupmesh = surface->groupmesh;
+                                                       R_Mesh_VertexPointer(groupmesh->data_vertex3f);
+                                                       R_Mesh_TexCoordPointer(0, 2, groupmesh->data_texcoordtexture2f);
+                                               }
+                                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                               GL_LockArrays(0, 0);
+                                       }
                                }
                        }
                }
@@ -1070,8 +1151,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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                {
                                        c[0] = r;
                                        c[1] = g;
@@ -1082,13 +1163,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->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                       if (!surface->lightmaptexture && (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->num_vertices);
-                               R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1104,9 +1185,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->groupmesh->data_texcoorddetail2f + 2 * surface->num_firstvertex));
-                               GL_LockArrays(0, surface->num_vertices);
-                               R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoorddetail2f);
+                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1133,11 +1214,11 @@ 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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
                                        R_Mesh_ColorPointer(varray_color4f);
-                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                       if (!surface->lightmaptexture && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                        {
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        VectorSubtract(v, modelorg, diff);
                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -1149,7 +1230,7 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                        }
                                        else
                                        {
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        VectorSubtract(v, modelorg, diff);
                                                        f = 1 - exp(fogdensity/DotProduct(diff, diff));
@@ -1159,8 +1240,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                        c[3] = a;
                                                }
                                        }
-                                       GL_LockArrays(0, surface->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1171,11 +1252,11 @@ 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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
-                                       if ((surface->groupmesh->data_lightmapcolor4f + 4 * surface->num_firstvertex) && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
+                                       R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+                                       if (!surface->lightmaptexture && (texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                        {
                                                R_Mesh_ColorPointer(varray_color4f);
-                                               for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                               for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                                {
                                                        c[0] = r;
                                                        c[1] = g;
@@ -1188,8 +1269,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->num_vertices);
-                                       R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                                       GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                        GL_LockArrays(0, 0);
                                }
                        }
@@ -1226,12 +1307,12 @@ 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->groupmesh->data_texcoordtexture2f + 2 * surface->num_firstvertex));
+                               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
                                R_Mesh_ColorPointer(varray_color4f);
                                //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))
+                               if (surface->lightmaptexture && !(texture->currentmaterialflags & MATERIALFLAG_TRANSPARENT))
                                {
-                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                       for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
                                                VectorSubtract(v, modelorg, diff);
                                                f = exp(fogdensity/DotProduct(diff, diff));
@@ -1243,7 +1324,7 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                }
                                else
                                {
-                                       for (i = 0, v = vertex3f, c = varray_color4f;i < surface->num_vertices;i++, v += 3, c += 4)
+                                       for (i = 0, v = (vertex3f + 3 * surface->num_firstvertex), c = (varray_color4f + 4 * surface->num_firstvertex);i < surface->num_vertices;i++, v += 3, c += 4)
                                        {
                                                VectorSubtract(v, modelorg, diff);
                                                f = exp(fogdensity/DotProduct(diff, diff));
@@ -1253,8 +1334,8 @@ static void R_DrawSurfaceList(const entity_render_t *ent, texture_t *texture, in
                                                c[3] = f * a;
                                        }
                                }
-                               GL_LockArrays(0, surface->num_vertices);
-                               R_Mesh_Draw(0, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+                               GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                                GL_LockArrays(0, 0);
                        }
                }
@@ -1443,23 +1524,31 @@ static void R_DrawPortal_Callback(const void *calldata1, int calldata2)
 // LordHavoc: this is just a nice debugging tool, very slow
 static void R_DrawPortals(void)
 {
-       int i, portalnum;
+       int i, leafnum;//, portalnum;
        mportal_t *portal;
        float center[3], f;
        model_t *model = r_refdef.worldmodel;
        if (model == NULL)
                return;
-       for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
+       for (leafnum = 0;leafnum < r_refdef.worldmodel->brush.num_leafs;leafnum++)
        {
-               if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
-               if (!R_CullBox(portal->mins, portal->maxs))
+               if (r_worldleafvisible[leafnum])
                {
-                       VectorClear(center);
-                       for (i = 0;i < portal->numpoints;i++)
-                               VectorAdd(center, portal->points[i].position, center);
-                       f = ixtable[portal->numpoints];
-                       VectorScale(center, f, center);
-                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
+                       //for (portalnum = 0, portal = model->brush.data_portals;portalnum < model->brush.num_portals;portalnum++, portal++)
+                       for (portal = r_refdef.worldmodel->brush.data_leafs[leafnum].portals;portal;portal = portal->next)
+                       {
+                               if (portal->numpoints <= POLYGONELEMENTS_MAXPOINTS)
+                               if (!R_CullBox(portal->mins, portal->maxs))
+                               {
+                                       VectorClear(center);
+                                       for (i = 0;i < portal->numpoints;i++)
+                                               VectorAdd(center, portal->points[i].position, center);
+                                       f = ixtable[portal->numpoints];
+                                       VectorScale(center, f, center);
+                                       //R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, portalnum);
+                                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, portal, leafnum);
+                               }
+                       }
                }
        }
 }
@@ -1746,7 +1835,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, vec3_t relativelightorigin, vec3_t
                                // 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->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));
+                                       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, surface->groupmesh->data_svector3f, surface->groupmesh->data_tvector3f, surface->groupmesh->data_normal3f, surface->groupmesh->data_texcoordtexture2f, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
                        }
                        else if (ent != r_refdef.worldentity || r_worldsurfacevisible[surfacelist[surfacelistindex]])
                        {
@@ -1756,7 +1845,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->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);
+                                       R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), surface->groupmesh->data_vertex3f, surface->groupmesh->data_svector3f, surface->groupmesh->data_tvector3f, surface->groupmesh->data_normal3f, surface->groupmesh->data_texcoordtexture2f, 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 04e6635..fcaa747 100644 (file)
@@ -175,7 +175,7 @@ static void Mod_Alias_Mesh_CompileFrameZero(aliasmesh_t *mesh)
        mesh->data_basetvector3f = mesh->data_basevertex3f + mesh->num_vertices * 6;
        mesh->data_basenormal3f = mesh->data_basevertex3f + mesh->num_vertices * 9;
        Mod_Alias_GetMesh_Vertex3f(loadmodel, frameblend, mesh, mesh->data_basevertex3f);
-       Mod_BuildTextureVectorsAndNormals(mesh->num_vertices, mesh->num_triangles, mesh->data_basevertex3f, mesh->data_texcoord2f, mesh->data_element3i, mesh->data_basesvector3f, mesh->data_basetvector3f, mesh->data_basenormal3f);
+       Mod_BuildTextureVectorsAndNormals(0, mesh->num_vertices, mesh->num_triangles, mesh->data_basevertex3f, mesh->data_texcoord2f, mesh->data_element3i, mesh->data_basesvector3f, mesh->data_basetvector3f, mesh->data_basenormal3f);
 }
 
 static void Mod_MDLMD2MD3_TraceBox(model_t *model, int frame, trace_t *trace, const vec3_t boxstartmins, const vec3_t boxstartmaxs, const vec3_t boxendmins, const vec3_t boxendmaxs, int hitsupercontentsmask)
index 315c203..ce9dcd3 100644 (file)
@@ -223,9 +223,9 @@ static void Mod_Q1BSP_FindNonSolidLocation_r_Leaf(findnonsolidlocationinfo_t *in
                        for (k = 0;k < surface->num_triangles;k++)
                        {
                                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]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + tri[0] * 3), vert[0]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + tri[1] * 3), vert[1]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + 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);
@@ -1007,6 +1007,7 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                tx->width = 16;
                tx->height = 16;
                tx->skin.base = r_texture_notexture;
+               tx->basematerialflags = 0;
                if (i == loadmodel->brush.num_textures - 1)
                {
                        tx->basematerialflags |= MATERIALFLAG_WATER | MATERIALFLAG_LIGHTBOTHSIDES;
@@ -1017,7 +1018,6 @@ static void Mod_Q1BSP_LoadTextures(lump_t *l)
                        tx->basematerialflags |= MATERIALFLAG_WALL;
                        tx->supercontents = SUPERCONTENTS_SOLID;
                }
-               tx->basematerialflags = 0;
                tx->currentframe = tx;
        }
 
@@ -1847,13 +1847,13 @@ static void Mod_Q1BSP_LoadFaces(lump_t *l)
 
                for (i = 0;i < surface->num_triangles;i++)
                {
-                       (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;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 0] = 0 + surface->num_firstvertex;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 1] = i + 1 + surface->num_firstvertex;
+                       (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle)[i * 3 + 2] = i + 2 + surface->num_firstvertex;
                }
 
                // compile additional data about the surface geometry
-               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));
+               Mod_BuildTextureVectorsAndNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, surface->groupmesh->data_vertex3f, surface->groupmesh->data_texcoordtexture2f, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle), surface->groupmesh->data_svector3f, surface->groupmesh->data_tvector3f, surface->groupmesh->data_normal3f);
                BoxFromPoints(surface->mins, surface->maxs, surface->num_vertices, (surface->groupmesh->data_vertex3f + 3 * surface->num_firstvertex));
 
                // generate surface extents information
@@ -2650,69 +2650,69 @@ static void Mod_Q1BSP_RecursiveNodePortals(mnode_t *node)
                Con_Print("Mod_Q1BSP_RecursiveNodePortals: WARNING: new portal has too many points\n");
                nodeportal->numpoints = 0;
        }
-       else
-       {
-               AddPortalToNodes(nodeportal, front, back);
 
-               // split the portals of this node along this node's plane and assign them to the children of this node
-               // (migrating the portals downward through the tree)
-               for (portal = (portal_t *)node->portals;portal;portal = nextportal)
-               {
-                       if (portal->nodes[0] == portal->nodes[1])
-                               Host_Error("Mod_Q1BSP_RecursiveNodePortals: portal has same node on both sides(2)");
-                       if (portal->nodes[0] == node)
-                               side = 0;
-                       else if (portal->nodes[1] == node)
-                               side = 1;
-                       else
-                               Host_Error("Mod_Q1BSP_RecursiveNodePortals: mislinked portal");
-                       nextportal = portal->next[side];
+       AddPortalToNodes(nodeportal, front, back);
 
-                       other_node = portal->nodes[!side];
-                       RemovePortalFromNodes(portal);
+       // split the portals of this node along this node's plane and assign them to the children of this node
+       // (migrating the portals downward through the tree)
+       for (portal = (portal_t *)node->portals;portal;portal = nextportal)
+       {
+               if (portal->nodes[0] == portal->nodes[1])
+                       Host_Error("Mod_Q1BSP_RecursiveNodePortals: portal has same node on both sides(2)");
+               if (portal->nodes[0] == node)
+                       side = 0;
+               else if (portal->nodes[1] == node)
+                       side = 1;
+               else
+                       Host_Error("Mod_Q1BSP_RecursiveNodePortals: mislinked portal");
+               nextportal = portal->next[side];
+               if (!portal->numpoints)
+                       continue;
 
-                       // cut the portal into two portals, one on each side of the node plane
-                       PolygonD_Divide(portal->numpoints, portal->points, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, 1.0/32.0, MAX_PORTALPOINTS, frontpoints, &numfrontpoints, MAX_PORTALPOINTS, backpoints, &numbackpoints);
+               other_node = portal->nodes[!side];
+               RemovePortalFromNodes(portal);
 
-                       if (!numfrontpoints)
-                       {
-                               if (side == 0)
-                                       AddPortalToNodes(portal, back, other_node);
-                               else
-                                       AddPortalToNodes(portal, other_node, back);
-                               continue;
-                       }
-                       if (!numbackpoints)
-                       {
-                               if (side == 0)
-                                       AddPortalToNodes(portal, front, other_node);
-                               else
-                                       AddPortalToNodes(portal, other_node, front);
-                               continue;
-                       }
-
-                       // the portal is split
-                       splitportal = AllocPortal();
-                       temp = splitportal->chain;
-                       *splitportal = *portal;
-                       splitportal->chain = temp;
-                       for (i = 0;i < numbackpoints*3;i++)
-                               splitportal->points[i] = backpoints[i];
-                       splitportal->numpoints = numbackpoints;
-                       for (i = 0;i < numfrontpoints*3;i++)
-                               portal->points[i] = frontpoints[i];
-                       portal->numpoints = numfrontpoints;
+               // cut the portal into two portals, one on each side of the node plane
+               PolygonD_Divide(portal->numpoints, portal->points, plane->normal[0], plane->normal[1], plane->normal[2], plane->dist, 1.0/32.0, MAX_PORTALPOINTS, frontpoints, &numfrontpoints, MAX_PORTALPOINTS, backpoints, &numbackpoints);
 
+               if (!numfrontpoints)
+               {
+                       if (side == 0)
+                               AddPortalToNodes(portal, back, other_node);
+                       else
+                               AddPortalToNodes(portal, other_node, back);
+                       continue;
+               }
+               if (!numbackpoints)
+               {
                        if (side == 0)
-                       {
                                AddPortalToNodes(portal, front, other_node);
-                               AddPortalToNodes(splitportal, back, other_node);
-                       }
                        else
-                       {
                                AddPortalToNodes(portal, other_node, front);
-                               AddPortalToNodes(splitportal, other_node, back);
-                       }
+                       continue;
+               }
+
+               // the portal is split
+               splitportal = AllocPortal();
+               temp = splitportal->chain;
+               *splitportal = *portal;
+               splitportal->chain = temp;
+               for (i = 0;i < numbackpoints*3;i++)
+                       splitportal->points[i] = backpoints[i];
+               splitportal->numpoints = numbackpoints;
+               for (i = 0;i < numfrontpoints*3;i++)
+                       portal->points[i] = frontpoints[i];
+               portal->numpoints = numfrontpoints;
+
+               if (side == 0)
+               {
+                       AddPortalToNodes(portal, front, other_node);
+                       AddPortalToNodes(splitportal, back, other_node);
+               }
+               else
+               {
+                       AddPortalToNodes(portal, other_node, front);
+                       AddPortalToNodes(splitportal, other_node, back);
                }
        }
 
@@ -2970,7 +2970,7 @@ void Mod_Q1BSP_Load(model_t *mod, void *buffer)
        }
        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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->groupmesh->data_vertex3f, 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);
 
@@ -4276,7 +4276,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                        (out->groupmesh->data_lightmapcolor4f + 4 * out->num_firstvertex)[j * 4 + 3] = loadmodel->brushq3.data_color4f[(firstvertex + j) * 4 + 3];
                                }
                                for (j = 0;j < out->num_triangles*3;j++)
-                                       (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = loadmodel->brushq3.data_element3i[firstelement + j];
+                                       (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = loadmodel->brushq3.data_element3i[firstelement + j] + out->num_firstvertex;
                                break;
                        case Q3FACETYPE_PATCH:
                                patchsize[0] = LittleLong(in->specific.patch.patchsize[0]);
@@ -4313,8 +4313,8 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                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));
+                               Q3PatchTriangleElements((out->groupmesh->data_element3i + 3 * out->num_firsttriangle), finalwidth, finalheight, out->num_firstvertex);
+                               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);
                                if (developer.integer >= 2)
                                {
                                        if (out->num_triangles < finaltriangles)
@@ -4350,7 +4350,7 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                                out->num_collisionvertices = finalvertices;
                                out->num_collisiontriangles = finaltriangles;
                                Q3PatchTesselateFloat(3, sizeof(float[3]), out->data_collisionvertex3f, patchsize[0], patchsize[1], sizeof(float[3]), originalvertex3f, xtess, ytess);
-                               Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight);
+                               Q3PatchTriangleElements(out->data_collisionelement3i, finalwidth, finalheight, 0);
 
                                //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);
@@ -4367,21 +4367,21 @@ static void Mod_Q3BSP_LoadFaces(lump_t *l)
                        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)
+                               if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + 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->num_vertices, firstelement, out->num_triangles * 3);
                                for (j = 0;j < out->num_triangles * 3;j++)
                                {
-                                       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_Printf(" %i", (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] - out->num_firstvertex);
+                                       if ((out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] < out->num_firstvertex || (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] >= out->num_firstvertex + out->num_vertices)
+                                               (out->groupmesh->data_element3i + 3 * out->num_firsttriangle)[j] = out->num_firstvertex;
                                }
                                Con_Print("\n");
                        }
                        // for per pixel lighting
-                       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));
+                       Mod_BuildTextureVectorsAndNormals(out->num_firstvertex, out->num_vertices, out->num_triangles, out->groupmesh->data_vertex3f, out->groupmesh->data_texcoordtexture2f, (out->groupmesh->data_element3i + 3 * out->num_firsttriangle), out->groupmesh->data_svector3f, out->groupmesh->data_tvector3f, out->groupmesh->data_normal3f);
                        // calculate a bounding box
                        VectorClear(out->mins);
                        VectorClear(out->maxs);
@@ -5446,7 +5446,7 @@ void Mod_Q3BSP_Load(model_t *mod, void *buffer)
        }
        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->groupmesh->data_vertex3f + 3 * surface->num_firstvertex), NULL, NULL, NULL, NULL, surface->num_triangles, (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle));
+               Mod_ShadowMesh_AddMesh(loadmodel->mempool, loadmodel->brush.shadowmesh, NULL, NULL, NULL, surface->groupmesh->data_vertex3f, 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 5064ac4..9e8200f 100644 (file)
@@ -612,13 +612,13 @@ void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, c
 }
 
 // warning: this is an expensive function!
-void Mod_BuildNormals(int numverts, int numtriangles, const float *vertex3f, const int *elements, float *normal3f)
+void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f)
 {
        int i, tnum;
        float normal[3], *v;
        const int *e;
        // clear the vectors
-       memset(normal3f, 0, numverts * sizeof(float[3]));
+       memset(normal3f + 3 * firstvertex, 0, numvertices * sizeof(float[3]));
        // process each vertex of each triangle and accumulate the results
        for (tnum = 0, e = elements;tnum < numtriangles;tnum++, e += 3)
        {
@@ -639,7 +639,7 @@ void Mod_BuildNormals(int numverts, int numtriangles, const float *vertex3f, con
        }
        // now we could divide the vectors by the number of averaged values on
        // each vertex...  but instead normalize them
-       for (i = 0, v = normal3f;i < numverts;i++, v += 3)
+       for (i = 0, v = normal3f + 3 * firstvertex;i < numvertices;i++, v += 3)
                VectorNormalize(v);
 }
 
@@ -693,18 +693,18 @@ void Mod_BuildBumpVectors(const float *v0, const float *v1, const float *v2, con
 }
 
 // warning: this is a very expensive function!
-void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex3f, const float *texcoord2f, const int *elements, float *svector3f, float *tvector3f, float *normal3f)
+void Mod_BuildTextureVectorsAndNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const float *texcoord2f, const int *elements, float *svector3f, float *tvector3f, float *normal3f)
 {
        int i, tnum;
        float sdir[3], tdir[3], normal[3], *v;
        const int *e;
        // clear the vectors
        if (svector3f)
-               memset(svector3f, 0, numverts * sizeof(float[3]));
+               memset(svector3f + 3 * firstvertex, 0, numvertices * sizeof(float[3]));
        if (tvector3f)
-               memset(tvector3f, 0, numverts * sizeof(float[3]));
+               memset(tvector3f + 3 * firstvertex, 0, numvertices * sizeof(float[3]));
        if (normal3f)
-               memset(normal3f, 0, numverts * sizeof(float[3]));
+               memset(normal3f + 3 * firstvertex, 0, numvertices * sizeof(float[3]));
        // process each vertex of each triangle and accumulate the results
        for (tnum = 0, e = elements;tnum < numtriangles;tnum++, e += 3)
        {
@@ -741,15 +741,15 @@ void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const flo
        // each vertex...  but instead normalize them
        // 4 assignments, 1 divide, 1 sqrt, 2 adds, 6 multiplies
        if (svector3f)
-               for (i = 0, v = svector3f;i < numverts;i++, v += 3)
+               for (i = 0, v = svector3f + 3 * firstvertex;i < numvertices;i++, v += 3)
                        VectorNormalize(v);
        // 4 assignments, 1 divide, 1 sqrt, 2 adds, 6 multiplies
        if (tvector3f)
-               for (i = 0, v = tvector3f;i < numverts;i++, v += 3)
+               for (i = 0, v = tvector3f + 3 * firstvertex;i < numvertices;i++, v += 3)
                        VectorNormalize(v);
        // 4 assignments, 1 divide, 1 sqrt, 2 adds, 6 multiplies
        if (normal3f)
-               for (i = 0, v = normal3f;i < numverts;i++, v += 3)
+               for (i = 0, v = normal3f + 3 * firstvertex;i < numvertices;i++, v += 3)
                        VectorNormalize(v);
 }
 
@@ -757,7 +757,7 @@ surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriang
 {
        surfmesh_t *mesh;
        qbyte *data;
-       mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + (neighbors ? 3 : 0)) * sizeof(int));
+       mesh = Mem_Alloc(mempool, sizeof(surfmesh_t) + numvertices * (3 + 3 + 3 + 3 + 2 + 2 + (detailtexcoords ? 2 : 0) + (vertexcolors ? 4 : 0)) * sizeof(float) + numvertices * (lightmapoffsets ? 1 : 0) * sizeof(int) + numtriangles * (3 + 3 + (neighbors ? 3 : 0)) * sizeof(int));
        mesh->num_vertices = numvertices;
        mesh->num_triangles = numtriangles;
        data = (qbyte *)(mesh + 1);
@@ -779,6 +779,7 @@ surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriang
        if (mesh->num_triangles)
        {
                mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
+               mesh->data_element3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
                if (neighbors)
                        mesh->data_neighbor3i = (int *)data, data += sizeof(int[3]) * mesh->num_triangles;
        }
index bf7218e..9456dab 100644 (file)
@@ -462,8 +462,8 @@ extern char loadname[32];   // for hunk tags
 int Mod_BuildVertexRemapTableFromElements(int numelements, const int *elements, int numvertices, int *remapvertices);
 void Mod_BuildTriangleNeighbors(int *neighbors, const int *elements, int numtriangles);
 void Mod_ValidateElements(const int *elements, int numtriangles, int numverts, const char *filename, int fileline);
-void Mod_BuildNormals(int numverts, int numtriangles, const float *vertex3f, const int *elements, float *normal3f);
-void Mod_BuildTextureVectorsAndNormals(int numverts, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
+void Mod_BuildNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex3f, const int *elements, float *normal3f);
+void Mod_BuildTextureVectorsAndNormals(int firstvertex, int numvertices, int numtriangles, const float *vertex, const float *texcoord, const int *elements, float *svectors, float *tvectors, float *normals);
 
 surfmesh_t *Mod_AllocSurfMesh(mempool_t *mempool, int numvertices, int numtriangles, qboolean detailtexcoords, qboolean lightmapoffsets, qboolean vertexcolors, qboolean neighbors);
 
index 8e76acb..f6f8576 100644 (file)
--- a/portals.c
+++ b/portals.c
@@ -347,9 +347,9 @@ void Portal_RecursiveFlow_ExactLeafFaces(portalrecursioninfo_t *info, int *mark,
                        surface = info->model->brush.data_surfaces + *mark;
                        for (j = 0, elements = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);j < surface->num_triangles;j++, elements += 3)
                        {
-                               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]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + elements[0] * 3), trianglepoints[0]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + elements[1] * 3), trianglepoints[1]);
+                               VectorCopy((surface->groupmesh->data_vertex3f + 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]));
index 316bc2e..dd9ca8e 100644 (file)
--- a/pr_cmds.c
+++ b/pr_cmds.c
@@ -2605,15 +2605,16 @@ static void clippointtosurface(msurface_t *surface, vec3_t p, vec3_t out)
 {
        int i, j, k;
        float *v[3], facenormal[3], edgenormal[3], sidenormal[3], temp[3], offsetdist, dist, bestdist;
+       const int *e;
        bestdist = 1000000000;
        VectorCopy(p, out);
-       for (i = 0;i < surface->num_triangles;i++)
+       for (i = 0, e = (surface->groupmesh->data_element3i + 3 * surface->num_firsttriangle);i < surface->num_triangles;i++, e += 3)
        {
                // clip original point to each triangle of the surface and find the
                // triangle that is closest
-               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;
+               v[0] = surface->groupmesh->data_vertex3f + e[0] * 3;
+               v[1] = surface->groupmesh->data_vertex3f + e[1] * 3;
+               v[2] = surface->groupmesh->data_vertex3f + e[2] * 3;
                TriangleNormal(v[0], v[1], v[2], facenormal);
                VectorNormalize(facenormal);
                offsetdist = DotProduct(v[0], facenormal) - DotProduct(p, facenormal);
index 9575f9c..f5cbf9f 100644 (file)
@@ -1552,7 +1552,7 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(float *out3f, int numve
        }
 }
 
-void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, const float *relativelightorigin, const float *relativeeyeorigin, const float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *glosstexture, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale)
+void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *elements, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, const float *relativelightorigin, const float *relativeeyeorigin, const float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *glosstexture, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale)
 {
        int renders;
        float color[3], color2[3], colorscale;
@@ -1641,8 +1641,8 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                        qglUniform1fARB(qglGetUniformLocationARB(prog, "OffsetMapping_Bias"), r_shadow_glsl_offsetmapping_bias.value);CHECKGLERROR
                }
                CHECKGLERROR
-               GL_LockArrays(0, numverts);
-               R_Mesh_Draw(0, numverts, numtriangles, elements);
+               GL_LockArrays(firstvertex, numvertices);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                c_rt_lightmeshes++;
                c_rt_lighttris += numtriangles;
                GL_LockArrays(0, 0);
@@ -1680,7 +1680,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord3f[0] = varray_texcoord3f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(basetexture);
                                m.pointer_texcoord[1] = texcoord2f;
@@ -1690,7 +1690,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[2] = *matrix_modeltolight;
 #else
                                m.pointer_texcoord3f[2] = varray_texcoord3f[2];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2], numverts, vertex3f, matrix_modeltolight);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                GL_BlendFunc(GL_ONE, GL_ONE);
                        }
@@ -1705,7 +1705,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord3f[0] = varray_texcoord3f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(basetexture);
                                m.pointer_texcoord[1] = texcoord2f;
@@ -1722,7 +1722,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -1730,7 +1730,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                m.tex[2] = R_GetTexture(basetexture);
                                m.pointer_texcoord[2] = texcoord2f;
@@ -1742,7 +1742,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[3] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[3] = varray_texcoord3f[3];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[3], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[3] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_ONE, GL_ONE);
@@ -1758,7 +1758,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -1766,7 +1766,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                m.tex[2] = R_GetTexture(basetexture);
                                m.pointer_texcoord[2] = texcoord2f;
@@ -1783,7 +1783,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -1791,13 +1791,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -1814,7 +1814,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1823,11 +1823,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                        R_Mesh_State(&m);
                        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
                        VectorScale(lightcolor, colorscale, color2);
-                       GL_LockArrays(0, numverts);
+                       GL_LockArrays(firstvertex, numvertices);
                        for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                        {
                                GL_Color(bound(0, color2[0], 1), bound(0, color2[1], 1), bound(0, color2[2], 1), 1);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                        }
@@ -1855,20 +1855,20 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin);
                                m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture);
 #ifdef USETEXMATRIX
                                m.pointer_texcoord3f[2] = vertex3f;
                                m.texmatrix[2] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord3f[2] = varray_texcoord3f[2];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -1885,7 +1885,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1901,13 +1901,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord3f[0] = varray_texcoord3f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -1920,11 +1920,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -1941,7 +1941,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1957,12 +1957,12 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -1977,7 +1977,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
                        }
@@ -1992,14 +1992,14 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin);
                                m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
                                m.pointer_texcoord3f[2] = vertex3f;
                                m.texmatrix[2] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[2] = varray_texcoord2f[2];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -2007,13 +2007,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[3] = *matrix_modeltoattenuationz;
 #else
                                m.pointer_texcoord[3] = varray_texcoord2f[3];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[3], numverts, vertex3f, matrix_modeltoattenuationz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[3] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -2030,7 +2030,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -2046,7 +2046,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -2054,13 +2054,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -2073,11 +2073,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -2094,7 +2094,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltolight;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                }
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -2103,11 +2103,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                        R_Mesh_State(&m);
                        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
                        VectorScale(lightcolor, colorscale, color2);
-                       GL_LockArrays(0, numverts);
+                       GL_LockArrays(firstvertex, numvertices);
                        for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                        {
                                GL_Color(bound(0, color2[0], 1), bound(0, color2[1], 1), bound(0, color2[2], 1), 1);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                        }
@@ -2130,13 +2130,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                        m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
+                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin);
                                        R_Mesh_State(&m);
                                        GL_ColorMask(0,0,0,1);
                                        // this squares the result
                                        GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                                       GL_LockArrays(0, numverts);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       GL_LockArrays(firstvertex, numvertices);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        GL_LockArrays(0, 0);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
@@ -2144,17 +2144,17 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        memset(&m, 0, sizeof(m));
                                        m.pointer_vertex = vertex3f;
                                        R_Mesh_State(&m);
-                                       GL_LockArrays(0, numverts);
+                                       GL_LockArrays(firstvertex, numvertices);
                                        // square alpha in framebuffer a few times to make it shiny
                                        GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                                        // these comments are a test run through this math for intensity 0.5
                                        // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier)
                                        // 0.25 * 0.25 = 0.0625 (this is another pass)
                                        // 0.0625 * 0.0625 = 0.00390625 (this is another pass)
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
                                        GL_LockArrays(0, 0);
@@ -2167,12 +2167,12 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                        m.pointer_texcoord3f[0] = varray_texcoord3f[0];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                        R_Mesh_State(&m);
                                        GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                                       GL_LockArrays(0, numverts);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       GL_LockArrays(firstvertex, numvertices);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        GL_LockArrays(0, 0);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
@@ -2189,7 +2189,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                                m.texmatrix[1] = *matrix_modeltolight;
 #else
                                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                        }
                                        GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -2204,13 +2204,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                        m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
+                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin);
                                        R_Mesh_State(&m);
                                        GL_ColorMask(0,0,0,1);
                                        // this squares the result
                                        GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                                       GL_LockArrays(0, numverts);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       GL_LockArrays(firstvertex, numvertices);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        GL_LockArrays(0, 0);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
@@ -2218,17 +2218,17 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        memset(&m, 0, sizeof(m));
                                        m.pointer_vertex = vertex3f;
                                        R_Mesh_State(&m);
-                                       GL_LockArrays(0, numverts);
+                                       GL_LockArrays(firstvertex, numvertices);
                                        // square alpha in framebuffer a few times to make it shiny
                                        GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                                        // these comments are a test run through this math for intensity 0.5
                                        // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier)
                                        // 0.25 * 0.25 = 0.0625 (this is another pass)
                                        // 0.0625 * 0.0625 = 0.00390625 (this is another pass)
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
                                        GL_LockArrays(0, 0);
@@ -2243,7 +2243,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltoattenuationxyz;
 #else
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                        GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
                                }
@@ -2257,13 +2257,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                        m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                        m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
+                                       R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, svector3f + 3 * firstvertex, tvector3f + 3 * firstvertex, normal3f + 3 * firstvertex, relativelightorigin, relativeeyeorigin);
                                        R_Mesh_State(&m);
                                        GL_ColorMask(0,0,0,1);
                                        // this squares the result
                                        GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                                       GL_LockArrays(0, numverts);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       GL_LockArrays(firstvertex, numvertices);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        GL_LockArrays(0, 0);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
@@ -2271,17 +2271,17 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        memset(&m, 0, sizeof(m));
                                        m.pointer_vertex = vertex3f;
                                        R_Mesh_State(&m);
-                                       GL_LockArrays(0, numverts);
+                                       GL_LockArrays(firstvertex, numvertices);
                                        // square alpha in framebuffer a few times to make it shiny
                                        GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                                        // these comments are a test run through this math for intensity 0.5
                                        // 0.5 * 0.5 = 0.25 (done by the BlendFunc earlier)
                                        // 0.25 * 0.25 = 0.0625 (this is another pass)
                                        // 0.0625 * 0.0625 = 0.00390625 (this is another pass)
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
                                        GL_LockArrays(0, 0);
@@ -2294,7 +2294,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[0] = *matrix_modeltoattenuationxyz;
 #else
                                        m.pointer_texcoord[0] = varray_texcoord2f[0];
-                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                        m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
 #ifdef USETEXMATRIX
@@ -2302,12 +2302,12 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[1] = *matrix_modeltoattenuationz;
 #else
                                        m.pointer_texcoord[1] = varray_texcoord2f[1];
-                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                        R_Mesh_State(&m);
                                        GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                                       GL_LockArrays(0, numverts);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       GL_LockArrays(firstvertex, numvertices);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        GL_LockArrays(0, 0);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
@@ -2324,7 +2324,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                                m.texmatrix[1] = *matrix_modeltolight;
 #else
                                                m.pointer_texcoord3f[1] = varray_texcoord3f[1];
-                                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
+                                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltolight);
 #endif
                                        }
                                        GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -2332,11 +2332,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                R_Mesh_State(&m);
                                GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 0);
                                VectorScale(lightcolor, colorscale, color2);
-                               GL_LockArrays(0, numverts);
+                               GL_LockArrays(firstvertex, numvertices);
                                for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                                {
                                        GL_Color(bound(0, color2[0], 1), bound(0, color2[1], 1), bound(0, color2[2], 1), 1);
-                                       R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                        c_rt_lightmeshes++;
                                        c_rt_lighttris += numtriangles;
                                }
@@ -2363,7 +2363,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                if (r_textureunits.integer >= 3)
                                {
@@ -2374,7 +2374,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[2] = *matrix_modeltoattenuationz;
 #else
                                        m.pointer_texcoord[2] = varray_texcoord2f[2];
-                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2], numverts, vertex3f, matrix_modeltoattenuationz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                }
                        }
@@ -2391,11 +2391,11 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                if (r_textureunits.integer >= 3)
                                        GL_Color(color[0], color[1], color[2], 1);
                                else if (r_textureunits.integer >= 2)
-                                       R_Shadow_VertexNoShadingWithZAttenuation(numverts, vertex3f, color, matrix_modeltolight);
+                                       R_Shadow_VertexNoShadingWithZAttenuation(numvertices, vertex3f + 3 * firstvertex, color + 3 * firstvertex, matrix_modeltolight);
                                else
-                                       R_Shadow_VertexNoShadingWithXYZAttenuation(numverts, vertex3f, color, matrix_modeltolight);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Shadow_VertexNoShadingWithXYZAttenuation(numvertices, vertex3f + 3 * firstvertex, color + 3 * firstvertex, matrix_modeltolight);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -2419,7 +2419,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.texmatrix[1] = *matrix_modeltoattenuationxyz;
 #else
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationxyz);
 #endif
                                if (r_textureunits.integer >= 3)
                                {
@@ -2430,7 +2430,7 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        m.texmatrix[2] = *matrix_modeltoattenuationz;
 #else
                                        m.pointer_texcoord[2] = varray_texcoord2f[2];
-                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2], numverts, vertex3f, matrix_modeltoattenuationz);
+                                       R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2] + 3 * firstvertex, numvertices, vertex3f + 3 * firstvertex, matrix_modeltoattenuationz);
 #endif
                                }
                        }
@@ -2441,13 +2441,13 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                color[1] = bound(0, color2[1], 1);
                                color[2] = bound(0, color2[2], 1);
                                if (r_textureunits.integer >= 3)
-                                       R_Shadow_VertexShading(numverts, vertex3f, normal3f, color, matrix_modeltolight);
+                                       R_Shadow_VertexShading(numvertices, vertex3f + 3 * firstvertex, normal3f + 3 * firstvertex, color + 3 * firstvertex, matrix_modeltolight);
                                else if (r_textureunits.integer >= 2)
-                                       R_Shadow_VertexShadingWithZAttenuation(numverts, vertex3f, normal3f, color, matrix_modeltolight);
+                                       R_Shadow_VertexShadingWithZAttenuation(numvertices, vertex3f + 3 * firstvertex, normal3f + 3 * firstvertex, color + 3 * firstvertex, matrix_modeltolight);
                                else
-                                       R_Shadow_VertexShadingWithXYZAttenuation(numverts, vertex3f, normal3f, color, matrix_modeltolight);
-                               GL_LockArrays(0, numverts);
-                               R_Mesh_Draw(0, numverts, numtriangles, elements);
+                                       R_Shadow_VertexShadingWithXYZAttenuation(numvertices, vertex3f + 3 * firstvertex, normal3f + 3 * firstvertex, color + 3 * firstvertex, matrix_modeltolight);
+                               GL_LockArrays(firstvertex, numvertices);
+                               R_Mesh_Draw(firstvertex, numvertices, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
@@ -2804,7 +2804,7 @@ void R_DrawRTLight(rtlight_t *rtlight, int visiblevolumes)
                        {
                                R_Mesh_Matrix(&ent->matrix);
                                for (mesh = rtlight->static_meshchain_light;mesh;mesh = mesh->next)
-                                       R_Shadow_RenderLighting(mesh->numverts, mesh->numtriangles, mesh->element3i, mesh->vertex3f, mesh->svector3f, mesh->tvector3f, mesh->normal3f, mesh->texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, &matrix_modeltolight, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, mesh->map_diffuse, mesh->map_normal, mesh->map_specular, cubemaptexture, rtlight->ambientscale, rtlight->diffusescale, rtlight->specularscale);
+                                       R_Shadow_RenderLighting(0, mesh->numverts, mesh->numtriangles, mesh->element3i, mesh->vertex3f, mesh->svector3f, mesh->tvector3f, mesh->normal3f, mesh->texcoord2f, relativelightorigin, relativeeyeorigin, lightcolor2, &matrix_modeltolight, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, mesh->map_diffuse, mesh->map_normal, mesh->map_specular, cubemaptexture, rtlight->ambientscale, rtlight->diffusescale, rtlight->specularscale);
                        }
                        else
                                ent->model->DrawLight(ent, relativelightorigin, relativeeyeorigin, rtlight->radius, lightcolor2, &matrix_modeltolight, &matrix_modeltoattenuationxyz, &matrix_modeltoattenuationz, cubemaptexture, rtlight->ambientscale, rtlight->diffusescale, rtlight->specularscale, numsurfaces, surfacelist);
index 782a990..371c060 100644 (file)
@@ -34,7 +34,7 @@ extern mempool_t *r_shadow_mempool;
 void R_Shadow_Init(void);
 void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, float projectdistance, int nummarktris, const int *marktris);
 void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs);
-void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, const float *relativelightorigin, const float *relativeeyeorigin, const float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *glosstexture, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale);
+void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *elements, const float *vertex3f, const float *svector3f, const float *tvector3f, const float *normal3f, const float *texcoord2f, const float *relativelightorigin, const float *relativeeyeorigin, const float *lightcolor, const matrix4x4_t *matrix_modeltolight, const matrix4x4_t *matrix_modeltoattenuationxyz, const matrix4x4_t *matrix_modeltoattenuationz, rtexture_t *basetexture, rtexture_t *bumptexture, rtexture_t *glosstexture, rtexture_t *lightcubemap, vec_t ambientscale, vec_t diffusescale, vec_t specularscale);
 void R_Shadow_ClearStencil(void);
 
 void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *vertex3f, const int *element3i);