]> de.git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - r_shadow.c
optimizations to surface rendering setup
[xonotic/darkplaces.git] / r_shadow.c
index dfa7d99b0758cc5daaa9abed05137ce0f562db22..6383a67b7913993222b735486a03ecedeeb5e536 100644 (file)
@@ -876,15 +876,7 @@ void R_Shadow_RenderMode_StencilShadowVolumes(void)
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(false);
        GL_DepthTest(true);
-       if (!r_showtrispass)
-               qglPolygonOffset(r_shadow_shadow_polygonfactor.value, r_shadow_shadow_polygonoffset.value);
-       //if (r_shadow_shadow_polygonoffset.value != 0)
-       //{
-       //      qglPolygonOffset(r_shadow_shadow_polygonfactor.value, r_shadow_shadow_polygonoffset.value);
-       //      qglEnable(GL_POLYGON_OFFSET_FILL);
-       //}
-       //else
-       //      qglDisable(GL_POLYGON_OFFSET_FILL);
+       qglPolygonOffset(r_shadowpolygonfactor, r_shadowpolygonoffset);
        qglDepthFunc(GL_LESS);
        qglCullFace(GL_FRONT); // quake is backwards, this culls back faces
        qglEnable(GL_STENCIL_TEST);
@@ -918,8 +910,7 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
        GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
        GL_DepthMask(false);
        GL_DepthTest(true);
-       if (!r_showtrispass)
-               qglPolygonOffset(0, 0);
+       qglPolygonOffset(r_polygonfactor, r_polygonoffset);
        //qglDisable(GL_POLYGON_OFFSET_FILL);
        GL_Color(1, 1, 1, 1);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
@@ -962,8 +953,7 @@ void R_Shadow_RenderMode_VisibleShadowVolumes(void)
        GL_BlendFunc(GL_ONE, GL_ONE);
        GL_DepthMask(false);
        GL_DepthTest(!r_showdisabledepthtest.integer);
-       if (!r_showtrispass)
-               qglPolygonOffset(0, 0);
+       qglPolygonOffset(r_polygonfactor, r_polygonoffset);
        GL_Color(0.0, 0.0125, 0.1, 1);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
        qglDepthFunc(GL_GEQUAL);
@@ -979,8 +969,7 @@ void R_Shadow_RenderMode_VisibleLighting(qboolean stenciltest, qboolean transpar
        GL_BlendFunc(GL_ONE, GL_ONE);
        GL_DepthMask(false);
        GL_DepthTest(!r_showdisabledepthtest.integer);
-       if (!r_showtrispass)
-               qglPolygonOffset(0, 0);
+       qglPolygonOffset(r_polygonfactor, r_polygonoffset);
        GL_Color(0.1, 0.0125, 0, 1);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
        if (transparent)
@@ -1003,8 +992,7 @@ void R_Shadow_RenderMode_End(void)
        GL_BlendFunc(GL_ONE, GL_ZERO);
        GL_DepthMask(true);
        GL_DepthTest(true);
-       if (!r_showtrispass)
-               qglPolygonOffset(0, 0);
+       qglPolygonOffset(r_polygonfactor, r_polygonoffset);
        //qglDisable(GL_POLYGON_OFFSET_FILL);
        GL_Color(1, 1, 1, 1);
        GL_ColorMask(r_refdef.colormask[0], r_refdef.colormask[1], r_refdef.colormask[2], 1);
@@ -1111,12 +1099,6 @@ qboolean R_Shadow_ScissorForBBox(const float *mins, const float *maxs)
        return false;
 }
 
-extern float *rsurface_vertex3f;
-extern float *rsurface_svector3f;
-extern float *rsurface_tvector3f;
-extern float *rsurface_normal3f;
-extern void RSurf_SetVertexPointer(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t modelorg, qboolean generatenormals, qboolean generatetangents);
-
 static void R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(const msurface_t *surface, const float *diffusecolor, const float *ambientcolor)
 {
        int numverts = surface->num_vertices;
@@ -1254,16 +1236,19 @@ static void R_Shadow_RenderSurfacesLighting_VisibleLighting(const entity_render_
 {
        // used to display how many times a surface is lit for level design purposes
        int surfacelistindex;
+       model_t *model = ent->model;
        rmeshstate_t m;
        GL_Color(0.1, 0.025, 0, 1);
        memset(&m, 0, sizeof(m));
        R_Mesh_State(&m);
+       RSurf_SetPointersForPass(false, false);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, false, false);
+               if (rsurface_dynamicvertex)
+                       RSurf_PrepareDynamicSurfaceVertices(surface);
                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);
+               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, model->surfmesh.data_element3i + 3 * surface->num_firsttriangle);
                GL_LockArrays(0, 0);
        }
 }
