eliminated rsurface.model, so there is now no dependence on having an
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 May 2007 01:36:13 +0000 (01:36 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 24 May 2007 01:36:13 +0000 (01:36 +0000)
actual model in the material renderer
(except transparent surface queuing still needing an entity)
this cleanup means that the material renderer could be called from other
places without an entity (effects such as particles and lightning beams)

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

gl_rmain.c
gl_rsurf.c
r_shadow.c
r_shadow.h
r_sprites.c
render.h

index 31594e2..478613b 100644 (file)
@@ -822,12 +822,12 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
        unsigned int permutation = 0;
        r_glsl_permutation = NULL;
        // TODO: implement geometry-shader based shadow volumes someday
-       if (r_shadow_rtlight)
+       if (rsurface.rtlight)
        {
                // light source
                shaderfilename = "glsl/default.glsl";
                permutation = SHADERPERMUTATION_MODE_LIGHTSOURCE | SHADERPERMUTATION_USES_VERTEXSHADER | SHADERPERMUTATION_USES_FRAGMENTSHADER;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                        permutation |= SHADERPERMUTATION_CUBEFILTER;
                if (diffusescale > 0)
                        permutation |= SHADERPERMUTATION_DIFFUSE;
@@ -952,8 +952,8 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
        R_Mesh_TexMatrix(0, &rsurface.texture->currenttexmatrix);
        if (permutation & SHADERPERMUTATION_MODE_LIGHTSOURCE)
        {
-               if (r_glsl_permutation->loc_Texture_Cube >= 0 && r_shadow_rtlight) R_Mesh_TexBindCubeMap(3, R_GetTexture(r_shadow_rtlight->currentcubemap));
-               if (r_glsl_permutation->loc_LightPosition >= 0) qglUniform3fARB(r_glsl_permutation->loc_LightPosition, r_shadow_entitylightorigin[0], r_shadow_entitylightorigin[1], r_shadow_entitylightorigin[2]);
+               if (r_glsl_permutation->loc_Texture_Cube >= 0 && rsurface.rtlight) R_Mesh_TexBindCubeMap(3, R_GetTexture(rsurface.rtlight->currentcubemap));
+               if (r_glsl_permutation->loc_LightPosition >= 0) qglUniform3fARB(r_glsl_permutation->loc_LightPosition, rsurface.entitylightorigin[0], rsurface.entitylightorigin[1], rsurface.entitylightorigin[2]);
                if (permutation & SHADERPERMUTATION_DIFFUSE)
                {
                        if (r_glsl_permutation->loc_LightColor >= 0) qglUniform3fARB(r_glsl_permutation->loc_LightColor, lightcolorbase[0], lightcolorbase[1], lightcolorbase[2]);
@@ -990,7 +990,7 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
        if (r_glsl_permutation->loc_Texture_Normal >= 0) R_Mesh_TexBind(0, R_GetTexture(rsurface.texture->currentskinframe->nmap));
        if (r_glsl_permutation->loc_Texture_Color >= 0) R_Mesh_TexBind(1, R_GetTexture(rsurface.texture->basetexture));
        if (r_glsl_permutation->loc_Texture_Gloss >= 0) R_Mesh_TexBind(2, R_GetTexture(rsurface.texture->glosstexture));
-       //if (r_glsl_permutation->loc_Texture_Cube >= 0 && permutation & SHADERPERMUTATION_MODE_LIGHTSOURCE) R_Mesh_TexBindCubeMap(3, R_GetTexture(r_shadow_rtlight->currentcubemap));
+       //if (r_glsl_permutation->loc_Texture_Cube >= 0 && permutation & SHADERPERMUTATION_MODE_LIGHTSOURCE) R_Mesh_TexBindCubeMap(3, R_GetTexture(rsurface.rtlight->currentcubemap));
        if (r_glsl_permutation->loc_Texture_Attenuation >= 0) R_Mesh_TexBind(10, R_GetTexture(r_shadow_attenuationgradienttexture));
        if (r_glsl_permutation->loc_Texture_FogMask >= 0) R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation));
        if (r_glsl_permutation->loc_Texture_Pants >= 0) R_Mesh_TexBind(5, R_GetTexture(rsurface.texture->currentskinframe->pants));
@@ -1003,7 +1003,7 @@ int R_SetupSurfaceShader(const vec3_t lightcolorbase, qboolean modellighting, fl
        if (r_glsl_permutation->loc_FogColor >= 0)
        {
                // additive passes are only darkened by fog, not tinted
-               if (r_shadow_rtlight || (rsurface.texture->currentmaterialflags & MATERIALFLAG_ADD))
+               if (rsurface.rtlight || (rsurface.texture->currentmaterialflags & MATERIALFLAG_ADD))
                        qglUniform3fARB(r_glsl_permutation->loc_FogColor, 0, 0, 0);
                else
                        qglUniform3fARB(r_glsl_permutation->loc_FogColor, r_refdef.fogcolor[0], r_refdef.fogcolor[1], r_refdef.fogcolor[2]);
@@ -2907,7 +2907,7 @@ void R_DrawNoModel(entity_render_t *ent)
        vec3_t org;
        Matrix4x4_OriginFromMatrix(&ent->matrix, org);
        //if ((ent->effects & EF_ADDITIVE) || (ent->alpha < 1))
-               R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_DrawNoModel_TransparentCallback, ent, 0, r_shadow_rtlight);
+               R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_DrawNoModel_TransparentCallback, ent, 0, rsurface.rtlight);
        //else
        //      R_DrawNoModelCallback(ent, 0);
 }
@@ -3371,10 +3371,10 @@ void RSurf_CleanUp(void)
 
 void RSurf_ActiveWorldEntity(void)
 {
+       model_t *model = r_refdef.worldmodel;
        RSurf_CleanUp();
-       rsurface.model = r_refdef.worldmodel;
-       if (rsurface.array_size < rsurface.model->surfmesh.num_vertices)
-               R_Mesh_ResizeArrays(rsurface.model->surfmesh.num_vertices);
+       if (rsurface.array_size < model->surfmesh.num_vertices)
+               R_Mesh_ResizeArrays(model->surfmesh.num_vertices);
        rsurface.matrix = identitymatrix;
        rsurface.inversematrix = identitymatrix;
        R_Mesh_Matrix(&identitymatrix);
@@ -3392,18 +3392,34 @@ void RSurf_ActiveWorldEntity(void)
        rsurface.frameblend[2].lerp = 0;
        rsurface.frameblend[3].frame = 0;
        rsurface.frameblend[3].lerp = 0;
-       rsurface.modelvertex3f  = rsurface.model->surfmesh.data_vertex3f;
-       rsurface.modelvertex3f_bufferobject = rsurface.model->surfmesh.vbo;
-       rsurface.modelvertex3f_bufferoffset = rsurface.model->surfmesh.vbooffset_vertex3f;
-       rsurface.modelsvector3f = rsurface.model->surfmesh.data_svector3f;
-       rsurface.modelsvector3f_bufferobject = rsurface.model->surfmesh.vbo;
-       rsurface.modelsvector3f_bufferoffset = rsurface.model->surfmesh.vbooffset_svector3f;
-       rsurface.modeltvector3f = rsurface.model->surfmesh.data_tvector3f;
-       rsurface.modeltvector3f_bufferobject = rsurface.model->surfmesh.vbo;
-       rsurface.modeltvector3f_bufferoffset = rsurface.model->surfmesh.vbooffset_tvector3f;
-       rsurface.modelnormal3f  = rsurface.model->surfmesh.data_normal3f;
-       rsurface.modelnormal3f_bufferobject = rsurface.model->surfmesh.vbo;
-       rsurface.modelnormal3f_bufferoffset = rsurface.model->surfmesh.vbooffset_normal3f;
+       rsurface.modelvertex3f  = model->surfmesh.data_vertex3f;
+       rsurface.modelvertex3f_bufferobject = model->surfmesh.vbo;
+       rsurface.modelvertex3f_bufferoffset = model->surfmesh.vbooffset_vertex3f;
+       rsurface.modelsvector3f = model->surfmesh.data_svector3f;
+       rsurface.modelsvector3f_bufferobject = model->surfmesh.vbo;
+       rsurface.modelsvector3f_bufferoffset = model->surfmesh.vbooffset_svector3f;
+       rsurface.modeltvector3f = model->surfmesh.data_tvector3f;
+       rsurface.modeltvector3f_bufferobject = model->surfmesh.vbo;
+       rsurface.modeltvector3f_bufferoffset = model->surfmesh.vbooffset_tvector3f;
+       rsurface.modelnormal3f  = model->surfmesh.data_normal3f;
+       rsurface.modelnormal3f_bufferobject = model->surfmesh.vbo;
+       rsurface.modelnormal3f_bufferoffset = model->surfmesh.vbooffset_normal3f;
+       rsurface.modellightmapcolor4f  = model->surfmesh.data_lightmapcolor4f;
+       rsurface.modellightmapcolor4f_bufferobject = model->surfmesh.vbo;
+       rsurface.modellightmapcolor4f_bufferoffset = model->surfmesh.vbooffset_lightmapcolor4f;
+       rsurface.modeltexcoordtexture2f  = model->surfmesh.data_texcoordtexture2f;
+       rsurface.modeltexcoordtexture2f_bufferobject = model->surfmesh.vbo;
+       rsurface.modeltexcoordtexture2f_bufferoffset = model->surfmesh.vbooffset_texcoordtexture2f;
+       rsurface.modeltexcoordlightmap2f  = model->surfmesh.data_texcoordlightmap2f;
+       rsurface.modeltexcoordlightmap2f_bufferobject = model->surfmesh.vbo;
+       rsurface.modeltexcoordlightmap2f_bufferoffset = model->surfmesh.vbooffset_texcoordlightmap2f;
+       rsurface.modelelement3i = model->surfmesh.data_element3i;
+       rsurface.modelelement3i_bufferobject = model->surfmesh.ebo;
+       rsurface.modelneighbor3i = model->surfmesh.data_neighbor3i;
+       rsurface.modellightmapoffsets = model->surfmesh.data_lightmapoffsets;
+       rsurface.modelnum_vertices = model->surfmesh.num_vertices;
+       rsurface.modelnum_triangles = model->surfmesh.num_triangles;
+       rsurface.modelsurfaces = model->data_surfaces;
        rsurface.generatedvertex = false;
        rsurface.vertex3f  = rsurface.modelvertex3f;
        rsurface.vertex3f_bufferobject = rsurface.modelvertex3f_bufferobject;
@@ -3421,10 +3437,10 @@ void RSurf_ActiveWorldEntity(void)
 
 void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents)
 {
+       model_t *model = ent->model;
        RSurf_CleanUp();
-       rsurface.model = ent->model;
-       if (rsurface.array_size < rsurface.model->surfmesh.num_vertices)
-               R_Mesh_ResizeArrays(rsurface.model->surfmesh.num_vertices);
+       if (rsurface.array_size < model->surfmesh.num_vertices)
+               R_Mesh_ResizeArrays(model->surfmesh.num_vertices);
        rsurface.matrix = ent->matrix;
        rsurface.inversematrix = ent->inversematrix;
        R_Mesh_Matrix(&rsurface.matrix);
@@ -3438,7 +3454,7 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
        rsurface.frameblend[1] = ent->frameblend[1];
        rsurface.frameblend[2] = ent->frameblend[2];
        rsurface.frameblend[3] = ent->frameblend[3];
-       if (rsurface.model->surfmesh.isanimated && (rsurface.frameblend[0].lerp != 1 || rsurface.frameblend[0].frame != 0))
+       if (model->surfmesh.isanimated && (rsurface.frameblend[0].lerp != 1 || rsurface.frameblend[0].frame != 0))
        {
                if (wanttangents)
                {
@@ -3446,7 +3462,7 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
                        rsurface.modelsvector3f = rsurface.array_modelsvector3f;
                        rsurface.modeltvector3f = rsurface.array_modeltvector3f;
                        rsurface.modelnormal3f = rsurface.array_modelnormal3f;
-                       Mod_Alias_GetMesh_Vertices(rsurface.model, rsurface.frameblend, rsurface.array_modelvertex3f, rsurface.array_modelnormal3f, rsurface.array_modelsvector3f, rsurface.array_modeltvector3f);
+                       Mod_Alias_GetMesh_Vertices(model, rsurface.frameblend, rsurface.array_modelvertex3f, rsurface.array_modelnormal3f, rsurface.array_modelsvector3f, rsurface.array_modeltvector3f);
                }
                else if (wantnormals)
                {
@@ -3454,7 +3470,7 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
                        rsurface.modelsvector3f = NULL;
                        rsurface.modeltvector3f = NULL;
                        rsurface.modelnormal3f = rsurface.array_modelnormal3f;
-                       Mod_Alias_GetMesh_Vertices(rsurface.model, rsurface.frameblend, rsurface.array_modelvertex3f, rsurface.array_modelnormal3f, NULL, NULL);
+                       Mod_Alias_GetMesh_Vertices(model, rsurface.frameblend, rsurface.array_modelvertex3f, rsurface.array_modelnormal3f, NULL, NULL);
                }
                else
                {
@@ -3462,7 +3478,7 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
                        rsurface.modelsvector3f = NULL;
                        rsurface.modeltvector3f = NULL;
                        rsurface.modelnormal3f = NULL;
-                       Mod_Alias_GetMesh_Vertices(rsurface.model, rsurface.frameblend, rsurface.array_modelvertex3f, NULL, NULL, NULL);
+                       Mod_Alias_GetMesh_Vertices(model, rsurface.frameblend, rsurface.array_modelvertex3f, NULL, NULL, NULL);
                }
                rsurface.modelvertex3f_bufferobject = 0;
                rsurface.modelvertex3f_bufferoffset = 0;
@@ -3476,20 +3492,36 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
        }
        else
        {
-               rsurface.modelvertex3f  = rsurface.model->surfmesh.data_vertex3f;
-               rsurface.modelvertex3f_bufferobject = rsurface.model->surfmesh.vbo;
-               rsurface.modelvertex3f_bufferoffset = rsurface.model->surfmesh.vbooffset_vertex3f;
-               rsurface.modelsvector3f = rsurface.model->surfmesh.data_svector3f;
-               rsurface.modelsvector3f_bufferobject = rsurface.model->surfmesh.vbo;
-               rsurface.modelsvector3f_bufferoffset = rsurface.model->surfmesh.vbooffset_svector3f;
-               rsurface.modeltvector3f = rsurface.model->surfmesh.data_tvector3f;
-               rsurface.modeltvector3f_bufferobject = rsurface.model->surfmesh.vbo;
-               rsurface.modeltvector3f_bufferoffset = rsurface.model->surfmesh.vbooffset_tvector3f;
-               rsurface.modelnormal3f  = rsurface.model->surfmesh.data_normal3f;
-               rsurface.modelnormal3f_bufferobject = rsurface.model->surfmesh.vbo;
-               rsurface.modelnormal3f_bufferoffset = rsurface.model->surfmesh.vbooffset_normal3f;
+               rsurface.modelvertex3f  = model->surfmesh.data_vertex3f;
+               rsurface.modelvertex3f_bufferobject = model->surfmesh.vbo;
+               rsurface.modelvertex3f_bufferoffset = model->surfmesh.vbooffset_vertex3f;
+               rsurface.modelsvector3f = model->surfmesh.data_svector3f;
+               rsurface.modelsvector3f_bufferobject = model->surfmesh.vbo;
+               rsurface.modelsvector3f_bufferoffset = model->surfmesh.vbooffset_svector3f;
+               rsurface.modeltvector3f = model->surfmesh.data_tvector3f;
+               rsurface.modeltvector3f_bufferobject = model->surfmesh.vbo;
+               rsurface.modeltvector3f_bufferoffset = model->surfmesh.vbooffset_tvector3f;
+               rsurface.modelnormal3f  = model->surfmesh.data_normal3f;
+               rsurface.modelnormal3f_bufferobject = model->surfmesh.vbo;
+               rsurface.modelnormal3f_bufferoffset = model->surfmesh.vbooffset_normal3f;
                rsurface.generatedvertex = false;
        }
+       rsurface.modellightmapcolor4f  = model->surfmesh.data_lightmapcolor4f;
+       rsurface.modellightmapcolor4f_bufferobject = model->surfmesh.vbo;
+       rsurface.modellightmapcolor4f_bufferoffset = model->surfmesh.vbooffset_lightmapcolor4f;
+       rsurface.modeltexcoordtexture2f  = model->surfmesh.data_texcoordtexture2f;
+       rsurface.modeltexcoordtexture2f_bufferobject = model->surfmesh.vbo;
+       rsurface.modeltexcoordtexture2f_bufferoffset = model->surfmesh.vbooffset_texcoordtexture2f;
+       rsurface.modeltexcoordlightmap2f  = model->surfmesh.data_texcoordlightmap2f;
+       rsurface.modeltexcoordlightmap2f_bufferobject = model->surfmesh.vbo;
+       rsurface.modeltexcoordlightmap2f_bufferoffset = model->surfmesh.vbooffset_texcoordlightmap2f;
+       rsurface.modelelement3i = model->surfmesh.data_element3i;
+       rsurface.modelelement3i_bufferobject = model->surfmesh.ebo;
+       rsurface.modelneighbor3i = model->surfmesh.data_neighbor3i;
+       rsurface.modellightmapoffsets = model->surfmesh.data_lightmapoffsets;
+       rsurface.modelnum_vertices = model->surfmesh.num_vertices;
+       rsurface.modelnum_triangles = model->surfmesh.num_triangles;
+       rsurface.modelsurfaces = model->data_surfaces;
        rsurface.vertex3f  = rsurface.modelvertex3f;
        rsurface.vertex3f_bufferobject = rsurface.modelvertex3f_bufferobject;
        rsurface.vertex3f_bufferoffset = rsurface.modelvertex3f_bufferoffset;
@@ -3519,7 +3551,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        rsurface.normal3f = rsurface.modelnormal3f = rsurface.array_modelnormal3f;
                        rsurface.normal3f_bufferobject = rsurface.modelnormal3f_bufferobject = 0;
                        rsurface.normal3f_bufferoffset = rsurface.modelnormal3f_bufferoffset = 0;
-                       Mod_BuildNormals(0, rsurface.model->surfmesh.num_vertices, rsurface.model->surfmesh.num_triangles, rsurface.modelvertex3f, rsurface.model->surfmesh.data_element3i, rsurface.array_modelnormal3f, r_smoothnormals_areaweighting.integer);
+                       Mod_BuildNormals(0, rsurface.modelnum_vertices, rsurface.modelnum_triangles, rsurface.modelvertex3f, rsurface.modelelement3i, rsurface.array_modelnormal3f, r_smoothnormals_areaweighting.integer);
                }
                if (generatetangents && !rsurface.modelsvector3f)
                {
@@ -3529,7 +3561,7 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        rsurface.tvector3f = rsurface.modeltvector3f = rsurface.array_modeltvector3f;
                        rsurface.tvector3f_bufferobject = rsurface.modeltvector3f_bufferobject = 0;
                        rsurface.tvector3f_bufferoffset = rsurface.modeltvector3f_bufferoffset = 0;
-                       Mod_BuildTextureVectorsFromNormals(0, rsurface.model->surfmesh.num_vertices, rsurface.model->surfmesh.num_triangles, rsurface.modelvertex3f, rsurface.model->surfmesh.data_texcoordtexture2f, rsurface.modelnormal3f, rsurface.model->surfmesh.data_element3i, rsurface.array_modelsvector3f, rsurface.array_modeltvector3f, r_smoothnormals_areaweighting.integer);
+                       Mod_BuildTextureVectorsFromNormals(0, rsurface.modelnum_vertices, rsurface.modelnum_triangles, rsurface.modelvertex3f, rsurface.modeltexcoordtexture2f, rsurface.modelnormal3f, rsurface.modelelement3i, rsurface.array_modelsvector3f, rsurface.array_modeltvector3f, r_smoothnormals_areaweighting.integer);
                }
        }
        // if vertices are deformed (sprite flares and things in maps, possibly water waves, bulges and other deformations), generate them into rsurface.deform* arrays from whatever the rsurface.model* array pointers point to (may be static model data or generated data for an animated model)
