Add Renderer::DrawActors for quick actors rendering in custom render passes
This commit is contained in:
@@ -2,6 +2,9 @@
|
||||
|
||||
#include "RenderList.h"
|
||||
#include "Engine/Core/Collections/Sorting.h"
|
||||
#if !BUILD_RELEASE
|
||||
#include "Engine/Core/Utilities.h"
|
||||
#endif
|
||||
#include "Engine/Graphics/Materials/IMaterial.h"
|
||||
#include "Engine/Graphics/RenderTask.h"
|
||||
#include "Engine/Graphics/GPUContext.h"
|
||||
@@ -646,6 +649,9 @@ void RenderList::ExecuteDrawCalls(const RenderContext& renderContext, DrawCallsL
|
||||
{
|
||||
if (list.IsEmpty())
|
||||
return;
|
||||
#if !BUILD_RELEASE
|
||||
CHECK(Utilities::CountBits((uint32)renderContext.View.Pass) == 1); // Ensure proper pass is set (single bit flag)
|
||||
#endif
|
||||
PROFILE_GPU_CPU("Drawing");
|
||||
const auto* drawCallsData = drawCalls.Get();
|
||||
const auto* listData = list.Indices.Get();
|
||||
|
||||
@@ -236,24 +236,7 @@ void Renderer::DrawSceneDepth(GPUContext* context, SceneRenderTask* task, GPUTex
|
||||
renderContext.View.Prepare(renderContext);
|
||||
|
||||
// Call drawing (will collect draw calls)
|
||||
if (customActors.HasItems())
|
||||
{
|
||||
// Draw custom actors
|
||||
for (auto actor : customActors)
|
||||
{
|
||||
if (actor && actor->GetIsActive())
|
||||
actor->Draw(renderContext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw scene actors
|
||||
RenderContextBatch renderContextBatch(renderContext);
|
||||
Level::DrawActors(renderContextBatch);
|
||||
for (const int64 label : renderContextBatch.WaitLabels)
|
||||
JobSystem::Wait(label);
|
||||
renderContextBatch.WaitLabels.Clear();
|
||||
}
|
||||
DrawActors(renderContext, customActors);
|
||||
|
||||
// Sort draw calls
|
||||
renderContext.List->SortDrawCalls(renderContext, false, DrawCallsListType::Depth);
|
||||
@@ -287,6 +270,31 @@ void Renderer::DrawPostFxMaterial(GPUContext* context, const RenderContext& rend
|
||||
context->ResetRenderTarget();
|
||||
}
|
||||
|
||||
void Renderer::DrawActors(RenderContext& renderContext, const Array<Actor*>& customActors)
|
||||
{
|
||||
if (customActors.HasItems())
|
||||
{
|
||||
// Draw custom actors
|
||||
for (Actor* actor : customActors)
|
||||
{
|
||||
if (actor && actor->GetIsActive())
|
||||
actor->Draw(renderContext);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Draw scene actors
|
||||
RenderContextBatch renderContextBatch(renderContext);
|
||||
JobSystem::SetJobStartingOnDispatch(false);
|
||||
Level::DrawActors(renderContextBatch, SceneRendering::DrawCategory::SceneDraw);
|
||||
Level::DrawActors(renderContextBatch, SceneRendering::DrawCategory::SceneDrawAsync);
|
||||
JobSystem::SetJobStartingOnDispatch(true);
|
||||
for (const int64 label : renderContextBatch.WaitLabels)
|
||||
JobSystem::Wait(label);
|
||||
renderContextBatch.WaitLabels.Clear();
|
||||
}
|
||||
}
|
||||
|
||||
void RenderInner(SceneRenderTask* task, RenderContext& renderContext, RenderContextBatch& renderContextBatch)
|
||||
{
|
||||
auto context = GPUDevice::Instance->GetMainContext();
|
||||
|
||||
@@ -13,9 +13,21 @@ namespace FlaxEngine
|
||||
/// <param name="task">Render task to use it's view description and the render buffers.</param>
|
||||
/// <param name="output">The output texture. Must be valid and created.</param>
|
||||
/// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param>
|
||||
[Unmanaged]
|
||||
public static void DrawSceneDepth(GPUContext context, SceneRenderTask task, GPUTexture output, List<Actor> customActors)
|
||||
{
|
||||
Internal_DrawSceneDepth(FlaxEngine.Object.GetUnmanagedPtr(context), FlaxEngine.Object.GetUnmanagedPtr(task), FlaxEngine.Object.GetUnmanagedPtr(output), Utils.ExtractArrayFromList(customActors));
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Invoked drawing of the scene objects (collects draw calls into RenderList for a given RenderContext).
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param>
|
||||
[Unmanaged]
|
||||
public static void DrawActors(ref RenderContext renderContext, List<Actor> customActors)
|
||||
{
|
||||
Internal_DrawActors(ref renderContext, Utils.ExtractArrayFromList(customActors));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,13 +18,11 @@ class Actor;
|
||||
/// </summary>
|
||||
API_CLASS(Static) class FLAXENGINE_API Renderer
|
||||
{
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Renderer);
|
||||
DECLARE_SCRIPTING_TYPE_NO_SPAWN(Renderer);
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Determines whether the scene rendering system is ready (all shaders are loaded and helper resources are ready).
|
||||
/// </summary>
|
||||
/// <returns><c>true</c> if this rendering service is ready for scene rendering; otherwise, <c>false</c>.</returns>
|
||||
static bool IsReady();
|
||||
|
||||
/// <summary>
|
||||
@@ -34,7 +32,6 @@ public:
|
||||
static void Render(SceneRenderTask* task);
|
||||
|
||||
public:
|
||||
|
||||
/// <summary>
|
||||
/// Draws scene objects depth (to the output Z buffer). The output must be depth texture to write hardware depth to it.
|
||||
/// </summary>
|
||||
@@ -53,4 +50,11 @@ public:
|
||||
/// <param name="output">The output texture. Must be valid and created.</param>
|
||||
/// <param name="input">The input texture. It's optional.</param>
|
||||
API_FUNCTION() static void DrawPostFxMaterial(GPUContext* context, API_PARAM(Ref) const RenderContext& renderContext, MaterialBase* material, GPUTexture* output, GPUTextureView* input);
|
||||
|
||||
/// <summary>
|
||||
/// Invoked drawing of the scene objects (collects draw calls into RenderList for a given RenderContext).
|
||||
/// </summary>
|
||||
/// <param name="renderContext">The rendering context.</param>
|
||||
/// <param name="customActors">The custom set of actors to render. If empty, the loaded scenes will be rendered.</param>
|
||||
API_FUNCTION() static void DrawActors(API_PARAM(Ref) RenderContext& renderContext, API_PARAM(DefaultValue=null) const Array<Actor*, HeapAllocation>& customActors);
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user