implemented vbo rendering of map, models, and compiled shadow volumes
authorhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 4 Apr 2007 15:22:02 +0000 (15:22 +0000)
committerhavoc <havoc@d7cf8633-e32d-0410-b094-e92efae38249>
Wed, 4 Apr 2007 15:22:02 +0000 (15:22 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@7046 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
gl_rsurf.c
model_shared.c
r_shadow.c
r_shadow.h
render.h

index 12be21a..3837e8e 100644 (file)
@@ -2879,14 +2879,32 @@ void R_Mesh_ResizeArrays(int newvertices)
 }
 
 float *rsurface_modelvertex3f;
+int rsurface_modelvertex3f_bufferobject;
+size_t rsurface_modelvertex3f_bufferoffset;
 float *rsurface_modelsvector3f;
+int rsurface_modelsvector3f_bufferobject;
+size_t rsurface_modelsvector3f_bufferoffset;
 float *rsurface_modeltvector3f;
+int rsurface_modeltvector3f_bufferobject;
+size_t rsurface_modeltvector3f_bufferoffset;
 float *rsurface_modelnormal3f;
+int rsurface_modelnormal3f_bufferobject;
+size_t rsurface_modelnormal3f_bufferoffset;
 float *rsurface_vertex3f;
+int rsurface_vertex3f_bufferobject;
+size_t rsurface_vertex3f_bufferoffset;
 float *rsurface_svector3f;
+int rsurface_svector3f_bufferobject;
+size_t rsurface_svector3f_bufferoffset;
 float *rsurface_tvector3f;
+int rsurface_tvector3f_bufferobject;
+size_t rsurface_tvector3f_bufferoffset;
 float *rsurface_normal3f;
+int rsurface_normal3f_bufferobject;
+size_t rsurface_normal3f_bufferoffset;
 float *rsurface_lightmapcolor4f;
+int rsurface_lightmapcolor4f_bufferobject;
+size_t rsurface_lightmapcolor4f_bufferoffset;
 vec3_t rsurface_modelorg;
 qboolean rsurface_generatedvertex;
 const entity_render_t *rsurface_entity;
@@ -2919,14 +2937,30 @@ void RSurf_ActiveWorldEntity(void)
        R_Mesh_Matrix(&identitymatrix);
        VectorCopy(r_view.origin, rsurface_modelorg);
        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_generatedvertex = false;
        rsurface_vertex3f  = rsurface_modelvertex3f;
+       rsurface_vertex3f_bufferobject = rsurface_modelvertex3f_bufferobject;
+       rsurface_vertex3f_bufferoffset = rsurface_modelvertex3f_bufferoffset;
        rsurface_svector3f = rsurface_modelsvector3f;
+       rsurface_svector3f_bufferobject = rsurface_modelsvector3f_bufferobject;
+       rsurface_svector3f_bufferoffset = rsurface_modelsvector3f_bufferoffset;
        rsurface_tvector3f = rsurface_modeltvector3f;
+       rsurface_tvector3f_bufferobject = rsurface_modeltvector3f_bufferobject;
+       rsurface_tvector3f_bufferoffset = rsurface_modeltvector3f_bufferoffset;
        rsurface_normal3f  = rsurface_modelnormal3f;
+       rsurface_normal3f_bufferobject = rsurface_modelnormal3f_bufferobject;
+       rsurface_normal3f_bufferoffset = rsurface_modelnormal3f_bufferoffset;
 }
 
 void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, qboolean wanttangents)
@@ -2964,20 +2998,44 @@ void RSurf_ActiveModelEntity(const entity_render_t *ent, qboolean wantnormals, q
                        rsurface_modelnormal3f = NULL;
                        Mod_Alias_GetMesh_Vertices(rsurface_model, rsurface_entity->frameblend, rsurface_array_modelvertex3f, NULL, NULL, NULL);
                }
+               rsurface_modelvertex3f_bufferobject = 0;
+               rsurface_modelvertex3f_bufferoffset = 0;
+               rsurface_modelsvector3f_bufferobject = 0;
+               rsurface_modelsvector3f_bufferoffset = 0;
+               rsurface_modeltvector3f_bufferobject = 0;
+               rsurface_modeltvector3f_bufferoffset = 0;
+               rsurface_modelnormal3f_bufferobject = 0;
+               rsurface_modelnormal3f_bufferoffset = 0;
                rsurface_generatedvertex = true;
        }
        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_generatedvertex = false;
        }
        rsurface_vertex3f  = rsurface_modelvertex3f;
+       rsurface_vertex3f_bufferobject = rsurface_modelvertex3f_bufferobject;
+       rsurface_vertex3f_bufferoffset = rsurface_modelvertex3f_bufferoffset;
        rsurface_svector3f = rsurface_modelsvector3f;
+       rsurface_svector3f_bufferobject = rsurface_modelsvector3f_bufferobject;
+       rsurface_svector3f_bufferoffset = rsurface_modelsvector3f_bufferoffset;
        rsurface_tvector3f = rsurface_modeltvector3f;
+       rsurface_tvector3f_bufferobject = rsurface_modeltvector3f_bufferobject;
+       rsurface_tvector3f_bufferoffset = rsurface_modeltvector3f_bufferoffset;
        rsurface_normal3f  = rsurface_modelnormal3f;
+       rsurface_normal3f_bufferobject = rsurface_modelnormal3f_bufferobject;
+       rsurface_normal3f_bufferoffset = rsurface_modelnormal3f_bufferoffset;
 }
 
 void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generatetangents, int texturenumsurfaces, msurface_t **texturesurfacelist)
@@ -2992,12 +3050,18 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                if (generatenormals && !rsurface_modelnormal3f)
                {
                        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);
                }
                if (generatetangents && !rsurface_modelsvector3f)
                {
                        rsurface_svector3f = rsurface_modelsvector3f = rsurface_array_modelsvector3f;
+                       rsurface_svector3f_bufferobject = rsurface_modelsvector3f_bufferobject = 0;
+                       rsurface_svector3f_bufferoffset = rsurface_modelsvector3f_bufferoffset = 0;
                        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);
                }
        }
@@ -3045,18 +3109,34 @@ void RSurf_PrepareVerticesForBatch(qboolean generatenormals, qboolean generateta
                        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);
                }
                rsurface_vertex3f = rsurface_array_deformedvertex3f;
+               rsurface_vertex3f_bufferobject = 0;
+               rsurface_vertex3f_bufferoffset = 0;
                rsurface_svector3f = rsurface_array_deformedsvector3f;
