reorganized texture setup code in R_Shadow_RenderLighting to be cleaner, fixed CVA...
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 15 Mar 2004 05:27:02 +0000 (05:27 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Mon, 15 Mar 2004 05:27:02 +0000 (05:27 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@4020 d7cf8633-e32d-0410-b094-e92efae38249

r_shadow.c

index e62ff11..b2e4d97 100644 (file)
@@ -1240,24 +1240,24 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
-                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
-                               m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                m.texcombinergb[0] = GL_REPLACE;
+                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
-                               m.pointer_texcoord[0] = texcoord2f;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[2] = varray_texcoord3f[2];
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(basetexture);
@@ -1292,33 +1292,33 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                m.pointer_vertex = vertex3f;
                                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[0] = varray_texcoord3f[0];
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
-                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[0] = GL_REPLACE;
-                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
+                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(basetexture);
@@ -1352,32 +1352,32 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
-                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[0] = GL_REPLACE;
-                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
+                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(basetexture);
-                               m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                R_Mesh_State(&m);
                                GL_LockArrays(0, numverts);
                                GL_ColorMask(1,1,1,0);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                VectorScale(lightcolor, r_shadow_lightintensityscale.value, color2);
                                for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                                {
@@ -1397,27 +1397,27 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
-                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[0] = GL_REPLACE;
-                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
-                               m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
-                               m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
+                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
+                               m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[2] = varray_texcoord2f[2];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[3] = varray_texcoord2f[3];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[3], numverts, vertex3f, matrix_modeltoattenuationz);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[2], numverts, vertex3f, matrix_modeltoattenuationxyz);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[3], numverts, vertex3f, matrix_modeltoattenuationz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(basetexture);
@@ -1451,37 +1451,37 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
-                               m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                GL_BlendFunc(GL_ONE, GL_ZERO);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
-                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[0] = GL_REPLACE;
-                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
+                               m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(basetexture);
@@ -1522,21 +1522,21 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
-                               m.pointer_texcoord[0] = texcoord2f;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                // this squares the result
                                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                R_Mesh_State(&m);
@@ -1554,30 +1554,30 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                                GL_LockArrays(0, 0);
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[0] = varray_texcoord3f[0];
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(glosstexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                if (lightcubemap)
                                {
                                        m.texcubemap[1] = R_GetTexture(lightcubemap);
                                        m.pointer_texcoord[1] = varray_texcoord3f[1];
                                        R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
                                }
-                               m.pointer_texcoord[0] = texcoord2f;
                                R_Mesh_State(&m);
                                GL_LockArrays(0, numverts);
                                GL_ColorMask(1,1,1,0);
@@ -1601,21 +1601,21 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
-                               m.pointer_texcoord[0] = texcoord2f;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                // this squares the result
                                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                R_Mesh_State(&m);
@@ -1633,18 +1633,18 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                                GL_LockArrays(0, 0);
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(glosstexture);
-                               m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[0] = texcoord2f;
+                               m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                R_Mesh_State(&m);
                                GL_LockArrays(0, numverts);
                                GL_ColorMask(1,1,1,0);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
-                               R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
                                VectorScale(lightcolor, colorscale, color2);
                                for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                                {
@@ -1664,21 +1664,21 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(bumptexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                m.texcubemap[1] = R_GetTexture(r_shadow_normalcubetexture);
                                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
-                               m.pointer_texcoord[0] = texcoord2f;
                                m.pointer_texcoord[1] = varray_texcoord3f[1];
+                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                R_Mesh_State(&m);
                                GL_ColorMask(0,0,0,1);
                                // this squares the result
                                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-                               R_Shadow_GenTexCoords_Specular_NormalCubeMap(varray_texcoord3f[1], numverts, vertex3f, svector3f, tvector3f, normal3f, relativelightorigin, relativeeyeorigin);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                R_Mesh_State(&m);
@@ -1696,33 +1696,33 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                                GL_LockArrays(0, 0);
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
-                               m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[0] = varray_texcoord2f[0];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
+                               m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                                m.pointer_texcoord[1] = varray_texcoord2f[1];
+                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
                                R_Mesh_State(&m);
                                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[0], numverts, vertex3f, matrix_modeltoattenuationxyz);
-                               R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationz);
                                GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
                                GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
-       
+
                                memset(&m, 0, sizeof(m));
                                m.pointer_vertex = vertex3f;
                                m.tex[0] = R_GetTexture(glosstexture);
+                               m.pointer_texcoord[0] = texcoord2f;
                                if (lightcubemap)
                                {
                                        m.texcubemap[1] = R_GetTexture(lightcubemap);
                                        m.pointer_texcoord[1] = varray_texcoord3f[1];
                                        R_Shadow_Transform_Vertex3f_TexCoord3f(varray_texcoord3f[1], numverts, vertex3f, matrix_modeltolight);
                                }
-                               m.pointer_texcoord[0] = texcoord2f;
                                R_Mesh_State(&m);
                                GL_LockArrays(0, numverts);
                                GL_ColorMask(1,1,1,0);
@@ -1761,7 +1761,6 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                R_Shadow_Transform_Vertex3f_TexCoord2f(varray_texcoord2f[1], numverts, vertex3f, matrix_modeltoattenuationxyz);
                        }
                        R_Mesh_State(&m);
-                       GL_LockArrays(0, numverts);
                        for (renders = 0;renders < 64 && (color2[0] > 0 || color2[1] > 0 || color2[2] > 0);renders++, color2[0]--, color2[1]--, color2[2]--)
                        {
                                color[0] = bound(0, color2[0], 1);
@@ -1771,11 +1770,12 @@ void R_Shadow_RenderLighting(int numverts, int numtriangles, const int *elements
                                        R_Shadow_VertexLightingWithXYAttenuationTexture(numverts, vertex3f, normal3f, color, matrix_modeltolight);
                                else
                                        R_Shadow_VertexLighting(numverts, vertex3f, normal3f, color, matrix_modeltolight);
+                               GL_LockArrays(0, numverts);
                                R_Mesh_Draw(numverts, numtriangles, elements);
+                               GL_LockArrays(0, 0);
                                c_rt_lightmeshes++;
                                c_rt_lighttris += numtriangles;
                        }
-                       GL_LockArrays(0, 0);
                }
        }
 }