@@ -356,7 +356,7 @@ void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, s
356356 }
357357} */
358358
359- std::vector<MaterialSurface> OptimiseMapGeometryMaterial ( world_t * world, int numSurfaces ) {
359+ std::vector<MaterialSurface> OptimiseMapGeometryMaterial ( world_t * world, bspSurface_t** rendererSurfaces, int numSurfaces ) {
360360 std::vector<MaterialSurface> materialSurfaces;
361361 materialSurfaces.reserve ( numSurfaces );
362362
@@ -366,23 +366,44 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int nu
366366 // std::unordered_map<TriEdge, TriIndex> triEdges;
367367
368368 int surfaceIndex = 0 ;
369- for ( int k = 0 ; k < world->numSurfaces ; k++ ) {
370- bspSurface_t* surface = &world->surfaces [k];
369+ vec3_t worldBounds[2 ] = {};
370+ for ( int i = 0 ; i < numSurfaces; i++ ) {
371+ bspSurface_t* surface = rendererSurfaces[i];
372+
373+ if ( surface->BSPModel ) {
374+ // Not implemented yet
375+ continue ;
376+ }
371377
372378 MaterialSurface srf {};
373379
374380 srf.shader = surface->shader ;
375381 srf.bspSurface = true ;
382+ srf.lightMapNum = surface->lightmapNum ;
376383 srf.fog = surface->fogIndex ;
384+ srf.portalNum = surface->portalNum ;
377385
378386 srf.firstIndex = ( ( srfGeneric_t* ) surface->data )->firstIndex ;
379- srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles ;
387+ srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles * 3 ;
380388 srf.verts = ( ( srfGeneric_t* ) surface->data )->verts ;
381389 srf.tris = ( ( srfGeneric_t* ) surface->data )->triangles ;
382390
391+ VectorCopy ( ( ( srfGeneric_t* ) surface->data )->origin , srf.origin );
392+ srf.radius = ( ( srfGeneric_t* ) surface->data )->radius ;
393+
394+ BoundsAdd ( worldBounds[0 ], worldBounds[1 ],
395+ ( ( srfGeneric_t* ) surface->data )->bounds [0 ], ( ( srfGeneric_t* ) surface->data )->bounds [1 ] );
396+
397+ materialSystem.GenerateMaterial ( &srf );
398+
383399 materialSurfaces.emplace_back ( srf );
384400 surfaceIndex++;
385401 }
386402
403+ materialSystem.GenerateWorldMaterialsBuffer ();
404+ materialSystem.GeneratePortalBoundingSpheres ();
405+ materialSystem.SetWorldBounds ( worldBounds );
406+ materialSystem.GenerateWorldCommandBuffer ( materialSurfaces );
407+
387408 return materialSurfaces;
388409}
0 commit comments