@@ -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,13 +2574,17 @@ 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 srfVert_t* materialVerts = ( srfVert_t* ) ri.Hunk_AllocateTempMemory ( numVerts * sizeof ( srfVert_t ) );
25892590 glIndex_t* materialIdxs = ( glIndex_t* ) ri.Hunk_AllocateTempMemory ( numTriangles * 3 * sizeof ( glIndex_t ) );
@@ -2594,26 +2595,6 @@ static void R_CreateWorldVBO() {
25942595 ri.Hunk_FreeTempMemory ( materialVerts );
25952596 }
25962597
2597- // set up triangle and vertex arrays
2598- int vboNumVerts = 0 ;
2599- int vboNumIndexes = 0 ;
2600-
2601- for ( int i = 0 ; i < numSurfaces; i++ ) {
2602- bspSurface_t* surface = rendererSurfaces[i];
2603- srfGeneric_t* srf = ( srfGeneric_t* ) surface->data ;
2604-
2605- srf->firstIndex = vboNumIndexes;
2606-
2607- for ( srfTriangle_t* surfTriangle = srf->triangles ; surfTriangle < srf->triangles + srf->numTriangles ; surfTriangle++ ) {
2608- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [0 ];
2609- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [1 ];
2610- vboIdxs[vboNumIndexes++] = vboNumVerts + surfTriangle->indexes [2 ];
2611- }
2612-
2613- std::copy_n ( srf->verts , srf->numVerts , vboVerts + vboNumVerts );
2614- vboNumVerts += srf->numVerts ;
2615- }
2616-
26172598 s_worldData.numPortals = numPortals;
26182599 s_worldData.portals = ( AABB* ) ri.Hunk_Alloc ( numPortals * sizeof ( AABB ), ha_pref::h_low );
26192600 int portal = 0 ;
@@ -2652,9 +2633,6 @@ static void R_CreateWorldVBO() {
26522633 }
26532634 }
26542635
2655- ASSERT_EQ ( vboNumVerts, numVerts );
2656- ASSERT_EQ ( vboNumIndexes, numTriangles * 3 );
2657-
26582636 vertexAttributeSpec_t attrs[]{
26592637 { ATTR_INDEX_POSITION, GL_FLOAT, GL_FLOAT, &vboVerts[0 ].xyz , 3 , sizeof ( *vboVerts ), 0 },
26602638 { ATTR_INDEX_COLOR, GL_UNSIGNED_BYTE, GL_UNSIGNED_BYTE, &vboVerts[0 ].lightColor , 4 , sizeof ( *vboVerts ), ATTR_OPTION_NORMALIZE },
@@ -2663,11 +2641,11 @@ static void R_CreateWorldVBO() {
26632641 };
26642642
26652643 if ( glConfig2.usingGeometryCache ) {
2666- geometryCache.AddMapGeometry ( vboNumVerts, vboNumIndexes , std::begin ( attrs ), std::end ( attrs ), vboIdxs );
2644+ geometryCache.AddMapGeometry ( numVerts, numIndices , std::begin ( attrs ), std::end ( attrs ), vboIdxs );
26672645 }
26682646
26692647 s_worldData.vbo = R_CreateStaticVBO (
2670- " staticWorld_VBO" , std::begin ( attrs ), std::end ( attrs ), vboNumVerts );
2648+ " staticWorld_VBO" , std::begin ( attrs ), std::end ( attrs ), numVerts );
26712649 s_worldData.ibo = R_CreateStaticIBO2 ( " staticWorld_IBO" , numTriangles, vboIdxs );
26722650
26732651 ri.Hunk_FreeTempMemory ( vboIdxs );
0 commit comments