@@ -2528,7 +2528,7 @@ R_CreateWorldVBO
25282528static void R_CreateWorldVBO () {
25292529 int startTime = ri.Milliseconds ();
25302530
2531- int numVerts = 0 ;
2531+ int numVertsInitial = 0 ;
25322532 int numTriangles = 0 ;
25332533 int numSurfaces = 0 ;
25342534 int numPortals = 0 ;
@@ -2545,23 +2545,20 @@ static void R_CreateWorldVBO() {
25452545 }
25462546
25472547 if ( *surface->data == surfaceType_t::SF_FACE || *surface->data == surfaceType_t::SF_GRID
2548- || *surface->data == surfaceType_t::SF_TRIANGLES )
2549- {
2548+ || *surface->data == surfaceType_t::SF_TRIANGLES ) {
25502549 srfGeneric_t* srf = ( srfGeneric_t* ) surface->data ;
25512550
2552- numVerts += srf->numVerts ;
2551+ numVertsInitial += srf->numVerts ;
25532552 numTriangles += srf->numTriangles ;
2554- }
2555- else
2556- {
2553+ } else {
25572554 continue ;
25582555 }
25592556
25602557 surface->renderable = true ;
25612558 numSurfaces++;
25622559 }
25632560
2564- if ( !numVerts || !numTriangles || !numSurfaces ) {
2561+ if ( !numVertsInitial || !numTriangles || !numSurfaces ) {
25652562 return ;
25662563 }
25672564
@@ -2577,37 +2574,21 @@ static void R_CreateWorldVBO() {
25772574
25782575 OptimiseMapGeometryCore ( &s_worldData, rendererSurfaces, numSurfaces );
25792576
2580- Log::Debug ( " ...calculating world VBO ( %i verts %i tris )" , numVerts , numTriangles );
2577+ Log::Debug ( " ...calculating world VBO ( %i verts %i tris )" , numVertsInitial , numTriangles );
25812578
25822579 // Use srfVert_t for the temporary array used to feed R_CreateStaticVBO, despite containing
25832580 // extraneous data, so that verts can be conveniently be bulk copied from the surface.
2584- srfVert_t* vboVerts = ( srfVert_t* ) ri.Hunk_AllocateTempMemory ( numVerts * sizeof ( srfVert_t ) );
2581+ srfVert_t* vboVerts = ( srfVert_t* ) ri.Hunk_AllocateTempMemory ( numVertsInitial * sizeof ( srfVert_t ) );
25852582 glIndex_t* vboIdxs = ( glIndex_t* ) ri.Hunk_AllocateTempMemory ( 3 * numTriangles * sizeof ( glIndex_t ) );
25862583
2584+ int numVerts;
2585+ int numIndices;
2586+ MergeDuplicateVertices ( rendererSurfaces, numSurfaces, vboVerts, numVertsInitial, vboIdxs, 3 * numTriangles, numVerts, numIndices );
2587+
25872588 if ( glConfig2.usingMaterialSystem ) {
25882589 OptimiseMapGeometryMaterial ( &s_worldData, numSurfaces );
25892590 }
25902591
2591- // set up triangle and vertex arrays
2592- int vboNumVerts = 0 ;
2593- int vboNumIndexes = 0 ;
2594-
2595- for ( int i = 0 ; i < numSurfaces; i++ ) {
2596- bspSurface_t* surface = rendererSurfaces[i];
2597- srfGeneric_t* srf = ( srfGeneric_t* ) surface->data ;
2598-
2599- srf->firstIndex = vboNumIndexes;
2600-
2601- for ( srfTriangle_t* surfTriangle = srf->triangles ; surfTriangle < srf->triangles + srf->numTriangles ; surfTriangle++ ) {
2602- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [0 ];
2603- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [1 ];
2604- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [2 ];
2605- }
2606-
2607- std::copy_n ( srf->verts , srf->numVerts , vboVerts + vboNumVerts );
2608- vboNumVerts += srf->numVerts ;
2609- }
2610-
26112592 s_worldData.numPortals = numPortals;
26122593 s_worldData.portals = ( AABB* ) ri.Hunk_Alloc ( numPortals * sizeof ( AABB ), ha_pref::h_low );
26132594 int portal = 0 ;
@@ -2646,9 +2627,6 @@ static void R_CreateWorldVBO() {
26462627 }
26472628 }
26482629
2649- ASSERT_EQ ( vboNumVerts, numVerts );
2650- ASSERT_EQ ( vboNumIndexes, numTriangles * 3 );
2651-
26522630 vertexAttributeSpec_t attrs[]{
26532631 { ATTR_INDEX_POSITION, GL_FLOAT, GL_FLOAT, &vboVerts[0 ].xyz , 3 , sizeof ( *vboVerts ), 0 },
26542632 { ATTR_INDEX_COLOR, GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE, &vboVerts[0 ].lightColor , 4 , sizeof ( *vboVerts ), ATTR_OPTION_NORMALIZE },
@@ -2657,11 +2635,11 @@ static void R_CreateWorldVBO() {
26572635 };
26582636
26592637 if ( glConfig2.usingGeometryCache ) {
2660- geometryCache.AddMapGeometry ( vboNumVerts, vboNumIndexes , std::begin ( attrs ), std::end ( attrs ), vboIdxs );
2638+ geometryCache.AddMapGeometry ( numVerts, numIndices , std::begin ( attrs ), std::end ( attrs ), vboIdxs );
26612639 }
26622640
26632641 s_worldData.vbo = R_CreateStaticVBO (
2664- " staticWorld_VBO" , std::begin ( attrs ), std::end ( attrs ), vboNumVerts );
2642+ " staticWorld_VBO" , std::begin ( attrs ), std::end ( attrs ), numVerts );
26652643 s_worldData.ibo = R_CreateStaticIBO2 ( " staticWorld_IBO" , numTriangles, vboIdxs );
26662644
26672645 ri.Hunk_FreeTempMemory ( vboIdxs );
0 commit comments