// Copyright (c) Wojciech Figat. All rights reserved. #pragma once #include "Engine/Core/Collections/Array.h" #include "Engine/Platform/CriticalSection.h" #include "Engine/Scripting/ScriptingType.h" #include "Engine/Renderer/RendererAllocation.h" #include "RenderView.h" class RenderBuffers; class RenderList; class SceneRenderTask; /// /// The high-level renderer context. Used to collect the draw calls for the scene rendering. Can be used to perform a custom rendering. /// API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContext { DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContext); /// /// The render buffers that contain drawing state (eg. LOD transitions) and scene buffers (eg. GBuffer, DDGI, Shadow Maps). /// API_FIELD() RenderBuffers* Buffers = nullptr; /// /// The render list that collects draw calls. /// API_FIELD() RenderList* List = nullptr; /// /// The scene rendering task that is a source of renderable objects (optional). /// API_FIELD() SceneRenderTask* Task = nullptr; /// /// The proxy render view used to synchronize objects level of detail during rendering (eg. during shadow maps rendering passes). It's optional. /// API_FIELD() RenderView* LodProxyView = nullptr; /// /// The render view. /// API_FIELD() RenderView View; /// /// The GPU access locking critical section to protect data access when performing multi-threaded rendering. /// static CriticalSection GPULocker; RenderContext() = default; RenderContext(SceneRenderTask* task) noexcept; }; /// /// The high-level renderer context batch that encapsulates multiple rendering requests within a single task (eg. optimize main view scene rendering and shadow projections at once). /// API_STRUCT(NoDefault) struct FLAXENGINE_API RenderContextBatch { DECLARE_SCRIPTING_TYPE_MINIMAL(RenderContextBatch); /// /// The render buffers. /// API_FIELD() RenderBuffers* Buffers = nullptr; /// /// The scene rendering task that is a source of renderable objects (optional). /// API_FIELD() SceneRenderTask* Task = nullptr; /// /// The all render views collection for the current rendering (main view, shadow projections, etc.). /// API_FIELD() Array Contexts; /// /// The Job System labels to wait on, after draw calls collecting. /// API_FIELD() Array> WaitLabels; /// /// Enables using async tasks via Job System when performing drawing. /// API_FIELD() bool EnableAsync = true; RenderContextBatch() = default; RenderContextBatch(SceneRenderTask* task); RenderContextBatch(const RenderContext& context); FORCE_INLINE RenderContext& GetMainContext() { return Contexts.Get()[0]; } FORCE_INLINE const RenderContext& GetMainContext() const { return Contexts.Get()[0]; } /// /// Waits for all scheduled async jobs to complete and clears WaitLabels. /// void FlushWaitLabels(); };