+               rsurface_svector3f_bufferobject = 0;
+               rsurface_svector3f_bufferoffset = 0;
                rsurface_tvector3f = rsurface_array_deformedtvector3f;
+               rsurface_tvector3f_bufferobject = 0;
+               rsurface_tvector3f_bufferoffset = 0;
                rsurface_normal3f = rsurface_array_deformednormal3f;
+               rsurface_normal3f_bufferobject = 0;
+               rsurface_normal3f_bufferoffset = 0;
        }
        else
        {
-               rsurface_vertex3f = rsurface_modelvertex3f;
+               rsurface_vertex3f  = rsurface_modelvertex3f;
+               rsurface_vertex3f_bufferobject = rsurface_modelvertex3f_bufferobject;
+               rsurface_vertex3f_bufferoffset = rsurface_modelvertex3f_bufferoffset;
                rsurface_svector3f = rsurface_modelsvector3f;
+               rsurface_svector3f_bufferobject = rsurface_modelsvector3f_bufferobject;
+               rsurface_svector3f_bufferoffset = rsurface_modelsvector3f_bufferoffset;
                rsurface_tvector3f = rsurface_modeltvector3f;
-               rsurface_normal3f = rsurface_modelnormal3f;
+               rsurface_tvector3f_bufferobject = rsurface_modeltvector3f_bufferobject;
+               rsurface_tvector3f_bufferoffset = rsurface_modeltvector3f_bufferoffset;
+               rsurface_normal3f  = rsurface_modelnormal3f;
+               rsurface_normal3f_bufferobject = rsurface_modelnormal3f_bufferobject;
+               rsurface_normal3f_bufferoffset = rsurface_modelnormal3f_bufferoffset;
        }
-       R_Mesh_VertexPointer(rsurface_vertex3f, 0, 0);
+       R_Mesh_VertexPointer(rsurface_vertex3f, rsurface_vertex3f_bufferobject, rsurface_vertex3f_bufferoffset);
 }
 
 void RSurf_DrawBatch_Simple(int texturenumsurfaces, msurface_t **texturesurfacelist)
@@ -3072,7 +3152,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), 0, 0);
+               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));
        }
        else if (r_batchmode.integer == 2)
        {
@@ -3085,7 +3165,7 @@ 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), 0, 0);
+                               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));
                                continue;
                        }
                        memcpy(batchelements, rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
@@ -3119,7 +3199,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), 0, 0);
+                       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));
                }
        }
        else
@@ -3128,7 +3208,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), 0, 0);
+                       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));
                }
        }
 }
@@ -3150,7 +3230,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), 0, 0);
+               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));
        }
        else if (r_batchmode.integer == 2)
        {
@@ -3166,7 +3246,7 @@ 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), 0, 0);
+                               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));
                                continue;
                        }
                        memcpy(batchelements, rsurface_model->surfmesh.data_element3i + 3 * surface->num_firsttriangle, surface->num_triangles * sizeof(int[3]));
@@ -3219,7 +3299,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), 0, 0);
+                       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));
                }
 #if 0
                Con_Printf("\n");
@@ -3234,7 +3314,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), 0, 0);
+                       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));
                }
        }
 }
@@ -3252,7 +3332,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)), 0, 0);
+                               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)));
                        }
                }
        }
@@ -3264,7 +3344,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), 0, 0);
+                       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));
                }
        }
 }
@@ -3307,6 +3387,8 @@ static void RSurf_DrawBatch_GL11_ApplyFog(int texturenumsurfaces, msurface_t **t
                }
        }
        rsurface_lightmapcolor4f = rsurface_array_color4f;
+       rsurface_lightmapcolor4f_bufferobject = 0;
+       rsurface_lightmapcolor4f_bufferoffset = 0;
 }
 
 static void RSurf_DrawBatch_GL11_ApplyColor(int texturenumsurfaces, msurface_t **texturesurfacelist, float r, float g, float b, float a)
@@ -3328,15 +3410,19 @@ static void RSurf_DrawBatch_GL11_ApplyColor(int texturenumsurfaces, msurface_t *
                }
        }
        rsurface_lightmapcolor4f = rsurface_array_color4f;
+       rsurface_lightmapcolor4f_bufferobject = 0;
+       rsurface_lightmapcolor4f_bufferoffset = 0;
 }
 
 static void RSurf_DrawBatch_GL11_Lightmap(int texturenumsurfaces, msurface_t **texturesurfacelist, float r, float g, float b, float a, qboolean applycolor, qboolean applyfog)
 {
        // TODO: optimize
        rsurface_lightmapcolor4f = NULL;
+       rsurface_lightmapcolor4f_bufferobject = 0;
+       rsurface_lightmapcolor4f_bufferoffset = 0;
        if (applyfog)   RSurf_DrawBatch_GL11_ApplyFog(texturenumsurfaces, texturesurfacelist);
        if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(texturenumsurfaces, texturesurfacelist, r, g, b, a);
-       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, 0, 0);
+       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, rsurface_lightmapcolor4f_bufferobject, rsurface_lightmapcolor4f_bufferoffset);
        GL_Color(r, g, b, a);
        RSurf_DrawBatch_WithLightmapSwitching(texturenumsurfaces, texturesurfacelist, 0, -1);
 }
@@ -3346,9 +3432,11 @@ static void RSurf_DrawBatch_GL11_Unlit(int texturenumsurfaces, msurface_t **text
        // TODO: optimize applyfog && applycolor case
        // just apply fog if necessary, and tint the fog color array if necessary
        rsurface_lightmapcolor4f = NULL;
+       rsurface_lightmapcolor4f_bufferobject = 0;
+       rsurface_lightmapcolor4f_bufferoffset = 0;
        if (applyfog)   RSurf_DrawBatch_GL11_ApplyFog(texturenumsurfaces, texturesurfacelist);
        if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(texturenumsurfaces, texturesurfacelist, r, g, b, a);
-       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, 0, 0);
+       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, rsurface_lightmapcolor4f_bufferobject, rsurface_lightmapcolor4f_bufferoffset);
        GL_Color(r, g, b, a);
        RSurf_DrawBatch_Simple(texturenumsurfaces, texturesurfacelist);
 }
@@ -3398,12 +3486,18 @@ static void RSurf_DrawBatch_GL11_VertexColor(int texturenumsurfaces, msurface_t
                        }
                }
                rsurface_lightmapcolor4f = rsurface_array_color4f;
