@@ -12,45 +12,37 @@ namespace FlaxEditor.Gizmo
|
||||
[HideInEditor]
|
||||
public class GridGizmo : GizmoBase
|
||||
{
|
||||
private bool _enabled = true;
|
||||
[HideInEditor]
|
||||
private sealed class Renderer : PostProcessEffect
|
||||
{
|
||||
private IntPtr _debugDrawContext;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="GridGizmo"/> is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
public Renderer()
|
||||
{
|
||||
get => _enabled;
|
||||
set
|
||||
{
|
||||
if (_enabled != value)
|
||||
{
|
||||
_enabled = value;
|
||||
EnabledChanged?.Invoke(this);
|
||||
}
|
||||
}
|
||||
Order = -100;
|
||||
UseSingleTarget = true;
|
||||
Location = PostProcessEffectLocation.BeforeForwardPass;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when enabled state gets changed.
|
||||
/// </summary>
|
||||
public event Action<GridGizmo> EnabledChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GridGizmo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="owner">The gizmos owner.</param>
|
||||
public GridGizmo(IGizmoOwner owner)
|
||||
: base(owner)
|
||||
~Renderer()
|
||||
{
|
||||
if (_debugDrawContext != IntPtr.Zero)
|
||||
{
|
||||
DebugDraw.FreeContext(_debugDrawContext);
|
||||
_debugDrawContext = IntPtr.Zero;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Draw(ref RenderContext renderContext)
|
||||
public override void Render(GPUContext context, ref RenderContext renderContext, GPUTexture input, GPUTexture output)
|
||||
{
|
||||
if (!Enabled)
|
||||
return;
|
||||
Profiler.BeginEventGPU("Editor Grid");
|
||||
|
||||
var viewPos = Owner.ViewPosition;
|
||||
if (_debugDrawContext == IntPtr.Zero)
|
||||
_debugDrawContext = DebugDraw.AllocateContext();
|
||||
DebugDraw.SetContext(_debugDrawContext);
|
||||
DebugDraw.UpdateContext(_debugDrawContext, 1.0f / Mathf.Max(Engine.FramesPerSecond, 1));
|
||||
|
||||
var viewPos = (Vector3)renderContext.View.Position;
|
||||
var plane = new Plane(Vector3.Zero, Vector3.UnitY);
|
||||
var dst = CollisionsHelper.DistancePlanePoint(ref plane, ref viewPos);
|
||||
|
||||
@@ -91,6 +83,51 @@ namespace FlaxEditor.Gizmo
|
||||
start.Z = end.Z = i * space + start.X;
|
||||
DebugDraw.DrawLine(start, end, color);
|
||||
}
|
||||
|
||||
DebugDraw.Draw(ref renderContext, input.View(), null, true);
|
||||
DebugDraw.SetContext(IntPtr.Zero);
|
||||
|
||||
Profiler.EndEventGPU();
|
||||
}
|
||||
}
|
||||
|
||||
private Renderer _renderer;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether this <see cref="GridGizmo"/> is enabled.
|
||||
/// </summary>
|
||||
public bool Enabled
|
||||
{
|
||||
get => _renderer.Enabled;
|
||||
set
|
||||
{
|
||||
if (_renderer.Enabled != value)
|
||||
{
|
||||
_renderer.Enabled = value;
|
||||
EnabledChanged?.Invoke(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Occurs when enabled state gets changed.
|
||||
/// </summary>
|
||||
public event Action<GridGizmo> EnabledChanged;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="GridGizmo"/> class.
|
||||
/// </summary>
|
||||
/// <param name="owner">The gizmos owner.</param>
|
||||
public GridGizmo(IGizmoOwner owner)
|
||||
: base(owner)
|
||||
{
|
||||
_renderer = new Renderer();
|
||||
owner.RenderTask.AddCustomPostFx(_renderer);
|
||||
}
|
||||
|
||||
~GridGizmo()
|
||||
{
|
||||
FlaxEngine.Object.Destroy(ref _renderer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -466,7 +466,7 @@ inline void DrawText3D(const DebugText3D& t, const RenderContext& renderContext,
|
||||
Matrix::Multiply(fw, vp, m);
|
||||
Render2D::Begin(context, target, depthBuffer, viewport, m);
|
||||
const StringView text(t.Text.Get(), t.Text.Count() - 1);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont(t.Size), text, t.Color, Vector2::Zero);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont((float)t.Size), text, t.Color, Vector2::Zero);
|
||||
Render2D::End();
|
||||
}
|
||||
|
||||
@@ -777,7 +777,7 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
|
||||
context->BindSR(0, renderContext.Buffers->DepthBuffer);
|
||||
const bool enableDepthWrite = data.EnableDepthTest;
|
||||
|
||||
context->SetRenderTarget(depthBuffer ? depthBuffer : *renderContext.Buffers->DepthBuffer, target);
|
||||
context->SetRenderTarget(depthBuffer ? depthBuffer : (data.EnableDepthTest ? nullptr : renderContext.Buffers->DepthBuffer->View()), target);
|
||||
|
||||
// Lines
|
||||
if (depthTestLines.VertexCount)
|
||||
@@ -859,12 +859,12 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
|
||||
for (auto& t : Context->DebugDrawDefault.DefaultText2D)
|
||||
{
|
||||
const StringView text(t.Text.Get(), t.Text.Count() - 1);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont(t.Size), text, t.Color, t.Position);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont((float)t.Size), text, t.Color, t.Position);
|
||||
}
|
||||
for (auto& t : Context->DebugDrawDefault.OneFrameText2D)
|
||||
{
|
||||
const StringView text(t.Text.Get(), t.Text.Count() - 1);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont(t.Size), text, t.Color, t.Position);
|
||||
Render2D::DrawText(DebugDrawFont->CreateFont((float)t.Size), text, t.Color, t.Position);
|
||||
}
|
||||
Render2D::End();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user