| 808 | } |
| 809 | |
| 810 | void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest) |
| 811 | { |
| 812 | PROFILE_GPU_CPU("Debug Draw"); |
| 813 | const RenderView& view = renderContext.View; |
| 814 | SetView(view); |
| 815 | |
| 816 | // Ensure to have shader loaded and any lines to render |
| 817 | const int32 debugDrawDepthTestCount = Context->DebugDrawDepthTest.Count(); |
| 818 | const int32 debugDrawDefaultCount = Context->DebugDrawDefault.Count(); |
| 819 | if (DebugDrawShader == nullptr || !DebugDrawShader->IsLoaded() || debugDrawDepthTestCount + debugDrawDefaultCount == 0 || DebugDrawPsWireTrianglesDepthTest.Depth == nullptr) |
| 820 | return; |
| 821 | if (renderContext.Buffers == nullptr || !DebugDrawVB) |
| 822 | return; |
| 823 | auto context = GPUDevice::Instance->GetMainContext(); |
| 824 | if (Context->Origin != view.Origin) |
| 825 | { |
| 826 | // Teleport existing debug shapes to maintain their location |
| 827 | Float3 delta = Context->Origin - view.Origin; |
| 828 | Context->DebugDrawDefault.Teleport(delta); |
| 829 | Context->DebugDrawDepthTest.Teleport(delta); |
| 830 | Context->Origin = view.Origin; |
| 831 | } |
| 832 | TaaJitterRemoveContext taaJitterRemove(view); |
| 833 | |
| 834 | // Fallback to task buffers |
| 835 | if (target == nullptr && renderContext.Task) |
| 836 | target = renderContext.Task->GetOutputView(); |
| 837 | |
| 838 | // Fill vertex buffer and upload data |
| 839 | DebugDrawCall depthTestLines, defaultLines, depthTestTriangles, defaultTriangles, depthTestWireTriangles, defaultWireTriangles; |
| 840 | { |
| 841 | PROFILE_CPU_NAMED("Update Buffer"); |
| 842 | DebugDrawVB->Clear(); |
| 843 | int32 vertexCounter = 0; |
| 844 | depthTestLines = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultLines, Context->DebugDrawDepthTest.OneFrameLines); |
| 845 | defaultLines = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultLines, Context->DebugDrawDefault.OneFrameLines); |
| 846 | depthTestTriangles = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultTriangles, Context->DebugDrawDepthTest.OneFrameTriangles); |
| 847 | defaultTriangles = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultTriangles, Context->DebugDrawDefault.OneFrameTriangles); |
| 848 | depthTestWireTriangles = WriteLists(vertexCounter, Context->DebugDrawDepthTest.DefaultWireTriangles, Context->DebugDrawDepthTest.OneFrameWireTriangles); |
| 849 | defaultWireTriangles = WriteLists(vertexCounter, Context->DebugDrawDefault.DefaultWireTriangles, Context->DebugDrawDefault.OneFrameWireTriangles); |
| 850 | { |
| 851 | PROFILE_CPU_NAMED("Flush"); |
| 852 | ZoneValue(DebugDrawVB->Data.Count() / 1024); // Size in kB |
| 853 | DebugDrawVB->Flush(context); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | // Update constant buffer |
| 858 | const auto cb = DebugDrawShader->GetShader()->GetCB(0); |
| 859 | ShaderData data; |
| 860 | Matrix vp; |
| 861 | Matrix::Multiply(view.View, view.Projection, vp); |
| 862 | Matrix::Transpose(vp, data.ViewProjection); |
| 863 | data.ClipPosZBias = view.IsPerspectiveProjection() ? -0.2f : 0.0f; // Reduce Z-fighting artifacts (eg. editor grid) |
| 864 | data.EnableDepthTest = enableDepthTest; |
| 865 | context->UpdateCB(cb, &data); |
| 866 | context->BindCB(0, cb); |
| 867 | auto vb = DebugDrawVB->GetBuffer(); |
nothing calls this directly
no test coverage detected