+               rsurface_lightmapcolor4f_bufferobject = 0;
+               rsurface_lightmapcolor4f_bufferoffset = 0;
        }
        else
+       {
                rsurface_lightmapcolor4f = rsurface_model->surfmesh.data_lightmapcolor4f;
+               rsurface_lightmapcolor4f_bufferobject = rsurface_model->surfmesh.vbo;
+               rsurface_lightmapcolor4f_bufferoffset = rsurface_model->surfmesh.vbooffset_lightmapcolor4f;
+       }
        if (applyfog)   RSurf_DrawBatch_GL11_ApplyFog(texturenumsurfaces, texturesurfacelist);
        if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(texturenumsurfaces, texturesurfacelist, r, g, b, a);
-       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, 0, 0);
+       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, rsurface_lightmapcolor4f_bufferobject, rsurface_lightmapcolor4f_bufferoffset);
        GL_Color(r, g, b, a);
        RSurf_DrawBatch_Simple(texturenumsurfaces, texturesurfacelist);
 }
@@ -3452,6 +3546,8 @@ static void RSurf_DrawBatch_GL11_VertexShade(int texturenumsurfaces, msurface_t
                a = 1;
                applycolor = false;
                rsurface_lightmapcolor4f = rsurface_array_color4f;
+               rsurface_lightmapcolor4f_bufferobject = 0;
+               rsurface_lightmapcolor4f_bufferoffset = 0;
        }
        else
        {
@@ -3459,10 +3555,12 @@ static void RSurf_DrawBatch_GL11_VertexShade(int texturenumsurfaces, msurface_t
                g = ambientcolor[1];
                b = ambientcolor[2];
                rsurface_lightmapcolor4f = NULL;
+               rsurface_lightmapcolor4f_bufferobject = 0;
+               rsurface_lightmapcolor4f_bufferoffset = 0;
        }
        if (applyfog)   RSurf_DrawBatch_GL11_ApplyFog(texturenumsurfaces, texturesurfacelist);
        if (applycolor) RSurf_DrawBatch_GL11_ApplyColor(texturenumsurfaces, texturesurfacelist, r, g, b, a);
-       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, 0, 0);
+       R_Mesh_ColorPointer(rsurface_lightmapcolor4f, rsurface_lightmapcolor4f_bufferobject, rsurface_lightmapcolor4f_bufferoffset);
        GL_Color(r, g, b, a);
        RSurf_DrawBatch_Simple(texturenumsurfaces, texturesurfacelist);
 }
@@ -3553,11 +3651,11 @@ static void R_DrawTextureSurfaceList_GL20(int texturenumsurfaces, msurface_t **t
                RSurf_PrepareVerticesForBatch(true, r_glsl_permutation->loc_Texture_Normal, texturenumsurfaces, texturesurfacelist);
        else
                RSurf_PrepareVerticesForBatch(r_glsl_permutation->loc_Texture_Normal, r_glsl_permutation->loc_Texture_Normal, texturenumsurfaces, texturesurfacelist);
-       R_Mesh_TexCoordPointer(0, 2, rsurface_model->surfmesh.data_texcoordtexture2f, 0, 0);
-       R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f, 0, 0);
-       R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f, 0, 0);
-       R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f, 0, 0);
-       R_Mesh_TexCoordPointer(4, 2, rsurface_model->surfmesh.data_texcoordlightmap2f, 0, 0);
+       R_Mesh_TexCoordPointer(0, 2, rsurface_model->surfmesh.data_texcoordtexture2f, rsurface_model->surfmesh.vbo, rsurface_model->surfmesh.vbooffset_texcoordtexture2f);
+       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);
 
        if (rsurface_texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT)
        {
@@ -3578,7 +3676,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, 0, 0);
+               R_Mesh_ColorPointer(rsurface_model->surfmesh.data_lightmapcolor4f, rsurface_model->surfmesh.vbo, rsurface_model->surfmesh.vbooffset_lightmapcolor4f);
        }
 
        if (rsurface_uselightmaptexture && !(rsurface_texture->currentmaterialflags & MATERIALFLAG_FULLBRIGHT))
@@ -3643,10 +3741,14 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t
                        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.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;
                        R_Mesh_TextureState(&m);
                        if (rsurface_lightmode == 2)
                                RSurf_DrawBatch_GL11_VertexShade(texturenumsurfaces, texturesurfacelist, layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
@@ -3661,6 +3763,8 @@ static void R_DrawTextureSurfaceList_GL13(int texturenumsurfaces, msurface_t **t
                        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;
                        R_Mesh_TextureState(&m);
                        RSurf_DrawBatch_GL11_Unlit(texturenumsurfaces, texturesurfacelist, layercolor[0], layercolor[1], layercolor[2], layercolor[3], applycolor, applyfog);
                        break;
@@ -3672,6 +3776,8 @@ 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;
                        }
                        R_Mesh_TextureState(&m);
                        // generate a color array for the fog pass
@@ -3742,6 +3848,8 @@ static void R_DrawTextureSurfaceList_GL11(int texturenumsurfaces, msurface_t **t
                                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;
                                R_Mesh_TextureState(&m);
                                if (rsurface_lightmode == 2)
                                        RSurf_DrawBatch_GL11_VertexShade(texturenumsurfaces, texturesurfacelist, 1, 1, 1, 1, false, false);
@@ -3756,6 +3864,8 @@ static void R_DrawTextureSurfaceList_GL11(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;
                                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);
                        }
@@ -3766,6 +3876,8 @@ static void R_DrawTextureSurfaceList_GL11(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;
                                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);
@@ -3779,6 +3891,8 @@ static void R_DrawTextureSurfaceList_GL11(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;
                        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;
@@ -3791,6 +3905,8 @@ static void R_DrawTextureSurfaceList_GL11(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;
                                R_Mesh_TextureState(&m);
                        }
                        else
index 8aa3255..91042d0 100644 (file)
@@ -969,7 +969,7 @@ static void R_Q1BSP_DrawLight_TransparentCallback(const entity_render_t *ent, co
                        if (t != surface->texture)
                                break;
                        RSurf_PrepareVerticesForBatch(true, true, 1, &surface);
-                       R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, ent->model->surfmesh.data_element3i + surface->num_firsttriangle * 3);
+                       R_Shadow_RenderLighting(surface->num_firstvertex, surface->num_vertices, surface->num_triangles, ent->model->surfmesh.data_element3i + surface->num_firsttriangle * 3, ent->model->surfmesh.ebo, (sizeof(int[3]) * surface->num_firsttriangle));
                }
        }
        R_Shadow_RenderMode_End();
