Add logic to allow lazy rendering

This commit is contained in:
Georg Hagen
2024-07-01 21:13:21 +02:00
parent 3dd7269470
commit 142c683c7f
4 changed files with 18 additions and 5 deletions

View File

@@ -17,9 +17,10 @@ namespace OpenVulkano
{
namespace
{
const char *NUM_THREADS_STR = "num_threads";
const char *FRAMEBUFFER_CLEAR_COLOR_STR = "framebuffer_clear_color";
const char *PREFER_FRAMEBUFFER_FORMAT_SRGB_STR = "prefer_framebuffer_format_srgb";
const char* NUM_THREADS_STR = "NumThreads";
const char* FRAMEBUFFER_CLEAR_COLOR_STR = "FramebufferClearColor";
const char* PREFER_FRAMEBUFFER_FORMAT_SRGB_STR = "PreferFramebufferFormatSRGB";
const char* LAZY_RENDERING_STR = "LazyRendering";
}
EngineConfiguration::EngineConfiguration()
@@ -50,6 +51,11 @@ namespace OpenVulkano
{
root[PREFER_FRAMEBUFFER_FORMAT_SRGB_STR] >> m_preferFramebufferFormatSRGB;
}
if (root.has_child(LAZY_RENDERING_STR))
{
root[LAZY_RENDERING_STR] >> m_lazyRendering;
}
}
EngineConfiguration* EngineConfiguration::GetEngineConfiguration()

View File

@@ -22,6 +22,7 @@ namespace OpenVulkano
uint32_t m_numThreads = 1;
std::array<float, 4> m_frameBufferClearColor = { 0.39f, 0.58f, 0.93f, 1.0f };
bool m_preferFramebufferFormatSRGB = true;
bool m_lazyRendering = false;
public:
[[nodiscard]] static EngineConfiguration* GetEngineConfiguration();
@@ -32,7 +33,10 @@ namespace OpenVulkano
void SetFrameBufferClearColor(std::array<float, 4> frameBufferClearColor) { m_frameBufferClearColor = frameBufferClearColor; }
[[nodiscard]] const std::array<float, 4>& GetFrameBufferClearColor() const { return m_frameBufferClearColor; }
[[nodiscard]] bool GetPreferFramebufferFormatSRGB() const {return m_preferFramebufferFormatSRGB; }
[[nodiscard]] bool GetPreferFramebufferFormatSRGB() const { return m_preferFramebufferFormatSRGB; }
void SetPreferFramebufferFormatSRGB(bool sRGB) { m_preferFramebufferFormatSRGB = sRGB; }
[[nodiscard]] bool GetLazyRendering() const { return m_lazyRendering; }
void SetLazyRendering(bool lazyRender) { m_lazyRendering = lazyRender; }
};
}

View File

@@ -15,6 +15,7 @@ namespace OpenVulkano
public:
uint64_t frameId = 0;
double frameTime = 1;
bool shouldDraw = true;
FrameMetadata() = default;
};

View File

@@ -10,6 +10,7 @@
#include "Base/FrameMetadata.hpp"
#include "PlatformProducer.hpp"
#include "Input/InputManager.hpp"
#include "Base/EngineConfiguration.hpp"
#include <chrono>
#include <thread>
#include <stdexcept>
@@ -140,11 +141,12 @@ namespace OpenVulkano
{
Input::InputManager::GetInstance()->Tick();
app->Tick();
renderer->Tick();
if (CURRENT_FRAME.shouldDraw) renderer->Tick();
frameTimer.Tick();
UpdateFps();
CURRENT_FRAME.frameId = frameCount;
CURRENT_FRAME.frameTime = frameTimer.GetTickSeconds();
CURRENT_FRAME.shouldDraw = !EngineConfiguration::GetEngineConfiguration()->GetLazyRendering();
}
}