Merge remote-tracking branch 'origin/1.1' into linux-editor
# Conflicts: # Source/Engine/Core/Math/BoundingSphere.cs # Source/Engine/Debug/DebugDraw.cpp # Source/Engine/Platform/Win32/Win32Platform.cpp # Source/Engine/Platform/Win32/Win32Platform.h
This commit is contained in:
@@ -62,7 +62,7 @@ namespace FlaxEditor.Viewport
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEngine.PostProcessEffect" />
|
||||
[HideInEditor]
|
||||
public sealed class EditorSpritesRenderer : PostProcessEffect
|
||||
public class EditorSpritesRenderer : PostProcessEffect
|
||||
{
|
||||
/// <summary>
|
||||
/// The rendering task.
|
||||
@@ -100,11 +100,7 @@ namespace FlaxEditor.Viewport
|
||||
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);
|
||||
}
|
||||
Draw(ref renderContext);
|
||||
|
||||
// Sort draw calls
|
||||
renderList.SortDrawCalls(ref renderContext, true, DrawCallsListType.Forward);
|
||||
@@ -118,6 +114,18 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
Profiler.EndEventGPU();
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Draws the icons.
|
||||
/// </summary>
|
||||
protected virtual void Draw(ref RenderContext renderContext)
|
||||
{
|
||||
for (int i = 0; i < Level.ScenesCount; i++)
|
||||
{
|
||||
var scene = Level.GetScene(i);
|
||||
ViewportIconsRenderer.DrawIcons(ref renderContext, scene);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||
@@ -175,10 +183,10 @@ namespace FlaxEditor.Viewport
|
||||
_editor = editor;
|
||||
|
||||
// Prepare rendering task
|
||||
Task.ActorsSource = ActorsSources.ScenesAndCustomActors;
|
||||
Task.ActorsSource = ActorsSources.Scenes;
|
||||
Task.ViewFlags = ViewFlags.DefaultEditor;
|
||||
Task.Begin += RenderTaskOnBegin;
|
||||
Task.CollectDrawCalls += RenderTaskOnCollectDrawCalls;
|
||||
Task.Begin += OnBegin;
|
||||
Task.CollectDrawCalls += OnCollectDrawCalls;
|
||||
Task.PostRender += OnPostRender;
|
||||
|
||||
// Render task after the main game task so streaming and render state data will use main game task instead of editor preview
|
||||
@@ -396,7 +404,7 @@ namespace FlaxEditor.Viewport
|
||||
Editor.Instance.SceneEditing.Spawn(actor);
|
||||
}
|
||||
|
||||
private void RenderTaskOnBegin(RenderTask task, GPUContext context)
|
||||
private void OnBegin(RenderTask task, GPUContext context)
|
||||
{
|
||||
_debugDrawData.Clear();
|
||||
|
||||
@@ -412,7 +420,7 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
}
|
||||
|
||||
private void RenderTaskOnCollectDrawCalls(RenderContext renderContext)
|
||||
private void OnCollectDrawCalls(RenderContext renderContext)
|
||||
{
|
||||
if (_previewStaticModel)
|
||||
{
|
||||
@@ -441,7 +449,7 @@ namespace FlaxEditor.Viewport
|
||||
{
|
||||
fixed (IntPtr* actors = _debugDrawData.ActorsPtrs)
|
||||
{
|
||||
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount);
|
||||
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount, true);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,18 @@ namespace FlaxEditor.Viewport
|
||||
/// <seealso cref="IGizmoOwner" />
|
||||
public class PrefabWindowViewport : PrefabPreview, IEditorPrimitivesOwner
|
||||
{
|
||||
private sealed class PrefabSpritesRenderer : MainEditorGizmoViewport.EditorSpritesRenderer
|
||||
{
|
||||
public PrefabWindowViewport Viewport;
|
||||
|
||||
public override bool CanRender => (Task.View.Flags & ViewFlags.EditorSprites) == ViewFlags.EditorSprites && Enabled;
|
||||
|
||||
protected override void Draw(ref RenderContext renderContext)
|
||||
{
|
||||
ViewportIconsRenderer.DrawIcons(ref renderContext, Viewport.Instance);
|
||||
}
|
||||
}
|
||||
|
||||
private readonly PrefabWindow _window;
|
||||
private UpdateDelegate _update;
|
||||
|
||||
@@ -37,6 +49,9 @@ namespace FlaxEditor.Viewport
|
||||
private ViewportWidgetButton _rotateSnapping;
|
||||
private ViewportWidgetButton _scaleSnapping;
|
||||
|
||||
private readonly ViewportDebugDrawData _debugDrawData = new ViewportDebugDrawData(32);
|
||||
private IntPtr _debugDrawContext;
|
||||
private PrefabSpritesRenderer _spritesRenderer;
|
||||
private readonly DragAssets _dragAssets = new DragAssets(ValidateDragItem);
|
||||
private readonly DragActorType _dragActorType = new DragActorType(ValidateDragActorType);
|
||||
private readonly DragHandlers _dragHandlers = new DragHandlers();
|
||||
@@ -56,6 +71,11 @@ namespace FlaxEditor.Viewport
|
||||
/// </summary>
|
||||
public EditorPrimitives EditorPrimitives;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether draw <see cref="DebugDraw"/> shapes.
|
||||
/// </summary>
|
||||
public bool DrawDebugDraw = true;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="PrefabWindowViewport"/> class.
|
||||
/// </summary>
|
||||
@@ -67,10 +87,13 @@ namespace FlaxEditor.Viewport
|
||||
_window.SelectionChanged += OnSelectionChanged;
|
||||
Undo = window.Undo;
|
||||
ViewportCamera = new FPSCamera();
|
||||
_debugDrawContext = DebugDraw.AllocateContext();
|
||||
|
||||
// Prepare rendering task
|
||||
Task.ActorsSource = ActorsSources.CustomActors;
|
||||
Task.ViewFlags = ViewFlags.DefaultEditor & ~ViewFlags.EditorSprites;
|
||||
Task.ViewFlags = ViewFlags.DefaultEditor;
|
||||
Task.Begin += OnBegin;
|
||||
Task.CollectDrawCalls += OnCollectDrawCalls;
|
||||
Task.PostRender += OnPostRender;
|
||||
|
||||
// Create post effects
|
||||
@@ -80,6 +103,10 @@ namespace FlaxEditor.Viewport
|
||||
EditorPrimitives = FlaxEngine.Object.New<EditorPrimitives>();
|
||||
EditorPrimitives.Viewport = this;
|
||||
Task.CustomPostFx.Add(EditorPrimitives);
|
||||
_spritesRenderer = FlaxEngine.Object.New<PrefabSpritesRenderer>();
|
||||
_spritesRenderer.Task = Task;
|
||||
_spritesRenderer.Viewport = this;
|
||||
Task.CustomPostFx.Add(_spritesRenderer);
|
||||
|
||||
// Add transformation gizmo
|
||||
TransformGizmo = new TransformGizmo(this);
|
||||
@@ -226,6 +253,27 @@ namespace FlaxEditor.Viewport
|
||||
}
|
||||
}
|
||||
|
||||
private void OnBegin(RenderTask task, GPUContext context)
|
||||
{
|
||||
_debugDrawData.Clear();
|
||||
|
||||
// Collect selected objects debug shapes and visuals
|
||||
var selectedParents = TransformGizmo.SelectedParents;
|
||||
if (selectedParents.Count > 0)
|
||||
{
|
||||
for (int i = 0; i < selectedParents.Count; i++)
|
||||
{
|
||||
if (selectedParents[i].IsActiveInHierarchy)
|
||||
selectedParents[i].OnDebugDraw(_debugDrawData);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OnCollectDrawCalls(RenderContext renderContext)
|
||||
{
|
||||
_debugDrawData.OnDraw(ref renderContext);
|
||||
}
|
||||
|
||||
private void OnPostRender(GPUContext context, RenderContext renderContext)
|
||||
{
|
||||
if (renderContext.View.Mode != ViewMode.Default)
|
||||
@@ -234,7 +282,30 @@ namespace FlaxEditor.Viewport
|
||||
|
||||
// Render editor primitives, gizmo and debug shapes in debug view modes
|
||||
// Note: can use Output buffer as both input and output because EditorPrimitives is using a intermediate buffers
|
||||
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
|
||||
if (EditorPrimitives && EditorPrimitives.CanRender)
|
||||
{
|
||||
EditorPrimitives.Render(context, ref renderContext, task.Output, task.Output);
|
||||
}
|
||||
|
||||
// Render editor sprites
|
||||
if (_spritesRenderer && _spritesRenderer.CanRender)
|
||||
{
|
||||
_spritesRenderer.Render(context, ref renderContext, task.Output, task.Output);
|
||||
}
|
||||
|
||||
// Render selection outline
|
||||
if (SelectionOutline && SelectionOutline.CanRender)
|
||||
{
|
||||
// Use temporary intermediate buffer
|
||||
var desc = task.Output.Description;
|
||||
var temp = RenderTargetPool.Get(ref desc);
|
||||
SelectionOutline.Render(context, ref renderContext, task.Output, temp);
|
||||
|
||||
// Copy the results back to the output
|
||||
context.CopyTexture(task.Output, 0, 0, 0, 0, temp, 0);
|
||||
|
||||
RenderTargetPool.Release(temp);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -819,8 +890,14 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public override void OnDestroy()
|
||||
{
|
||||
if (_debugDrawContext != IntPtr.Zero)
|
||||
{
|
||||
DebugDraw.FreeContext(_debugDrawContext);
|
||||
_debugDrawContext = IntPtr.Zero;
|
||||
}
|
||||
FlaxEngine.Object.Destroy(ref SelectionOutline);
|
||||
FlaxEngine.Object.Destroy(ref EditorPrimitives);
|
||||
FlaxEngine.Object.Destroy(ref _spritesRenderer);
|
||||
|
||||
base.OnDestroy();
|
||||
}
|
||||
@@ -828,6 +905,21 @@ namespace FlaxEditor.Viewport
|
||||
/// <inheritdoc />
|
||||
public void DrawEditorPrimitives(GPUContext context, ref RenderContext renderContext, GPUTexture target, GPUTexture targetDepth)
|
||||
{
|
||||
// Draw selected objects debug shapes and visuals
|
||||
if (DrawDebugDraw && (renderContext.View.Flags & ViewFlags.DebugDraw) == ViewFlags.DebugDraw)
|
||||
{
|
||||
DebugDraw.SetContext(_debugDrawContext);
|
||||
DebugDraw.UpdateContext(_debugDrawContext, 1.0f / Engine.FramesPerSecond);
|
||||
unsafe
|
||||
{
|
||||
fixed (IntPtr* actors = _debugDrawData.ActorsPtrs)
|
||||
{
|
||||
DebugDraw.DrawActors(new IntPtr(actors), _debugDrawData.ActorsCount, false);
|
||||
}
|
||||
}
|
||||
DebugDraw.Draw(ref renderContext, target.View(), targetDepth.View(), true);
|
||||
DebugDraw.SetContext(IntPtr.Zero);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user