@@ -982,6 +982,7 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
        model_t *model = ent->model;
        msurface_t *surface;
        int i, k, l, m, mend, endsurface, batchnumsurfaces, batchnumtriangles, batchfirstvertex, batchlastvertex;
+       qboolean usebufferobject;
        const int *element3i;
        msurface_t *batchsurfacelist[RSURF_MAX_BATCHSURFACES];
        int batchelements[BATCHSIZE*3];
@@ -1034,6 +1035,8 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                }
                                else
                                {
+                                       // use the bufferobject if all triangles are accepted
+                                       usebufferobject = true;
                                        batchnumtriangles = 0;
                                        // note: this only accepts consecutive surfaces because
                                        // non-consecutive surfaces often have extreme vertex
@@ -1050,12 +1053,18 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                                                if (trispvs)
                                                                {
                                                                        if (!CHECKPVSBIT(trispvs, m))
+                                                                       {
+                                                                               usebufferobject = false;
                                                                                continue;
+                                                                       }
                                                                }
                                                                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))
+                                                                       {
+                                                                               usebufferobject = false;
                                                                                continue;
+                                                                       }
                                                                }
                                                        }
                                                        batchelements[batchnumtriangles*3+0] = element3i[m*3+0];
@@ -1066,8 +1075,9 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                                        if (batchnumtriangles >= BATCHSIZE)
                                                        {
                                                                Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
-                                                               R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements);
+                                                               R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, 0, 0);
                                                                batchnumtriangles = 0;
+                                                               usebufferobject = false;
                                                        }
                                                }
                                                r_refdef.stats.lights_lighttriangles += batchsurfacelist[l]->num_triangles;
@@ -1075,7 +1085,10 @@ void R_Q1BSP_DrawLight(entity_render_t *ent, int numsurfaces, const int *surface
                                        if (batchnumtriangles > 0)
                                        {
                                                Mod_VertexRangeFromElements(batchnumtriangles*3, batchelements, &batchfirstvertex, &batchlastvertex);
-                                               R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements);
+                                               if (usebufferobject)
+                                                       R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, ent->model->surfmesh.ebo, sizeof(int[3]) * batchsurfacelist[k]->num_firsttriangle);
+                                               else
+                                                       R_Shadow_RenderLighting(batchfirstvertex, batchlastvertex + 1 - batchfirstvertex, batchnumtriangles, batchelements, 0, 0);
                                        }
                                }
                        }
index 4e9b1a2..de52950 100644 (file)
@@ -930,19 +930,19 @@ static void Mod_ShadowMesh_CreateVBOs(shadowmesh_t *mesh)
        if (mesh->numverts)
        {
                size_t size;
-               unsigned char *data, *mem;
+               unsigned char *mem;
                size = 0;
                mesh->vbooffset_vertex3f           = size;if (mesh->vertex3f          ) size += mesh->numverts * sizeof(float[3]);
                mesh->vbooffset_svector3f          = size;if (mesh->svector3f         ) size += mesh->numverts * sizeof(float[3]);
                mesh->vbooffset_tvector3f          = size;if (mesh->tvector3f         ) size += mesh->numverts * sizeof(float[3]);
                mesh->vbooffset_normal3f           = size;if (mesh->normal3f          ) size += mesh->numverts * sizeof(float[3]);
                mesh->vbooffset_texcoord2f         = size;if (mesh->texcoord2f        ) size += mesh->numverts * sizeof(float[2]);
-               data = mem = (unsigned char *)Mem_Alloc(tempmempool, size);
-               if (mesh->vertex3f          ) {memcpy(data, mesh->vertex3f          , mesh->numverts * sizeof(float[3]));data += mesh->numverts * sizeof(float[3]);}
-               if (mesh->svector3f         ) {memcpy(data, mesh->svector3f         , mesh->numverts * sizeof(float[3]));data += mesh->numverts * sizeof(float[3]);}
-               if (mesh->tvector3f         ) {memcpy(data, mesh->tvector3f         , mesh->numverts * sizeof(float[3]));data += mesh->numverts * sizeof(float[3]);}
-               if (mesh->normal3f          ) {memcpy(data, mesh->normal3f          , mesh->numverts * sizeof(float[3]));data += mesh->numverts * sizeof(float[3]);}
-               if (mesh->texcoord2f        ) {memcpy(data, mesh->texcoord2f        , mesh->numverts * sizeof(float[2]));data += mesh->numverts * sizeof(float[2]);}
+               mem = (unsigned char *)Mem_Alloc(tempmempool, size);
+               if (mesh->vertex3f          ) memcpy(mem + mesh->vbooffset_vertex3f          , mesh->vertex3f          , mesh->numverts * sizeof(float[3]));
+               if (mesh->svector3f         ) memcpy(mem + mesh->vbooffset_svector3f         , mesh->svector3f         , mesh->numverts * sizeof(float[3]));
+               if (mesh->tvector3f         ) memcpy(mem + mesh->vbooffset_tvector3f         , mesh->tvector3f         , mesh->numverts * sizeof(float[3]));
+               if (mesh->normal3f          ) memcpy(mem + mesh->vbooffset_normal3f          , mesh->normal3f          , mesh->numverts * sizeof(float[3]));
+               if (mesh->texcoord2f        ) memcpy(mem + mesh->vbooffset_texcoord2f        , mesh->texcoord2f        , mesh->numverts * sizeof(float[2]));
                mesh->vbo = R_Mesh_CreateStaticVBO(mem, size);
                Mem_Free(mem);
        }
