SleakEngine 0.1.0
C++23 multi-backend game engine
Loading...
Searching...
No Matches
Sleak::Application Class Reference

#include <Application.hpp>

Public Member Functions

 Application (ApplicationDefaults settings)
 Application (const char *ProjectName)
 ~Application ()
void ApplyGraphicsConfig (const GraphicsConfig &cfg)
 Pushes every field of cfg onto the active renderer in one call.
void CloseApplication ()
Benchmark * GetBenchmark ()
int GetFPS () const
 Frames rendered in the last second.
float GetFrameTime () const
 Duration of the last frame, in seconds.
GameBase * GetGame ()
size_t GetGPUMemoryBudget () const
size_t GetGPUMemoryUsed () const
uint32_t GetGraphicsCaps () const
const GraphicsConfig & GetGraphicsConfig () const
 Config last passed to ApplyGraphicsConfig().
float GetIBLIntensity () const
const bool GetIsDeferredEnabled () const
 Deferred rendering.
uint32_t GetMaxMSAASampleCount () const
uint32_t GetMSAASampleCount () const
RenderEngine::Renderer * GetRenderer ()
 Active renderer backend, or null before Run() initializes it.
void GetRendererTypeColor (float &r, float &g, float &b) const
 UI accent color associated with the active backend.
const char * GetRendererTypeStr () const
 Human-readable name of the active backend (e.g. "Vulkan").
float GetSharpenStrength () const
 Post-TAA contrast-adaptive sharpening strength, 0 = off, 1 = strongest.
float GetSSAOBias () const
float GetSSAOPower () const
float GetSSAORadius () const
int GetTriangles () const
 Triangles submitted in the last frame.
int GetVertices () const
 Vertices submitted in the last frame.
bool GetVSync () const
Window & GetWindow ()
bool IsBloomEnabled () const
bool IsIBLEnabled () const
bool IsSSAOEnabled () const
bool IsSSREnabled () const
bool IsTAAEnabled () const
void OnKeyPressed (const Sleak::Events::Input::KeyPressedEvent &e)
 Handles engine-level hotkeys (F9 camera toggle, F11 fullscreen, F12 benchmark, Esc).
void onMouseClick (const Sleak::Events::Input::MouseButtonPressedEvent &e)
void onMouseMove (const Sleak::Events::Input::MouseMovedEvent &e)
void OnWindowFullScreen (const Sleak::Events::WindowFullScreen &e)
 Treats entering/leaving fullscreen as a resize to the current window size.
void OnWindowResize (const Sleak::Events::WindowResizeEvent &e)
 Stashes the new size; the resize is applied at the start of the next frame.
Application & operator= (Application &&)=delete
Application & operator= (const Application &)=delete
int Run (GameBase *game)
 Drives the game loop until the window closes; returns the process exit code.
void SetBloomEnabled (bool enabled)
void SetCursorVisible (bool visible)
void SetDeferredEnabled (bool enabled)
void SetIBLEnabled (bool enabled)
void SetIBLIntensity (float intensity)
void SetMouseRelativeMode (bool enabled)
void SetMSAASampleCount (uint32_t samples)
void SetSharpenStrength (float strength)
 Sets post-TAA sharpening strength; only applied on frames TAA resolves.
void SetSSAOBias (float bias)
void SetSSAOEnabled (bool enabled)
void SetSSAOPower (float power)
void SetSSAORadius (float radius)
void SetSSREnabled (bool enabled)
void SetTAAEnabled (bool enabled)
void SetVSync (bool enabled)
void WaitGPUIdle ()
 Blocks until the GPU finishes all in-flight work. Call before tearing down scene resources.

Static Public Member Functions

static Application * GetInstance ()
 The one Application for this process, or null before construction.

Detailed Description

Owns the window, renderer, and game loop. One instance per process, reachable globally through GetInstance().

Construct one in main(), hand it your GameBase, and call Run(). It creates the window, selects a graphics backend, and then drives the frame loop until the window closes: poll events, update the active scene, call GameBase::Loop, render, present.

The backend comes from the -r command line flag when Sleak::CommandLine::Parse has run, otherwise from the platform default (DirectX 11 on Windows, Vulkan elsewhere). Window size and title honor -w, -h, and -t the same way.

Everything on this class is main-thread only. Constructing a second Application throws.

Rendering quality settings (MSAA, VSync, SSAO, SSR, TAA, bloom, IBL) can be changed at any point after Run() starts. Settings that belong to the deferred path are ignored by backends that do not implement it, so check GetGraphicsCaps() before exposing them in a settings UI.

