/// <inheritdoc /> public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output) { Profiler.BeginEventGPU("Editor Primitives"); // Prepare var renderList = RenderList.GetFromPool(); var prevList = renderContext.List; renderContext.List = renderList; renderContext.View.Pass = DrawPass.Forward; // Bind output float width = input.Width; float height = input.Height; context.SetViewport(width, height); var depthBuffer = renderContext.Buffers.DepthBuffer; var depthBufferHandle = depthBuffer.View(); if ((depthBuffer.Flags & GPUTextureFlags.ReadOnlyDepthView) == GPUTextureFlags.ReadOnlyDepthView) { depthBufferHandle = depthBuffer.ViewReadOnlyDepth(); } context.SetRenderTarget(depthBufferHandle, input.View()); // Collect draw calls for (int i = 0; i < Level.ScenesCount; i++) { var scene = Level.GetScene(i); ViewportIconsRenderer.DrawIcons(ref renderContext, scene); } // Sort draw calls renderList.SortDrawCalls(ref renderContext, true, DrawCallsListType.Forward); // Perform the rendering renderList.ExecuteDrawCalls(ref renderContext, DrawCallsListType.Forward); // Cleanup RenderList.ReturnToPool(renderList); renderContext.List = prevList; Profiler.EndEventGPU(); }
/// <inheritdoc /> public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output) { if (Viewport == null) { throw new NullReferenceException(); } Profiler.BeginEventGPU("Editor Primitives"); // Check if use MSAA var format = output.Format; var formatFeatures = GPUDevice.Instance.GetFormatFeatures(format); bool enableMsaa = formatFeatures.MSAALevelMax >= MSAALevel.X4 && Editor.Instance.Options.Options.Visual.EnableMSAAForDebugDraw; // Prepare var msaaLevel = enableMsaa ? MSAALevel.X4 : MSAALevel.None; var width = output.Width; var height = output.Height; var desc = GPUTextureDescription.New2D(width, height, format, GPUTextureFlags.RenderTarget | GPUTextureFlags.ShaderResource, 1, 1, msaaLevel); var target = RenderTargetPool.Get(ref desc); desc = GPUTextureDescription.New2D(width, height, PixelFormat.D24_UNorm_S8_UInt, GPUTextureFlags.DepthStencil, 1, 1, msaaLevel); var targetDepth = RenderTargetPool.Get(ref desc); // Copy frame and clear depth context.Draw(target, input); context.ClearDepth(targetDepth.View()); context.SetViewport(width, height); context.SetRenderTarget(targetDepth.View(), target.View()); // Draw gizmos and other editor primitives var renderList = RenderList.GetFromPool(); var prevList = renderContext.List; renderContext.List = renderList; for (int i = 0; i < Viewport.Gizmos.Count; i++) { Viewport.Gizmos[i].Draw(ref renderContext); } Viewport.DrawEditorPrimitives(context, ref renderContext, target, targetDepth); // Sort draw calls renderList.SortDrawCalls(ref renderContext, false, DrawCallsListType.GBuffer); renderList.SortDrawCalls(ref renderContext, false, DrawCallsListType.GBufferNoDecals); renderList.SortDrawCalls(ref renderContext, true, DrawCallsListType.Forward); // Perform the rendering renderContext.View.Pass = DrawPass.GBuffer; renderList.ExecuteDrawCalls(ref renderContext, DrawCallsListType.GBuffer); renderList.ExecuteDrawCalls(ref renderContext, DrawCallsListType.GBufferNoDecals); renderContext.View.Pass = DrawPass.Forward; renderList.ExecuteDrawCalls(ref renderContext, DrawCallsListType.Forward); // Resolve MSAA texture if (enableMsaa) { context.ResolveMultisample(target, output); } else { context.Draw(output, target); } // Cleanup RenderTargetPool.Release(targetDepth); RenderTargetPool.Release(target); RenderList.ReturnToPool(renderList); renderContext.List = prevList; Profiler.EndEventGPU(); }