@@ -1446,7 +1446,7 @@ static void Mod_BuildVBOs(void)
        if (loadmodel->surfmesh.num_vertices)
        {
                size_t size;
-               unsigned char *data, *mem;
+               unsigned char *mem;
                size = 0;
                loadmodel->surfmesh.vbooffset_vertex3f           = size;if (loadmodel->surfmesh.data_vertex3f          ) size += loadmodel->surfmesh.num_vertices * sizeof(float[3]);
                loadmodel->surfmesh.vbooffset_svector3f          = size;if (loadmodel->surfmesh.data_svector3f         ) size += loadmodel->surfmesh.num_vertices * sizeof(float[3]);
@@ -1455,14 +1455,14 @@ static void Mod_BuildVBOs(void)
                loadmodel->surfmesh.vbooffset_texcoordtexture2f  = size;if (loadmodel->surfmesh.data_texcoordtexture2f ) size += loadmodel->surfmesh.num_vertices * sizeof(float[2]);
                loadmodel->surfmesh.vbooffset_texcoordlightmap2f = size;if (loadmodel->surfmesh.data_texcoordlightmap2f) size += loadmodel->surfmesh.num_vertices * sizeof(float[2]);
                loadmodel->surfmesh.vbooffset_lightmapcolor4f    = size;if (loadmodel->surfmesh.data_lightmapcolor4f   ) size += loadmodel->surfmesh.num_vertices * sizeof(float[4]);
-               data = mem = (unsigned char *)Mem_Alloc(tempmempool, size);
-               if (loadmodel->surfmesh.data_vertex3f          ) {memcpy(data, loadmodel->surfmesh.data_vertex3f          , loadmodel->surfmesh.num_vertices * sizeof(float[3]));data += loadmodel->surfmesh.num_vertices * sizeof(float[3]);}
-               if (loadmodel->surfmesh.data_svector3f         ) {memcpy(data, loadmodel->surfmesh.data_svector3f         , loadmodel->surfmesh.num_vertices * sizeof(float[3]));data += loadmodel->surfmesh.num_vertices * sizeof(float[3]);}
-               if (loadmodel->surfmesh.data_tvector3f         ) {memcpy(data, loadmodel->surfmesh.data_tvector3f         , loadmodel->surfmesh.num_vertices * sizeof(float[3]));data += loadmodel->surfmesh.num_vertices * sizeof(float[3]);}
-               if (loadmodel->surfmesh.data_normal3f          ) {memcpy(data, loadmodel->surfmesh.data_normal3f          , loadmodel->surfmesh.num_vertices * sizeof(float[3]));data += loadmodel->surfmesh.num_vertices * sizeof(float[3]);}
-               if (loadmodel->surfmesh.data_texcoordtexture2f ) {memcpy(data, loadmodel->surfmesh.data_texcoordtexture2f , loadmodel->surfmesh.num_vertices * sizeof(float[2]));data += loadmodel->surfmesh.num_vertices * sizeof(float[2]);}
-               if (loadmodel->surfmesh.data_texcoordlightmap2f) {memcpy(data, loadmodel->surfmesh.data_texcoordlightmap2f, loadmodel->surfmesh.num_vertices * sizeof(float[2]));data += loadmodel->surfmesh.num_vertices * sizeof(float[2]);}
-               if (loadmodel->surfmesh.data_lightmapcolor4f   ) {memcpy(data, loadmodel->surfmesh.data_lightmapcolor4f   , loadmodel->surfmesh.num_vertices * sizeof(float[4]));data += loadmodel->surfmesh.num_vertices * sizeof(float[4]);}
+               mem = (unsigned char *)Mem_Alloc(tempmempool, size);
+               if (loadmodel->surfmesh.data_vertex3f          ) memcpy(mem + loadmodel->surfmesh.vbooffset_vertex3f          , loadmodel->surfmesh.data_vertex3f          , loadmodel->surfmesh.num_vertices * sizeof(float[3]));
+               if (loadmodel->surfmesh.data_svector3f         ) memcpy(mem + loadmodel->surfmesh.vbooffset_svector3f         , loadmodel->surfmesh.data_svector3f         , loadmodel->surfmesh.num_vertices * sizeof(float[3]));
+               if (loadmodel->surfmesh.data_tvector3f         ) memcpy(mem + loadmodel->surfmesh.vbooffset_tvector3f         , loadmodel->surfmesh.data_tvector3f         , loadmodel->surfmesh.num_vertices * sizeof(float[3]));
+               if (loadmodel->surfmesh.data_normal3f          ) memcpy(mem + loadmodel->surfmesh.vbooffset_normal3f          , loadmodel->surfmesh.data_normal3f          , loadmodel->surfmesh.num_vertices * sizeof(float[3]));
+               if (loadmodel->surfmesh.data_texcoordtexture2f ) memcpy(mem + loadmodel->surfmesh.vbooffset_texcoordtexture2f , loadmodel->surfmesh.data_texcoordtexture2f , loadmodel->surfmesh.num_vertices * sizeof(float[2]));
+               if (loadmodel->surfmesh.data_texcoordlightmap2f) memcpy(mem + loadmodel->surfmesh.vbooffset_texcoordlightmap2f, loadmodel->surfmesh.data_texcoordlightmap2f, loadmodel->surfmesh.num_vertices * sizeof(float[2]));
+               if (loadmodel->surfmesh.data_lightmapcolor4f   ) memcpy(mem + loadmodel->surfmesh.vbooffset_lightmapcolor4f   , loadmodel->surfmesh.data_lightmapcolor4f   , loadmodel->surfmesh.num_vertices * sizeof(float[4]));
                loadmodel->surfmesh.vbo = R_Mesh_CreateStaticVBO(mem, size);
                Mem_Free(mem);
        }
index 7702620..cc4e6a1 100644 (file)
@@ -1464,35 +1464,35 @@ static void R_Shadow_GenTexCoords_Specular_NormalCubeMap(int firstvertex, int nu
        }
 }
 
-static void R_Shadow_RenderLighting_VisibleLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i, 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)
+static void R_Shadow_RenderLighting_VisibleLighting(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)
 {
        // used to display how many times a surface is lit for level design purposes
        GL_Color(0.1 * r_view.colorscale, 0.025 * r_view.colorscale, 0, 1);
        R_Mesh_ColorPointer(NULL, 0, 0);
        R_Mesh_ResetTextureState();
-       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 }
 
-static void R_Shadow_RenderLighting_Light_GLSL(int firstvertex, int numvertices, int numtriangles, const int *element3i, 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)
+static void R_Shadow_RenderLighting_Light_GLSL(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)
 {
        // ARB2 GLSL shader path (GFFX5200, Radeon 9500)
        R_SetupSurfaceShader(lightcolorbase, false, ambientscale, diffusescale, specularscale);
-       R_Mesh_TexCoordPointer(0, 2, rsurface_model->surfmesh.data_texcoordtexture2f, 0, 0);
-       R_Mesh_TexCoordPointer(1, 3, rsurface_svector3f, 0, 0);
-       R_Mesh_TexCoordPointer(2, 3, rsurface_tvector3f, 0, 0);
-       R_Mesh_TexCoordPointer(3, 3, rsurface_normal3f, 0, 0);
+       R_Mesh_TexCoordPointer(0, 2, rsurface_model->surfmesh.data_texcoordtexture2f, rsurface_model->surfmesh.vbo, rsurface_model->surfmesh.vbooffset_texcoordtexture2f);
+       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);
        if (rsurface_texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
        {
                qglDepthFunc(GL_EQUAL);CHECKGLERROR
        }
-       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
        if (rsurface_texture->currentmaterialflags & MATERIALFLAG_ALPHATEST)
        {
                qglDepthFunc(GL_LEQUAL);CHECKGLERROR
        }
 }
 