int main(int argc, char** argv) {
.Name = "MyGame",
.CommandLineArgs = Sleak::Arguments(argc, argv)};
Game* game = new Game();
Sleak::Application app(defaults);
return app.Run(game);
}
// Anywhere later, from game code:
app->SetMSAASampleCount(8);
app->SetVSync(true);
SLEAK_INFO("{} at {} FPS", app->GetRendererTypeStr(), app->GetFPS());
// Before tearing down scene resources:
app->WaitGPUIdle();
#define SLEAK_INFO(...)
Definition Logger.hpp:20
static Application * GetInstance()
The one Application for this process, or null before construction.
static void Parse(int argc, char **argv)
Parses argv into the value/flag tables. Call once from main(), before Application.
static void Init(const std::string &ProjectName)
Creates the console + file sinks and registers both loggers. Call once at startup.
Definition Logger.cpp:34
See also
GameBase, Scene, CommandLine, Logger, GraphicsConfig

Definition at line 109 of file Application.hpp.

Constructor & Destructor Documentation

◆ Application() [1/2]

Sleak::Application::Application ( const char * ProjectName)

Definition at line 50 of file Application.cpp.

◆ Application() [2/2]

Sleak::Application::Application ( ApplicationDefaults settings)

Definition at line 56 of file Application.cpp.

◆ ~Application()

Sleak::Application::~Application ( )

Definition at line 106 of file Application.cpp.

Member Function Documentation

◆ ApplyGraphicsConfig()

void Sleak::Application::ApplyGraphicsConfig ( const GraphicsConfig & cfg)

Pushes every field of cfg onto the active renderer in one call.

Definition at line 478 of file Application.cpp.

◆ CloseApplication()

void Sleak::Application::CloseApplication ( )

Definition at line 396 of file Application.cpp.

◆ GetBenchmark()

Benchmark * Sleak::Application::GetBenchmark ( )
inline

Definition at line 203 of file Application.hpp.

◆ GetFPS()

int Sleak::Application::GetFPS ( ) const

Frames rendered in the last second.

Definition at line 416 of file Application.cpp.

◆ GetFrameTime()

float Sleak::Application::GetFrameTime ( ) const

Duration of the last frame, in seconds.

Definition at line 417 of file Application.cpp.

◆ GetGame()

GameBase * Sleak::Application::GetGame ( )
inline

Definition at line 130 of file Application.hpp.

◆ GetGPUMemoryBudget()

size_t Sleak::Application::GetGPUMemoryBudget ( ) const

Definition at line 421 of file Application.cpp.

◆ GetGPUMemoryUsed()

size_t Sleak::Application::GetGPUMemoryUsed ( ) const

Definition at line 420 of file Application.cpp.

◆ GetGraphicsCaps()

uint32_t Sleak::Application::GetGraphicsCaps ( ) const

Definition at line 502 of file Application.cpp.

◆ GetGraphicsConfig()

const GraphicsConfig & Sleak::Application::GetGraphicsConfig ( ) const

Config last passed to ApplyGraphicsConfig().

Definition at line 498 of file Application.cpp.

◆ GetIBLIntensity()

float Sleak::Application::GetIBLIntensity ( ) const

Definition at line 459 of file Application.cpp.

◆ GetInstance()

Application * Sleak::Application::GetInstance ( )
inlinestatic

The one Application for this process, or null before construction.

Definition at line 133 of file Application.hpp.

◆ GetIsDeferredEnabled()

const bool Sleak::Application::GetIsDeferredEnabled ( ) const

Deferred rendering.

Definition at line 441 of file Application.cpp.

◆ GetMaxMSAASampleCount()

uint32_t Sleak::Application::GetMaxMSAASampleCount ( ) const

Definition at line 435 of file Application.cpp.

◆ GetMSAASampleCount()

uint32_t Sleak::Application::GetMSAASampleCount ( ) const

Definition at line 434 of file Application.cpp.

◆ GetRenderer()

RenderEngine::Renderer * Sleak::Application::GetRenderer ( )
inline

Active renderer backend, or null before Run() initializes it.

Definition at line 129 of file Application.hpp.

◆ GetRendererTypeColor()

void Sleak::Application::GetRendererTypeColor ( float & r,
float & g,
float & b ) const

UI accent color associated with the active backend.

Definition at line 424 of file Application.cpp.

◆ GetRendererTypeStr()

const char * Sleak::Application::GetRendererTypeStr ( ) const

Human-readable name of the active backend (e.g. "Vulkan").

Definition at line 422 of file Application.cpp.

◆ GetSharpenStrength()

float Sleak::Application::GetSharpenStrength ( ) const

Post-TAA contrast-adaptive sharpening strength, 0 = off, 1 = strongest.

Definition at line 468 of file Application.cpp.

◆ GetSSAOBias()

float Sleak::Application::GetSSAOBias ( ) const

Definition at line 452 of file Application.cpp.

◆ GetSSAOPower()

float Sleak::Application::GetSSAOPower ( ) const

Definition at line 454 of file Application.cpp.

◆ GetSSAORadius()

float Sleak::Application::GetSSAORadius ( ) const

Definition at line 450 of file Application.cpp.

◆ GetTriangles()

int Sleak::Application::GetTriangles ( ) const

Triangles submitted in the last frame.

Definition at line 419 of file Application.cpp.

◆ GetVertices()

int Sleak::Application::GetVertices ( ) const

Vertices submitted in the last frame.

