mirror of
https://github.com/NoelFB/blah.git
synced 2025-06-29 19:25:26 +08:00
Refactored Graphics to allow Renderer choice at runtime
This commit is contained in:
@ -10,74 +10,20 @@ namespace Blah
|
||||
// Application Logging Functions
|
||||
using AppLogFn = Func<void(const char* message, Log::Category category)>;
|
||||
|
||||
// Application Configuration
|
||||
struct Config
|
||||
{
|
||||
// Application name.
|
||||
// This has no default and must be set.
|
||||
const char* name;
|
||||
|
||||
// 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.
|
||||
int width;
|
||||
|
||||
// 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.
|
||||
int height;
|
||||
|
||||
// maximum updates to run before "giving up" and reducing frame rate.
|
||||
// this avoids the 'spiral of death'.
|
||||
// defaults to 5.
|
||||
int max_updates;
|
||||
|
||||
// target framerate.
|
||||
// defaults to 60.
|
||||
int target_framerate;
|
||||
|
||||
// Callback on application startup
|
||||
// Defaults to nothing.
|
||||
AppEventFn on_startup;
|
||||
|
||||
// Callback on application shutdown
|
||||
// Defaults to nothing.
|
||||
AppEventFn on_shutdown;
|
||||
|
||||
// Callback on application update
|
||||
// Defaults to nothing.
|
||||
AppEventFn on_update;
|
||||
|
||||
// Callback on application render
|
||||
// Defaults to nothing.
|
||||
AppEventFn on_render;
|
||||
|
||||
// Callback when the user has requested the application close.
|
||||
// For example, pressing the Close button, ALT+F4, etc
|
||||
// By default this calls `App::exit()`
|
||||
AppEventFn on_exit_request;
|
||||
|
||||
// Callback when the application logs info/warning/errors
|
||||
// Defaults to printf.
|
||||
AppLogFn on_log;
|
||||
|
||||
// Default config setup
|
||||
Config();
|
||||
};
|
||||
|
||||
// Renderer the Application is using
|
||||
enum class Renderer
|
||||
// Type of Renderer the Application is using
|
||||
enum class RendererType
|
||||
{
|
||||
None = -1,
|
||||
OpenGL,
|
||||
D3D11,
|
||||
Metal,
|
||||
Count
|
||||
};
|
||||
|
||||
// Features available on the current Renderer
|
||||
// Renderer Information
|
||||
struct RendererFeatures
|
||||
{
|
||||
// The type of Renderer being used
|
||||
RendererType type = RendererType::None;
|
||||
|
||||
// Whether Mesh Instancing is available
|
||||
bool instancing = false;
|
||||
|
||||
@ -89,6 +35,55 @@ namespace Blah
|
||||
int max_texture_size = 0;
|
||||
};
|
||||
|
||||
// Application Configuration
|
||||
struct Config
|
||||
{
|
||||
// Application name.
|
||||
const char* name = "blah";
|
||||
|
||||
// Which renderer to use
|
||||
// Default depends on the Platform
|
||||
RendererType renderer_type = RendererType::None;
|
||||
|
||||
// Starting width, in pixels.
|
||||
// Depending on the OS DPI, the true window size may be a multiple of this.
|
||||
int width = 1280;
|
||||
|
||||
// Starting height, in pixels.
|
||||
// Depending on the OS DPI, the true window size may be a multiple of this.
|
||||
int height = 720;
|
||||
|
||||
// maximum updates to run before "giving up" and reducing frame rate.
|
||||
// this avoids the 'spiral of death'.
|
||||
// defaults to 5.
|
||||
int max_updates = 5;
|
||||
|
||||
// target framerate.
|
||||
// defaults to 60.
|
||||
int target_framerate = 60;
|
||||
|
||||
// Callback on application startup
|
||||
AppEventFn on_startup = nullptr;
|
||||
|
||||
// Callback on application shutdown
|
||||
AppEventFn on_shutdown = nullptr;
|
||||
|
||||
// Callback on application update
|
||||
AppEventFn on_update = nullptr;
|
||||
|
||||
// Callback on application render
|
||||
AppEventFn on_render = nullptr;
|
||||
|
||||
// Callback when the user has requested the application close.
|
||||
// For example, pressing the Close button, ALT+F4, etc
|
||||
// By default this calls `App::exit()`
|
||||
AppEventFn on_exit_request = nullptr;
|
||||
|
||||
// Callback when the application logs info/warning/errors
|
||||
// Defaults to printf.
|
||||
AppLogFn on_log = nullptr;
|
||||
};
|
||||
|
||||
// Forward declare Target for the BackBuffer
|
||||
class Target;
|
||||
using TargetRef = Ref<Target>;
|
||||
@ -119,31 +114,22 @@ namespace Blah
|
||||
// Sets the Window Title
|
||||
void set_title(const char* title);
|
||||
|
||||
// Gets the Window Position
|
||||
// Gets the Window Position in Screen Coordinates
|
||||
Point get_position();
|
||||
|
||||
// Sets the Window Position
|
||||
// Sets the Window Position in Screen Coordinates
|
||||
void set_position(Point point);
|
||||
|
||||
// Gets the Window Size
|
||||
// Gets the size of the Window in Screen Coordinates.
|
||||
// On High DPI displays this may not be 1:1 with pixels.
|
||||
// For the size in pixels, use App::get_backbuffer_size()
|
||||
Point get_size();
|
||||
|
||||
// Sets the Window Size
|
||||
// Sets the Window Size in Screen Coordinates
|
||||
void set_size(Point point);
|
||||
|
||||
// Gets the width of the window
|
||||
int width();
|
||||
|
||||
// Gets the height of the window
|
||||
int height();
|
||||
|
||||
// Gets the drawable width of the window, in pixels.
|
||||
// This may differ from the width when on platforms with High DPI Displays.
|
||||
int draw_width();
|
||||
|
||||
// Gets the drawable height of the window, in pixels.
|
||||
// This may differ from the height when on platforms with High DPI Displays.
|
||||
int draw_height();
|
||||
// Gets the size of the BackBuffer, in pixels
|
||||
Point get_backbuffer_size();
|
||||
|
||||
// Gets the content scale based on the platform.
|
||||
// macOS is usually 2.0, other platforms vary.
|
||||
@ -156,14 +142,11 @@ namespace Blah
|
||||
// Otherwise this function does nothing.
|
||||
void fullscreen(bool enabled);
|
||||
|
||||
// Returns the Rendering API in use
|
||||
Renderer renderer();
|
||||
|
||||
// Retrieves the Renderer Features
|
||||
const RendererFeatures& renderer_features();
|
||||
const RendererFeatures& renderer();
|
||||
|
||||
// Reference to the window's back buffer
|
||||
extern const TargetRef backbuffer;
|
||||
// Gets the BackBuffer
|
||||
const TargetRef& backbuffer();
|
||||
}
|
||||
|
||||
namespace System
|
||||
|
@ -128,7 +128,7 @@ namespace Blah
|
||||
void set_sampler(const TextureSampler& sampler);
|
||||
|
||||
// Draws the batch to the given target
|
||||
void render(const TargetRef& target = App::backbuffer);
|
||||
void render(const TargetRef& target = nullptr);
|
||||
|
||||
// Draws the batch to the given target, with the provided matrix
|
||||
void render(const TargetRef& target, const Mat4x4f& matrix);
|
||||
|
Reference in New Issue
Block a user