diff options
Diffstat (limited to 'src/rendering/include/engine')
| -rw-r--r-- | src/rendering/include/engine/rendering/platform.h | 57 | ||||
| -rw-r--r-- | src/rendering/include/engine/rendering/platform_glfw.h | 32 |
2 files changed, 89 insertions, 0 deletions
diff --git a/src/rendering/include/engine/rendering/platform.h b/src/rendering/include/engine/rendering/platform.h new file mode 100644 index 0000000..5d2408e --- /dev/null +++ b/src/rendering/include/engine/rendering/platform.h @@ -0,0 +1,57 @@ +#ifndef PLATFORM_H +#define PLATFORM_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <cglm/cglm.h> + +#include <engine/core/types.h> +// TODO: We only need the window once all the garbage in Instance is cleaned up. +#include <engine/core/platform.h> +#include <engine/rendering/window.h> + +#define DAW_WINDOW_VSYNC (1 << 0) +#define DAW_WINDOW_FULLSCREEN (1 << 1) +#define DAW_WINDOW_RESIZEABLE (1 << 2) + +// Whether or not it is clever to force API consistency using a struct like this +// can be debated, at the time of writing it seemed like a smart idea. + +// Platform libraries must implement a struct Platform: +struct Platform { + /* Initialize a window for the given platform. The rendering backend should + * also be initialized here. + * Parameters: + * const char* title: window title. + * ivec2 windowsize: the size in pixels for the new window. + * const u32 flags: window flags, such as static size and fullscreen. + * The flags are platform agnostic and needs to be + * converted to the specific library + * Returns: + * A pointer to a struct Window, NULL on error. + */ + Window* (*window_init)(const Instance *restrict i, const char *restrict title, ivec2 windowsize, const u32 flags); + + /* Destroy, close, and free up resources related to the window and the + * platform library specific resources. + */ + void (*window_destroy)(Window *restrict w); + + /* Resize the given window. Resize callbacks are handled by the wrapper + * implementation. + */ + void (*window_resize)(Window *restrict window, int width, int height); + + /* Return true if the platform has ordered the window to exit. */ + bool (*window_should_close)(Window *restrict w); + + /* Poll events on the window from the operating system. */ + void (*window_poll)(void); +}; + +#ifdef __cplusplus +} +#endif +#endif diff --git a/src/rendering/include/engine/rendering/platform_glfw.h b/src/rendering/include/engine/rendering/platform_glfw.h new file mode 100644 index 0000000..cbc3520 --- /dev/null +++ b/src/rendering/include/engine/rendering/platform_glfw.h @@ -0,0 +1,32 @@ +#ifndef PLATFORM_GLFW_H +#define PLATFORM_GLFW_H + +#ifdef __cplusplus +extern "C" { +#endif + +#include <cglm/cglm.h> + +#include <engine/core/types.h> +#include <engine/rendering/platform.h> +#include <engine/rendering/window.h> + +Window* window_init_glfw(const Instance *restrict i, const char *restrict windowtitle, ivec2 windowsize, const u32 flags); +void window_destroy_glfw(Window *restrict w); +void window_resize_glfw(Window *restrict window, int width, int height); +bool window_should_close_glfw(Window *restrict window); +void window_poll_glfw(void); + +const struct Platform Platform_GLFW = { + .window_init = window_init_glfw, + .window_destroy = window_destroy_glfw, + .window_resize = window_resize_glfw, + .window_should_close = window_should_close_glfw, + .window_poll = window_poll_glfw, +}; + +#ifdef __cplusplus +} +#endif +#endif + |