@@ -3632,8 +3664,8 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                                        }
                                }
                        }
-                       Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.modelvertex3f, rsurface.model->surfmesh.data_element3i + surface->num_firsttriangle * 3, rsurface.array_deformednormal3f, r_smoothnormals_areaweighting.integer);
-                       Mod_BuildTextureVectorsFromNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.modelvertex3f, rsurface.model->surfmesh.data_texcoordtexture2f, rsurface.array_deformednormal3f, rsurface.model->surfmesh.data_element3i + surface->num_firsttriangle * 3, rsurface.array_deformedsvector3f, rsurface.array_deformedtvector3f, r_smoothnormals_areaweighting.integer);
+                       Mod_BuildNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.modelvertex3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformednormal3f, r_smoothnormals_areaweighting.integer);
+                       Mod_BuildTextureVectorsFromNormals(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, rsurface.modelvertex3f, rsurface.modeltexcoordtexture2f, rsurface.array_deformednormal3f, rsurface.modelelement3i + surface->num_firsttriangle * 3, rsurface.array_deformedsvector3f, rsurface.array_deformedtvector3f, r_smoothnormals_areaweighting.integer);
                }
                rsurface.vertex3f = rsurface.array_deformedvertex3f;
                rsurface.vertex3f_bufferobject = 0;
