Implement custom rendering framerate for RenderTask

This commit is contained in:
2023-10-01 17:52:01 +03:00
parent d83220aad6
commit a818f39464
2 changed files with 24 additions and 2 deletions

View File

@@ -14,6 +14,7 @@
#include "Engine/Renderer/Renderer.h"
#include "Engine/Render2D/Render2D.h"
#include "Engine/Engine/Engine.h"
#include "Engine/Engine/Time.h"
#include "Engine/Profiler/Profiler.h"
#include "Engine/Renderer/RenderList.h"
#include "Engine/Threading/Threading.h"
@@ -71,9 +72,20 @@ RenderTask::~RenderTask()
bool RenderTask::CanDraw() const
{
if (SwapChain && SwapChain->GetWindow() && !SwapChain->GetWindow()->IsVisible() && !SwapChain->GetWindow()->GetSettings().ShowAfterFirstPaint)
if (!Enabled)
return false;
return Enabled;
const Window* window = SwapChain ? SwapChain->GetWindow() : nullptr;
if (window && !window->IsVisible() && !window->GetSettings().ShowAfterFirstPaint)
return false;
if (LastUsedFrame > 0 && RenderFPS > ZeroTolerance)
{
if (Time::Draw.UnscaledTime.GetTotalSeconds() < _lastFrameTime + (1.0f / RenderFPS))
return false;
}
return true;
}
void RenderTask::OnDraw()
@@ -82,6 +94,9 @@ void RenderTask::OnDraw()
OnBegin(context);
OnRender(context);
OnEnd(context);
if (RenderFPS > ZeroTolerance)
_lastFrameTime = Time::Draw.UnscaledTime.GetTotalSeconds();
}
void RenderTask::OnBegin(GPUContext* context)

View File

@@ -52,6 +52,8 @@ API_CLASS() class FLAXENGINE_API RenderTask : public ScriptingObject
private:
RenderTask* _prevTask = nullptr;
float _lastFrameTime = 0.0f;
public:
/// <summary>
@@ -70,6 +72,11 @@ public:
/// </summary>
API_FIELD() int32 Order = 0;
/// <summary>
/// The framerate of the task, or how often the task rendering is performed per second.
/// </summary>
API_FIELD() int32 RenderFPS = 0;
/// <summary>
/// The amount of frames rendered by this task. It is auto incremented on task drawing.
/// </summary>