-static void R_Shadow_RenderLighting_Light_Dot3_Finalize(int firstvertex, int numvertices, int numtriangles, const int *element3i, float r, float g, float b)
+static void R_Shadow_RenderLighting_Light_Dot3_Finalize(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, float r, float g, float b)
 {
        // shared final code for all the dot3 layers
        int renders;
@@ -1500,11 +1500,11 @@ static void R_Shadow_RenderLighting_Light_Dot3_Finalize(int firstvertex, int num
        for (renders = 0;renders < 64 && (r > 0 || g > 0 || b > 0);renders++, r--, g--, b--)
        {
                GL_Color(bound(0, r, 1), bound(0, g, 1), bound(0, b, 1), 1);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
        }
 }
 
-static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int numvertices, int numtriangles, const int *element3i, const vec3_t lightcolorbase, rtexture_t *basetexture, float colorscale)
+static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, const vec3_t lightcolorbase, rtexture_t *basetexture, float colorscale)
 {
        rmeshstate_t m;
        // colorscale accounts for how much we multiply the brightness
@@ -1521,12 +1521,18 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                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.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.texmatrix[1] = rsurface_texture->currenttexmatrix;
                m.texcubemap[2] = R_GetTexture(r_shadow_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;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1536,9 +1542,13 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                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.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.texmatrix[1] = rsurface_texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1548,17 +1558,25 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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.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.texmatrix[2] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[3] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_ONE, GL_ONE);
@@ -1569,12 +1587,18 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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.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.texmatrix[2] = rsurface_texture->currenttexmatrix;
                GL_BlendFunc(GL_ONE, GL_ONE);
        }
@@ -1584,34 +1608,42 @@ static void R_Shadow_RenderLighting_Light_Dot3_AmbientPass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        // this final code is shared
        R_Mesh_TextureState(&m);
-       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
+       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
 }
 
-static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int numvertices, int numtriangles, const int *element3i, const vec3_t lightcolorbase, rtexture_t *basetexture, rtexture_t *normalmaptexture, float colorscale)
+static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, const vec3_t lightcolorbase, rtexture_t *basetexture, rtexture_t *normalmaptexture, float colorscale)
 {
        rmeshstate_t m;
        // colorscale accounts for how much we multiply the brightness
@@ -1631,27 +1663,37 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                m.tex3d[2] = R_GetTexture(r_shadow_attenuation3dtexture);
                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;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1662,34 +1704,44 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                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;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // second pass
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1701,22 +1753,30 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.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;
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -1727,30 +1787,42 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                m.tex[2] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1761,47 +1833,59 @@ static void R_Shadow_RenderLighting_Light_Dot3_DiffusePass(int firstvertex, int
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                GL_BlendFunc(GL_ONE, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // second pass
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        // this final code is shared
        R_Mesh_TextureState(&m);
-       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
+       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
 }
 
-static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int numvertices, int numtriangles, const int *element3i, const vec3_t lightcolorbase, rtexture_t *glosstexture, rtexture_t *normalmaptexture, float colorscale)
+static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset, const vec3_t lightcolorbase, rtexture_t *glosstexture, rtexture_t *normalmaptexture, float colorscale)
 {
        float glossexponent;
        rmeshstate_t m;
@@ -1817,41 +1901,51 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // second and third pass
                R_Mesh_ResetTextureState();
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                for (glossexponent = 2;glossexponent * 2 <= r_shadow_glossexponent.value;glossexponent *= 2)
-                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // fourth pass
                memset(&m, 0, sizeof(m));
                m.tex3d[0] = R_GetTexture(r_shadow_attenuation3dtexture);
                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;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
@@ -1862,30 +1956,38 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // second and third pass
                R_Mesh_ResetTextureState();
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                for (glossexponent = 2;glossexponent * 2 <= r_shadow_glossexponent.value;glossexponent *= 2)
-                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.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;
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
@@ -1895,54 +1997,66 @@ static void R_Shadow_RenderLighting_Light_Dot3_SpecularPass(int firstvertex, int
                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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                m.texcubemap[1] = R_GetTexture(r_texture_normalizationcube);
                m.texcombinergb[1] = GL_DOT3_RGBA_ARB;
                m.pointer_texcoord3f[1] = rsurface_array_texcoord3f;
+               m.pointer_texcoord_bufferobject[1] = 0;
+               m.pointer_texcoord_bufferoffset[1] = 0;
                R_Mesh_TextureState(&m);
                GL_ColorMask(0,0,0,1);
                // this squares the result
                GL_BlendFunc(GL_SRC_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // second and third pass
                R_Mesh_ResetTextureState();
                // square alpha in framebuffer a few times to make it shiny
                GL_BlendFunc(GL_ZERO, GL_DST_ALPHA);
                for (glossexponent = 2;glossexponent * 2 <= r_shadow_glossexponent.value;glossexponent *= 2)
-                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+                       R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // fourth pass
                memset(&m, 0, sizeof(m));
                m.tex[0] = R_GetTexture(r_shadow_attenuation2dtexture);
                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.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;
                R_Mesh_TextureState(&m);
                GL_BlendFunc(GL_DST_ALPHA, GL_ZERO);
-               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, 0, 0);
+               R_Mesh_Draw(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
 
                // 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.texmatrix[0] = rsurface_texture->currenttexmatrix;
                if (r_shadow_rtlight->currentcubemap != r_texture_whitecube)
                {
                        m.texcubemap[1] = R_GetTexture(r_shadow_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;
                }
                GL_BlendFunc(GL_DST_ALPHA, GL_ONE);
        }
        // this final code is shared
        R_Mesh_TextureState(&m);
-       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
+       R_Shadow_RenderLighting_Light_Dot3_Finalize(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase[0] * colorscale, lightcolorbase[1] * colorscale, lightcolorbase[2] * colorscale);
 }
 
-static void R_Shadow_RenderLighting_Light_Dot3(int firstvertex, int numvertices, int numtriangles, const int *element3i, 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)
+static void R_Shadow_RenderLighting_Light_Dot3(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)
 {
        // ARB path (any Geforce, any Radeon)
        qboolean doambient = ambientscale > 0;
@@ -1952,28 +2066,28 @@ static void R_Shadow_RenderLighting_Light_Dot3(int firstvertex, int numvertices,
                return;
        R_Mesh_ColorPointer(NULL, 0, 0);
        if (doambient)
-               R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, basetexture, ambientscale * r_view.colorscale);
+               R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, basetexture, ambientscale * r_view.colorscale);
        if (dodiffuse)
-               R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, basetexture, normalmaptexture, diffusescale * r_view.colorscale);
+               R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, basetexture, normalmaptexture, diffusescale * r_view.colorscale);
        if (dopants)
        {
                if (doambient)
-                       R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, lightcolorpants, pantstexture, ambientscale * r_view.colorscale);
+                       R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorpants, pantstexture, ambientscale * r_view.colorscale);
                if (dodiffuse)
