Advertisement
Zgragselus

Render batch

Nov 12th, 2022
1,084
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.64 KB | None | 0 0
  1.         // GpuMappedBuffer approach
  2.         bool matused = false;
  3.         int batchBound = -1;
  4.         for (const Engine::RenderNode& node : nodes)
  5.         {
  6.             bool hasMaterial = false;
  7.             int batch = node.mID / 16;
  8.  
  9.             if (node.mObject->Has<Engine::MaterialComponent>())
  10.             {
  11.                 context->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(1, node.mObject->Get<Engine::MaterialComponent>()->GetDiffuseMap()->GetSRV().mGpuHandle);
  12.                 context->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(2, node.mObject->Get<Engine::MaterialComponent>()->GetNormalsMap()->GetSRV().mGpuHandle);
  13.                 context->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(3, node.mObject->Get<Engine::MaterialComponent>()->GetMetallicMap()->GetSRV().mGpuHandle);
  14.                 context->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(4, node.mObject->Get<Engine::MaterialComponent>()->GetRoughnessMap()->GetSRV().mGpuHandle);
  15.                 context->GetCommandList()->Get()->SetGraphicsRootDescriptorTable(5, node.mObject->Get<Engine::MaterialComponent>()->GetHeightMap()->GetSRV().mGpuHandle);
  16.                 hasMaterial = true;
  17.                 matused = true;
  18.             }
  19.  
  20.             if (node.mObject->Has<Engine::MeshComponent>() && hasMaterial)
  21.             {
  22.                 if (batchBound != batch)
  23.                 {
  24.                     batchBound = batch;
  25.                     context->SetConstantBuffer(6, matrices->GetGpuVirtualAddress(batch * 16 * sizeof(float) * 16 * 2));
  26.                 }
  27.                 context->SetConstants(7, Engine::DWParam(node.mID % 16));
  28.  
  29.                 node.mObject->Get<Engine::MeshComponent>()->GetMesh()->Render(context);
  30.             }
  31.         }
  32.  
  33.         // StructuredBuffer approach
  34.         for (const Engine::RenderNode& node : nodes)
  35.         {
  36.             node.mObject->Get<Engine::MeshComponent>()->GetMesh()->Render(context);
  37.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement