39#define DEFAULT_CAPTURE_FRAME 600
58 throw std::runtime_error(
"The Application is already running!");
66 if (!wStr.empty())
try {
width = std::stoi(wStr); }
catch (...) {}
67 if (!hStr.empty())
try {
height = std::stoi(hStr); }
catch (...) {}
73 std::replace(title.begin(), title.end(),
'_',
' ');
74 Specification.Name = title;
82 if (!rendererArg.empty()) {
94 catch (std::exception& e) {
112 if (renderer) renderer->WaitIdle();
118 m_benchmark =
nullptr;
119 delete m_DebugOverlay;
120 m_DebugOverlay =
nullptr;
127 SLEAK_LOG(
"The application has been successfully closed, have a good day sir");
133 float lastTime = FrameTimer.Elapsed();
135 if(CoreWindow && CoreWindow->InitializeWindow()) {
137 if(renderer && renderer->Initialize()) {
139 renderer->CreateImGUI();
140 if (renderer->GetImGUIEnabled())
141 CoreWindow->SetImGuiReady(
true);
144 m_DebugOverlay->Initialize(renderer, game);
147 m_benchmark->Initialize(renderer);
148 renderer->RegisterBenchmarkMetrics(*m_benchmark);
149 m_benchmark->RegisterMetric(
"CPU_frame_ms",
150 [
this]() {
return m_cpuFrameMs; });
152 auto& cfg = m_DebugOverlay->GetConfig();
153 cfg.ShowCameraPanel =
false;
154 cfg.ShowPerformancePanel =
false;
157 auto context = renderer->GetContext();
160 float lastTime = FrameTimer.Elapsed();
161 float accumulator = 0.0f;
162 const float fixedTimestep = 1.0f / 60.0f;
166 const bool captureMode = !capturePath.empty();
168 const std::string frameArg =
170 if (!frameArg.empty()) {
172 captureFrame = std::stoull(frameArg);
178 "Frame capture: frame {} -> {} (fixed 1/60 s step, "
180 captureFrame, capturePath);
181 uint64_t frameIndex = 0;
182 bool captureArmed =
false;
188 if (!Game->Initialize()) {
201 if (!msaaStr.empty()) {
202 try { renderer->SetMSAASampleCount(
203 static_cast<uint32_t
>(std::stoi(msaaStr))); }
213 m_benchmark->ToggleRecording();
216 while(!CoreWindow->ShouldClose()) {
218 float currentTime = FrameTimer.Elapsed();
220 captureMode ? fixedTimestep : currentTime - lastTime;
221 lastTime = currentTime;
223 #if defined(_DEBUG) && defined(COUNT_FRAME)
227 CoreWindow->Update();
230 if (m_pendingResize && !captureMode) {
231 renderer->Resize(m_pendingResizeW, m_pendingResizeH);
232 width =
static_cast<int>(m_pendingResizeW);
233 height =
static_cast<int>(m_pendingResizeH);
234 m_pendingResize =
false;
239 if (Game && Game->GetActiveScene()) {
240 if (
auto* cam = Game->GetActiveScene()->GetActiveCamera())
241 cam->OnResize(m_pendingResizeW, m_pendingResizeH);
245 if (captureMode && !captureArmed &&
246 frameIndex >= captureFrame) {
248 if (!renderer->RequestFrameCapture(capturePath)) {
250 renderer->GetTypeStr());
257 renderer->BeginRender();
258 const auto cpuFrameStart = std::chrono::steady_clock::now();
261 if (Game && Game->GetActiveScene()) {
262 auto* activeScene = Game->GetActiveScene();
265 accumulator += DeltaTime;
266 while (accumulator >= fixedTimestep) {
267 activeScene->FixedUpdate(fixedTimestep);
268 accumulator -= fixedTimestep;
272 activeScene->Update(DeltaTime);
275 activeScene->LateUpdate(DeltaTime);
280 Game->Loop(DeltaTime);
282 m_DebugOverlay->Render(DeltaTime);
285 m_benchmark->Tick(DeltaTime);
287 renderer->FlushPendingTransfers();
289 if (queue && context)
290 queue->ExecuteCommands(context);
293 std::chrono::duration<float, std::milli>(
294 std::chrono::steady_clock::now() - cpuFrameStart)
296 renderer->EndRender();
298 if (captureArmed && !renderer->IsFrameCapturePending())
321 m_pendingResize =
true;
327 if (w > 0 && h > 0) {
328 m_pendingResizeW =
static_cast<uint32_t
>(w);
329 m_pendingResizeH =
static_cast<uint32_t
>(h);
330 m_pendingResize =
true;
363 if (Game && Game->GetActiveScene()) {
364 Camera* cam = Game->GetActiveScene()->GetActiveCamera();
368 fpc->SetEnabled(!fpc->IsEnabled());
380 CoreWindow->ToggleFullScreen();
385 m_benchmark->ToggleRecording();
401 if (renderer) renderer->WaitIdle();
413 CoreWindow->SetRelativeMouseMode(enabled);
425 switch (renderer->GetType()) {
430 default: r = 0.5f; g = 0.5f; b = 0.5f;
break;
442 return renderer->GetDeferredEnabled();
445 renderer->SetDeferredEnabled(enable);
469 return renderer->GetSharpenStrength();
472 renderer->SetSharpenStrength(s);
479 m_graphicsConfig = cfg;
482 renderer->SetSSAOBias(cfg.
ssaoBias);
493 renderer->SetExposure(cfg.
exposure);
494 renderer->SetGamma(cfg.
gamma);
499 return m_graphicsConfig;
503 return renderer->GetFeatureCaps();
#define DEFAULT_CAPTURE_FRAME
Application(const char *ProjectName)
void SetVSync(bool enabled)
void SetDeferredEnabled(bool enabled)
uint32_t GetMSAASampleCount() const
void OnWindowResize(const Sleak::Events::WindowResizeEvent &e)
Stashes the new size; the resize is applied at the start of the next frame.
void SetSSAOPower(float power)
void SetSSREnabled(bool enabled)
int GetFPS() const
Frames rendered in the last second.
void SetBloomEnabled(bool enabled)
float GetSharpenStrength() const
Post-TAA contrast-adaptive sharpening strength, 0 = off, 1 = strongest.
void onMouseClick(const Sleak::Events::Input::MouseButtonPressedEvent &e)
void OnKeyPressed(const Sleak::Events::Input::KeyPressedEvent &e)
Handles engine-level hotkeys (F9 camera toggle, F11 fullscreen, F12 benchmark, Esc).
bool IsBloomEnabled() const
void SetSharpenStrength(float strength)
Sets post-TAA sharpening strength; only applied on frames TAA resolves.
void SetIBLEnabled(bool enabled)
const bool GetIsDeferredEnabled() const
Deferred rendering.
void SetIBLIntensity(float intensity)
const char * GetRendererTypeStr() const
Human-readable name of the active backend (e.g. "Vulkan").
float GetIBLIntensity() const
void OnWindowFullScreen(const Sleak::Events::WindowFullScreen &e)
Treats entering/leaving fullscreen as a resize to the current window size.
int GetVertices() const
Vertices submitted in the last frame.
void SetSSAORadius(float radius)
void SetMSAASampleCount(uint32_t samples)
size_t GetGPUMemoryBudget() const
void onMouseMove(const Sleak::Events::Input::MouseMovedEvent &e)
float GetFrameTime() const
Duration of the last frame, in seconds.
const GraphicsConfig & GetGraphicsConfig() const
Config last passed to ApplyGraphicsConfig().
void GetRendererTypeColor(float &r, float &g, float &b) const
UI accent color associated with the active backend.
bool IsSSAOEnabled() const
void WaitGPUIdle()
Blocks until the GPU finishes all in-flight work. Call before tearing down scene resources.
void ApplyGraphicsConfig(const GraphicsConfig &cfg)
Pushes every field of cfg onto the active renderer in one call.
float GetSSAORadius() const
void SetSSAOBias(float bias)
void SetMouseRelativeMode(bool enabled)
size_t GetGPUMemoryUsed() const
bool IsIBLEnabled() const
int GetTriangles() const
Triangles submitted in the last frame.
bool IsSSREnabled() const
int Run(GameBase *game)
Drives the game loop until the window closes; returns the process exit code.
float GetSSAOPower() const
void SetCursorVisible(bool visible)
uint32_t GetGraphicsCaps() const
float GetSSAOBias() const
uint32_t GetMaxMSAASampleCount() const
bool IsTAAEnabled() const
void SetTAAEnabled(bool enabled)
void SetSSAOEnabled(bool enabled)
static std::string GetValue(const std::string &flag, const std::string &defaultVal="")
Returns the raw string value stored for -flag, or defaultVal if it was not passed.
static bool HasFlag(const std::string &flag)
True if --flag was present on the command line.
static void AddSourceDirectory(const std::string &dir)
Watches a shader source folder. Later folders override earlier ones.
static void Poll()
Rebuilds changed shaders. Called once per frame by Application.
static std::string RegisterEventHandler(T *instance, void(T::*memberFunction)(const EventT &))
Registers a member-function handler bound to instance, returning an ID for later unregistration.
uint16_t GetHeight() const
uint16_t GetWidth() const
void SetEnabled(bool enabled) override
Toggles relative mouse mode and, when re-enabling, resets velocity and re-syncs yaw/pitch.
T * GetComponent()
Finds the first attached component of type T, or nullptr.
static void Shutdown()
Release static resources before renderer cleanup.
static RenderCommandQueue * GetInstance()
Lazily creates and returns the process-wide singleton instance.
static Renderer * ParseArg(std::string arg, Window *window)
Resolves a CLI backend name (e.g. "-vulkan") to a Renderer instance.
static Renderer * CreateRenderer(RendererType type, Window *window)
Instantiates and returns the Renderer for the given backend, bound to a window.
ScopedTimer(const std::string &name)
static int GetHeight()
Returns the current window height in pixels.
Window()
Constructs a window with the default size and no title.
static int GetWidth()
Returns the current window width in pixels.
void Close()
Marks the window for close; actual teardown happens in the destructor.
Vectors, matrices, quaternions, colors, AABBs, and random helpers.
ENGINE_API void ShutdownTextureCache()
Root namespace for everything the engine exposes.
Arguments(int argc, char **argv)
uint32_t shadowMapResolution