-                       R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, lightcolorpants, pantstexture, normalmaptexture, diffusescale * r_view.colorscale);
+                       R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorpants, pantstexture, normalmaptexture, diffusescale * r_view.colorscale);
        }
        if (doshirt)
        {
                if (doambient)
-                       R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, lightcolorshirt, shirttexture, ambientscale * r_view.colorscale);
+                       R_Shadow_RenderLighting_Light_Dot3_AmbientPass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorshirt, shirttexture, ambientscale * r_view.colorscale);
                if (dodiffuse)
-                       R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, lightcolorshirt, shirttexture, normalmaptexture, diffusescale * r_view.colorscale);
+                       R_Shadow_RenderLighting_Light_Dot3_DiffusePass(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorshirt, shirttexture, normalmaptexture, diffusescale * r_view.colorscale);
        }
        if (dospecular)
-               R_Shadow_RenderLighting_Light_Dot3_SpecularPass(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, glosstexture, normalmaptexture, specularscale * r_view.colorscale);
+               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, vec3_t diffusecolor2, vec3_t ambientcolor2)
+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)
 {
        int renders;
        int i;
@@ -1984,7 +2098,7 @@ void R_Shadow_RenderLighting_Light_Vertex_Pass(const model_t *model, int firstve
        int *newe;
        const int *e;
        float *c;
-       int newelements[3072];
+       int newelements[4096*3];
        R_Shadow_RenderLighting_Light_Vertex_Shading(firstvertex, numvertices, numtriangles, element3i, diffusecolor2, ambientcolor2);
        for (renders = 0;renders < 64;renders++)
        {
@@ -2021,7 +2135,7 @@ void R_Shadow_RenderLighting_Light_Vertex_Pass(const model_t *model, int firstve
                                newe[2] = e[2];
                                newnumtriangles++;
                                newe += 3;
-                               if (newnumtriangles >= 1024)
+                               if (newnumtriangles >= (int)(sizeof(newelements)/sizeof(float[3])))
                                {
                                        R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, newnumtriangles, newelements, 0, 0);
                                        newnumtriangles = 0;
@@ -2032,7 +2146,11 @@ void R_Shadow_RenderLighting_Light_Vertex_Pass(const model_t *model, int firstve
                }
                if (newnumtriangles >= 1)
                {
-                       R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, newnumtriangles, newelements, 0, 0);
+                       // if all triangles are included, use the original array to take advantage of the bufferobject if possible
+                       if (newnumtriangles == numtriangles)
+                               R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset);
+                       else
+                               R_Mesh_Draw(newfirstvertex, newlastvertex - newfirstvertex + 1, newnumtriangles, newelements, 0, 0);
                        stop = false;
                }
                // if we couldn't find any lit triangles, exit early
@@ -2061,7 +2179,7 @@ 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, 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)
+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)
        model_t *model = rsurface_entity->model;
@@ -2081,36 +2199,42 @@ static void R_Shadow_RenderLighting_Light_Vertex(int firstvertex, int numvertice
        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;
        if (r_textureunits.integer >= 2)
        {
                // voodoo2 or TNT
                m.tex[1] = R_GetTexture(r_shadow_attenuation2dtexture);
                m.texmatrix[1] = r_shadow_entitytoattenuationxyz;
                m.pointer_texcoord3f[1] = rsurface_vertex3f;
+               m.pointer_texcoord_bufferobject[1] = rsurface_vertex3f_bufferobject;
+               m.pointer_texcoord_bufferoffset[1] = rsurface_vertex3f_bufferoffset;
                if (r_textureunits.integer >= 3)
                {
                        // 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.pointer_texcoord3f[2] = rsurface_vertex3f;
+                       m.pointer_texcoord_bufferobject[2] = rsurface_vertex3f_bufferobject;
+                       m.pointer_texcoord_bufferoffset[2] = rsurface_vertex3f_bufferoffset;
                }
        }
        R_Mesh_TextureState(&m);
        //R_Mesh_TexBind(0, R_GetTexture(basetexture));
-       R_Shadow_RenderLighting_Light_Vertex_Pass(model, firstvertex, numvertices, numtriangles, element3i, diffusecolorbase, ambientcolorbase);
+       R_Shadow_RenderLighting_Light_Vertex_Pass(model, 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, diffusecolorpants, ambientcolorpants);
+               R_Shadow_RenderLighting_Light_Vertex_Pass(model, 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, diffusecolorshirt, ambientcolorshirt);
+               R_Shadow_RenderLighting_Light_Vertex_Pass(model, firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, diffusecolorshirt, ambientcolorshirt);
        }
 }
 
