@@ -315,13 +315,13 @@ void MergeDuplicateVertices( bspSurface_t** rendererSurfaces, int numSurfaces, s
315315 srfVert_t& vert = face->verts [triangle->indexes [j]];
316316 uint32_t index = verts[vert];
317317
318- ASSERT_LT ( idx, numIndicesIn );
318+ ASSERT_LT ( idx, ( uint32_t ) numIndicesIn );
319319 if ( !index ) {
320320 verts[vert] = vertIdx + 1 ;
321321 vertices[vertIdx] = vert;
322322 indices[idx] = vertIdx;
323323
324- ASSERT_LT ( vertIdx, numVerticesIn );
324+ ASSERT_LT ( vertIdx, ( uint32_t ) numVerticesIn );
325325
326326 vertIdx++;
327327 } else {
@@ -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 (bspSurface_t** rendererSurfaces , int numSurfaces ) {
360360 std::vector<MaterialSurface> materialSurfaces;
361361 materialSurfaces.reserve ( numSurfaces );
362362
@@ -365,24 +365,43 @@ std::vector<MaterialSurface> OptimiseMapGeometryMaterial( world_t* world, int nu
365365
366366 // std::unordered_map<TriEdge, TriIndex> triEdges;
367367
368- int surfaceIndex = 0 ;
369- for ( int k = 0 ; k < world->numSurfaces ; k++ ) {
370- bspSurface_t* surface = &world->surfaces [k];
368+ vec3_t worldBounds[2 ] = {};
369+ for ( int i = 0 ; i < numSurfaces; i++ ) {
370+ bspSurface_t* surface = rendererSurfaces[i];
371+
372+ if ( surface->BSPModel ) {
373+ // Not implemented yet
374+ continue ;
375+ }
371376
372377 MaterialSurface srf {};
373378
374379 srf.shader = surface->shader ;
375380 srf.bspSurface = true ;
381+ srf.lightMapNum = surface->lightmapNum ;
376382 srf.fog = surface->fogIndex ;
383+ srf.portalNum = surface->portalNum ;
377384
378385 srf.firstIndex = ( ( srfGeneric_t* ) surface->data )->firstIndex ;
379- srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles ;
386+ srf.count = ( ( srfGeneric_t* ) surface->data )->numTriangles * 3 ;
380387 srf.verts = ( ( srfGeneric_t* ) surface->data )->verts ;
381388 srf.tris = ( ( srfGeneric_t* ) surface->data )->triangles ;
382389
390+ VectorCopy ( ( ( srfGeneric_t* ) surface->data )->origin , srf.origin );
391+ srf.radius = ( ( srfGeneric_t* ) surface->data )->radius ;
392+
393+ BoundsAdd ( worldBounds[0 ], worldBounds[1 ],
394+ ( ( srfGeneric_t* ) surface->data )->bounds [0 ], ( ( srfGeneric_t* ) surface->data )->bounds [1 ] );
395+
396+ materialSystem.GenerateMaterial ( &srf );
397+
383398 materialSurfaces.emplace_back ( srf );
384- surfaceIndex++;
385399 }
386400
401+ materialSystem.GenerateWorldMaterialsBuffer ();
402+ materialSystem.GeneratePortalBoundingSpheres ();
403+ materialSystem.SetWorldBounds ( worldBounds );
404+ materialSystem.GenerateWorldCommandBuffer ( materialSurfaces );
405+
387406 return materialSurfaces;
388407}
0 commit comments