@@ -387,8 +387,6 @@ void UpdateSurfaceDataFog( uint32_t* materials, shaderStage_t* pStage, bool, boo
387387void MaterialSystem::GenerateWorldMaterialsBuffer () {
388388 Log::Debug ( " Generating materials buffer" );
389389
390- materialsUBO.BindBuffer ();
391-
392390 // Sort by padded size to avoid extra padding
393391 std::sort ( materialStages.begin (), materialStages.end (),
394392 [&]( const shaderStage_t* lhs, const shaderStage_t* rhs ) {
@@ -431,7 +429,7 @@ void MaterialSystem::GenerateWorldMaterialsBuffer() {
431429 totalStageSize = offset;
432430
433431 // 4 bytes per component
434- glBufferData ( GL_UNIFORM_BUFFER, offset * sizeof ( uint32_t ) , nullptr , GL_DYNAMIC_DRAW );
432+ materialsUBO. BufferData ( offset, nullptr , GL_DYNAMIC_DRAW );
435433 uint32_t * materialsData = materialsUBO.MapBufferRange ( offset );
436434
437435 GenerateMaterialsBuffer ( materialStages, offset, materialsData );
@@ -565,11 +563,9 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
565563
566564 Log::Debug ( " Total batch count: %u" , totalBatchCount );
567565
568- surfaceDescriptorsSSBO.BindBuffer ();
569566 surfaceDescriptorsCount = totalDrawSurfs;
570567 descriptorSize = BOUNDING_SPHERE_SIZE + maxStages;
571- glBufferData ( GL_SHADER_STORAGE_BUFFER, surfaceDescriptorsCount * descriptorSize * sizeof ( uint32_t ),
572- nullptr , GL_STATIC_DRAW );
568+ surfaceDescriptorsSSBO.BufferData ( surfaceDescriptorsCount * descriptorSize, nullptr , GL_STATIC_DRAW );
573569 uint32_t * surfaceDescriptors = surfaceDescriptorsSSBO.MapBufferRange ( surfaceDescriptorsCount * descriptorSize );
574570
575571 texDataBufferType = glConfig2.maxUniformBlockSize >= MIN_MATERIAL_UBO_SIZE ? GL_UNIFORM_BUFFER : GL_SHADER_STORAGE_BUFFER;
@@ -593,20 +589,20 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
593589
594590 lightMapDataUBO.BufferStorage ( MAX_LIGHTMAPS * LIGHTMAP_SIZE, 1 , nullptr );
595591 lightMapDataUBO.MapAll ();
596- uint64_t * lightmapData = ( uint64_t * ) lightMapDataUBO.GetData ();
597- memset ( lightmapData , 0 , MAX_LIGHTMAPS * LIGHTMAP_SIZE * sizeof ( uint32_t ) );
592+ uint64_t * lightMapData = ( uint64_t * ) lightMapDataUBO.GetData ();
593+ memset ( lightMapData , 0 , MAX_LIGHTMAPS * LIGHTMAP_SIZE * sizeof ( uint32_t ) );
598594
599595 for ( uint32_t i = 0 ; i < tr.lightmaps .size (); i++ ) {
600596 if ( !tr.lightmaps [i]->texture ->hasBindlessHandle ) {
601597 tr.lightmaps [i]->texture ->GenBindlessHandle ();
602598 }
603- lightmapData [i * 2 ] = tr.lightmaps [i]->texture ->bindlessTextureHandle ;
599+ lightMapData [i * 2 ] = tr.lightmaps [i]->texture ->bindlessTextureHandle ;
604600 }
605601 for ( uint32_t i = 0 ; i < tr.deluxemaps .size (); i++ ) {
606602 if ( !tr.deluxemaps [i]->texture ->hasBindlessHandle ) {
607603 tr.deluxemaps [i]->texture ->GenBindlessHandle ();
608604 }
609- lightmapData [i * 2 + 1 ] = tr.deluxemaps [i]->texture ->bindlessTextureHandle ;
605+ lightMapData [i * 2 + 1 ] = tr.deluxemaps [i]->texture ->bindlessTextureHandle ;
610606 }
611607
612608 ASSERT_LE ( tr.lightmaps .size (), 256 ); // Engine supports up to 256 lightmaps currently, so we use 8 bits to address them
@@ -624,16 +620,15 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
624620 tr.blackImage ->texture ->GenBindlessHandle ();
625621 }
626622 // Use lightmap 255 for drawSurfs that use a full white image for their lightmap
627- lightmapData [255 * 2 ] = tr.whiteImage ->texture ->bindlessTextureHandle ;
628- lightmapData [255 * 2 + 1 ] = tr.blackImage ->texture ->bindlessTextureHandle ;
623+ lightMapData [255 * 2 ] = tr.whiteImage ->texture ->bindlessTextureHandle ;
624+ lightMapData [255 * 2 + 1 ] = tr.blackImage ->texture ->bindlessTextureHandle ;
629625 }
630626
631627 lightMapDataUBO.FlushAll ();
632628 lightMapDataUBO.UnmapBuffer ();
633629
634630 surfaceCommandsCount = totalBatchCount * SURFACE_COMMANDS_PER_BATCH;
635631
636- surfaceCommandsSSBO.BindBuffer ();
637632 surfaceCommandsSSBO.BufferStorage ( surfaceCommandsCount * SURFACE_COMMAND_SIZE * MAX_VIEWFRAMES, 1 , nullptr );
638633 surfaceCommandsSSBO.MapAll ();
639634 SurfaceCommand* surfaceCommands = ( SurfaceCommand* ) surfaceCommandsSSBO.GetData ();
@@ -645,12 +640,11 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
645640 memset ( culledCommands, 0 , surfaceCommandsCount * sizeof ( GLIndirectBuffer::GLIndirectCommand ) * MAX_VIEWFRAMES );
646641 culledCommandsBuffer.FlushAll ();
647642
648- surfaceBatchesUBO.BindBuffer ();
649- glBufferData ( GL_UNIFORM_BUFFER, MAX_SURFACE_COMMAND_BATCHES * sizeof ( SurfaceCommandBatch ), nullptr , GL_STATIC_DRAW );
643+ surfaceBatchesUBO.BufferData ( MAX_SURFACE_COMMAND_BATCHES * SURFACE_COMMAND_BATCH_SIZE, nullptr , GL_STATIC_DRAW );
650644 SurfaceCommandBatch* surfaceCommandBatches =
651645 ( SurfaceCommandBatch* ) surfaceBatchesUBO.MapBufferRange ( MAX_SURFACE_COMMAND_BATCHES * SURFACE_COMMAND_BATCH_SIZE );
652646
653- // memset( (void*) surfaceCommandBatches, 0, MAX_SURFACE_COMMAND_BATCHES * sizeof( SurfaceCommandBatch ) );
647+ // memset( (void*) surfaceCommandBatches, 0, MAX_SURFACE_COMMAND_BATCHES * SURFACE_COMMAND_BATCH_SIZE );
654648 // Fuck off gcc
655649 for ( int i = 0 ; i < MAX_SURFACE_COMMAND_BATCHES; i++ ) {
656650 surfaceCommandBatches[i] = {};
@@ -679,8 +673,7 @@ void MaterialSystem::GenerateWorldCommandBuffer() {
679673 if ( r_materialDebug.Get () ) {
680674 const uint32_t debugSize = surfaceCommandsCount * 20 ;
681675
682- debugSSBO.BindBuffer ();
683- glBufferData ( GL_SHADER_STORAGE_BUFFER, debugSize * sizeof ( uint32_t ), nullptr , GL_STATIC_DRAW );
676+ debugSSBO.BufferData ( debugSize, nullptr , GL_STATIC_DRAW );
684677 uint32_t * debugBuffer = debugSSBO.MapBufferRange ( debugSize );
685678 memset ( debugBuffer, 0 , debugSize * sizeof ( uint32_t ) );
686679 debugSSBO.UnmapBuffer ();
@@ -1594,7 +1587,6 @@ void MaterialSystem::AddStageTextures( drawSurf_t* drawSurf, const uint32_t stag
15941587// Dynamic surfaces are those whose values in the SSBO can be updated
15951588void MaterialSystem::UpdateDynamicSurfaces () {
15961589 if ( dynamicStagesSize > 0 ) {
1597- materialsUBO.BindBuffer ();
15981590 uint32_t * materialsData = materialsUBO.MapBufferRange ( dynamicStagesOffset, dynamicStagesSize );
15991591
16001592 GenerateMaterialsBuffer ( dynamicStages, dynamicStagesSize, materialsData );
@@ -1603,16 +1595,15 @@ void MaterialSystem::UpdateDynamicSurfaces() {
16031595 }
16041596
16051597 if ( dynamicTexDataSize > 0 ) {
1606- texDataBuffer.BindBuffer ( texDataBufferType );
1607- GL_CheckErrors ();
16081598 TexBundle* textureBundles =
16091599 ( TexBundle* ) texDataBuffer.MapBufferRange ( dynamicTexDataOffset, dynamicTexDataSize );
1610- GL_CheckErrors ();
16111600
16121601 GenerateTexturesBuffer ( dynamicTexData, textureBundles );
16131602
16141603 texDataBuffer.UnmapBuffer ();
16151604 }
1605+
1606+ GL_CheckErrors ();
16161607}
16171608
16181609void MaterialSystem::UpdateFrameData () {
@@ -1855,10 +1846,8 @@ void MaterialSystem::GeneratePortalBoundingSpheres() {
18551846 index++;
18561847 }
18571848
1858- portalSurfacesSSBO.BindBuffer ();
18591849 portalSurfacesSSBO.BufferStorage ( totalPortals * PORTAL_SURFACE_SIZE * MAX_VIEWS, 2 , portalSurfs );
18601850 portalSurfacesSSBO.MapAll ();
1861- portalSurfacesSSBO.UnBindBuffer ();
18621851
18631852 portalSurfacesTmp.clear ();
18641853}
0 commit comments