fix text render sorting

This commit is contained in:
DCFApixels 2025-02-28 09:47:18 +08:00
parent c91c27c1cb
commit 94bf266d18
4 changed files with 25 additions and 71 deletions

View File

@ -307,8 +307,9 @@ namespace DCFApixels
{ {
RenderContextController.StaicContextController.Prepare(); RenderContextController.StaicContextController.Prepare();
RenderContextController.StaicContextController.Render(cbExecutor); RenderContextController.StaicContextController.Render(cbExecutor);
cbExecutor.Submit();
CallDrawGizmos(camera); RenderContextController.StaicContextController.PostRender();
RenderContextController.StaicContextController.RunEnd();
} }
if (camera == null) { return; } if (camera == null) { return; }
@ -316,54 +317,10 @@ namespace DCFApixels
RenderContextController contextController = RenderContextController.GetController(new RenderContext(camera)); RenderContextController contextController = RenderContextController.GetController(new RenderContext(camera));
contextController.Prepare(); contextController.Prepare();
contextController.Render(cbExecutor); 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 #endregion
@ -586,13 +543,13 @@ namespace DCFApixels
_buffers[i].Render(cbExecutor); _buffers[i].Render(cbExecutor);
} }
RunEnd(); //RunEnd();
} }
} }
[IN(LINE)] [IN(LINE)]
public void Render_UnityGizmos() public void PostRender()
{ {
#if UNITY_EDITOR #if UNITY_EDITOR
using (_cameraMarker.Auto()) using (_cameraMarker.Auto())
@ -600,7 +557,7 @@ namespace DCFApixels
{ {
for (int i = 0, iMax = _buffers.Count; i < iMax; i++) for (int i = 0, iMax = _buffers.Count; i < iMax; i++)
{ {
_buffers[i].Render_UnityGizmos(); _buffers[i].PostRender();
} }
//RunEnd(); //RunEnd();
@ -631,7 +588,7 @@ namespace DCFApixels
public abstract int UpdateTimer(float deltaTime); public abstract int UpdateTimer(float deltaTime);
public abstract void Prepare(); public abstract void Prepare();
public abstract void Render(ICommandBufferExecutor cbExecutor); public abstract void Render(ICommandBufferExecutor cbExecutor);
public abstract void Render_UnityGizmos(); public abstract void PostRender();
public abstract int RunEnd(); public abstract int RunEnd();
public abstract void Clear(); public abstract void Clear();
} }
@ -654,7 +611,7 @@ namespace DCFApixels
//private readonly CommandBuffer _dynamicCommandBuffer; //private readonly CommandBuffer _dynamicCommandBuffer;
private readonly IGizmoRenderer<T> _renderer; private readonly IGizmoRenderer<T> _renderer;
private readonly IGizmoRenderer_UnityGizmos<T> _rendererUnityGizmos; private readonly IGizmoRenderer_PostRender<T> _rendererUnityGizmos;
private readonly bool _isStatic; private readonly bool _isStatic;
#if DEV_MODE #if DEV_MODE
@ -681,7 +638,7 @@ namespace DCFApixels
_renderer = new DummyRenderer(); _renderer = new DummyRenderer();
} }
_isStatic = _renderer.IsStaticRender; _isStatic = _renderer.IsStaticRender;
_rendererUnityGizmos = _renderer as IGizmoRenderer_UnityGizmos<T>; _rendererUnityGizmos = _renderer as IGizmoRenderer_PostRender<T>;
All.Add(this); All.Add(this);
All.Sort((a, b) => a.ExecuteOrder - b.ExecuteOrder); All.Sort((a, b) => a.ExecuteOrder - b.ExecuteOrder);
@ -800,7 +757,7 @@ namespace DCFApixels
cbExecutor.Execute(_staticCommandBuffer); cbExecutor.Execute(_staticCommandBuffer);
} }
} }
public override void Render_UnityGizmos() public override void PostRender()
{ {
if (_rendererUnityGizmos == null) { return; } if (_rendererUnityGizmos == null) { return; }
//Debug.Log(_gizmos._count); //Debug.Log(_gizmos._count);
@ -812,7 +769,7 @@ namespace DCFApixels
GizmosList<T> list = GizmosList.From(_gizmos._items, _gizmos._count); GizmosList<T> list = GizmosList.From(_gizmos._items, _gizmos._count);
try try
{ {
_rendererUnityGizmos.Render_UnityGizmos(GetCurrentCamera(), list); _rendererUnityGizmos.PostRender(GetCurrentCamera(), list);
} }
catch (Exception e) { throw new Exception($"[{_debugName}] [Render] ", e); } catch (Exception e) { throw new Exception($"[{_debugName}] [Render] ", e); }
} }