-void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i)
+void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset)
 {
        float ambientscale, diffusescale, specularscale;
        // FIXME: support MATERIALFLAG_NODEPTHTEST
@@ -2156,16 +2280,16 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles,
                {
                case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
                        GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
-                       R_Shadow_RenderLighting_VisibleLighting(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
+                       R_Shadow_RenderLighting_VisibleLighting(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_GLSL:
-                       R_Shadow_RenderLighting_Light_GLSL(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
+                       R_Shadow_RenderLighting_Light_GLSL(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_DOT3:
-                       R_Shadow_RenderLighting_Light_Dot3(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
+                       R_Shadow_RenderLighting_Light_Dot3(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
-                       R_Shadow_RenderLighting_Light_Vertex(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
+                       R_Shadow_RenderLighting_Light_Vertex(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, lightcolorpants, lightcolorshirt, rsurface_texture->basetexture, rsurface_texture->currentskinframe->pants, rsurface_texture->currentskinframe->shirt, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, dopants, doshirt);
                        break;
                default:
                        Con_Printf("R_Shadow_RenderLighting: unknown r_shadow_rendermode %i\n", r_shadow_rendermode);
@@ -2178,16 +2302,16 @@ void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles,
                {
                case R_SHADOW_RENDERMODE_VISIBLELIGHTING:
                        GL_DepthTest(!(rsurface_texture->currentmaterialflags & MATERIALFLAG_NODEPTHTEST) && !r_showdisabledepthtest.integer);
-                       R_Shadow_RenderLighting_VisibleLighting(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
+                       R_Shadow_RenderLighting_VisibleLighting(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_GLSL:
-                       R_Shadow_RenderLighting_Light_GLSL(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
+                       R_Shadow_RenderLighting_Light_GLSL(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_DOT3:
-                       R_Shadow_RenderLighting_Light_Dot3(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
+                       R_Shadow_RenderLighting_Light_Dot3(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
                        break;
                case R_SHADOW_RENDERMODE_LIGHT_VERTEX:
-                       R_Shadow_RenderLighting_Light_Vertex(firstvertex, numvertices, numtriangles, element3i, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
+                       R_Shadow_RenderLighting_Light_Vertex(firstvertex, numvertices, numtriangles, element3i, element3i_bufferobject, element3i_bufferoffset, lightcolorbase, vec3_origin, vec3_origin, rsurface_texture->basetexture, r_texture_black, r_texture_black, rsurface_texture->currentskinframe->nmap, rsurface_texture->glosstexture, ambientscale, diffusescale, specularscale, false, false);
                        break;
                default:
                        Con_Printf("R_Shadow_RenderLighting: unknown r_shadow_rendermode %i\n", r_shadow_rendermode);
@@ -2526,19 +2650,19 @@ void R_Shadow_DrawWorldShadow(int numsurfaces, int *surfacelist, const unsigned
                for (mesh = r_shadow_rtlight->static_meshchain_shadow;mesh;mesh = mesh->next)
                {
                        r_refdef.stats.lights_shadowtriangles += mesh->numtriangles;
-                       R_Mesh_VertexPointer(mesh->vertex3f, 0, 0);
+                       R_Mesh_VertexPointer(mesh->vertex3f, mesh->vbo, mesh->vbooffset_vertex3f);
                        GL_LockArrays(0, mesh->numverts);
                        if (r_shadow_rendermode == R_SHADOW_RENDERMODE_STENCIL)
                        {
                                // decrement stencil if backface is behind depthbuffer
                                GL_CullFace(GL_BACK); // quake is backwards, this culls front faces
                                qglStencilOp(GL_KEEP, GL_DECR, GL_KEEP);CHECKGLERROR
-                               R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i, 0, 0);
+                               R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i, mesh->ebo, 0);
                                // increment stencil if frontface is behind depthbuffer
                                GL_CullFace(GL_FRONT); // quake is backwards, this culls back faces
                                qglStencilOp(GL_KEEP, GL_INCR, GL_KEEP);CHECKGLERROR
                        }
-                       R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i, 0, 0);
+                       R_Mesh_Draw(0, mesh->numverts, mesh->numtriangles, mesh->element3i, mesh->ebo, 0);
                        GL_LockArrays(0, 0);
                }
                CHECKGLERROR
index 07a6846..963dc5d 100644 (file)
@@ -40,7 +40,7 @@ extern cvar_t gl_ext_stenciltwoside;
 void R_Shadow_Init(void);
 void R_Shadow_VolumeFromList(int numverts, int numtris, const float *invertex3f, const int *elements, const int *neighbors, const vec3_t projectorigin, const vec3_t projectdirection, float projectdistance, int nummarktris, const int *marktris);
 void R_Shadow_MarkVolumeFromBox(int firsttriangle, int numtris, const float *invertex3f, const int *elements, const vec3_t projectorigin, const vec3_t projectdirection, const vec3_t lightmins, const vec3_t lightmaxs, const vec3_t surfacemins, const vec3_t surfacemaxs);
-void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i);
+void R_Shadow_RenderLighting(int firstvertex, int numvertices, int numtriangles, const int *element3i, int element3i_bufferobject, size_t element3i_bufferoffset);
 void R_Shadow_RenderMode_Begin(void);
 void R_Shadow_RenderMode_ActiveLight(rtlight_t *rtlight);
 void R_Shadow_RenderMode_Reset(void);
index e84837f..3b89d21 100644 (file)
--- a/render.h
+++ b/render.h
@@ -206,11 +206,33 @@ typedef enum rsurfmode_e
 }
 rsurfmode_t;
 
+extern float *rsurface_modelvertex3f;
+extern int rsurface_modelvertex3f_bufferobject;
+extern size_t rsurface_modelvertex3f_bufferoffset;
+extern float *rsurface_modelsvector3f;
+extern int rsurface_modelsvector3f_bufferobject;
+extern size_t rsurface_modelsvector3f_bufferoffset;
+extern float *rsurface_modeltvector3f;
+extern int rsurface_modeltvector3f_bufferobject;
+extern size_t rsurface_modeltvector3f_bufferoffset;
+extern float *rsurface_modelnormal3f;
+extern int rsurface_modelnormal3f_bufferobject;
+extern size_t rsurface_modelnormal3f_bufferoffset;
 extern float *rsurface_vertex3f;
+extern int rsurface_vertex3f_bufferobject;
+extern size_t rsurface_vertex3f_bufferoffset;
 extern float *rsurface_svector3f;
+extern int rsurface_svector3f_bufferobject;
+extern size_t rsurface_svector3f_bufferoffset;
 extern float *rsurface_tvector3f;
+extern int rsurface_tvector3f_bufferobject;
+extern size_t rsurface_tvector3f_bufferoffset;
 extern float *rsurface_normal3f;
+extern int rsurface_normal3f_bufferobject;
+extern size_t rsurface_normal3f_bufferoffset;
 extern float *rsurface_lightmapcolor4f;
+extern int rsurface_lightmapcolor4f_bufferobject;
+extern size_t rsurface_lightmapcolor4f_bufferoffset;
 extern vec3_t rsurface_modelorg;
 extern qboolean rsurface_generatedvertex;
 extern const entity_render_t *rsurface_entity;