From 94bf266d1824659dcf83668e0c67fcfc8cee9850 Mon Sep 17 00:00:00 2001 From: DCFApixels <99481254+DCFApixels@users.noreply.github.com> Date: Fri, 28 Feb 2025 09:47:18 +0800 Subject: [PATCH] fix text render sorting --- Runtime/DebugX.cs | 71 +++++----------------- Runtime/Gizmos/DebugX.text.cs | 15 +---- Runtime/Internal/CommandBufferExecutors.cs | 6 ++ Runtime/Utils/IGizmo.cs | 4 +- 4 files changed, 25 insertions(+), 71 deletions(-) diff --git a/Runtime/DebugX.cs b/Runtime/DebugX.cs index 215f83f..2a2c6e4 100644 --- a/Runtime/DebugX.cs +++ b/Runtime/DebugX.cs @@ -307,8 +307,9 @@ namespace DCFApixels { RenderContextController.StaicContextController.Prepare(); RenderContextController.StaicContextController.Render(cbExecutor); - - CallDrawGizmos(camera); + cbExecutor.Submit(); + RenderContextController.StaicContextController.PostRender(); + RenderContextController.StaicContextController.RunEnd(); } if (camera == null) { return; } @@ -316,54 +317,10 @@ namespace DCFApixels RenderContextController contextController = RenderContextController.GetController(new RenderContext(camera)); contextController.Prepare(); contextController.Render(cbExecutor); - + cbExecutor.Submit(); + contextController.PostRender(); + contextController.RunEnd(); } - -#if UNITY_EDITOR - - [DrawGizmo(GizmoType.NonSelected | GizmoType.Selected)] - private static void DrawGizmos(Camera obj, GizmoType gizmoType) - { - if (obj != Camera.main) { return; } - - //if (_lastEditorToRenderGizmosTicks != _editorTicks) - //{ - // _renderGizmosTicks++; - // _lastEditorToRenderGizmosTicks = _editorTicks; - //} - - //Camera camera = Camera.current; - //CallDrawGizmos(camera); - } -#endif - - private static void CallDrawGizmos(Camera camera) - { - - Color guiColor = GUI.color; - Color guiContextColor = GUI.contentColor; - Color guiBackgroundColor = GUI.backgroundColor; - Color gizmosColor = Gizmos.color; -#if Handles - Color handlesColor = Handles.color; - GL.MultMatrix(Handles.matrix); -#endif - - RenderContextController.StaicContextController.Render_UnityGizmos(); - - if (camera == null) { return; } - _currentCamera = camera; - RenderContextController.GetController(new RenderContext(camera)).Render_UnityGizmos(); - - GUI.color = guiColor; - GUI.contentColor = guiContextColor; - GUI.backgroundColor = guiBackgroundColor; - Gizmos.color = gizmosColor; -#if Handles - Handles.color = handlesColor; -#endif - } - #endregion @@ -586,13 +543,13 @@ namespace DCFApixels _buffers[i].Render(cbExecutor); } - RunEnd(); + //RunEnd(); } } [IN(LINE)] - public void Render_UnityGizmos() + public void PostRender() { #if UNITY_EDITOR using (_cameraMarker.Auto()) @@ -600,7 +557,7 @@ namespace DCFApixels { for (int i = 0, iMax = _buffers.Count; i < iMax; i++) { - _buffers[i].Render_UnityGizmos(); + _buffers[i].PostRender(); } //RunEnd(); @@ -631,7 +588,7 @@ namespace DCFApixels public abstract int UpdateTimer(float deltaTime); public abstract void Prepare(); public abstract void Render(ICommandBufferExecutor cbExecutor); - public abstract void Render_UnityGizmos(); + public abstract void PostRender(); public abstract int RunEnd(); public abstract void Clear(); } @@ -654,7 +611,7 @@ namespace DCFApixels //private readonly CommandBuffer _dynamicCommandBuffer; private readonly IGizmoRenderer _renderer; - private readonly IGizmoRenderer_UnityGizmos _rendererUnityGizmos; + private readonly IGizmoRenderer_PostRender _rendererUnityGizmos; private readonly bool _isStatic; #if DEV_MODE @@ -681,7 +638,7 @@ namespace DCFApixels _renderer = new DummyRenderer(); } _isStatic = _renderer.IsStaticRender; - _rendererUnityGizmos = _renderer as IGizmoRenderer_UnityGizmos; + _rendererUnityGizmos = _renderer as IGizmoRenderer_PostRender; All.Add(this); All.Sort((a, b) => a.ExecuteOrder - b.ExecuteOrder); @@ -800,7 +757,7 @@ namespace DCFApixels cbExecutor.Execute(_staticCommandBuffer); } } - public override void Render_UnityGizmos() + public override void PostRender() { if (_rendererUnityGizmos == null) { return; } //Debug.Log(_gizmos._count); @@ -812,7 +769,7 @@ namespace DCFApixels GizmosList list = GizmosList.From(_gizmos._items, _gizmos._count); try { - _rendererUnityGizmos.Render_UnityGizmos(GetCurrentCamera(), list); + _rendererUnityGizmos.PostRender(GetCurrentCamera(), list); } catch (Exception e) { throw new Exception($"[{_debugName}] [Render] ", e); } } diff --git a/Runtime/Gizmos/DebugX.text.cs b/Runtime/Gizmos/DebugX.text.cs index d74257b..22aade5 100644 --- a/Runtime/Gizmos/DebugX.text.cs +++ b/Runtime/Gizmos/DebugX.text.cs @@ -37,7 +37,7 @@ namespace DCFApixels public IGizmoRenderer RegisterNewRenderer() { return new Renderer(); } #region Renderer - private class Renderer : IGizmoRenderer + private class Renderer : IGizmoRenderer_PostRender { private static GUIStyle _labelStyle; private static GUIContent _labelDummy; @@ -45,11 +45,8 @@ namespace DCFApixels public int ExecuteOrder => default(UnlitMat).GetExecuteOrder(); public bool IsStaticRender => false; public void Prepare(Camera camera, GizmosList list) { } - public void Render(Camera camera, GizmosList list, CommandBuffer cb) - { - Render_UnityGizmos(camera, list); - } - public void Render_UnityGizmos(Camera camera, GizmosList list) + public void Render(Camera camera, GizmosList list, CommandBuffer cb) { } + public void PostRender(Camera camera, GizmosList list) { if (Event.current.type != EventType.Repaint) { return; } Color dfColor = GUI.color; @@ -88,19 +85,13 @@ namespace DCFApixels { Rect rect = WorldPointToSizedRect(camera, item.Value.Position, _labelDummy, _labelStyle); - - - Color c = item.Value.Settings.BackgroundColor * GlobalColor; - GUI.color = c; var mat = DebugXAssets.Materials.Unlit; mat.SetColor(ColorPropertyID, c); Graphics.DrawTexture(rect, _whiteTexture, mat); GUI.color = item.Color * GlobalColor; style.Draw(rect, _labelDummy, false, false, false, false); - - } } GUI.color = dfColor; diff --git a/Runtime/Internal/CommandBufferExecutors.cs b/Runtime/Internal/CommandBufferExecutors.cs index af78f59..506d42f 100644 --- a/Runtime/Internal/CommandBufferExecutors.cs +++ b/Runtime/Internal/CommandBufferExecutors.cs @@ -7,6 +7,7 @@ namespace DCFApixels.DebugXCore.Internal internal interface ICommandBufferExecutor { void Execute(CommandBuffer cb); + void Submit(); } internal class CommandBufferExecutorSRP : ICommandBufferExecutor { @@ -24,6 +25,10 @@ namespace DCFApixels.DebugXCore.Internal { RenderContext.ExecuteCommandBuffer(cb); } + public void Submit() + { + RenderContext.Submit(); + } } internal class CommandBufferExecutorBRP : ICommandBufferExecutor { @@ -39,5 +44,6 @@ namespace DCFApixels.DebugXCore.Internal { Graphics.ExecuteCommandBuffer(cb); } + public void Submit() { } } } \ No newline at end of file diff --git a/Runtime/Utils/IGizmo.cs b/Runtime/Utils/IGizmo.cs index e1073c0..e692740 100644 --- a/Runtime/Utils/IGizmo.cs +++ b/Runtime/Utils/IGizmo.cs @@ -17,9 +17,9 @@ namespace DCFApixels.DebugXCore void Prepare(Camera camera, GizmosList list); void Render(Camera camera, GizmosList list, CommandBuffer cb); } - public interface IGizmoRenderer_UnityGizmos : IGizmoRenderer where T : IGizmo + public interface IGizmoRenderer_PostRender : IGizmoRenderer where T : IGizmo { - void Render_UnityGizmos(Camera camera, GizmosList list); + void PostRender(Camera camera, GizmosList list); }