@@ -1272,13 +1257,16 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en
 {
        // ARB2 GLSL shader path (GFFX5200, Radeon 9500)
        int surfacelistindex;
+       model_t *model = ent->model;
        R_SetupSurfaceShader(ent, texture, r_shadow_entityeyeorigin, lightcolorbase, false);
+       RSurf_SetPointersForPass(false, true);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
-               RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, false, true);
-               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+               const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
+               if (rsurface_dynamicvertex)
+                       RSurf_PrepareDynamicSurfaceVertices(surface);
+               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f);
                R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f);
                R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f);
@@ -1291,9 +1279,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_GLSL(const entity_render_t *en
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *basetexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        GL_Color(1,1,1,1);
        // colorscale accounts for how much we multiply the brightness
        // during combine.
@@ -1311,7 +1300,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[1] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[1] = texture->currenttexmatrix;
                m.texcubemap[2] = R_GetTexture(r_shadow_rtlight->currentcubemap);
                m.pointer_texcoord3f[2] = rsurface_vertex3f;
@@ -1327,7 +1316,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[0] = rsurface_vertex3f;
                m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[1] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[1] = texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1343,7 +1332,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[2] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[2] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1365,7 +1354,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
                m.texmatrix[1] = r_shadow_entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[2] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[2] = texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1390,7 +1379,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1416,9 +1405,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(const entity_
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *basetexture, rtexture_t *normalmaptexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        GL_Color(1,1,1,1);
        // colorscale accounts for how much we multiply the brightness
        // during combine.
@@ -1434,7 +1424,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1453,7 +1443,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1482,7 +1472,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1497,7 +1487,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1514,7 +1504,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1530,7 +1520,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
@@ -1544,7 +1534,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1566,7 +1556,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1598,7 +1588,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1613,7 +1603,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1639,9 +1629,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_DiffusePass(const entity_
 static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity_render_t *ent, const texture_t *texture, const msurface_t *surface, const vec3_t lightcolorbase, rtexture_t *glosstexture, rtexture_t *normalmaptexture, float colorscale)
 {
        int renders;
+       model_t *model = ent->model;
        float color2[3];
        rmeshstate_t m;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        // FIXME: detect blendsquare!
        //if (!gl_support_blendsquare)
        //      return;
@@ -1652,7 +1643,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1694,7 +1685,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1710,7 +1701,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1741,7 +1732,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
@@ -1754,7 +1745,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1799,7 +1790,7 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3_SpecularPass(const entity
                memset(&m, 0, sizeof(m));
                m.pointer_vertex = rsurface_vertex3f;
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = surface->groupmesh->data_texcoordtexture2f;
+               m.pointer_texcoord[0] = model->surfmesh.data_texcoordtexture2f;
                m.texmatrix[0] = texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
@@ -1830,10 +1821,12 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en
        qboolean dospecular = specularscale > 0;
        if (!doambient && !dodiffuse && !dospecular)
                return;
+       RSurf_SetPointersForPass(false, true);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, false, true);
+               if (rsurface_dynamicvertex)
+                       RSurf_PrepareDynamicSurfaceVertices(surface);
                if (doambient)
                        R_Shadow_RenderSurfacesLighting_Light_Dot3_AmbientPass(ent, texture, surface, lightcolorbase, basetexture, r_shadow_rtlight->ambientscale);
                if (dodiffuse)
@@ -1857,10 +1850,10 @@ static void R_Shadow_RenderSurfacesLighting_Light_Dot3(const entity_render_t *en
        }
 }
 
-void R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(const msurface_t *surface, vec3_t diffusecolor2, vec3_t ambientcolor2)
+void R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(const model_t *model, const msurface_t *surface, vec3_t diffusecolor2, vec3_t ambientcolor2)
 {
        int renders;
-       const int *elements = surface->groupmesh->data_element3i + surface->num_firsttriangle * 3;
+       const int *elements = model->surfmesh.data_element3i + surface->num_firsttriangle * 3;
        R_Shadow_RenderSurfacesLighting_Light_Vertex_Shading(surface, diffusecolor2, ambientcolor2);
        for (renders = 0;renders < 64 && (ambientcolor2[0] > renders || ambientcolor2[1] > renders || ambientcolor2[2] > renders || diffusecolor2[0] > renders || diffusecolor2[1] > renders || diffusecolor2[2] > renders);renders++)
        {
@@ -1930,6 +1923,7 @@ goodpass:
 static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *ent, const texture_t *texture, int numsurfaces, msurface_t **surfacelist, const vec3_t lightcolorbase, const vec3_t lightcolorpants, const vec3_t lightcolorshirt, rtexture_t *basetexture, rtexture_t *pantstexture, rtexture_t *shirttexture, rtexture_t *normalmaptexture, rtexture_t *glosstexture, float specularscale, qboolean dopants, qboolean doshirt)
 {
        int surfacelistindex;
+       model_t *model = ent->model;
        float ambientcolorbase[3], diffusecolorbase[3];
        float ambientcolorpants[3], diffusecolorpants[3];
        float ambientcolorshirt[3], diffusecolorshirt[3];
@@ -1957,12 +1951,14 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *
        }
        m.pointer_color = rsurface_array_color4f;
        R_Mesh_State(&m);
+       RSurf_SetPointersForPass(true, false);
        for (surfacelistindex = 0;surfacelistindex < numsurfaces;surfacelistindex++)
        {
                const msurface_t *surface = surfacelist[surfacelistindex];
-               RSurf_SetVertexPointer(ent, texture, surface, r_shadow_entityeyeorigin, true, false);
+               if (rsurface_dynamicvertex)
+                       RSurf_PrepareDynamicSurfaceVertices(surface);
                // OpenGL 1.1 path (anything)
-               R_Mesh_TexCoordPointer(0, 2, surface->groupmesh->data_texcoordtexture2f);
+               R_Mesh_TexCoordPointer(0, 2, model->surfmesh.data_texcoordtexture2f);
                R_Mesh_TexMatrix(0, &texture->currenttexmatrix);
                if (r_textureunits.integer >= 2)
                {
@@ -1975,16 +1971,16 @@ static void R_Shadow_RenderSurfacesLighting_Light_Vertex(const entity_render_t *
                        }
                }
                R_Mesh_TexBind(0, R_GetTexture(basetexture));
-               R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorbase, ambientcolorbase);
+               R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorbase, ambientcolorbase);
                if (dopants)
                {
                        R_Mesh_TexBind(0, R_GetTexture(pantstexture));
-                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorpants, ambientcolorpants);
+                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorpants, ambientcolorpants);
                }
                if (doshirt)
                {
                        R_Mesh_TexBind(0, R_GetTexture(shirttexture));
-                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(surface, diffusecolorshirt, ambientcolorshirt);
+                       R_Shadow_RenderSurfacesLighting_Light_Vertex_Pass(model, surface, diffusecolorshirt, ambientcolorshirt);
                }
        }
 }