Definition at line 418 of file Application.cpp.

◆ GetVSync()

bool Sleak::Application::GetVSync ( ) const

Definition at line 438 of file Application.cpp.

◆ GetWindow()

Window & Sleak::Application::GetWindow ( )

Definition at line 392 of file Application.cpp.

◆ IsBloomEnabled()

bool Sleak::Application::IsBloomEnabled ( ) const

Definition at line 475 of file Application.cpp.

◆ IsIBLEnabled()

bool Sleak::Application::IsIBLEnabled ( ) const

Definition at line 457 of file Application.cpp.

◆ IsSSAOEnabled()

bool Sleak::Application::IsSSAOEnabled ( ) const

Definition at line 448 of file Application.cpp.

◆ IsSSREnabled()

bool Sleak::Application::IsSSREnabled ( ) const

Definition at line 462 of file Application.cpp.

◆ IsTAAEnabled()

bool Sleak::Application::IsTAAEnabled ( ) const

Definition at line 465 of file Application.cpp.

◆ OnKeyPressed()

void Sleak::Application::OnKeyPressed ( const Sleak::Events::Input::KeyPressedEvent & e)

Handles engine-level hotkeys (F9 camera toggle, F11 fullscreen, F12 benchmark, Esc).

Definition at line 341 of file Application.cpp.

◆ onMouseClick()

void Sleak::Application::onMouseClick ( const Sleak::Events::Input::MouseButtonPressedEvent & e)

Definition at line 334 of file Application.cpp.

◆ onMouseMove()

void Sleak::Application::onMouseMove ( const Sleak::Events::Input::MouseMovedEvent & e)

Definition at line 338 of file Application.cpp.

◆ OnWindowFullScreen()

void Sleak::Application::OnWindowFullScreen ( const Sleak::Events::WindowFullScreen & e)

Treats entering/leaving fullscreen as a resize to the current window size.

Definition at line 324 of file Application.cpp.

◆ OnWindowResize()

void Sleak::Application::OnWindowResize ( const Sleak::Events::WindowResizeEvent & e)

Stashes the new size; the resize is applied at the start of the next frame.

Definition at line 317 of file Application.cpp.

◆ operator=() [1/2]

Application & Sleak::Application::operator= ( Application && )
delete

◆ operator=() [2/2]

Application & Sleak::Application::operator= ( const Application & )
delete

◆ Run()

int Sleak::Application::Run ( GameBase * game)

Drives the game loop until the window closes; returns the process exit code.

Definition at line 130 of file Application.cpp.

◆ SetBloomEnabled()

void Sleak::Application::SetBloomEnabled ( bool enabled)

Definition at line 476 of file Application.cpp.

◆ SetCursorVisible()

void Sleak::Application::SetCursorVisible ( bool visible)

Definition at line 404 of file Application.cpp.

◆ SetDeferredEnabled()

void Sleak::Application::SetDeferredEnabled ( bool enabled)

Definition at line 444 of file Application.cpp.

◆ SetIBLEnabled()

void Sleak::Application::SetIBLEnabled ( bool enabled)

Definition at line 458 of file Application.cpp.

◆ SetIBLIntensity()

void Sleak::Application::SetIBLIntensity ( float intensity)

Definition at line 460 of file Application.cpp.

◆ SetMouseRelativeMode()

void Sleak::Application::SetMouseRelativeMode ( bool enabled)

Definition at line 411 of file Application.cpp.

◆ SetMSAASampleCount()

void Sleak::Application::SetMSAASampleCount ( uint32_t samples)

Definition at line 436 of file Application.cpp.

◆ SetSharpenStrength()

void Sleak::Application::SetSharpenStrength ( float strength)

Sets post-TAA sharpening strength; only applied on frames TAA resolves.

Definition at line 471 of file Application.cpp.

◆ SetSSAOBias()

void Sleak::Application::SetSSAOBias ( float bias)

Definition at line 453 of file Application.cpp.

◆ SetSSAOEnabled()

void Sleak::Application::SetSSAOEnabled ( bool enabled)

Definition at line 449 of file Application.cpp.

◆ SetSSAOPower()

void Sleak::Application::SetSSAOPower ( float power)

Definition at line 455 of file Application.cpp.

◆ SetSSAORadius()

void Sleak::Application::SetSSAORadius ( float radius)

Definition at line 451 of file Application.cpp.

◆ SetSSREnabled()

void Sleak::Application::SetSSREnabled ( bool enabled)

Definition at line 463 of file Application.cpp.

◆ SetTAAEnabled()

void Sleak::Application::SetTAAEnabled ( bool enabled)

Definition at line 466 of file Application.cpp.

◆ SetVSync()

void Sleak::Application::SetVSync ( bool enabled)

Definition at line 439 of file Application.cpp.

◆ WaitGPUIdle()

void Sleak::Application::WaitGPUIdle ( )

Blocks until the GPU finishes all in-flight work. Call before tearing down scene resources.

Definition at line 400 of file Application.cpp.