@@ -3679,7 +3711,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacel
        if (texturenumsurfaces == 1)
        {
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
        }
        else if (r_batchmode.integer == 2)
        {
@@ -3692,10 +3724,10 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacel
                        j = i + 1;
                        if (surface->num_triangles > MAXBATCHTRIANGLES)
                        {
-                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                                continue;
                        }
-                       memcpy(batchelements, rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
+                       memcpy(batchelements, rsurface.modelelement3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
                        batchtriangles = surface->num_triangles;
                        firstvertex = surface->num_firstvertex;
                        endvertex = surface->num_firstvertex + surface->num_vertices;
@@ -3704,7 +3736,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacel
                                surface2 = texturesurfacelist[j];
                                if (batchtriangles + surface2->num_triangles > MAXBATCHTRIANGLES)
                                        break;
-                               memcpy(batchelements + batchtriangles * 3, rsurface.model->surfmesh.data_element3i + 3 * surface2->num_firsttriangle, surface2->num_triangles * sizeof(int[3]));
+                               memcpy(batchelements + batchtriangles * 3, rsurface.modelelement3i + 3 * surface2->num_firsttriangle, surface2->num_triangles * sizeof(int[3]));
                                batchtriangles += surface2->num_triangles;
                                firstvertex = min(firstvertex, surface2->num_firstvertex);
                                endvertex = max(endvertex, surface2->num_firstvertex + surface2->num_vertices);
@@ -3726,7 +3758,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacel
                        numvertices = surface2->num_firstvertex + surface2->num_vertices - surface->num_firstvertex;
                        numtriangles = surface2->num_firsttriangle + surface2->num_triangles - surface->num_firsttriangle;
                        GL_LockArrays(surface->num_firstvertex, numvertices);
-                       R_Mesh_Draw(surface->num_firstvertex, numvertices, numtriangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                       R_Mesh_Draw(surface->num_firstvertex, numvertices, numtriangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                }
        }
        else
@@ -3735,7 +3767,7 @@ void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacel
                {
                        surface = texturesurfacelist[i];
                        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                }
        }
 }
@@ -3757,7 +3789,7 @@ static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurfa
                if (deluxemaptexunit >= 0)
                        R_Mesh_TexBind(deluxemaptexunit, R_GetTexture(surface->deluxemaptexture));
                GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
        }
        else if (r_batchmode.integer == 2)
        {
@@ -3773,10 +3805,10 @@ static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurfa
                        j = i + 1;
                        if (surface->num_triangles > MAXBATCHTRIANGLES)
                        {
-                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                                continue;
                        }
-                       memcpy(batchelements, rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
+                       memcpy(batchelements, rsurface.modelelement3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
                        batchtriangles = surface->num_triangles;
                        firstvertex = surface->num_firstvertex;
                        endvertex = surface->num_firstvertex + surface->num_vertices;
@@ -3785,7 +3817,7 @@ static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurfa
                                surface2 = texturesurfacelist[j];
                                if (surface2->lightmaptexture != surface->lightmaptexture || batchtriangles + surface2->num_triangles > MAXBATCHTRIANGLES)
                                        break;
-                               memcpy(batchelements + batchtriangles * 3, rsurface.model->surfmesh.data_element3i + 3 * surface2->num_firsttriangle, surface2->num_triangles * sizeof(int[3]));
+                               memcpy(batchelements + batchtriangles * 3, rsurface.modelelement3i + 3 * surface2->num_firsttriangle, surface2->num_triangles * sizeof(int[3]));
                                batchtriangles += surface2->num_triangles;
                                firstvertex = min(firstvertex, surface2->num_firstvertex);
                                endvertex = max(endvertex, surface2->num_firstvertex + surface2->num_vertices);
@@ -3826,7 +3858,7 @@ static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurfa
                        numvertices = surface2->num_firstvertex + surface2->num_vertices - surface->num_firstvertex;
                        numtriangles = surface2->num_firsttriangle + surface2->num_triangles - surface->num_firsttriangle;
                        GL_LockArrays(surface->num_firstvertex, numvertices);
-                       R_Mesh_Draw(surface->num_firstvertex, numvertices, numtriangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                       R_Mesh_Draw(surface->num_firstvertex, numvertices, numtriangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                }
 #if 0
                Con_Printf("\n");
@@ -3841,7 +3873,7 @@ static void RSurf_DrawBatch_WithLightmapSwitching(int texturenumsurfaces, msurfa
                        if (deluxemaptexunit >= 0)
                                R_Mesh_TexBind(deluxemaptexunit, R_GetTexture(surface->deluxemaptexture));
                        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                }
        }
 }
@@ -3859,7 +3891,7 @@ static void RSurf_DrawBatch_ShowSurfaces(int texturenumsurfaces, msurface_t **te
                        {
                                float f = ((j + surface->num_firsttriangle) & 31) * (1.0f / 31.0f) * r_view.colorscale;
                                GL_Color(f, f, f, 1);
-                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, 1, (rsurface.model->surfmesh.data_element3i + 3 * (j + surface->num_firsttriangle)), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * (j + surface->num_firsttriangle)));
+                               R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, 1, (rsurface.modelelement3i + 3 * (j + surface->num_firsttriangle)), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * (j + surface->num_firsttriangle)));
                        }
                }
        }
@@ -3871,7 +3903,7 @@ static void RSurf_DrawBatch_ShowSurfaces(int texturenumsurfaces, msurface_t **te
                        int k = (int)(((size_t)surface) / sizeof(msurface_t));
                        GL_Color((k & 15) * (1.0f / 16.0f) * r_view.colorscale, ((k >> 4) & 15) * (1.0f / 16.0f) * r_view.colorscale, ((k >> 8) & 15) * (1.0f / 16.0f) * r_view.colorscale, 1);
                        GL_LockArrays(surface->num_firstvertex, surface->num_vertices);
-                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.model->surfmesh.data_element3i + 3 * surface->num_firsttriangle), rsurface.model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
+                       R_Mesh_Draw(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, (rsurface.modelelement3i + 3 * surface->num_firsttriangle), rsurface.modelelement3i_bufferobject, (sizeof(int[3]) * surface->num_firsttriangle));
                }
        }
 }