@@ -2003,6 +1999,7 @@ void R_Shadow_RenderSurfacesLighting(const entity_render_t *ent, const texture_t
                qglDisable(GL_CULL_FACE);
        else
                qglEnable(GL_CULL_FACE);
+       RSurf_PrepareForBatch(ent, texture, r_shadow_entityeyeorigin);
        if (texture->colormapping)
        {
                qboolean dopants = texture->skin.pants != NULL && VectorLength2(ent->colormap_pantscolor) >= (1.0f / 1048576.0f);
@@ -2174,7 +2171,8 @@ void R_RTLight_Compile(rtlight_t *rtlight)
                }
        }
 
-       Con_DPrintf("static light built: %f %f %f : %f %f %f box, %i shadow volume triangles (in %i meshes)\n", rtlight->cullmins[0], rtlight->cullmins[1], rtlight->cullmins[2], rtlight->cullmaxs[0], rtlight->cullmaxs[1], rtlight->cullmaxs[2], shadowtris, shadowmeshes);
+       if (developer.integer >= 10)
+               Con_Printf("static light built: %f %f %f : %f %f %f box, %i shadow volume triangles (in %i meshes)\n", rtlight->cullmins[0], rtlight->cullmins[1], rtlight->cullmins[2], rtlight->cullmaxs[0], rtlight->cullmaxs[1], rtlight->cullmaxs[2], shadowtris, shadowmeshes);
 }
 
 void R_RTLight_Uncompile(rtlight_t *rtlight)
