Merge remote-tracking branch 'origin/1.1' into linux-editor

# Conflicts:
#	Source/FlaxEngine.Gen.cs
#	Source/Tools/Flax.Build/Utilities/Utilities.cs
This commit is contained in:
Wojtek Figat
2021-02-16 18:54:25 +01:00
654 changed files with 19651 additions and 10556 deletions

View File

@@ -19,6 +19,7 @@
#include "Engine/Graphics/RenderBuffers.h"
#include "Engine/Animations/AnimationUtils.h"
#include "Engine/Profiler/Profiler.h"
#include "Engine/Debug/DebugLog.h"
// Debug draw service configuration
#define DEBUG_DRAW_INITIAL_VB_CAPACITY (4 * 1024)
@@ -130,6 +131,8 @@ struct DebugDrawData
Array<DebugLine> OneFrameLines;
Array<DebugTriangle> DefaultTriangles;
Array<DebugTriangle> OneFrameTriangles;
Array<DebugTriangle> DefaultWireTriangles;
Array<DebugTriangle> OneFrameWireTriangles;
inline int32 Count() const
{
@@ -143,7 +146,7 @@ struct DebugDrawData
inline int32 TrianglesCount() const
{
return DefaultTriangles.Count() + OneFrameTriangles.Count();
return DefaultTriangles.Count() + OneFrameTriangles.Count() + DefaultWireTriangles.Count() + OneFrameWireTriangles.Count();
}
inline void Add(const DebugLine& l)
@@ -162,13 +165,23 @@ struct DebugDrawData
OneFrameTriangles.Add(t);
}
inline void AddWire(const DebugTriangle& t)
{
if (t.TimeLeft > 0)
DefaultWireTriangles.Add(t);
else
OneFrameWireTriangles.Add(t);
}
inline void Update(float deltaTime)
{
UpdateList(deltaTime, DefaultLines);
UpdateList(deltaTime, DefaultTriangles);
UpdateList(deltaTime, DefaultWireTriangles);
OneFrameLines.Clear();
OneFrameTriangles.Clear();
OneFrameWireTriangles.Clear();
}
inline void Clear()
@@ -177,6 +190,8 @@ struct DebugDrawData
OneFrameLines.Clear();
DefaultTriangles.Clear();
OneFrameTriangles.Clear();
DefaultWireTriangles.Clear();
OneFrameWireTriangles.Clear();
}
inline void Release()
@@ -185,16 +200,20 @@ struct DebugDrawData
OneFrameLines.Resize(0);
DefaultTriangles.Resize(0);
OneFrameTriangles.Resize(0);
DefaultWireTriangles.Resize(0);
OneFrameWireTriangles.Resize(0);
}
};
DebugDrawData DebugDrawDefault;
DebugDrawData DebugDrawDepthTest;
AssetReference<Shader> DebugDrawShader;
PsData DebugDrawPsWireDefault;
PsData DebugDrawPsWireDepthTest;
PsData DebugDrawPsDefault;
PsData DebugDrawPsDepthTest;
PsData DebugDrawPsLinesDefault;
PsData DebugDrawPsLinesDepthTest;
PsData DebugDrawPsWireTrianglesDefault;
PsData DebugDrawPsWireTrianglesDepthTest;
PsData DebugDrawPsTrianglesDefault;
PsData DebugDrawPsTrianglesDepthTest;
DynamicVertexBuffer* DebugDrawVB = nullptr;
Vector3 SphereCache[DEBUG_DRAW_SPHERE_VERTICES];
Vector3 CircleCache[DEBUG_DRAW_CIRCLE_VERTICES];
@@ -453,16 +472,21 @@ void DebugDrawService::Update()
// Default
desc.PS = shader->GetPS("PS");
desc.PrimitiveTopologyType = PrimitiveTopologyType::Line;
failed |= DebugDrawPsWireDefault.Create(desc);
failed |= DebugDrawPsLinesDefault.Create(desc);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Triangle;
failed |= DebugDrawPsDefault.Create(desc);
failed |= DebugDrawPsTrianglesDefault.Create(desc);
desc.Wireframe = true;
failed |= DebugDrawPsWireTrianglesDefault.Create(desc);
// Depth Test
desc.Wireframe = false;
desc.PS = shader->GetPS("PS_DepthTest");
desc.PrimitiveTopologyType = PrimitiveTopologyType::Line;
failed |= DebugDrawPsWireDepthTest.Create(desc);
failed |= DebugDrawPsLinesDepthTest.Create(desc);
desc.PrimitiveTopologyType = PrimitiveTopologyType::Triangle;
failed |= DebugDrawPsDepthTest.Create(desc);
failed |= DebugDrawPsTrianglesDepthTest.Create(desc);
desc.Wireframe = true;
failed |= DebugDrawPsWireTrianglesDepthTest.Create(desc);
if (failed)
{
@@ -482,12 +506,14 @@ void DebugDrawService::Dispose()
// Release resources
SphereTriangleCache.Resize(0);
DebugDrawPsWireDefault.Release();
DebugDrawPsWireDepthTest.Release();
DebugDrawPsDepthTest.Release();
DebugDrawPsDepthTest.Release();
DebugDrawPsLinesDefault.Release();
DebugDrawPsLinesDepthTest.Release();
DebugDrawPsWireTrianglesDefault.Release();
DebugDrawPsWireTrianglesDepthTest.Release();
DebugDrawPsTrianglesDefault.Release();
DebugDrawPsTrianglesDepthTest.Release();
SAFE_DELETE(DebugDrawVB);
DebugDrawShader.Unlink();
DebugDrawShader = nullptr;
}
void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTextureView* depthBuffer, bool enableDepthTest)
@@ -495,9 +521,9 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
PROFILE_GPU_CPU("Debug Draw");
// Ensure to have shader loaded and any lines to render
const int32 DebugDrawDepthTestCount = DebugDrawDepthTest.Count();
const int32 DebugDrawDefaultCount = DebugDrawDefault.Count();
if (DebugDrawShader == nullptr || !DebugDrawShader->IsLoaded() || DebugDrawDepthTestCount + DebugDrawDefaultCount == 0)
const int32 debugDrawDepthTestCount = DebugDrawDepthTest.Count();
const int32 debugDrawDefaultCount = DebugDrawDefault.Count();
if (DebugDrawShader == nullptr || !DebugDrawShader->IsLoaded() || debugDrawDepthTestCount + debugDrawDefaultCount == 0)
return;
if (renderContext.Buffers == nullptr || !DebugDrawVB)
return;
@@ -517,6 +543,8 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
const DebugDrawCall defaultLines = WriteLists(vertexCounter, DebugDrawDefault.DefaultLines, DebugDrawDefault.OneFrameLines);
const DebugDrawCall depthTestTriangles = WriteLists(vertexCounter, DebugDrawDepthTest.DefaultTriangles, DebugDrawDepthTest.OneFrameTriangles);
const DebugDrawCall defaultTriangles = WriteLists(vertexCounter, DebugDrawDefault.DefaultTriangles, DebugDrawDefault.OneFrameTriangles);
const DebugDrawCall depthTestWireTriangles = WriteLists(vertexCounter, DebugDrawDepthTest.DefaultWireTriangles, DebugDrawDepthTest.OneFrameWireTriangles);
const DebugDrawCall defaultWireTriangles = WriteLists(vertexCounter, DebugDrawDefault.DefaultWireTriangles, DebugDrawDefault.OneFrameWireTriangles);
DebugDrawVB->Flush(context);
#if COMPILE_WITH_PROFILER
ProfilerCPU::EndEvent(updateBufferProfileKey);
@@ -536,7 +564,7 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
#define DRAW(drawCall) if (drawCall.VertexCount)
// Draw with depth test
if (depthTestLines.VertexCount + depthTestTriangles.VertexCount > 0)
if (depthTestLines.VertexCount + depthTestTriangles.VertexCount + depthTestWireTriangles.VertexCount > 0)
{
if (data.EnableDepthTest)
context->BindSR(0, renderContext.Buffers->DepthBuffer);
@@ -547,16 +575,25 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
// Lines
if (depthTestLines.VertexCount)
{
auto state = data.EnableDepthTest ? &DebugDrawPsWireDepthTest : &DebugDrawPsWireDefault;
auto state = data.EnableDepthTest ? &DebugDrawPsLinesDepthTest : &DebugDrawPsLinesDefault;
context->SetState(state->Get(enableDepthWrite, true));
context->BindVB(ToSpan(&vb, 1));
context->Draw(depthTestLines.StartVertex, depthTestLines.VertexCount);
}
// Wire Triangles
if (depthTestWireTriangles.VertexCount)
{
auto state = data.EnableDepthTest ? &DebugDrawPsWireTrianglesDepthTest : &DebugDrawPsWireTrianglesDefault;
context->SetState(state->Get(enableDepthWrite, true));
context->BindVB(ToSpan(&vb, 1));
context->Draw(depthTestWireTriangles.StartVertex, depthTestWireTriangles.VertexCount);
}
// Triangles
if (depthTestTriangles.VertexCount)
{
auto state = data.EnableDepthTest ? &DebugDrawPsDepthTest : &DebugDrawPsDefault;
auto state = data.EnableDepthTest ? &DebugDrawPsTrianglesDepthTest : &DebugDrawPsTrianglesDefault;
context->SetState(state->Get(enableDepthWrite, true));
context->BindVB(ToSpan(&vb, 1));
context->Draw(depthTestTriangles.StartVertex, depthTestTriangles.VertexCount);
@@ -567,22 +604,30 @@ void DebugDraw::Draw(RenderContext& renderContext, GPUTextureView* target, GPUTe
}
// Draw without depth
if (defaultLines.VertexCount + defaultTriangles.VertexCount > 0)
if (defaultLines.VertexCount + defaultTriangles.VertexCount + defaultWireTriangles.VertexCount > 0)
{
context->SetRenderTarget(target);
// Lines
if (defaultLines.VertexCount)
{
context->SetState(DebugDrawPsWireDefault.Get(false, false));
context->SetState(DebugDrawPsLinesDefault.Get(false, false));
context->BindVB(ToSpan(&vb, 1));
context->Draw(defaultLines.StartVertex, defaultLines.VertexCount);
}
// Wire Triangles
if (defaultWireTriangles.VertexCount)
{
context->SetState(DebugDrawPsWireTrianglesDefault.Get(false, false));
context->BindVB(ToSpan(&vb, 1));
context->Draw(defaultWireTriangles.StartVertex, defaultWireTriangles.VertexCount);
}
// Triangles
if (defaultTriangles.VertexCount)
{
context->SetState(DebugDrawPsDefault.Get(false, false));
context->SetState(DebugDrawPsTrianglesDefault.Get(false, false));
context->BindVB(ToSpan(&vb, 1));
context->Draw(defaultTriangles.StartVertex, defaultTriangles.VertexCount);
}
@@ -606,6 +651,7 @@ namespace
void DebugDraw::DrawActors(Actor** selectedActors, int32 selectedActorsCount)
{
PROFILE_CPU();
if (selectedActors)
{
for (int32 i = 0; i < selectedActorsCount; i++)
@@ -635,7 +681,11 @@ void DebugDraw::DrawLine(const Vector3& start, const Vector3& end, const Color&
void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, const Color& color, float duration, bool depthTest)
{
ASSERT(lines.Length() % 2 == 0);
if (lines.Length() % 2 != 0)
{
DebugLog::ThrowException("Cannot draw debug lines with uneven amount of items in array");
return;
}
// Create draw call entry
DebugLine l = { Vector3::Zero, Vector3::Zero, Color32(color), duration };
@@ -643,10 +693,12 @@ void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, c
// Add lines
const Vector3* p = lines.Get();
Array<DebugLine>* list;
if (depthTest)
if (depthTest)
list = duration > 0 ? &DebugDrawDepthTest.DefaultLines : &DebugDrawDepthTest.OneFrameLines;
else
list = duration > 0 ? &DebugDrawDefault.DefaultLines : &DebugDrawDefault.OneFrameLines;
list->EnsureCapacity(list->Count() + lines.Length());
for (int32 i = 0; i < lines.Length(); i += 2)
{
@@ -656,16 +708,6 @@ void DebugDraw::DrawLines(const Span<Vector3>& lines, const Matrix& transform, c
}
}
static Vector3 GetPoint(Vector3 p0, Vector3 p1, Vector3 p2, Vector3 p3, float t)
{
const float oneMinusT = 1.0f - t;
return
oneMinusT * oneMinusT * oneMinusT * p0 +
3.0f * oneMinusT * oneMinusT * t * p1 +
3.0f * oneMinusT * t * t * p2 +
t * t * t * p3;
}
void DebugDraw::DrawBezier(const Vector3& p1, const Vector3& p2, const Vector3& p3, const Vector3& p4, const Color& color, float duration, bool depthTest)
{
// Create draw call entry
@@ -682,13 +724,13 @@ void DebugDraw::DrawBezier(const Vector3& p1, const Vector3& p2, const Vector3&
const Vector3 d3 = p4 - p3;
const float len = d1.Length() + d2.Length() + d3.Length();
const int32 segmentCount = Math::Clamp(Math::CeilToInt(len * 0.05f), 1, 100);
const float segmentCountInv = 1.0f / segmentCount;
const float segmentCountInv = 1.0f / (float)segmentCount;
list->EnsureCapacity(list->Count() + segmentCount + 2);
// Draw segmented curve
for (int32 i = 0; i <= segmentCount; i++)
{
const float t = i * segmentCountInv;
const float t = (float)i * segmentCountInv;
AnimationUtils::Bezier(p1, p2, p3, p4, t, l.End);
list->Add(l);
l.Start = l.End;
@@ -884,18 +926,22 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Color& color,
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
list->EnsureCapacity(list->Count() + vertices.Length());
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
for (int32 i = 0; i < vertices.Length() * 3;)
for (int32 i = 0; i < vertices.Length();)
{
t.V0 = vertices[i++];
t.V1 = vertices[i++];
t.V2 = vertices[i++];
list->Add(t);
}
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration, bool depthTest)
{
ASSERT(indices.Length() % 3 == 0);
@@ -909,18 +955,80 @@ void DebugDraw::DrawTriangles(const Span<Vector3>& vertices, const Span<int32>&
list = duration > 0 ? &DebugDrawDepthTest.DefaultTriangles : &DebugDrawDepthTest.OneFrameTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultTriangles : &DebugDrawDefault.OneFrameTriangles;
list->EnsureCapacity(list->Count() + indices.Length());
list->EnsureCapacity(list->Count() + indices.Length() / 3);
for (int32 i = 0; i < indices.Length() * 3;)
for (int32 i = 0; i < indices.Length();)
{
t.V0 = vertices[indices[i++]];
t.V1 = vertices[indices[i++]];
t.V2 = vertices[indices[i++]];
list->Add(t);
}
}
void DebugDraw::DrawTriangles(const Array<Vector3>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration, bool depthTest)
{
DrawTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), Span<int32>(indices.Get(), indices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
ASSERT(vertices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
t.TimeLeft = duration;
Array<DebugTriangle>* list;
if (depthTest)
list = duration > 0 ? &DebugDrawDepthTest.DefaultWireTriangles : &DebugDrawDepthTest.OneFrameWireTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultWireTriangles : &DebugDrawDefault.OneFrameWireTriangles;
list->EnsureCapacity(list->Count() + vertices.Length() / 3);
for (int32 i = 0; i < vertices.Length();)
{
t.V0 = vertices[i++];
t.V1 = vertices[i++];
t.V2 = vertices[i++];
list->Add(t);
}
}
void DebugDraw::DrawWireTriangles(const Array<Vector3>& vertices, const Color& color, float duration, bool depthTest)
{
DrawWireTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawWireTriangles(const Span<Vector3>& vertices, const Span<int32>& indices, const Color& color, float duration, bool depthTest)
{
ASSERT(indices.Length() % 3 == 0);
DebugTriangle t;
t.Color = Color32(color);
t.TimeLeft = duration;
Array<DebugTriangle>* list;
if (depthTest)
list = duration > 0 ? &DebugDrawDepthTest.DefaultWireTriangles : &DebugDrawDepthTest.OneFrameWireTriangles;
else
list = duration > 0 ? &DebugDrawDefault.DefaultWireTriangles : &DebugDrawDefault.OneFrameWireTriangles;
list->EnsureCapacity(list->Count() + indices.Length() / 3);
for (int32 i = 0; i < indices.Length();)
{
t.V0 = vertices[indices[i++]];
t.V1 = vertices[indices[i++]];
t.V2 = vertices[indices[i++]];
list->Add(t);
}
}
void DebugDraw::DrawWireTriangles(const Array<Vector3>& vertices, const Array<int32, HeapAllocation>& indices, const Color& color, float duration, bool depthTest)
{
DrawWireTriangles(Span<Vector3>(vertices.Get(), vertices.Count()), Span<int32>(indices.Get(), indices.Count()), color, duration, depthTest);
}
void DebugDraw::DrawWireTube(const Vector3& position, const Quaternion& orientation, float radius, float length, const Color& color, float duration, bool depthTest)
{
// Check if has no length (just sphere)