View File

@ -37,7 +37,7 @@ namespace DCFApixels
public IGizmoRenderer<TextGizmo> RegisterNewRenderer() { return new Renderer(); } public IGizmoRenderer<TextGizmo> RegisterNewRenderer() { return new Renderer(); }
#region Renderer #region Renderer
private class Renderer : IGizmoRenderer<TextGizmo> private class Renderer : IGizmoRenderer_PostRender<TextGizmo>
{ {
private static GUIStyle _labelStyle; private static GUIStyle _labelStyle;
private static GUIContent _labelDummy; private static GUIContent _labelDummy;
@ -45,11 +45,8 @@ namespace DCFApixels
public int ExecuteOrder => default(UnlitMat).GetExecuteOrder(); public int ExecuteOrder => default(UnlitMat).GetExecuteOrder();
public bool IsStaticRender => false; public bool IsStaticRender => false;
public void Prepare(Camera camera, GizmosList<TextGizmo> list) { } public void Prepare(Camera camera, GizmosList<TextGizmo> list) { }
public void Render(Camera camera, GizmosList<TextGizmo> list, CommandBuffer cb) public void Render(Camera camera, GizmosList<TextGizmo> list, CommandBuffer cb) { }
{ public void PostRender(Camera camera, GizmosList<TextGizmo> list)
Render_UnityGizmos(camera, list);
}
public void Render_UnityGizmos(Camera camera, GizmosList<TextGizmo> list)
{ {
if (Event.current.type != EventType.Repaint) { return; } if (Event.current.type != EventType.Repaint) { return; }
Color dfColor = GUI.color; Color dfColor = GUI.color;
@ -88,19 +85,13 @@ namespace DCFApixels
{ {
Rect rect = WorldPointToSizedRect(camera, item.Value.Position, _labelDummy, _labelStyle); Rect rect = WorldPointToSizedRect(camera, item.Value.Position, _labelDummy, _labelStyle);
Color c = item.Value.Settings.BackgroundColor * GlobalColor; Color c = item.Value.Settings.BackgroundColor * GlobalColor;
GUI.color = c;
var mat = DebugXAssets.Materials.Unlit; var mat = DebugXAssets.Materials.Unlit;
mat.SetColor(ColorPropertyID, c); mat.SetColor(ColorPropertyID, c);
Graphics.DrawTexture(rect, _whiteTexture, mat); Graphics.DrawTexture(rect, _whiteTexture, mat);
GUI.color = item.Color * GlobalColor; GUI.color = item.Color * GlobalColor;
style.Draw(rect, _labelDummy, false, false, false, false); style.Draw(rect, _labelDummy, false, false, false, false);
} }
} }
GUI.color = dfColor; GUI.color = dfColor;

View File

@ -7,6 +7,7 @@ namespace DCFApixels.DebugXCore.Internal
internal interface ICommandBufferExecutor internal interface ICommandBufferExecutor
{ {
void Execute(CommandBuffer cb); void Execute(CommandBuffer cb);
void Submit();
} }
internal class CommandBufferExecutorSRP : ICommandBufferExecutor internal class CommandBufferExecutorSRP : ICommandBufferExecutor
{ {
@ -24,6 +25,10 @@ namespace DCFApixels.DebugXCore.Internal
{ {
RenderContext.ExecuteCommandBuffer(cb); RenderContext.ExecuteCommandBuffer(cb);
} }
public void Submit()
{
RenderContext.Submit();
}
} }
internal class CommandBufferExecutorBRP : ICommandBufferExecutor internal class CommandBufferExecutorBRP : ICommandBufferExecutor
{ {
@ -39,5 +44,6 @@ namespace DCFApixels.DebugXCore.Internal
{ {
Graphics.ExecuteCommandBuffer(cb); Graphics.ExecuteCommandBuffer(cb);
} }
public void Submit() { }
} }
} }

View File

@ -17,9 +17,9 @@ namespace DCFApixels.DebugXCore
void Prepare(Camera camera, GizmosList<T> list); void Prepare(Camera camera, GizmosList<T> list);
void Render(Camera camera, GizmosList<T> list, CommandBuffer cb); void Render(Camera camera, GizmosList<T> list, CommandBuffer cb);
} }
public interface IGizmoRenderer_UnityGizmos<T> : IGizmoRenderer<T> where T : IGizmo<T> public interface IGizmoRenderer_PostRender<T> : IGizmoRenderer<T> where T : IGizmo<T>
{ {
void Render_UnityGizmos(Camera camera, GizmosList<T> list); void PostRender(Camera camera, GizmosList<T> list);
} }