@@ -2206,6 +2204,7 @@ void R_Shadow_UncompileWorldLights(void)
 
 void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfacelist)
 {
+       model_t *model = ent->model;
        vec3_t relativeshadoworigin, relativeshadowmins, relativeshadowmaxs;
        vec_t relativeshadowradius;
        if (ent == r_refdef.worldentity)
@@ -2236,7 +2235,7 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfa
                else if (numsurfaces)
                {
                        R_Mesh_Matrix(&ent->matrix);
-                       ent->model->DrawShadowVolume(ent, r_shadow_rtlight->shadoworigin, r_shadow_rtlight->radius, numsurfaces, surfacelist, r_shadow_rtlight->cullmins, r_shadow_rtlight->cullmaxs);
+                       model->DrawShadowVolume(ent, r_shadow_rtlight->shadoworigin, r_shadow_rtlight->radius, numsurfaces, surfacelist, r_shadow_rtlight->cullmins, r_shadow_rtlight->cullmaxs);
                }
        }
        else
@@ -2250,7 +2249,7 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent, int numsurfaces, int *surfa
                relativeshadowmaxs[1] = relativeshadoworigin[1] + relativeshadowradius;
                relativeshadowmaxs[2] = relativeshadoworigin[2] + relativeshadowradius;
                R_Mesh_Matrix(&ent->matrix);
-               ent->model->DrawShadowVolume(ent, relativeshadoworigin, relativeshadowradius, ent->model->nummodelsurfaces, ent->model->surfacelist, relativeshadowmins, relativeshadowmaxs);
+               model->DrawShadowVolume(ent, relativeshadoworigin, relativeshadowradius, model->nummodelsurfaces, model->surfacelist, relativeshadowmins, relativeshadowmaxs);
        }
 }
 
@@ -2267,11 +2266,14 @@ void R_Shadow_SetupEntityLight(const entity_render_t *ent)
 
 void R_Shadow_DrawEntityLight(entity_render_t *ent, int numsurfaces, int *surfacelist)
 {
+       model_t *model = ent->model;
+       if (!model->DrawLight)
+               return;
        R_Shadow_SetupEntityLight(ent);
        if (ent == r_refdef.worldentity)
-               ent->model->DrawLight(ent, numsurfaces, surfacelist);
+               model->DrawLight(ent, numsurfaces, surfacelist);
        else
-               ent->model->DrawLight(ent, ent->model->nummodelsurfaces, ent->model->surfacelist);
+               model->DrawLight(ent, model->nummodelsurfaces, model->surfacelist);
 }
 
 void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
@@ -2378,16 +2380,17 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
        {
                for (i = 0;i < r_refdef.numentities;i++)
                {
+                       model_t *model;
                        entity_render_t *ent = r_refdef.entities[i];
                        if (BoxesOverlap(ent->mins, ent->maxs, rtlight->cullmins, rtlight->cullmaxs)
-                        && ent->model
+                        && (model = ent->model)
                         && !(ent->flags & RENDER_TRANSPARENT)
                         && (r_refdef.worldmodel == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS == NULL || r_refdef.worldmodel->brush.BoxTouchingLeafPVS(r_refdef.worldmodel, leafpvs, ent->mins, ent->maxs)))
                        {
                                // about the VectorDistance2 - light emitting entities should not cast their own shadow
-                               if ((ent->flags & RENDER_SHADOW) && ent->model->DrawShadowVolume && VectorDistance2(ent->origin, rtlight->shadoworigin) > 0.1)
+                               if ((ent->flags & RENDER_SHADOW) && model->DrawShadowVolume && VectorDistance2(ent->origin, rtlight->shadoworigin) > 0.1)
                                        shadowentities[numshadowentities++] = ent;
-                               if (ent->visframe == r_framecount && (ent->flags & RENDER_LIGHT) && ent->model->DrawLight)
+                               if (ent->visframe == r_framecount && (ent->flags & RENDER_LIGHT) && model->DrawLight)
                                        lightentities[numlightentities++] = ent;
                        }
                }