Implement custom rendering framerate for RenderTask
This commit is contained in:
@@ -14,6 +14,7 @@
|
|||||||
#include "Engine/Renderer/Renderer.h"
|
#include "Engine/Renderer/Renderer.h"
|
||||||
#include "Engine/Render2D/Render2D.h"
|
#include "Engine/Render2D/Render2D.h"
|
||||||
#include "Engine/Engine/Engine.h"
|
#include "Engine/Engine/Engine.h"
|
||||||
|
#include "Engine/Engine/Time.h"
|
||||||
#include "Engine/Profiler/Profiler.h"
|
#include "Engine/Profiler/Profiler.h"
|
||||||
#include "Engine/Renderer/RenderList.h"
|
#include "Engine/Renderer/RenderList.h"
|
||||||
#include "Engine/Threading/Threading.h"
|
#include "Engine/Threading/Threading.h"
|
||||||
@@ -71,9 +72,20 @@ RenderTask::~RenderTask()
|
|||||||
|
|
||||||
bool RenderTask::CanDraw() const
|
bool RenderTask::CanDraw() const
|
||||||
{
|
{
|
||||||
if (SwapChain && SwapChain->GetWindow() && !SwapChain->GetWindow()->IsVisible() && !SwapChain->GetWindow()->GetSettings().ShowAfterFirstPaint)
|
if (!Enabled)
|
||||||
return false;
|
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()
|
void RenderTask::OnDraw()
|
||||||
@@ -82,6 +94,9 @@ void RenderTask::OnDraw()
|
|||||||
OnBegin(context);
|
OnBegin(context);
|
||||||
OnRender(context);
|
OnRender(context);
|
||||||
OnEnd(context);
|
OnEnd(context);
|
||||||
|
|
||||||
|
if (RenderFPS > ZeroTolerance)
|
||||||
|
_lastFrameTime = Time::Draw.UnscaledTime.GetTotalSeconds();
|
||||||
}
|
}
|
||||||
|
|
||||||
void RenderTask::OnBegin(GPUContext* context)
|
void RenderTask::OnBegin(GPUContext* context)
|
||||||
|
|||||||
@@ -53,6 +53,8 @@ API_CLASS() class FLAXENGINE_API RenderTask : public ScriptingObject
|
|||||||
private:
|
private:
|
||||||
RenderTask* _prevTask = nullptr;
|
RenderTask* _prevTask = nullptr;
|
||||||
|
|
||||||
|
float _lastFrameTime = 0.0f;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Finalizes an instance of the <see cref="RenderTask"/> class.
|
/// Finalizes an instance of the <see cref="RenderTask"/> class.
|
||||||
@@ -70,6 +72,11 @@ public:
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
API_FIELD() int32 Order = 0;
|
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>
|
/// <summary>
|
||||||
/// The amount of frames rendered by this task. It is auto incremented on task drawing.
|
/// The amount of frames rendered by this task. It is auto incremented on task drawing.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|||||||
Reference in New Issue
Block a user