@@ -3984,7 +4016,7 @@ static void RSurf_DrawBatch_GL11_VertexColor(int texturenumsurfaces, msurface_t
                        {
                                if (surface->lightmapinfo->samples)
                                {
-                                       const unsigned char *lm = surface->lightmapinfo->samples + (rsurface.model->surfmesh.data_lightmapoffsets + surface->num_firstvertex)[i];
+                                       const unsigned char *lm = surface->lightmapinfo->samples + (rsurface.modellightmapoffsets + surface->num_firstvertex)[i];
                                        float scale = r_refdef.lightstylevalue[surface->lightmapinfo->styles[0]] * (1.0f / 32768.0f);
                                        VectorScale(lm, scale, c);
                                        if (surface->lightmapinfo->styles[1] != 255)
@@ -4018,9 +4050,9 @@ static void RSurf_DrawBatch_GL11_VertexColor(int texturenumsurfaces, msurface_t
        }
        else
        {
-               rsurface.lightmapcolor4f = rsurface.model->surfmesh.data_lightmapcolor4f;
-               rsurface.lightmapcolor4f_bufferobject = rsurface.model->surfmesh.vbo;
-               rsurface.lightmapcolor4f_bufferoffset = rsurface.model->surfmesh.vbooffset_lightmapcolor4f;
+               rsurface.lightmapcolor4f = rsurface.modellightmapcolor4f;
+               rsurface.lightmapcolor4f_bufferobject = rsurface.modellightmapcolor4f_bufferobject;
+               rsurface.lightmapcolor4f_bufferoffset = rsurface.modellightmapcolor4f_bufferoffset;
        }
        if (applyfog)   RSurf_DrawBatch_GL11_ApplyFog(texturenumsurfaces, texturesurfacelist);
        if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(texturenumsurfaces, texturesurfacelist, r, g, b, a);
@@ -4139,7 +4171,7 @@ static void R_DrawTextureSurfaceList_Sky(int texturenumsurfaces, msurface_t **te
        // in Quake3 maps as it causes problems with q3map2 sky tricks,
        // and skymasking also looks very bad when noclipping outside the
        // level, so don't use it then either.
-       if (rsurface.model->type == mod_brushq1 && r_q1bsp_skymasking.integer && !r_viewcache.world_novis)
+       if (r_refdef.worldmodel && r_refdef.worldmodel->type == mod_brushq1 && r_q1bsp_skymasking.integer && !r_viewcache.world_novis)
        {
                GL_Color(r_refdef.fogcolor[0] * r_view.colorscale, r_refdef.fogcolor[1] * r_view.colorscale, r_refdef.fogcolor[2] * r_view.colorscale, 1);
                R_Mesh_ColorPointer(NULL, 0, 0);
@@ -4180,11 +4212,11 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, msurface_t **t
                RSurf_PrepareVerticesForBatch(true, r_glsl_permutation->loc_Texture_Normal >= 0, texturenumsurfaces, texturesurfacelist);
        else
                RSurf_PrepareVerticesForBatch(r_glsl_permutation->loc_Texture_Normal >= 0, r_glsl_permutation->loc_Texture_Normal >= 0, texturenumsurfaces, texturesurfacelist);
-       R_Mesh_TexCoordPointer(0, 2, rsurface.model->surfmesh.data_texcoordtexture2f, rsurface.model->surfmesh.vbo, rsurface.model->surfmesh.vbooffset_texcoordtexture2f);
+       R_Mesh_TexCoordPointer(0, 2, rsurface.modeltexcoordtexture2f, rsurface.modeltexcoordtexture2f_bufferobject, rsurface.modeltexcoordtexture2f_bufferoffset);
        R_Mesh_TexCoordPointer(1, 3, rsurface.svector3f, rsurface.svector3f_bufferobject, rsurface.svector3f_bufferoffset);
        R_Mesh_TexCoordPointer(2, 3, rsurface.tvector3f, rsurface.tvector3f_bufferobject, rsurface.tvector3f_bufferoffset);
        R_Mesh_TexCoordPointer(3, 3, rsurface.normal3f, rsurface.normal3f_bufferobject, rsurface.normal3f_bufferoffset);
-       R_Mesh_TexCoordPointer(4, 2, rsurface.model->surfmesh.data_texcoordlightmap2f, rsurface.model->surfmesh.vbo, rsurface.model->surfmesh.vbooffset_texcoordlightmap2f);
+       R_Mesh_TexCoordPointer(4, 2, rsurface.modeltexcoordlightmap2f, rsurface.modeltexcoordlightmap2f_bufferobject, rsurface.modeltexcoordlightmap2f_bufferoffset);
 
        GL_Color(rsurface.texture->currentlayers[0].color[0], rsurface.texture->currentlayers[0].color[1], rsurface.texture->currentlayers[0].color[2], rsurface.texture->currentlayers[0].color[3]);
        if (rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
@@ -4206,7 +4238,7 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, msurface_t **t
                R_Mesh_TexBind(7, R_GetTexture(r_texture_white));
                if (r_glsl_permutation->loc_Texture_Deluxemap >= 0)
                        R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap));
-               R_Mesh_ColorPointer(rsurface.model->surfmesh.data_lightmapcolor4f, rsurface.model->surfmesh.vbo, rsurface.model->surfmesh.vbooffset_lightmapcolor4f);
+               R_Mesh_ColorPointer(rsurface.modellightmapcolor4f, rsurface.modellightmapcolor4f_bufferobject, rsurface.modellightmapcolor4f_bufferoffset);
        }
 
        if (rsurface.uselightmaptexture && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
@@ -4270,15 +4302,15 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t
                case TEXTURELAYERTYPE_LITTEXTURE:
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(r_texture_white);
-                       m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordlightmap2f;
-                       m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                       m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordlightmap2f;
+                       m.pointer_texcoord[0] = rsurface.modeltexcoordlightmap2f;
+                       m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordlightmap2f_bufferobject;
+                       m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordlightmap2f_bufferoffset;
                        m.tex[1] = R_GetTexture(layer->texture);
                        m.texmatrix[1] = layer->texmatrix;
                        m.texrgbscale[1] = layertexrgbscale;
-                       m.pointer_texcoord[1] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                       m.pointer_texcoord_bufferobject[1] = rsurface.model->surfmesh.vbo;
-                       m.pointer_texcoord_bufferoffset[1] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                       m.pointer_texcoord[1] = rsurface.modeltexcoordtexture2f;
+                       m.pointer_texcoord_bufferobject[1] = rsurface.modeltexcoordtexture2f_bufferobject;
+                       m.pointer_texcoord_bufferoffset[1] = rsurface.modeltexcoordtexture2f_bufferoffset;
                        R_Mesh_TextureState(&m);
                        if (rsurface.lightmode == 2)
                                RSurf_DrawBatch_GL11_VertexShade(texturenumsurfaces, texturesurfacelist, layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
@@ -4292,9 +4324,9 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t
                        m.tex[0] = R_GetTexture(layer->texture);
                        m.texmatrix[0] = layer->texmatrix;
                        m.texrgbscale[0] = layertexrgbscale;
-                       m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                       m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                       m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                       m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                       m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                       m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                        R_Mesh_TextureState(&m);
                        RSurf_DrawBatch_GL11_Unlit(texturenumsurfaces, texturesurfacelist, layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
                        break;
@@ -4305,9 +4337,9 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t
                        {
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                        }
                        R_Mesh_TextureState(&m);
                        // generate a color array for the fog pass
@@ -4377,9 +4409,9 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                                // first the lightmap pass
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(r_texture_white);
-                               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordlightmap2f;
-                               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordlightmap2f;
+                               m.pointer_texcoord[0] = rsurface.modeltexcoordlightmap2f;
+                               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordlightmap2f_bufferobject;
+                               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordlightmap2f_bufferoffset;
                                R_Mesh_TextureState(&m);
                                if (rsurface.lightmode == 2)
                                        RSurf_DrawBatch_GL11_VertexShade(texturenumsurfaces, texturesurfacelist, 1, 1, 1, 1, false, false);
@@ -4393,9 +4425,9 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                                R_Mesh_TextureState(&m);
                                RSurf_DrawBatch_GL11_Unlit(texturenumsurfaces, texturesurfacelist, layer->color[0] * 0.5f, layer->color[1] * 0.5f, layer->color[2] * 0.5f, layer->color[3], layer->color[0] != 2 || layer->color[1] != 2 || layer->color[2] != 2 || layer->color[3] != 1, false);
                        }
@@ -4405,9 +4437,9 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                                R_Mesh_TextureState(&m);
                                if (rsurface.lightmode == 2)
                                        RSurf_DrawBatch_GL11_VertexShade(texturenumsurfaces, texturesurfacelist, layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
@@ -4420,9 +4452,9 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                        memset(&m, 0, sizeof(m));
                        m.tex[0] = R_GetTexture(layer->texture);
                        m.texmatrix[0] = layer->texmatrix;
-                       m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                       m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                       m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                       m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                       m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                       m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                        R_Mesh_TextureState(&m);
                        RSurf_DrawBatch_GL11_Unlit(texturenumsurfaces, texturesurfacelist, layer->color[0], layer->color[1], layer->color[2], layer->color[3], layer->color[0] != 1 || layer->color[1] != 1 || layer->color[2] != 1 || layer->color[3] != 1, applyfog);
                        break;
@@ -4434,9 +4466,9 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                                memset(&m, 0, sizeof(m));
                                m.tex[0] = R_GetTexture(layer->texture);
                                m.texmatrix[0] = layer->texmatrix;
-                               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-                               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-                               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+                               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+                               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+                               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                                R_Mesh_TextureState(&m);
                        }
                        else
@@ -4475,7 +4507,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
 {
        if (rsurface.texture->currentmaterialflags & MATERIALFLAG_NODRAW)
                return;
-       r_shadow_rtlight = NULL;
+       rsurface.rtlight = NULL;
        CHECKGLERROR
        if (depthonly)
        {
@@ -4485,7 +4517,7 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                        rsurface.mode = RSURFMODE_MULTIPASS;
                if (r_depthfirst.integer == 3)
                {
-                       int i = (int)(texturesurfacelist[0] - rsurface.model->data_surfaces);
+                       int i = (int)(texturesurfacelist[0] - rsurface.modelsurfaces);
                        GL_Color(((i >> 6) & 7) / 7.0f, ((i >> 3) & 7) / 7.0f, (i & 7) / 7.0f,1);
                }
                else
@@ -4540,9 +4572,9 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                R_Mesh_ColorPointer(NULL, 0, 0);
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_texture_white);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordlightmap2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordlightmap2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordlightmap2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordlightmap2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordlightmap2f_bufferoffset;
                R_Mesh_TextureState(&m);
                RSurf_PrepareVerticesForBatch(rsurface.lightmode == 2, false, texturenumsurfaces, texturesurfacelist);
                if (rsurface.lightmode == 2)
@@ -4569,8 +4601,8 @@ static void R_DrawTextureSurfaceList(int texturenumsurfaces, msurface_t **textur
                GL_BlendFunc(rsurface.texture->currentlayers[0].blendfunc1, rsurface.texture->currentlayers[0].blendfunc2);
                GL_DepthMask(writedepth && !(rsurface.texture->currentmaterialflags & MATERIALFLAG_BLENDED));
                GL_AlphaTest((rsurface.texture->currentmaterialflags & MATERIALFLAG_ALPHATEST) != 0);
-               // FIXME: identify models using a better check than rsurface.model->brush.shadowmesh
-               rsurface.lightmode = ((rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT) || rsurface.model->brush.shadowmesh) ? 0 : 2;
+               // use lightmode 0 (fullbright or lightmap) or 2 (model lighting)
+               rsurface.lightmode = ((rsurface.texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT) || rsurface.modeltexcoordlightmap2f != NULL) ? 0 : 2;
                if (r_glsl.integer && gl_support_fragment_shader)
                        R_DrawTextureSurfaceList_GL20(texturenumsurfaces, texturesurfacelist);
                else if (gl_combine.integer && r_textureunits.integer >= 2)
@@ -4604,7 +4636,7 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const
        for (i = 0;i < numsurfaces;i = j)
        {
                j = i + 1;
-               surface = rsurface.model->data_surfaces + surfacelist[i];
+               surface = rsurface.modelsurfaces + surfacelist[i];
                texture = surface->texture;
                R_UpdateTextureInfo(ent, texture);
                rsurface.texture = texture->currentframe;
@@ -4615,7 +4647,7 @@ static void R_DrawSurface_TransparentCallback(const entity_render_t *ent, const
                texturesurfacelist[texturenumsurfaces++] = surface;
                for (;j < endsurface;j++)
                {
-                       surface = rsurface.model->data_surfaces + surfacelist[j];
+                       surface = rsurface.modelsurfaces + surfacelist[j];
                        if (texture != surface->texture || rsurface.uselightmaptexture != (surface->lightmaptexture != NULL))
                                break;
                        texturesurfacelist[texturenumsurfaces++] = surface;
@@ -4660,7 +4692,7 @@ void R_QueueSurfaceList(entity_render_t *ent, int numsurfaces, msurface_t **surf
                        tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
                        tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
                        Matrix4x4_Transform(&rsurface.matrix, tempcenter, center);
-                       R_MeshQueue_AddTransparent(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_DrawSurface_TransparentCallback, ent, surface - rsurface.model->data_surfaces, r_shadow_rtlight);
+                       R_MeshQueue_AddTransparent(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_DrawSurface_TransparentCallback, ent, surface - rsurface.modelsurfaces, rsurface.rtlight);
                }
                else
                {
index e275814..6f77b47 100644 (file)
@@ -396,7 +396,7 @@ void R_DrawPortals(void)
                                                VectorAdd(center, portal->points[i].position, center);
                                        f = ixtable[portal->numpoints];
                                        VectorScale(center, f, center);
-                                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, (entity_render_t *)portal, leafnum, r_shadow_rtlight);
+                                       R_MeshQueue_AddTransparent(center, R_DrawPortal_Callback, (entity_render_t *)portal, leafnum, rsurface.rtlight);
                                }
                        }
                }
@@ -585,7 +585,7 @@ void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t *node)
                //      return;
                if (!plane)
                        break;
-               //if (!r_shadow_compilingrtlight && R_CullBoxCustomPlanes(node->mins, node->maxs, r_shadow_rtlight_numfrustumplanes, r_shadow_rtlight_frustumplanes))
+               //if (!r_shadow_compilingrtlight && R_CullBoxCustomPlanes(node->mins, node->maxs, rsurface.rtlight_numfrustumplanes, rsurface.rtlight_frustumplanes))
                //      return;
                if (plane->type < 3)
                {
@@ -627,7 +627,7 @@ void R_Q1BSP_RecursiveGetLightInfo(r_q1bsp_getlightinfo_t *info, mnode_t *node)
                                node = node->children[sides - 1];
                }
        }
-       if (!r_shadow_compilingrtlight && R_CullBoxCustomPlanes(node->mins, node->maxs, r_shadow_rtlight_numfrustumplanes, r_shadow_rtlight_frustumplanes))
+       if (!r_shadow_compilingrtlight && R_CullBoxCustomPlanes(node->mins, node->maxs, rsurface.rtlight_numfrustumplanes, rsurface.rtlight_frustumplanes))
                return;
        leaf = (mleaf_t *)node;
        if (info->svbsp_active)
@@ -963,7 +963,7 @@ void R_Q1BSP_DrawShadowVolume(entity_render_t *ent, vec3_t relativelightorigin,
                        if (rsurface.texture->currentmaterialflags & MATERIALFLAG_NOSHADOW)
                                continue;
                        RSurf_PrepareVerticesForBatch(false, false, 1, &surface);
-                       R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface.vertex3f, rsurface.model->surfmesh.data_element3i, relativelightorigin, relativelightdirection, lightmins, lightmaxs, surface->mins, surface->maxs);
+                       R_Shadow_MarkVolumeFromBox(surface->num_firsttriangle, surface->num_triangles, rsurface.vertex3f, rsurface.modelelement3i, relativelightorigin, relativelightdirection, lightmins, lightmaxs, surface->mins, surface->maxs);
                }
                R_Shadow_VolumeFromList(model->surfmesh.num_vertices, model->surfmesh.num_triangles, rsurface.vertex3f, model->surfmesh.data_element3i, model->surfmesh.data_neighbor3i, relativelightorigin, relativelightdirection, projectdistance, numshadowmark, shadowmarklist);
        }
@@ -984,14 +984,14 @@ static void R_Q1BSP_DrawLight_TransparentCallback(const entity_render_t *ent, co
        for (i = 0;i < numsurfaces;i = j)
        {
                j = i + 1;
-               surface = rsurface.model->data_surfaces + surfacelist[i];
+               surface = rsurface.modelsurfaces + surfacelist[i];
                t = surface->texture;
                R_UpdateTextureInfo(ent, t);
                rsurface.texture = t->currentframe;
                endsurface = min(j + BATCHSIZE, numsurfaces);
                for (j = i;j < endsurface;j++)
                {
-                       surface = rsurface.model->data_surfaces + surfacelist[j];
+                       surface = rsurface.modelsurfaces + surfacelist[j];
                        if (t != surface->texture)
                                break;
                        RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
@@ -1018,7 +1018,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
        R_UpdateAllTextureInfo(ent);
        CHECKGLERROR
        culltriangles = r_shadow_culltriangles.integer && !(ent->flags & RENDER_NOSELFSHADOW);
-       element3i = rsurface.model->surfmesh.data_element3i;
+       element3i = rsurface.modelelement3i;
        // this is a double loop because non-visible surface skipping has to be
        // fast, and even if this is not the world model (and hence no visibility
        // checking) the input surface list and batch buffer are different formats
@@ -1057,7 +1057,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                                tempcenter[1] = (surface->mins[1] + surface->maxs[1]) * 0.5f;
                                                tempcenter[2] = (surface->mins[2] + surface->maxs[2]) * 0.5f;
                                                Matrix4x4_Transform(&rsurface.matrix, tempcenter, center);
-                                               R_MeshQueue_AddTransparent(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_Q1BSP_DrawLight_TransparentCallback, ent, surface - rsurface.model->data_surfaces, r_shadow_rtlight);
+                                               R_MeshQueue_AddTransparent(rsurface.texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST ? r_view.origin : center, R_Q1BSP_DrawLight_TransparentCallback, ent, surface - rsurface.modelsurfaces, rsurface.rtlight);
                                        }
                                }
                                else
@@ -1087,7 +1087,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                                                }
                                                                else
                                                                {
-                                                                       if (r_shadow_frontsidecasting.integer && !PointInfrontOfTriangle(r_shadow_entitylightorigin, rsurface.vertex3f + element3i[m*3+0]*3, rsurface.vertex3f + element3i[m*3+1]*3, rsurface.vertex3f + element3i[m*3+2]*3))
+                                                                       if (r_shadow_frontsidecasting.integer && !PointInfrontOfTriangle(rsurface.entitylightorigin, rsurface.vertex3f + element3i[m*3+0]*3, rsurface.vertex3f + element3i[m*3+1]*3, rsurface.vertex3f + element3i[m*3+2]*3))
                                                                        {
                                                                                usebufferobject = false;
                                                                                continue;
index c7f2d72..cc5b4bd 100644 (file)
@@ -190,13 +190,6 @@ unsigned char *r_shadow_buffer_shadowtrispvs;
 int r_shadow_buffer_numlighttrispvsbytes;
 unsigned char *r_shadow_buffer_lighttrispvs;
 
-// current light's cull box (copied out of an rtlight or calculated by GetLightInfo)
-vec3_t r_shadow_rtlight_cullmins;
-vec3_t r_shadow_rtlight_cullmaxs;
-// current light's culling planes
-int r_shadow_rtlight_numfrustumplanes;
-mplane_t r_shadow_rtlight_frustumplanes[12+6+6]; // see R_Shadow_ComputeShadowCasterCullingPlanes
-
 rtexturepool_t *r_shadow_texturepool;
 rtexture_t *r_shadow_attenuationgradienttexture;
 rtexture_t *r_shadow_attenuation2dtexture;
@@ -975,20 +968,6 @@ void R_Shadow_ValidateCvars(void)
                Cvar_SetValueQuick(&gl_ext_stenciltwoside, 0);
 }
 
-// light currently being rendered
-rtlight_t *r_shadow_rtlight;
-
-// this is the location of the light in entity space
-vec3_t r_shadow_entitylightorigin;
-// this transforms entity coordinates to light filter cubemap coordinates
-// (also often used for other purposes)
-matrix4x4_t r_shadow_entitytolight;
-// based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
-// of attenuation texturing in full 3D (Z result often ignored)
-matrix4x4_t r_shadow_entitytoattenuationxyz;
-// this transforms only the Z to S, and T is always 0.5
-matrix4x4_t r_shadow_entitytoattenuationz;
-
 void R_Shadow_RenderMode_Begin(void)
 {
        R_Shadow_ValidateCvars();
@@ -1028,7 +1007,7 @@ void R_Shadow_RenderMode_Begin(void)
 
 void R_Shadow_RenderMode_ActiveLight(rtlight_t *rtlight)
 {
-       r_shadow_rtlight = rtlight;
+       rsurface.rtlight = rtlight;
 }
 
 void R_Shadow_RenderMode_Reset(void)
@@ -1113,14 +1092,14 @@ void R_Shadow_RenderMode_Lighting(qboolean stenciltest, qboolean transparent)
                R_Mesh_TexBind(0, R_GetTexture(r_texture_blanknormalmap)); // normal
                R_Mesh_TexBind(1, R_GetTexture(r_texture_white)); // diffuse
                R_Mesh_TexBind(2, R_GetTexture(r_texture_white)); // gloss
-               R_Mesh_TexBindCubeMap(3, R_GetTexture(r_shadow_rtlight->currentcubemap)); // light filter
+               R_Mesh_TexBindCubeMap(3, R_GetTexture(rsurface.rtlight->currentcubemap)); // light filter
                R_Mesh_TexBind(4, R_GetTexture(r_texture_fogattenuation)); // fog
                R_Mesh_TexBind(5, R_GetTexture(r_texture_white)); // pants
                R_Mesh_TexBind(6, R_GetTexture(r_texture_white)); // shirt
                R_Mesh_TexBind(7, R_GetTexture(r_texture_white)); // lightmap
                R_Mesh_TexBind(8, R_GetTexture(r_texture_blanknormalmap)); // deluxemap
                R_Mesh_TexBind(9, R_GetTexture(r_texture_black)); // glow
-               //R_Mesh_TexMatrix(3, r_shadow_entitytolight); // light filter matrix
+               //R_Mesh_TexMatrix(3, rsurface.entitytolight); // light filter matrix
                GL_BlendFunc(GL_SRC_ALPHA, GL_ONE);
                GL_ColorMask(r_view.colormask[0], r_view.colormask[1], r_view.colormask[2], 0);
                CHECKGLERROR
@@ -1273,8 +1252,8 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                {
                        for (;numverts > 0;numverts--, vertex3f += 3, normal3f += 3, color4f += 4)
                        {
-                               Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
-                               Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n);
+                               Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
+                               Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
                                if ((dot = DotProduct(n, v)) < 0)
                                {
                                        shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
@@ -1299,7 +1278,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                                if (r_refdef.fogenabled)
                                {
                                        float f;
-                                       Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
+                                       Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
                                        f = FogPoint_Model(vertex3f);
                                        VectorScale(color4f, f, color4f);
                                }
@@ -1313,10 +1292,10 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                {
                        for (;numverts > 0;numverts--, vertex3f += 3, normal3f += 3, color4f += 4)
                        {
-                               Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
+                               Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
                                if ((dist = fabs(v[2])) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
                                {
-                                       Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n);
+                                       Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
                                        if ((dot = DotProduct(n, v)) < 0)
                                        {
                                                shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
@@ -1346,7 +1325,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                {
                        for (;numverts > 0;numverts--, vertex3f += 3, color4f += 4)
                        {
-                               Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
+                               Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
                                if ((dist = fabs(v[2])) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
                                {
                                        color4f[0] = ambientcolor[0] * distintensity;
@@ -1371,11 +1350,11 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                {
                        for (;numverts > 0;numverts--, vertex3f += 3, normal3f += 3, color4f += 4)
                        {
-                               Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
+                               Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
                                if ((dist = VectorLength(v)) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
                                {
                                        distintensity = (1 - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist);
-                                       Matrix4x4_Transform3x3(&r_shadow_entitytolight, normal3f, n);
+                                       Matrix4x4_Transform3x3(&rsurface.entitytolight, normal3f, n);
                                        if ((dot = DotProduct(n, v)) < 0)
                                        {
                                                shadeintensity = -dot / sqrt(VectorLength2(v) * VectorLength2(n));
@@ -1405,7 +1384,7 @@ static void R_Shadow_RenderLighting_Light_Vertex_Shading(int firstvertex, int nu
                {
                        for (;numverts > 0;numverts--, vertex3f += 3, color4f += 4)
                        {
-                               Matrix4x4_Transform(&r_shadow_entitytolight, vertex3f, v);
+                               Matrix4x4_Transform(&rsurface.entitytolight, vertex3f, v);
                                if ((dist = VectorLength(v)) < 1 && (distintensity = r_shadow_attentable[(int)(dist * ATTENTABLESIZE)]))
                                {
                                        distintensity = (1 - dist) * r_shadow_lightattenuationlinearscale.value / (r_shadow_lightattenuationdividebias.value + dist*dist);
@@ -1440,7 +1419,7 @@ static void R_Shadow_GenTexCoords_Diffuse_NormalCubeMap(int firstvertex, int num
        float lightdir[3];
        for (i = 0;i < numvertices;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3)
        {
-               VectorSubtract(r_shadow_entitylightorigin, vertex3f, lightdir);
+               VectorSubtract(rsurface.entitylightorigin, vertex3f, lightdir);
                // the cubemap normalizes this for us
                out3f[0] = DotProduct(svector3f, lightdir);
                out3f[1] = DotProduct(tvector3f, lightdir);
@@ -1459,7 +1438,7 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(int firstvertex, int nu
        float lightdir[3], eyedir[3], halfdir[3];
        for (i = 0;i < numvertices;i++, vertex3f += 3, svector3f += 3, tvector3f += 3, normal3f += 3, out3f += 3)
        {
-               VectorSubtract(r_shadow_entitylightorigin, vertex3f, lightdir);
+               VectorSubtract(rsurface.entitylightorigin, vertex3f, lightdir);
                VectorNormalize(lightdir);
                VectorSubtract(rsurface.modelorg, vertex3f, eyedir);
                VectorNormalize(eyedir);
@@ -1484,7 +1463,7 @@ static void R_Shadow_RenderLighting_Light_GLSL(int firstvertex, int numvertices,
 {
        // ARB2 GLSL shader path (GFFX5200, Radeon 9500)
        R_SetupSurfaceShader(lightcolorbase, false, ambientscale, diffusescale, specularscale);
-       R_Mesh_TexCoordPointer(0, 2, rsurface.model->surfmesh.data_texcoordtexture2f, rsurface.model->surfmesh.vbo, rsurface.model->surfmesh.vbooffset_texcoordtexture2f);
+       R_Mesh_TexCoordPointer(0, 2, rsurface.modeltexcoordtexture2f, rsurface.modeltexcoordtexture2f_bufferobject, rsurface.modeltexcoordtexture2f_bufferoffset);
        R_Mesh_TexCoordPointer(1, 3, rsurface.svector3f, rsurface.svector3f_bufferobject, rsurface.svector3f_bufferoffset);
        R_Mesh_TexCoordPointer(2, 3, rsurface.tvector3f, rsurface.tvector3f_bufferobject, rsurface.tvector3f_bufferoffset);
        R_Mesh_TexCoordPointer(3, 3, rsurface.normal3f, rsurface.normal3f_bufferobject, rsurface.normal3f_bufferoffset);
@@ -1522,7 +1501,7 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
        //
        // Limit mult to 64 for sanity sake.
        GL_Color(1,1,1,1);
-       if (r_shadow_texture3d.integer && r_shadow_rtlight->currentcubemap != r_texture_whitecube && r_textureunits.integer >= 4)
+       if (r_shadow_texture3d.integer && rsurface.rtlight->currentcubemap != r_texture_whitecube && r_textureunits.integer >= 4)
        {
                // 3 3D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
@@ -1530,20 +1509,20 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[1] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[1] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[1] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[1] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[1] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[1] = rsurface.texture->currenttexmatrix;
-               m.texcubemap[2] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+               m.texcubemap[2] = R_GetTexture(rsurface.rtlight->currentcubemap);
                m.pointer_texcoord3f[2] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[2] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[2] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[2] = r_shadow_entitytolight;
+               m.texmatrix[2] = rsurface.entitytolight;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
-       else if (r_shadow_texture3d.integer && r_shadow_rtlight->currentcubemap == r_texture_whitecube && r_textureunits.integer >= 2)
+       else if (r_shadow_texture3d.integer && rsurface.rtlight->currentcubemap == r_texture_whitecube && r_textureunits.integer >= 2)
        {
                // 2 3D combine path (Geforce3, original Radeon)
                memset(&m, 0, sizeof(m));
@@ -1551,15 +1530,15 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(basetexture);
-               m.pointer_texcoord[1] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[1] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[1] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[1] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[1] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[1] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[1] = rsurface.texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
-       else if (r_textureunits.integer >= 4 && r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+       else if (r_textureunits.integer >= 4 && rsurface.rtlight->currentcubemap != r_texture_whitecube)
        {
                // 4 2D combine path (Geforce3, Radeon 8500)
                memset(&m, 0, sizeof(m));
@@ -1567,28 +1546,28 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationz;
+               m.texmatrix[1] = rsurface.entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[2] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[2] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[2] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[2] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[2] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[2] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[3] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[3] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[3] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[3] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[3] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[3] = r_shadow_entitytolight;
+                       m.texmatrix[3] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
-       else if (r_textureunits.integer >= 3 && r_shadow_rtlight->currentcubemap == r_texture_whitecube)
+       else if (r_textureunits.integer >= 3 && rsurface.rtlight->currentcubemap == r_texture_whitecube)
        {
                // 3 2D combine path (Geforce3, original Radeon)
                memset(&m, 0, sizeof(m));
@@ -1596,16 +1575,16 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationz;
+               m.texmatrix[1] = rsurface.entitytoattenuationz;
                m.tex[2] = R_GetTexture(basetexture);
-               m.pointer_texcoord[2] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[2] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[2] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[2] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[2] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[2] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[2] = rsurface.texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1617,12 +1596,12 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationz;
+               m.texmatrix[1] = rsurface.entitytoattenuationz;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1631,17 +1610,17 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -1669,9 +1648,9 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1682,7 +1661,7 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                m.pointer_texcoord3f[2] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[2] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[2] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[2] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[2] = rsurface.entitytoattenuationxyz;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1691,21 +1670,21 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
-       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && rsurface.rtlight->currentcubemap != r_texture_whitecube)
        {
                // 1/2/2 3D combine path (original Radeon)
                memset(&m, 0, sizeof(m));
@@ -1713,7 +1692,7 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1723,9 +1702,9 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1739,29 +1718,29 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
-       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && r_shadow_rtlight->currentcubemap == r_texture_whitecube)
+       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && rsurface.rtlight->currentcubemap == r_texture_whitecube)
        {
                // 2/2 3D combine path (original Radeon)
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1776,15 +1755,15 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[1] = rsurface.entitytoattenuationxyz;
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        else if (r_textureunits.integer >= 4)
@@ -1793,9 +1772,9 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1806,12 +1785,12 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                m.pointer_texcoord3f[2] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[2] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[2] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[2] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[2] = rsurface.entitytoattenuationxyz;
                m.tex[3] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[3] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[3] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[3] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[3] = r_shadow_entitytoattenuationz;
+               m.texmatrix[3] = rsurface.entitytoattenuationz;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1820,17 +1799,17 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -1842,12 +1821,12 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationz;
+               m.texmatrix[1] = rsurface.entitytoattenuationz;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
@@ -1857,9 +1836,9 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
                m.texcombinergb[0] = GL_REPLACE;
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1873,17 +1852,17 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                // second pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(basetexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -1902,14 +1881,14 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
        GL_Color(1,1,1,1);
        // generate normalization cubemap texcoords
        R_Shadow_GenTexCoords_Specular_NormalCubeMap(firstvertex, numvertices, numtriangles, element3i);
-       if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+       if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && rsurface.rtlight->currentcubemap != r_texture_whitecube)
        {
                // 2/0/0/1/2 3D combine blendsquare path
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1935,7 +1914,7 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
@@ -1943,28 +1922,28 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                // fifth pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
-       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && r_shadow_rtlight->currentcubemap == r_texture_whitecube /* && gl_support_blendsquare*/) // FIXME: detect blendsquare!
+       else if (r_shadow_texture3d.integer && r_textureunits.integer >= 2 && rsurface.rtlight->currentcubemap == r_texture_whitecube /* && gl_support_blendsquare*/) // FIXME: detect blendsquare!
        {
                // 2/0/0/2 3D combine blendsquare path
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -1987,15 +1966,15 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                // fourth pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.tex3d[1] = R_GetTexture(r_shadow_attenuation3dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[1] = rsurface.entitytoattenuationxyz;
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        else
@@ -2003,9 +1982,9 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                // 2/0/0/2/2 2D combine blendsquare path
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(normalmaptexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
@@ -2031,12 +2010,12 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                m.pointer_texcoord3f[0] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[0] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[0] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[0] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[0] = rsurface.entitytoattenuationxyz;
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-               m.texmatrix[1] = r_shadow_entitytoattenuationz;
+               m.texmatrix[1] = rsurface.entitytoattenuationz;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
                R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
@@ -2044,17 +2023,17 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                // fifth pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(glosstexture);
-               m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-               m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-               m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+               m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+               m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+               m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
                m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-               if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
+               if (rsurface.rtlight->currentcubemap != r_texture_whitecube)
                {
-                       m.texcubemap[1] = R_GetTexture(r_shadow_rtlight->currentcubemap);
+                       m.texcubemap[1] = R_GetTexture(rsurface.rtlight->currentcubemap);
                        m.pointer_texcoord3f[1] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
-                       m.texmatrix[1] = r_shadow_entitytolight;
+                       m.texmatrix[1] = rsurface.entitytolight;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -2094,7 +2073,7 @@ static void R_Shadow_RenderLighting_Light_Dot3(int firstvertex, int numvertices,
                R_Shadow_RenderLighting_Light_Dot3_SpecularPass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, glosstexture, normalmaptexture, specularscale * r_view.colorscale);
 }
 
-void R_Shadow_RenderLighting_Light_Vertex_Pass(const model_t *model, int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, vec3_t diffusecolor2, vec3_t ambientcolor2)
+void R_Shadow_RenderLighting_Light_Vertex_Pass(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, vec3_t diffusecolor2, vec3_t ambientcolor2)
 {
        int renders;
        int i;
@@ -2189,7 +2168,6 @@ void R_Shadow_RenderLighting_Light_Vertex_Pass(const model_t *model, int firstve
 static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, 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 ambientscale, float diffusescale, float specularscale, qboolean dopants, qboolean doshirt)
 {
        // OpenGL 1.1 path (anything)
-       const model_t *model = rsurface.model;
        float ambientcolorbase[3], diffusecolorbase[3];
        float ambientcolorpants[3], diffusecolorpants[3];
        float ambientcolorshirt[3], diffusecolorshirt[3];
@@ -2205,14 +2183,14 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
        memset(&m, 0, sizeof(m));
        m.tex[0] = R_GetTexture(basetexture);
        m.texmatrix[0] = rsurface.texture->currenttexmatrix;
-       m.pointer_texcoord[0] = rsurface.model->surfmesh.data_texcoordtexture2f;
-       m.pointer_texcoord_bufferobject[0] = rsurface.model->surfmesh.vbo;
-       m.pointer_texcoord_bufferoffset[0] = rsurface.model->surfmesh.vbooffset_texcoordtexture2f;
+       m.pointer_texcoord[0] = rsurface.modeltexcoordtexture2f;
+       m.pointer_texcoord_bufferobject[0] = rsurface.modeltexcoordtexture2f_bufferobject;
+       m.pointer_texcoord_bufferoffset[0] = rsurface.modeltexcoordtexture2f_bufferoffset;
        if (r_textureunits.integer >= 2)
        {
                // voodoo2 or TNT
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
-               m.texmatrix[1] = r_shadow_entitytoattenuationxyz;
+               m.texmatrix[1] = rsurface.entitytoattenuationxyz;
                m.pointer_texcoord3f[1] = rsurface.vertex3f;
                m.pointer_texcoord_bufferobject[1] = rsurface.vertex3f_bufferobject;
                m.pointer_texcoord_bufferoffset[1] = rsurface.vertex3f_bufferoffset;
@@ -2220,7 +2198,7 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
                {
                        // Voodoo4 or Kyro (or Geforce3/Radeon with gl_combine off)
                        m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
-                       m.texmatrix[2] = r_shadow_entitytoattenuationz;
+                       m.texmatrix[2] = rsurface.entitytoattenuationz;
                        m.pointer_texcoord3f[2] = rsurface.vertex3f;
                        m.pointer_texcoord_bufferobject[2] = rsurface.vertex3f_bufferobject;
                        m.pointer_texcoord_bufferoffset[2] = rsurface.vertex3f_bufferoffset;
@@ -2228,16 +2206,16 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
        }
        R_Mesh_TextureState(&m);
        //R_Mesh_TexBind(0, R_GetTexture(basetexture));
-       R_Shadow_RenderLighting_Light_Vertex_Pass(model, firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorbase, ambientcolorbase);
+       R_Shadow_RenderLighting_Light_Vertex_Pass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorbase, ambientcolorbase);
        if (dopants)
        {
                R_Mesh_TexBind(0, R_GetTexture(pantstexture));
-               R_Shadow_RenderLighting_Light_Vertex_Pass(model, firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorpants, ambientcolorpants);
+               R_Shadow_RenderLighting_Light_Vertex_Pass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorpants, ambientcolorpants);
        }
        if (doshirt)
        {
                R_Mesh_TexBind(0, R_GetTexture(shirttexture));
-               R_Shadow_RenderLighting_Light_Vertex_Pass(model, firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorshirt, ambientcolorshirt);
+               R_Shadow_RenderLighting_Light_Vertex_Pass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorshirt, ambientcolorshirt);
        }
 }
 
@@ -2246,12 +2224,12 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles,
        float ambientscale, diffusescale, specularscale;
        vec3_t lightcolorbase, lightcolorpants, lightcolorshirt;
        // calculate colors to render this texture with
-       lightcolorbase[0] = r_shadow_rtlight->currentcolor[0] * rsurface.texture->currentlayers[0].color[0] * rsurface.texture->currentlayers[0].color[3];
-       lightcolorbase[1] = r_shadow_rtlight->currentcolor[1] * rsurface.texture->currentlayers[0].color[1] * rsurface.texture->currentlayers[0].color[3];
-       lightcolorbase[2] = r_shadow_rtlight->currentcolor[2] * rsurface.texture->currentlayers[0].color[2] * rsurface.texture->currentlayers[0].color[3];
-       ambientscale = r_shadow_rtlight->ambientscale;
-       diffusescale = r_shadow_rtlight->diffusescale;
-       specularscale = r_shadow_rtlight->specularscale * rsurface.texture->specularscale;
+       lightcolorbase[0] = rsurface.rtlight->currentcolor[0] * rsurface.texture->currentlayers[0].color[0] * rsurface.texture->currentlayers[0].color[3];
+       lightcolorbase[1] = rsurface.rtlight->currentcolor[1] * rsurface.texture->currentlayers[0].color[1] * rsurface.texture->currentlayers[0].color[3];
+       lightcolorbase[2] = rsurface.rtlight->currentcolor[2] * rsurface.texture->currentlayers[0].color[2] * rsurface.texture->currentlayers[0].color[3];
+       ambientscale = rsurface.rtlight->ambientscale;
+       diffusescale = rsurface.rtlight->diffusescale;
+       specularscale = rsurface.rtlight->specularscale * rsurface.texture->specularscale;
        if (!r_shadow_usenormalmap.integer)
        {
                ambientscale += 1.0f * diffusescale;
@@ -2499,9 +2477,9 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
        int i, j;
        mplane_t plane;
        // reset the count of frustum planes
-       // see r_shadow_rtlight_frustumplanes definition for how much this array
+       // see rsurface.rtlight_frustumplanes definition for how much this array
        // can hold
-       r_shadow_rtlight_numfrustumplanes = 0;
+       rsurface.rtlight_numfrustumplanes = 0;
 
 #if 1
        // generate a deformed frustum that includes the light origin, this is
@@ -2521,11 +2499,11 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
                if (PlaneDiff(rtlight->shadoworigin, &r_view.frustum[i]) < -0.03125)
                        continue;
                // copy the plane
-               r_shadow_rtlight_frustumplanes[r_shadow_rtlight_numfrustumplanes++] = r_view.frustum[i];
+               rsurface.rtlight_frustumplanes[rsurface.rtlight_numfrustumplanes++] = r_view.frustum[i];
        }
        // if all the standard frustum planes were accepted, the light is onscreen
        // otherwise we need to generate some more planes below...
-       if (r_shadow_rtlight_numfrustumplanes < 4)
+       if (rsurface.rtlight_numfrustumplanes < 4)
        {
                // at least one of the stock frustum planes failed, so we need to
                // create one or two custom planes to enclose the light origin
@@ -2556,12 +2534,12 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
                        // we have created a valid plane, compute extra info
                        PlaneClassify(&plane);
                        // copy the plane
-                       r_shadow_rtlight_frustumplanes[r_shadow_rtlight_numfrustumplanes++] = plane;
+                       rsurface.rtlight_frustumplanes[rsurface.rtlight_numfrustumplanes++] = plane;
 #if 1
                        // if we've found 5 frustum planes then we have constructed a
                        // proper split-side case and do not need to keep searching for
                        // planes to enclose the light origin
-                       if (r_shadow_rtlight_numfrustumplanes == 5)
+                       if (rsurface.rtlight_numfrustumplanes == 5)
                                break;
 #endif
                }
@@ -2569,9 +2547,9 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
 #endif
 
 #if 0
-       for (i = 0;i < r_shadow_rtlight_numfrustumplanes;i++)
+       for (i = 0;i < rsurface.rtlight_numfrustumplanes;i++)
        {
-               plane = r_shadow_rtlight_frustumplanes[i];
+               plane = rsurface.rtlight_frustumplanes[i];
                Con_Printf("light %p plane #%i %f %f %f : %f (%f %f %f %f %f)\n", rtlight, i, plane.normal[0], plane.normal[1], plane.normal[2], plane.dist, PlaneDiff(r_view.frustumcorner[0], &plane), PlaneDiff(r_view.frustumcorner[1], &plane), PlaneDiff(r_view.frustumcorner[2], &plane), PlaneDiff(r_view.frustumcorner[3], &plane), PlaneDiff(rtlight->shadoworigin, &plane));
        }
 #endif
@@ -2591,7 +2569,7 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
                        VectorSubtract(plane.normal, rtlight->shadoworigin, plane.normal);
                        plane.dist = VectorNormalizeLength(plane.normal);
                        plane.dist += DotProduct(plane.normal, rtlight->shadoworigin);
-                       r_shadow_rtlight_frustumplanes[r_shadow_rtlight_numfrustumplanes++] = plane;
+                       rsurface.rtlight_frustumplanes[rsurface.rtlight_numfrustumplanes++] = plane;
                }
        }
 #endif
@@ -2602,8 +2580,8 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
        {
                VectorClear(plane.normal);
                plane.normal[i >> 1] = (i & 1) ? -1 : 1;
-               plane.dist = (i & 1) ? -r_shadow_rtlight_cullmaxs[i >> 1] : r_shadow_rtlight_cullmins[i >> 1];
-               r_shadow_rtlight_frustumplanes[r_shadow_rtlight_numfrustumplanes++] = plane;
+               plane.dist = (i & 1) ? -rsurface.rtlight_cullmaxs[i >> 1] : rsurface.rtlight_cullmins[i >> 1];
+               rsurface.rtlight_frustumplanes[rsurface.rtlight_numfrustumplanes++] = plane;
        }
 #endif
 
@@ -2614,33 +2592,33 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
        vec_t bestdist;
        // reduce all plane distances to tightly fit the rtlight cull box, which
        // is in worldspace
-       VectorSet(points[0], r_shadow_rtlight_cullmins[0], r_shadow_rtlight_cullmins[1], r_shadow_rtlight_cullmins[2]);
-       VectorSet(points[1], r_shadow_rtlight_cullmaxs[0], r_shadow_rtlight_cullmins[1], r_shadow_rtlight_cullmins[2]);
-       VectorSet(points[2], r_shadow_rtlight_cullmins[0], r_shadow_rtlight_cullmaxs[1], r_shadow_rtlight_cullmins[2]);
-       VectorSet(points[3], r_shadow_rtlight_cullmaxs[0], r_shadow_rtlight_cullmaxs[1], r_shadow_rtlight_cullmins[2]);
-       VectorSet(points[4], r_shadow_rtlight_cullmins[0], r_shadow_rtlight_cullmins[1], r_shadow_rtlight_cullmaxs[2]);
-       VectorSet(points[5], r_shadow_rtlight_cullmaxs[0], r_shadow_rtlight_cullmins[1], r_shadow_rtlight_cullmaxs[2]);
-       VectorSet(points[6], r_shadow_rtlight_cullmins[0], r_shadow_rtlight_cullmaxs[1], r_shadow_rtlight_cullmaxs[2]);
-       VectorSet(points[7], r_shadow_rtlight_cullmaxs[0], r_shadow_rtlight_cullmaxs[1], r_shadow_rtlight_cullmaxs[2]);
-       oldnum = r_shadow_rtlight_numfrustumplanes;
-       r_shadow_rtlight_numfrustumplanes = 0;
+       VectorSet(points[0], rsurface.rtlight_cullmins[0], rsurface.rtlight_cullmins[1], rsurface.rtlight_cullmins[2]);
+       VectorSet(points[1], rsurface.rtlight_cullmaxs[0], rsurface.rtlight_cullmins[1], rsurface.rtlight_cullmins[2]);
+       VectorSet(points[2], rsurface.rtlight_cullmins[0], rsurface.rtlight_cullmaxs[1], rsurface.rtlight_cullmins[2]);
+       VectorSet(points[3], rsurface.rtlight_cullmaxs[0], rsurface.rtlight_cullmaxs[1], rsurface.rtlight_cullmins[2]);
+       VectorSet(points[4], rsurface.rtlight_cullmins[0], rsurface.rtlight_cullmins[1], rsurface.rtlight_cullmaxs[2]);
+       VectorSet(points[5], rsurface.rtlight_cullmaxs[0], rsurface.rtlight_cullmins[1], rsurface.rtlight_cullmaxs[2]);
+       VectorSet(points[6], rsurface.rtlight_cullmins[0], rsurface.rtlight_cullmaxs[1], rsurface.rtlight_cullmaxs[2]);
+       VectorSet(points[7], rsurface.rtlight_cullmaxs[0], rsurface.rtlight_cullmaxs[1], rsurface.rtlight_cullmaxs[2]);
+       oldnum = rsurface.rtlight_numfrustumplanes;
+       rsurface.rtlight_numfrustumplanes = 0;
        for (j = 0;j < oldnum;j++)
        {
                // find the nearest point on the box to this plane
-               bestdist = DotProduct(r_shadow_rtlight_frustumplanes[j].normal, points[0]);
+               bestdist = DotProduct(rsurface.rtlight_frustumplanes[j].normal, points[0]);
                for (i = 1;i < 8;i++)
                {
-                       dist = DotProduct(r_shadow_rtlight_frustumplanes[j].normal, points[i]);
+                       dist = DotProduct(rsurface.rtlight_frustumplanes[j].normal, points[i]);
                        if (bestdist > dist)
                                bestdist = dist;
                }
-               Con_Printf("light %p %splane #%i %f %f %f : %f < %f\n", rtlight, r_shadow_rtlight_frustumplanes[j].dist < bestdist + 0.03125 ? "^2" : "^1", j, r_shadow_rtlight_frustumplanes[j].normal[0], r_shadow_rtlight_frustumplanes[j].normal[1], r_shadow_rtlight_frustumplanes[j].normal[2], r_shadow_rtlight_frustumplanes[j].dist, bestdist);
+               Con_Printf("light %p %splane #%i %f %f %f : %f < %f\n", rtlight, rsurface.rtlight_frustumplanes[j].dist < bestdist + 0.03125 ? "^2" : "^1", j, rsurface.rtlight_frustumplanes[j].normal[0], rsurface.rtlight_frustumplanes[j].normal[1], rsurface.rtlight_frustumplanes[j].normal[2], rsurface.rtlight_frustumplanes[j].dist, bestdist);
                // if the nearest point is near or behind the plane, we want this
                // plane, otherwise the plane is useless as it won't cull anything
-               if (r_shadow_rtlight_frustumplanes[j].dist < bestdist + 0.03125)
+               if (rsurface.rtlight_frustumplanes[j].dist < bestdist + 0.03125)
                {
-                       PlaneClassify(&r_shadow_rtlight_frustumplanes[j]);
-                       r_shadow_rtlight_frustumplanes[r_shadow_rtlight_numfrustumplanes++] = r_shadow_rtlight_frustumplanes[j];
+                       PlaneClassify(&rsurface.rtlight_frustumplanes[j]);
+                       rsurface.rtlight_frustumplanes[rsurface.rtlight_numfrustumplanes++] = rsurface.rtlight_frustumplanes[j];
                }
        }
        }
@@ -2650,11 +2628,11 @@ void R_Shadow_ComputeShadowCasterCullingPlanes(rtlight_t *rtlight)
 void R_Shadow_DrawWorldShadow(int numsurfaces, int *surfacelist, const unsigned char *trispvs)
 {
        RSurf_ActiveWorldEntity();
-       if (r_shadow_rtlight->compiled && r_shadow_realtime_world_compile.integer && r_shadow_realtime_world_compileshadow.integer)
+       if (rsurface.rtlight->compiled && r_shadow_realtime_world_compile.integer && r_shadow_realtime_world_compileshadow.integer)
        {
                shadowmesh_t *mesh;
                CHECKGLERROR
-               for (mesh = r_shadow_rtlight->static_meshchain_shadow;mesh;mesh = mesh->next)
+               for (mesh = rsurface.rtlight->static_meshchain_shadow;mesh;mesh = mesh->next)
                {
                        r_refdef.stats.lights_shadowtriangles += mesh->numtriangles;
                        R_Mesh_VertexPointer(mesh->vertex3f, mesh->vbo, mesh->vbooffset_vertex3f);
@@ -2687,10 +2665,10 @@ void R_Shadow_DrawWorldShadow(int numsurfaces, int *surfacelist, const unsigned
                                if (CHECKPVSBIT(trispvs, t))
                                        shadowmarklist[numshadowmark++] = t;
                }
-               R_Shadow_VolumeFromList(r_refdef.worldmodel->brush.shadowmesh->numverts, r_refdef.worldmodel->brush.shadowmesh->numtriangles, r_refdef.worldmodel->brush.shadowmesh->vertex3f, r_refdef.worldmodel->brush.shadowmesh->element3i, r_refdef.worldmodel->brush.shadowmesh->neighbor3i, r_shadow_rtlight->shadoworigin, NULL, r_shadow_rtlight->radius + r_refdef.worldmodel->radius*2 + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
+               R_Shadow_VolumeFromList(r_refdef.worldmodel->brush.shadowmesh->numverts, r_refdef.worldmodel->brush.shadowmesh->numtriangles, r_refdef.worldmodel->brush.shadowmesh->vertex3f, r_refdef.worldmodel->brush.shadowmesh->element3i, r_refdef.worldmodel->brush.shadowmesh->neighbor3i, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius + r_refdef.worldmodel->radius*2 + r_shadow_projectdistance.value, numshadowmark, shadowmarklist);
        }
        else if (numsurfaces)
-               r_refdef.worldmodel->DrawShadowVolume(r_refdef.worldentity, r_shadow_rtlight->shadoworigin, NULL, r_shadow_rtlight->radius, numsurfaces, surfacelist, r_shadow_rtlight_cullmins, r_shadow_rtlight_cullmaxs);
+               r_refdef.worldmodel->DrawShadowVolume(r_refdef.worldentity, rsurface.rtlight->shadoworigin, NULL, rsurface.rtlight->radius, numsurfaces, surfacelist, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs);
 }
 
 void R_Shadow_DrawEntityShadow(entity_render_t *ent)
@@ -2698,8 +2676,8 @@ void R_Shadow_DrawEntityShadow(entity_render_t *ent)
        vec3_t relativeshadoworigin, relativeshadowmins, relativeshadowmaxs;
        vec_t relativeshadowradius;
        RSurf_ActiveModelEntity(ent, false, false);
-       Matrix4x4_Transform(&ent->inversematrix, r_shadow_rtlight->shadoworigin, relativeshadoworigin);
-       relativeshadowradius = r_shadow_rtlight->radius / ent->scale;
+       Matrix4x4_Transform(&ent->inversematrix, rsurface.rtlight->shadoworigin, relativeshadoworigin);
+       relativeshadowradius = rsurface.rtlight->radius / ent->scale;
        relativeshadowmins[0] = relativeshadoworigin[0] - relativeshadowradius;
        relativeshadowmins[1] = relativeshadoworigin[1] - relativeshadowradius;
        relativeshadowmins[2] = relativeshadoworigin[2] - relativeshadowradius;
@@ -2713,12 +2691,12 @@ void R_Shadow_SetupEntityLight(const entity_render_t *ent)
 {
        // set up properties for rendering light onto this entity
        RSurf_ActiveModelEntity(ent, true, true);
-       Matrix4x4_Concat(&r_shadow_entitytolight, &r_shadow_rtlight->matrix_worldtolight, &ent->matrix);
-       Matrix4x4_Concat(&r_shadow_entitytoattenuationxyz, &matrix_attenuationxyz, &r_shadow_entitytolight);
-       Matrix4x4_Concat(&r_shadow_entitytoattenuationz, &matrix_attenuationz, &r_shadow_entitytolight);
-       Matrix4x4_Transform(&ent->inversematrix, r_shadow_rtlight->shadoworigin, r_shadow_entitylightorigin);
+       Matrix4x4_Concat(&rsurface.entitytolight, &rsurface.rtlight->matrix_worldtolight, &ent->matrix);
+       Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
+       Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
+       Matrix4x4_Transform(&ent->inversematrix, rsurface.rtlight->shadoworigin, rsurface.entitylightorigin);
        if (r_shadow_lightingrendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
-               R_Mesh_TexMatrix(3, &r_shadow_entitytolight);
+               R_Mesh_TexMatrix(3, &rsurface.entitytolight);
 }
 
 void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned char *trispvs)
@@ -2728,12 +2706,12 @@ void R_Shadow_DrawWorldLight(int numsurfaces, int *surfacelist, const unsigned c
 
        // set up properties for rendering light onto this entity
        RSurf_ActiveWorldEntity();
-       r_shadow_entitytolight = r_shadow_rtlight->matrix_worldtolight;
-       Matrix4x4_Concat(&r_shadow_entitytoattenuationxyz, &matrix_attenuationxyz, &r_shadow_entitytolight);
-       Matrix4x4_Concat(&r_shadow_entitytoattenuationz, &matrix_attenuationz, &r_shadow_entitytolight);
-       VectorCopy(r_shadow_rtlight->shadoworigin, r_shadow_entitylightorigin);
+       rsurface.entitytolight = rsurface.rtlight->matrix_worldtolight;
+       Matrix4x4_Concat(&rsurface.entitytoattenuationxyz, &matrix_attenuationxyz, &rsurface.entitytolight);
+       Matrix4x4_Concat(&rsurface.entitytoattenuationz, &matrix_attenuationz, &rsurface.entitytolight);
+       VectorCopy(rsurface.rtlight->shadoworigin, rsurface.entitylightorigin);
        if (r_shadow_lightingrendermode == R_SHADOW_RENDERMODE_LIGHT_GLSL)
-               R_Mesh_TexMatrix(3, &r_shadow_entitytolight);
+               R_Mesh_TexMatrix(3, &rsurface.entitytolight);
 
        r_refdef.worldmodel->DrawLight(r_refdef.worldentity, numsurfaces, surfacelist, trispvs);
 }
@@ -2798,8 +2776,8 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
        if (R_CullBox(rtlight->cullmins, rtlight->cullmaxs))
                return;
 
-       VectorCopy(rtlight->cullmins, r_shadow_rtlight_cullmins);
-       VectorCopy(rtlight->cullmaxs, r_shadow_rtlight_cullmaxs);
+       VectorCopy(rtlight->cullmins, rsurface.rtlight_cullmins);
+       VectorCopy(rtlight->cullmaxs, rsurface.rtlight_cullmaxs);
 
        if (rtlight->compiled && r_shadow_realtime_world_compile.integer)
        {
@@ -2818,14 +2796,14 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                // dynamic light, world available and can receive realtime lighting
                // calculate lit surfaces and leafs
                R_Shadow_EnlargeLeafSurfaceTrisBuffer(r_refdef.worldmodel->brush.num_leafs, r_refdef.worldmodel->num_surfaces, r_refdef.worldmodel->brush.shadowmesh ? r_refdef.worldmodel->brush.shadowmesh->numtriangles : r_refdef.worldmodel->surfmesh.num_triangles, r_refdef.worldmodel->surfmesh.num_triangles);
-               r_refdef.worldmodel->GetLightInfo(r_refdef.worldentity, rtlight->shadoworigin, rtlight->radius, r_shadow_rtlight_cullmins, r_shadow_rtlight_cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs);
+               r_refdef.worldmodel->GetLightInfo(r_refdef.worldentity, rtlight->shadoworigin, rtlight->radius, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs, r_shadow_buffer_leaflist, r_shadow_buffer_leafpvs, &numleafs, r_shadow_buffer_surfacelist, r_shadow_buffer_surfacepvs, &numsurfaces, r_shadow_buffer_shadowtrispvs, r_shadow_buffer_lighttrispvs);
                leaflist = r_shadow_buffer_leaflist;
                leafpvs = r_shadow_buffer_leafpvs;
                surfacelist = r_shadow_buffer_surfacelist;
                shadowtrispvs = r_shadow_buffer_shadowtrispvs;
                lighttrispvs = r_shadow_buffer_lighttrispvs;
                // if the reduced leaf bounds are offscreen, skip it
-               if (R_CullBox(r_shadow_rtlight_cullmins, r_shadow_rtlight_cullmaxs))
+               if (R_CullBox(rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs))
                        return;
        }
        else
@@ -2849,7 +2827,7 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        return;
        }
        // set up a scissor rectangle for this light
-       if (R_Shadow_ScissorForBBox(r_shadow_rtlight_cullmins, r_shadow_rtlight_cullmaxs))
+       if (R_Shadow_ScissorForBBox(rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs))
                return;
 
        R_Shadow_ComputeShadowCasterCullingPlanes(rtlight);
@@ -2867,11 +2845,11 @@ void R_DrawRTLight(rtlight_t *rtlight, qboolean visible)
                        model_t *model;
                        entity_render_t *ent = r_refdef.entities[i];
                        vec3_t org;
-                       if (!BoxesOverlap(ent->mins, ent->maxs, r_shadow_rtlight_cullmins, r_shadow_rtlight_cullmaxs))
+                       if (!BoxesOverlap(ent->mins, ent->maxs, rsurface.rtlight_cullmins, rsurface.rtlight_cullmaxs))
                                continue;
                        // skip the object entirely if it is not within the valid
                        // shadow-casting region (which includes the lit region)
-                       if (R_CullBoxCustomPlanes(ent->mins, ent->maxs, r_shadow_rtlight_numfrustumplanes, r_shadow_rtlight_frustumplanes))
+                       if (R_CullBoxCustomPlanes(ent->mins, ent->maxs, rsurface.rtlight_numfrustumplanes, rsurface.rtlight_frustumplanes))
                                continue;
                        if (!(model = ent->model))
                                continue;
index 22572ed..b77be83 100644 (file)
@@ -50,27 +50,6 @@ void R_Shadow_RenderMode_VisibleLighting(qboolean stenciltest, qboolean transpar
 void R_Shadow_RenderMode_End(void);
 void R_Shadow_SetupEntityLight(const entity_render_t *ent);
 
-// light currently being rendered
-extern rtlight_t *r_shadow_rtlight;
-
-// this is the location of the light in entity space
-extern vec3_t r_shadow_entitylightorigin;
-// this transforms entity coordinates to light filter cubemap coordinates
-// (also often used for other purposes)
-extern matrix4x4_t r_shadow_entitytolight;
-// based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
-// of attenuation texturing in full 3D (Z result often ignored)
-extern matrix4x4_t r_shadow_entitytoattenuationxyz;
-// this transforms only the Z to S, and T is always 0.5
-extern matrix4x4_t r_shadow_entitytoattenuationz;
-
-// current light's cull box (copied out of an rtlight or calculated by GetLightInfo)
-extern vec3_t r_shadow_rtlight_cullmins;
-extern vec3_t r_shadow_rtlight_cullmaxs;
-// current light's culling planes
-extern int r_shadow_rtlight_numfrustumplanes;
-extern mplane_t r_shadow_rtlight_frustumplanes[12+6+6]; // see R_Shadow_ComputeShadowCasterCullingPlanes
-
 void R_Shadow_RenderVolume(int numvertices, int numtriangles, const float *vertex3f, const int *element3i);
 qboolean R_Shadow_ScissorForBBox(const float *mins, const float *maxs);
 
index ae19bde..6c8126b 100644 (file)
@@ -87,6 +87,6 @@ void R_Model_Sprite_Draw(entity_render_t *ent)
                return;
 
        Matrix4x4_OriginFromMatrix(&ent->matrix, org);
-       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, r_shadow_rtlight);
+       R_MeshQueue_AddTransparent(ent->effects & EF_NODEPTHTEST ? r_view.origin : org, R_Model_Sprite_Draw_TransparentCallback, ent, 0, rsurface.rtlight);
 }
 
index 10fc554..2a56bf6 100644 (file)
--- a/render.h
+++ b/render.h
@@ -244,6 +244,22 @@ typedef struct rsurfacestate_s
        float *modelnormal3f;
        int modelnormal3f_bufferobject;
        size_t modelnormal3f_bufferoffset;
+       float *modellightmapcolor4f;
+       int modellightmapcolor4f_bufferobject;
+       size_t modellightmapcolor4f_bufferoffset;
+       float *modeltexcoordtexture2f;
+       int modeltexcoordtexture2f_bufferobject;
+       size_t modeltexcoordtexture2f_bufferoffset;
+       float *modeltexcoordlightmap2f;
+       int modeltexcoordlightmap2f_bufferobject;
+       size_t modeltexcoordlightmap2f_bufferoffset;
+       int *modelelement3i;
+       int modelelement3i_bufferobject;
+       int *modelneighbor3i;
+       int *modellightmapoffsets;
+       int modelnum_vertices;
+       int modelnum_triangles;
+       msurface_t *modelsurfaces;
        // current rendering array pointers
        // these may point to any of several different buffers depending on how
        // much processing was needed to prepare this model for rendering
@@ -283,8 +299,6 @@ typedef struct rsurfacestate_s
        vec3_t colormap_shirtcolor;
        // view location in model space
        vec3_t modelorg; // TODO: rename this
-       // model being rendered
-       const model_t *model; // TODO: eliminate this
        // current texture in batching code
        texture_t *texture;
        // whether lightmapping is active on this batch
@@ -294,6 +308,27 @@ typedef struct rsurfacestate_s
        rsurfmode_t mode;
        // type of vertex lighting being used on this batch
        int lightmode; // 0 = lightmap or fullbright, 1 = color array from q3bsp, 2 = vertex shaded model
+
+       // rtlight rendering
+       // light currently being rendered
+       rtlight_t *rtlight;
+       // current light's cull box (copied out of an rtlight or calculated by GetLightInfo)
+       vec3_t rtlight_cullmins;
+       vec3_t rtlight_cullmaxs;
+       // current light's culling planes
+       int rtlight_numfrustumplanes;
+       mplane_t rtlight_frustumplanes[12+6+6]; // see R_Shadow_ComputeShadowCasterCullingPlanes
+
+       // this is the location of the light in entity space
+       vec3_t entitylightorigin;
+       // this transforms entity coordinates to light filter cubemap coordinates
+       // (also often used for other purposes)
+       matrix4x4_t entitytolight;
+       // based on entitytolight this transforms -1 to +1 to 0 to 1 for purposes
+       // of attenuation texturing in full 3D (Z result often ignored)
+       matrix4x4_t entitytoattenuationxyz;
+       // this transforms only the Z to S, and T is always 0.5
+       matrix4x4_t entitytoattenuationz;
 }
 rsurfacestate_t;