MCPcopy Create free account
hub / github.com/LukasBanana/LLGL / OnDrawFrame

Method OnDrawFrame

examples/Cpp/ClothPhysics/Example.cpp:578–646  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

576 }
577
578 void OnDrawFrame() override
579 {
580 UpdateScene();
581
582 // Record and submit compute commands
583 commands->Begin();
584 {
585 // Update scene state constant buffer
586 commands->UpdateBuffer(*constantBuffer, 0, &sceneState, sizeof(sceneState));
587
588 // Run compute shader to apply particle forces
589 commands->PushDebugGroup("CSForces");
590 {
591 commands->SetPipelineState(*computePipelines[CSForces]);
592 commands->SetResourceHeap(*computeResourceHeap, swapBufferIndex);
593 commands->Dispatch(clothSegmentsU + 1, clothSegmentsV + 1, 1);
594 }
595 commands->PopDebugGroup();
596
597 // Run compute shader to apply stretch constraints with number of integration steps
598 commands->PushDebugGroup("CSStretchConstraints");
599 {
600 commands->SetPipelineState(*computePipelines[CSStretchConstraints]);
601
602 for (std::uint32_t i = 0; i < numSolverIterations; ++i)
603 {
604 if (i > 0)
605 swapBufferIndex = (swapBufferIndex + 1) % 2;
606 commands->SetResourceHeap(*computeResourceHeap, swapBufferIndex);
607 commands->Dispatch(clothSegmentsU + 1, clothSegmentsV + 1, 1);
608 }
609 }
610 commands->PopDebugGroup();
611
612 // Run compute shader to adjust velocity of particles
613 commands->PushDebugGroup("CSRelaxation");
614 {
615 commands->SetPipelineState(*computePipelines[CSRelaxation]);
616 commands->SetResourceHeap(*computeResourceHeap, swapBufferIndex);
617 commands->Dispatch(clothSegmentsU + 1, clothSegmentsV + 1, 1);
618 }
619 commands->PopDebugGroup();
620
621 // Draw scene
622 commands->BeginRenderPass(*swapChain);
623 {
624 // Clear color buffer and set viewport
625 commands->Clear(LLGL::ClearFlags::ColorDepth, backgroundColor);
626 commands->SetViewport(swapChain->GetResolution());
627
628 // Set vertex and index buffers
629 #ifdef ENABLE_STORAGE_TEXTURES
630 commands->SetVertexBuffer(*vertexBufferNull);
631 #else
632 commands->SetVertexBufferArray(*vertexBufferArray);
633 #endif
634
635 commands->SetIndexBuffer(*indexBuffer);

Callers

nothing calls this directly

Calls 15

UpdateSceneFunction · 0.85
BeginMethod · 0.65
UpdateBufferMethod · 0.65
PushDebugGroupMethod · 0.65
SetPipelineStateMethod · 0.65
SetResourceHeapMethod · 0.65
DispatchMethod · 0.65
PopDebugGroupMethod · 0.65
BeginRenderPassMethod · 0.65
ClearMethod · 0.65
SetViewportMethod · 0.65
GetResolutionMethod · 0.65

Tested by

no test coverage detected