2020-08-26 15:38:01 +08:00
|
|
|
#pragma once
|
2021-05-10 08:23:02 +08:00
|
|
|
#include <blah/common.h>
|
2021-12-13 12:41:23 +08:00
|
|
|
#include <blah/numerics/spatial.h>
|
2020-08-26 15:38:01 +08:00
|
|
|
|
|
|
|
namespace Blah
|
|
|
|
{
|
2021-03-21 17:08:28 +08:00
|
|
|
// Application Event Functions
|
2021-05-10 08:23:02 +08:00
|
|
|
using AppEventFn = Func<void()>;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Application Logging Functions
|
2021-05-10 08:23:02 +08:00
|
|
|
using AppLogFn = Func<void(const char* message, Log::Category category)>;
|
2021-02-22 10:43:42 +08:00
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Application Configuration
|
2020-08-26 15:38:01 +08:00
|
|
|
struct Config
|
|
|
|
{
|
2021-03-21 17:08:28 +08:00
|
|
|
// Application name.
|
|
|
|
// This has no default and must be set.
|
2020-08-26 15:38:01 +08:00
|
|
|
const char* name;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Starting width, in pixels.
|
|
|
|
// Depending on the OS DPI, the true window size may be a multiple of this.
|
|
|
|
// This has no default and must be set.
|
2020-08-26 15:38:01 +08:00
|
|
|
int width;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Starting height, in pixels.
|
|
|
|
// Depending on the OS DPI, the true window size may be a multiple of this.
|
|
|
|
// This has no default and must be set.
|
2020-08-26 15:38:01 +08:00
|
|
|
int height;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// maximum updates to run before "giving up" and reducing frame rate.
|
|
|
|
// this avoids the 'spiral of death'.
|
|
|
|
// defaults to 5.
|
2020-08-26 15:38:01 +08:00
|
|
|
int max_updates;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// target framerate.
|
|
|
|
// defaults to 60.
|
2020-08-26 15:38:01 +08:00
|
|
|
int target_framerate;
|
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Callback on application startup
|
|
|
|
// Defaults to nothing.
|
2021-02-22 10:43:42 +08:00
|
|
|
AppEventFn on_startup;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Callback on application shutdown
|
|
|
|
// Defaults to nothing.
|
2021-02-22 10:43:42 +08:00
|
|
|
AppEventFn on_shutdown;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Callback on application update
|
|
|
|
// Defaults to nothing.
|
2021-02-22 10:43:42 +08:00
|
|
|
AppEventFn on_update;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Callback on application render
|
|
|
|
// Defaults to nothing.
|
2021-02-22 10:43:42 +08:00
|
|
|
AppEventFn on_render;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Callback when the user has requested the application close.
|
2021-05-20 02:21:08 +08:00
|
|
|
// For example, pressing the Close button, ALT+F4, etc
|
2021-03-21 17:08:28 +08:00
|
|
|
// By default this calls `App::exit()`
|
2021-02-22 10:43:42 +08:00
|
|
|
AppEventFn on_exit_request;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Callback when the application logs info/warning/errors
|
|
|
|
// Defaults to printf.
|
2021-02-22 10:43:42 +08:00
|
|
|
AppLogFn on_log;
|
2020-08-26 15:38:01 +08:00
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Default config setup
|
2020-08-26 15:38:01 +08:00
|
|
|
Config();
|
|
|
|
};
|
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Renderer the Application is using
|
2020-12-27 06:44:48 +08:00
|
|
|
enum class Renderer
|
|
|
|
{
|
|
|
|
None = -1,
|
|
|
|
OpenGL,
|
|
|
|
D3D11,
|
|
|
|
Metal,
|
|
|
|
Count
|
|
|
|
};
|
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Features available on the current Renderer
|
2020-12-27 06:44:48 +08:00
|
|
|
struct RendererFeatures
|
|
|
|
{
|
2021-03-21 17:08:28 +08:00
|
|
|
// Whether Mesh Instancing is available
|
2020-12-27 06:44:48 +08:00
|
|
|
bool instancing = false;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Whether the Texture origin is the bottom left.
|
|
|
|
// This is true for OpenGL.
|
2020-12-27 06:44:48 +08:00
|
|
|
bool origin_bottom_left = false;
|
2021-03-21 17:08:28 +08:00
|
|
|
|
|
|
|
// Maximum Texture Size available
|
2020-12-27 06:44:48 +08:00
|
|
|
int max_texture_size = 0;
|
|
|
|
};
|
|
|
|
|
2021-05-10 08:23:02 +08:00
|
|
|
// Forward declare Target for the BackBuffer
|
|
|
|
class Target;
|
|
|
|
using TargetRef = Ref<Target>;
|
2021-01-01 05:43:23 +08:00
|
|
|
|
2021-03-21 17:08:28 +08:00
|
|
|
// Application
|
2020-08-26 15:38:01 +08:00
|
|
|
namespace App
|
|
|
|
{
|
|
|
|
// Runs the application
|
|
|
|
bool run(const Config* config);
|
|
|
|
|
2021-03-23 16:56:53 +08:00
|
|
|
// Exits the application.
|
|
|
|
// This only signals for the application to close, it will not stop
|
|
|
|
// until the current update and render calls are finished.
|
2020-08-26 15:38:01 +08:00
|
|
|
void exit();
|
|
|
|
|
|
|
|
// Gets the config data used to run the application
|
2021-05-10 10:40:50 +08:00
|
|
|
const Config& config();
|
2020-08-26 15:38:01 +08:00
|
|
|
|
|
|
|
// Gets the working path
|
|
|
|
const char* path();
|
|
|
|
|
|
|
|
// Gets the user path
|
|
|
|
const char* user_path();
|
|
|
|
|
2021-05-10 10:46:08 +08:00
|
|
|
// Gets the Window Title
|
|
|
|
const char* get_title();
|
|
|
|
|
|
|
|
// Sets the Window Title
|
|
|
|
void set_title(const char* title);
|
|
|
|
|
|
|
|
// Gets the Window Position
|
|
|
|
Point get_position();
|
|
|
|
|
|
|
|
// Sets the Window Position
|
|
|
|
void set_position(Point point);
|
|
|
|
|
|
|
|
// Gets the Window Size
|
|
|
|
Point get_size();
|
|
|
|
|
|
|
|
// Sets the Window Size
|
|
|
|
void set_size(Point point);
|
|
|
|
|
2020-08-26 15:38:01 +08:00
|
|
|
// Gets the width of the window
|
|
|
|
int width();
|
|
|
|
|
|
|
|
// Gets the height of the window
|
|
|
|
int height();
|
|
|
|
|
2021-03-23 16:56:53 +08:00
|
|
|
// Gets the drawable width of the window, in pixels.
|
|
|
|
// This may differ from the width when on platforms with High DPI Displays.
|
2020-08-26 15:38:01 +08:00
|
|
|
int draw_width();
|
|
|
|
|
2021-03-23 16:56:53 +08:00
|
|
|
// Gets the drawable height of the window, in pixels.
|
|
|
|
// This may differ from the height when on platforms with High DPI Displays.
|
2020-08-26 15:38:01 +08:00
|
|
|
int draw_height();
|
|
|
|
|
2021-03-23 16:56:53 +08:00
|
|
|
// Gets the content scale based on the platform.
|
|
|
|
// macOS is usually 2.0, other platforms vary.
|
2020-08-26 15:38:01 +08:00
|
|
|
float content_scale();
|
|
|
|
|
2021-03-23 16:56:53 +08:00
|
|
|
// Toggles fullscreen if supported on the platform.
|
|
|
|
// Otherwise this function does nothing.
|
2020-08-26 15:38:01 +08:00
|
|
|
void fullscreen(bool enabled);
|
2020-12-27 06:44:48 +08:00
|
|
|
|
|
|
|
// Returns the Rendering API in use
|
|
|
|
Renderer renderer();
|
|
|
|
|
|
|
|
// Retrieves the Renderer Features
|
|
|
|
const RendererFeatures& renderer_features();
|
|
|
|
|
|
|
|
// Reference to the window's back buffer
|
2021-05-10 08:23:02 +08:00
|
|
|
extern const TargetRef backbuffer;
|
2020-08-26 15:38:01 +08:00
|
|
|
}
|
|
|
|
}
|