SleakEngine 1.0.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 ()
BenchmarkGetBenchmark ()
int GetFPS () const
 Frames rendered in the last second.
float GetFrameTime () const
 Duration of the last frame, in seconds.
GameBaseGetGame ()
size_t GetGPUMemoryBudget () const
size_t GetGPUMemoryUsed () const
uint32_t GetGraphicsCaps () const
const GraphicsConfigGetGraphicsConfig () const
 Config last passed to ApplyGraphicsConfig().
float GetIBLIntensity () const
uint32_t GetMaxMSAASampleCount () const
uint32_t GetMSAASampleCount () const
RenderEngine::RendererGetRenderer ()
 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 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
WindowGetWindow ()
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.
Applicationoperator= (Application &&)=delete
Applicationoperator= (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 SetIBLEnabled (bool enabled)
void SetIBLIntensity (float intensity)
void SetMouseRelativeMode (bool enabled)
void SetMSAASampleCount (uint32_t samples)
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 ApplicationGetInstance ()
 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 46 of file Application.cpp.

◆ Application() [2/2]

Sleak::Application::Application ( ApplicationDefaults settings)

Definition at line 52 of file Application.cpp.

◆ ~Application()

Sleak::Application::~Application ( )

Definition at line 102 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 413 of file Application.cpp.

◆ CloseApplication()

void Sleak::Application::CloseApplication ( )

Definition at line 345 of file Application.cpp.

◆ GetBenchmark()

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

Definition at line 194 of file Application.hpp.

◆ GetFPS()

int Sleak::Application::GetFPS ( ) const

Frames rendered in the last second.

Definition at line 365 of file Application.cpp.

◆ GetFrameTime()

float Sleak::Application::GetFrameTime ( ) const

Duration of the last frame, in seconds.

Definition at line 366 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 370 of file Application.cpp.

◆ GetGPUMemoryUsed()

size_t Sleak::Application::GetGPUMemoryUsed ( ) const

Definition at line 369 of file Application.cpp.

◆ GetGraphicsCaps()

uint32_t Sleak::Application::GetGraphicsCaps ( ) const

Definition at line 436 of file Application.cpp.

◆ GetGraphicsConfig()

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

Config last passed to ApplyGraphicsConfig().

Definition at line 432 of file Application.cpp.

◆ GetIBLIntensity()

float Sleak::Application::GetIBLIntensity ( ) const

Definition at line 401 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.

◆ GetMaxMSAASampleCount()

uint32_t Sleak::Application::GetMaxMSAASampleCount ( ) const

Definition at line 384 of file Application.cpp.

◆ GetMSAASampleCount()

uint32_t Sleak::Application::GetMSAASampleCount ( ) const

Definition at line 383 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 373 of file Application.cpp.

◆ GetRendererTypeStr()

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

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

Definition at line 371 of file Application.cpp.

◆ GetSSAOBias()

float Sleak::Application::GetSSAOBias ( ) const

Definition at line 394 of file Application.cpp.

◆ GetSSAOPower()

float Sleak::Application::GetSSAOPower ( ) const

Definition at line 396 of file Application.cpp.

◆ GetSSAORadius()

float Sleak::Application::GetSSAORadius ( ) const

Definition at line 392 of file Application.cpp.

◆ GetTriangles()

int Sleak::Application::GetTriangles ( ) const

Triangles submitted in the last frame.

Definition at line 368 of file Application.cpp.

◆ GetVertices()

int Sleak::Application::GetVertices ( ) const

Vertices submitted in the last frame.

Definition at line 367 of file Application.cpp.

◆ GetVSync()

bool Sleak::Application::GetVSync ( ) const

Definition at line 387 of file Application.cpp.

◆ GetWindow()

Window & Sleak::Application::GetWindow ( )

Definition at line 341 of file Application.cpp.

◆ IsBloomEnabled()

bool Sleak::Application::IsBloomEnabled ( ) const

Definition at line 410 of file Application.cpp.

◆ IsIBLEnabled()

bool Sleak::Application::IsIBLEnabled ( ) const

Definition at line 399 of file Application.cpp.

◆ IsSSAOEnabled()

bool Sleak::Application::IsSSAOEnabled ( ) const

Definition at line 390 of file Application.cpp.

◆ IsSSREnabled()

bool Sleak::Application::IsSSREnabled ( ) const

Definition at line 404 of file Application.cpp.

◆ IsTAAEnabled()

bool Sleak::Application::IsTAAEnabled ( ) const

Definition at line 407 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 290 of file Application.cpp.

◆ onMouseClick()

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

Definition at line 283 of file Application.cpp.

◆ onMouseMove()

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

Definition at line 287 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 273 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 266 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 126 of file Application.cpp.

◆ SetBloomEnabled()

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

Definition at line 411 of file Application.cpp.

◆ SetCursorVisible()

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

Definition at line 353 of file Application.cpp.

◆ SetIBLEnabled()

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

Definition at line 400 of file Application.cpp.

◆ SetIBLIntensity()

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

Definition at line 402 of file Application.cpp.

◆ SetMouseRelativeMode()

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

Definition at line 360 of file Application.cpp.

◆ SetMSAASampleCount()

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

Definition at line 385 of file Application.cpp.

◆ SetSSAOBias()

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

Definition at line 395 of file Application.cpp.

◆ SetSSAOEnabled()

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

Definition at line 391 of file Application.cpp.

◆ SetSSAOPower()

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

Definition at line 397 of file Application.cpp.

◆ SetSSAORadius()

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

Definition at line 393 of file Application.cpp.

◆ SetSSREnabled()

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

Definition at line 405 of file Application.cpp.

◆ SetTAAEnabled()

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

Definition at line 408 of file Application.cpp.

◆ SetVSync()

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

Definition at line 388 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 349 of file Application.cpp.